From 2235d629cd96f2ab887e841ffdd597eb5bf3fe5f Mon Sep 17 00:00:00 2001 From: Frank Mai Date: Mon, 29 Jun 2020 20:04:22 +0800 Subject: [PATCH] refactor: use new condition logic --- pkg/limb/controller/devicelink_adaptor.go | 6 +- pkg/limb/index/devicelink_by_adaptor.go | 1 + pkg/status/devicelink/condition.go | 185 ------------------ test/e2e/usability/usability_test.go | 3 +- .../brain/devicelink_controller_test.go | 5 +- .../brain/model_controller_test.go | 9 +- .../integration/brain/node_controller_test.go | 9 +- .../limb/devicelink_controller_test.go | 75 ++++--- 8 files changed, 47 insertions(+), 246 deletions(-) delete mode 100644 pkg/status/devicelink/condition.go diff --git a/pkg/limb/controller/devicelink_adaptor.go b/pkg/limb/controller/devicelink_adaptor.go index e3057aae..d4435c82 100644 --- a/pkg/limb/controller/devicelink_adaptor.go +++ b/pkg/limb/controller/devicelink_adaptor.go @@ -36,12 +36,8 @@ func (r *DeviceLinkReconciler) ReceiveAdaptorStatus(req suctioncup.RequestAdapto metrics.GetLimbMetricsRecorder().ResetConnections(req.Name) } + // NB(thxCode) all items are guaranteed by indexer to be associated with the current node. for _, link := range links.Items { - // filter out the corresponding links - if link.Status.NodeName != r.NodeName { - continue - } - if req.Registered { if link.GetAdaptorExistedStatus() == metav1.ConditionFalse { link.SucceedOnAdaptorExisted() diff --git a/pkg/limb/index/devicelink_by_adaptor.go b/pkg/limb/index/devicelink_by_adaptor.go index b7b89d94..417e939e 100644 --- a/pkg/limb/index/devicelink_by_adaptor.go +++ b/pkg/limb/index/devicelink_by_adaptor.go @@ -18,6 +18,7 @@ func DeviceLinkByAdaptorFuncFactory(nodeName string) func(runtime.Object) []stri return nil } + // rejects if not the target node if link.Status.NodeName != nodeName { return nil } diff --git a/pkg/status/devicelink/condition.go b/pkg/status/devicelink/condition.go deleted file mode 100644 index ddb2310b..00000000 --- a/pkg/status/devicelink/condition.go +++ /dev/null @@ -1,185 +0,0 @@ -package devicelink - -import ( - "time" - - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - - edgev1alpha1 "github.com/rancher/octopus/api/v1alpha1" -) - -func GetNodeExistedStatus(status *edgev1alpha1.DeviceLinkStatus) metav1.ConditionStatus { - return deviceLinkConditions(status.Conditions).get(edgev1alpha1.DeviceLinkNodeExisted).Status -} - -func FailOnNodeExisted(status *edgev1alpha1.DeviceLinkStatus, message string) { - status.Conditions = deviceLinkConditions(status.Conditions). - did(edgev1alpha1.DeviceLinkNodeExisted, metav1.ConditionFalse, "NotFound", message) -} - -func SuccessOnNodeExisted(status *edgev1alpha1.DeviceLinkStatus) { - status.Conditions = deviceLinkConditions(status.Conditions). - did(edgev1alpha1.DeviceLinkNodeExisted, metav1.ConditionTrue, "Found", ""). - next(edgev1alpha1.DeviceLinkModelExisted, "Confirming", "verify if there is a suitable model as a template") -} - -func ToCheckNodeExisted(status *edgev1alpha1.DeviceLinkStatus) { - status.Conditions = deviceLinkConditions(status.Conditions). - did(edgev1alpha1.DeviceLinkNodeExisted, metav1.ConditionUnknown, "Confirming", "verify if there is a suitable node to schedule") -} - -func GetModelExistedStatus(status *edgev1alpha1.DeviceLinkStatus) metav1.ConditionStatus { - return deviceLinkConditions(status.Conditions).get(edgev1alpha1.DeviceLinkModelExisted).Status -} - -func FailOnModelExisted(status *edgev1alpha1.DeviceLinkStatus, message string) { - status.Conditions = deviceLinkConditions(status.Conditions). - did(edgev1alpha1.DeviceLinkModelExisted, metav1.ConditionFalse, "NotFound", message) -} - -func SuccessOnModelExisted(status *edgev1alpha1.DeviceLinkStatus) { - status.Conditions = deviceLinkConditions(status.Conditions). - did(edgev1alpha1.DeviceLinkModelExisted, metav1.ConditionTrue, "Found", ""). - next(edgev1alpha1.DeviceLinkAdaptorExisted, "Confirming", "verify if there is a suitable adaptor to access") -} - -func ToCheckModelExisted(status *edgev1alpha1.DeviceLinkStatus) { - - status.Conditions = deviceLinkConditions(status.Conditions). - did(edgev1alpha1.DeviceLinkModelExisted, metav1.ConditionUnknown, "Confirming", "verify if there is a suitable model as a template") -} - -func GetAdaptorExistedStatus(status *edgev1alpha1.DeviceLinkStatus) metav1.ConditionStatus { - return deviceLinkConditions(status.Conditions).get(edgev1alpha1.DeviceLinkAdaptorExisted).Status -} - -func FailOnAdaptorExisted(status *edgev1alpha1.DeviceLinkStatus, message string) { - status.Conditions = deviceLinkConditions(status.Conditions). - did(edgev1alpha1.DeviceLinkAdaptorExisted, metav1.ConditionFalse, "NotFound", message) -} - -func SuccessOnAdaptorExisted(status *edgev1alpha1.DeviceLinkStatus) { - status.Conditions = deviceLinkConditions(status.Conditions). - did(edgev1alpha1.DeviceLinkAdaptorExisted, metav1.ConditionTrue, "Found", ""). - next(edgev1alpha1.DeviceLinkDeviceCreated, "Creating", "verify if there is a corresponding device created") -} - -func ToCheckAdaptorExisted(status *edgev1alpha1.DeviceLinkStatus) { - status.Conditions = deviceLinkConditions(status.Conditions). - did(edgev1alpha1.DeviceLinkAdaptorExisted, metav1.ConditionUnknown, "Confirming", "verify if there is a suitable adaptor to access") -} - -func GetDeviceCreatedStatus(status *edgev1alpha1.DeviceLinkStatus) metav1.ConditionStatus { - return deviceLinkConditions(status.Conditions).get(edgev1alpha1.DeviceLinkDeviceCreated).Status -} - -func FailOnDeviceCreated(status *edgev1alpha1.DeviceLinkStatus, message string) { - status.Conditions = deviceLinkConditions(status.Conditions). - did(edgev1alpha1.DeviceLinkDeviceCreated, metav1.ConditionFalse, "Fail", message) -} - -func SuccessOnDeviceCreated(status *edgev1alpha1.DeviceLinkStatus) { - status.Conditions = deviceLinkConditions(status.Conditions). - did(edgev1alpha1.DeviceLinkDeviceCreated, metav1.ConditionTrue, "Success", ""). - next(edgev1alpha1.DeviceLinkDeviceConnected, "Connecting", "connect device") -} - -func ToCheckDeviceCreated(status *edgev1alpha1.DeviceLinkStatus) { - status.Conditions = deviceLinkConditions(status.Conditions). - did(edgev1alpha1.DeviceLinkDeviceCreated, metav1.ConditionUnknown, "Creating", "verify if there is a corresponding device created") -} - -func GetDeviceConnectedStatus(status *edgev1alpha1.DeviceLinkStatus) metav1.ConditionStatus { - return deviceLinkConditions(status.Conditions).get(edgev1alpha1.DeviceLinkDeviceConnected).Status -} - -func FailOnDeviceConnected(status *edgev1alpha1.DeviceLinkStatus, message string) { - status.Conditions = deviceLinkConditions(status.Conditions). - did(edgev1alpha1.DeviceLinkDeviceConnected, metav1.ConditionFalse, "Unhealthy", message) -} - -func SuccessOnDeviceConnected(status *edgev1alpha1.DeviceLinkStatus) { - status.Conditions = deviceLinkConditions(status.Conditions). - did(edgev1alpha1.DeviceLinkDeviceConnected, metav1.ConditionTrue, "Healthy", "") -} - -func WaitForDeviceConnected(status *edgev1alpha1.DeviceLinkStatus) { - status.Conditions = deviceLinkConditions(status.Conditions). - did(edgev1alpha1.DeviceLinkDeviceConnected, metav1.ConditionTrue, "Waiting", "") -} - -func ToCheckDeviceConnected(status *edgev1alpha1.DeviceLinkStatus) { - status.Conditions = deviceLinkConditions(status.Conditions). - did(edgev1alpha1.DeviceLinkDeviceConnected, metav1.ConditionUnknown, "Connecting", "connect device") -} - -type deviceLinkConditions []edgev1alpha1.DeviceLinkCondition - -func (d deviceLinkConditions) get(t edgev1alpha1.DeviceLinkConditionType) edgev1alpha1.DeviceLinkCondition { - for _, c := range d { - if c.Type == t { - return c - } - } - return edgev1alpha1.DeviceLinkCondition{} -} - -func (d deviceLinkConditions) did(t edgev1alpha1.DeviceLinkConditionType, result metav1.ConditionStatus, reason, message string) deviceLinkConditions { - var ( - previous []edgev1alpha1.DeviceLinkCondition - lastItemLTT = metav1.Time{Time: time.Now()} - conditionsLen = len(d) - ) - - if conditionsLen > 0 { - i := 0 - for _, c := range d { - if c.Type != t { - i++ - } else { - break - } - } - previous = d[:i] - lastItemLTT = d[conditionsLen-1].LastUpdateTime - // confirm the previous status - if i > 1 { - if d[i-1].Status != metav1.ConditionTrue { - return previous - } - } - } - - return append(previous, - edgev1alpha1.DeviceLinkCondition{ - Type: t, - Status: result, - LastTransitionTime: lastItemLTT, - LastUpdateTime: metav1.Time{Time: time.Now()}, - Reason: reason, - Message: message, - }, - ) -} - -func (d deviceLinkConditions) next(t edgev1alpha1.DeviceLinkConditionType, reason, message string) deviceLinkConditions { - var ( - lastItemLTT = metav1.Time{Time: time.Now()} - conditionsLen = len(d) - ) - - if conditionsLen != 0 { - lastItemLTT = d[conditionsLen-1].LastUpdateTime - } - - return append(d, - edgev1alpha1.DeviceLinkCondition{ - Type: t, - Status: metav1.ConditionUnknown, - LastTransitionTime: lastItemLTT, - LastUpdateTime: lastItemLTT, - Reason: reason, - Message: message, - }, - ) -} diff --git a/test/e2e/usability/usability_test.go b/test/e2e/usability/usability_test.go index 68e5d6d7..5bd33572 100644 --- a/test/e2e/usability/usability_test.go +++ b/test/e2e/usability/usability_test.go @@ -14,7 +14,6 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" edgev1alpha1 "github.com/rancher/octopus/api/v1alpha1" - "github.com/rancher/octopus/pkg/status/devicelink" "github.com/rancher/octopus/pkg/util/object" "github.com/rancher/octopus/test/util/content" "github.com/rancher/octopus/test/util/exec" @@ -233,6 +232,6 @@ func verifyDeviceLink() { GinkgoT().Log(err) return false } - return devicelink.GetDeviceConnectedStatus(&targetItem.Status) == metav1.ConditionTrue + return targetItem.GetDeviceConnectedStatus() == metav1.ConditionTrue }, 300, 1).Should(BeTrue()) } diff --git a/test/integration/brain/devicelink_controller_test.go b/test/integration/brain/devicelink_controller_test.go index 93a8289c..de4c54f4 100644 --- a/test/integration/brain/devicelink_controller_test.go +++ b/test/integration/brain/devicelink_controller_test.go @@ -12,7 +12,6 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" edgev1alpha1 "github.com/rancher/octopus/api/v1alpha1" - "github.com/rancher/octopus/pkg/status/devicelink" "github.com/rancher/octopus/pkg/util/object" "github.com/rancher/octopus/test/util/content" "github.com/rancher/octopus/test/util/node" @@ -179,7 +178,7 @@ var _ = Describe("DeviceLink controller", func() { if !object.IsActivating(&targetItem) { return errors.Errorf("%s link isn't activated", key) } - if devicelink.GetNodeExistedStatus(&targetItem.Status) != metav1.ConditionFalse { + if targetItem.GetNodeExistedStatus() != metav1.ConditionFalse { return errors.Errorf("should not find the corresponding node of %s link", key) } return nil @@ -218,7 +217,7 @@ var _ = Describe("DeviceLink controller", func() { if !object.IsActivating(&targetItem) { return errors.Errorf("%s link isn't activated", key) } - if devicelink.GetModelExistedStatus(&targetItem.Status) != metav1.ConditionFalse { + if targetItem.GetModelExistedStatus() != metav1.ConditionFalse { return errors.Errorf("should not find the corresponding model of %s link", key) } return nil diff --git a/test/integration/brain/model_controller_test.go b/test/integration/brain/model_controller_test.go index 5ddb3d9d..325c676d 100644 --- a/test/integration/brain/model_controller_test.go +++ b/test/integration/brain/model_controller_test.go @@ -13,7 +13,6 @@ import ( "sigs.k8s.io/controller-runtime/pkg/envtest" edgev1alpha1 "github.com/rancher/octopus/api/v1alpha1" - "github.com/rancher/octopus/pkg/status/devicelink" "github.com/rancher/octopus/pkg/util/object" "github.com/rancher/octopus/test/util/content" "github.com/rancher/octopus/test/util/node" @@ -103,7 +102,7 @@ var _ = Describe("Model controller", func() { if !object.IsActivating(&targetItem) { return errors.Errorf("%s link isn't activated", key) } - if devicelink.GetModelExistedStatus(&targetItem.Status) != metav1.ConditionTrue { + if targetItem.GetModelExistedStatus() != metav1.ConditionTrue { return errors.Errorf("could not find the corresponding model of %s link", key) } return nil @@ -128,7 +127,7 @@ var _ = Describe("Model controller", func() { if !object.IsActivating(&targetItem) { return errors.Errorf("%s link isn't activated", key) } - if devicelink.GetModelExistedStatus(&targetItem.Status) != metav1.ConditionFalse { + if targetItem.GetModelExistedStatus() != metav1.ConditionFalse { return errors.Errorf("should not find the corresponding model of %s link", key) } return nil @@ -154,7 +153,7 @@ var _ = Describe("Model controller", func() { if !object.IsActivating(&targetItem) { return errors.Errorf("%s link isn't activated", key) } - if devicelink.GetModelExistedStatus(&targetItem.Status) != metav1.ConditionFalse { + if targetItem.GetModelExistedStatus() != metav1.ConditionFalse { return errors.Errorf("should not find the corresponding model of %s link", key) } return nil @@ -180,7 +179,7 @@ var _ = Describe("Model controller", func() { if !object.IsActivating(&targetItem) { return errors.Errorf("%s link isn't activated", key) } - if devicelink.GetModelExistedStatus(&targetItem.Status) != metav1.ConditionTrue { + if targetItem.GetModelExistedStatus() != metav1.ConditionTrue { return errors.Errorf("could not find the corresponding model of %s link", key) } return nil diff --git a/test/integration/brain/node_controller_test.go b/test/integration/brain/node_controller_test.go index dedbb767..187c574c 100644 --- a/test/integration/brain/node_controller_test.go +++ b/test/integration/brain/node_controller_test.go @@ -13,7 +13,6 @@ import ( . "github.com/rancher/octopus/test/framework/ginkgo" edgev1alpha1 "github.com/rancher/octopus/api/v1alpha1" - "github.com/rancher/octopus/pkg/status/devicelink" "github.com/rancher/octopus/pkg/util/object" . "github.com/rancher/octopus/test/framework" "github.com/rancher/octopus/test/util/content" @@ -105,7 +104,7 @@ var _ = Describe("Node controller", func() { if !object.IsActivating(&targetItem) { return errors.Errorf("%s link isn't activated", key) } - if devicelink.GetNodeExistedStatus(&targetItem.Status) != metav1.ConditionTrue { + if targetItem.GetNodeExistedStatus() != metav1.ConditionTrue { return errors.Errorf("could not find the corresponding node of %s link", key) } return nil @@ -133,7 +132,7 @@ var _ = Describe("Node controller", func() { if !object.IsActivating(&targetItem) { return errors.Errorf("%s link isn't activated", key) } - if devicelink.GetNodeExistedStatus(&targetItem.Status) != metav1.ConditionFalse { + if targetItem.GetNodeExistedStatus() != metav1.ConditionFalse { return errors.Errorf("should not find the corresponding node of %s link", key) } return nil @@ -167,7 +166,7 @@ var _ = Describe("Node controller", func() { if !object.IsActivating(&targetItem) { return errors.Errorf("%s link isn't activated", key) } - if devicelink.GetNodeExistedStatus(&targetItem.Status) != metav1.ConditionFalse { + if targetItem.GetNodeExistedStatus() != metav1.ConditionFalse { return errors.Errorf("should not find the corresponding node of %s link", key) } return nil @@ -187,7 +186,7 @@ var _ = Describe("Node controller", func() { if !object.IsActivating(&targetItem) { return errors.Errorf("%s link isn't activated", key) } - if devicelink.GetNodeExistedStatus(&targetItem.Status) != metav1.ConditionTrue { + if targetItem.GetNodeExistedStatus() != metav1.ConditionTrue { return errors.Errorf("could not find the corresponding node of %s link", key) } return nil diff --git a/test/integration/limb/devicelink_controller_test.go b/test/integration/limb/devicelink_controller_test.go index 17c3337b..e7bfa1ac 100644 --- a/test/integration/limb/devicelink_controller_test.go +++ b/test/integration/limb/devicelink_controller_test.go @@ -11,7 +11,6 @@ import ( edgev1alpha1 "github.com/rancher/octopus/api/v1alpha1" api "github.com/rancher/octopus/pkg/adaptor/api/v1alpha1" - status "github.com/rancher/octopus/pkg/status/devicelink" "github.com/rancher/octopus/pkg/suctioncup/connection" "github.com/rancher/octopus/pkg/util/model" "github.com/rancher/octopus/pkg/util/object" @@ -26,7 +25,7 @@ import ( // - validate if the device of target link create when adding the corresponding adaptor var _ = Describe("DeviceLink controller", func() { var ( - mockingDummyAdaptor fakeDummyAdaptor + mockingAdaptor fakeAdaptor targetModel metav1.TypeMeta targetNamespace string @@ -52,7 +51,7 @@ var _ = Describe("DeviceLink controller", func() { Spec: edgev1alpha1.DeviceLinkSpec{ Adaptor: edgev1alpha1.DeviceAdaptor{ Node: targetNode, - Name: mockingDummyAdaptor.GetName(), + Name: mockingAdaptor.GetName(), }, Model: targetModel, Template: edgev1alpha1.DeviceTemplateSpec{ @@ -82,10 +81,8 @@ var _ = Describe("DeviceLink controller", func() { Expect(k8sCli.Create(testCtx, &targetItem)).Should(Succeed()) // simulated that has completed the validation of node and model - targetItem.Status.NodeName = targetItem.Spec.Adaptor.Node - status.SuccessOnNodeExisted(&targetItem.Status) - targetItem.Status.Model = targetItem.Spec.Model - status.SuccessOnModelExisted(&targetItem.Status) + targetItem.SuccessOnNodeExisted(nil) + targetItem.SuccessOnModelExisted() Expect(k8sCli.Status().Update(testCtx, &targetItem)).Should(Succeed()) var key = types.NamespacedName{ @@ -103,15 +100,15 @@ var _ = Describe("DeviceLink controller", func() { if !object.IsActivating(&targetItem) { return errors.Errorf("%s link isn't activated", key) } - if status.GetAdaptorExistedStatus(&targetItem.Status) != metav1.ConditionFalse { + if targetItem.GetAdaptorExistedStatus() != metav1.ConditionFalse { return errors.Errorf("should not find the corresponding adaptor of %s link", key) } return nil }, 30, 1).Should(Succeed()) // simulated that added the corresponding adaptor - testAdaptors.Put(mockingDummyAdaptor) - testEventQueue.GetAdaptorNotifier().NoticeAdaptorRegistered(mockingDummyAdaptor.GetName()) + testAdaptors.Put(mockingAdaptor) + testEventQueue.GetAdaptorNotifier().NoticeAdaptorRegistered(mockingAdaptor.GetName()) // confirmed Eventually(func() error { @@ -123,7 +120,7 @@ var _ = Describe("DeviceLink controller", func() { if !object.IsActivating(&targetItem) { return errors.Errorf("%s link isn't activated", key) } - if status.GetAdaptorExistedStatus(&targetItem.Status) != metav1.ConditionTrue { + if targetItem.GetAdaptorExistedStatus() != metav1.ConditionTrue { return errors.Errorf("could not find the corresponding adaptor of %s link", key) } return nil @@ -135,10 +132,8 @@ var _ = Describe("DeviceLink controller", func() { Expect(k8sCli.Create(testCtx, &targetItem)).Should(Succeed()) // simulated that has completed the validation of node and model - targetItem.Status.NodeName = targetItem.Spec.Adaptor.Node - status.SuccessOnNodeExisted(&targetItem.Status) - targetItem.Status.Model = targetItem.Spec.Model - status.SuccessOnModelExisted(&targetItem.Status) + targetItem.SuccessOnNodeExisted(nil) + targetItem.SuccessOnModelExisted() Expect(k8sCli.Status().Update(testCtx, &targetItem)).Should(Succeed()) var key = types.NamespacedName{ @@ -156,15 +151,15 @@ var _ = Describe("DeviceLink controller", func() { if !object.IsActivating(&targetItem) { return errors.Errorf("%s link isn't activated", key) } - if status.GetAdaptorExistedStatus(&targetItem.Status) != metav1.ConditionTrue { + if targetItem.GetAdaptorExistedStatus() != metav1.ConditionTrue { return errors.Errorf("could not find the corresponding adaptor of %s link", key) } return nil }, 30, 1).Should(Succeed()) // simulated that added the corresponding adaptor - testAdaptors.Delete(mockingDummyAdaptor.GetName()) - testEventQueue.GetAdaptorNotifier().NoticeAdaptorUnregistered(mockingDummyAdaptor.GetName()) + testAdaptors.Delete(mockingAdaptor.GetName()) + testEventQueue.GetAdaptorNotifier().NoticeAdaptorUnregistered(mockingAdaptor.GetName()) // confirmed Eventually(func() error { @@ -176,7 +171,7 @@ var _ = Describe("DeviceLink controller", func() { if !object.IsActivating(&targetItem) { return errors.Errorf("%s link isn't activated", key) } - if status.GetAdaptorExistedStatus(&targetItem.Status) != metav1.ConditionFalse { + if targetItem.GetAdaptorExistedStatus() != metav1.ConditionFalse { return errors.Errorf("should not find the corresponding adaptor of %s link", key) } return nil @@ -192,13 +187,11 @@ var _ = Describe("DeviceLink controller", func() { Expect(k8sCli.Create(testCtx, &targetItem)).Should(Succeed()) // simulated that added the corresponding adaptor - testAdaptors.Put(mockingDummyAdaptor) + testAdaptors.Put(mockingAdaptor) // simulated that has completed the validation of node and model - targetItem.Status.NodeName = targetItem.Spec.Adaptor.Node - status.SuccessOnNodeExisted(&targetItem.Status) - targetItem.Status.Model = targetItem.Spec.Model - status.SuccessOnModelExisted(&targetItem.Status) + targetItem.SuccessOnNodeExisted(nil) + targetItem.SuccessOnModelExisted() Expect(k8sCli.Status().Update(testCtx, &targetItem)).Should(Succeed()) var key = types.NamespacedName{ @@ -216,7 +209,7 @@ var _ = Describe("DeviceLink controller", func() { if !object.IsActivating(&targetItem) { return errors.Errorf("%s link isn't activated", key) } - if status.GetDeviceCreatedStatus(&targetItem.Status) != metav1.ConditionTrue { + if targetItem.GetDeviceCreatedStatus() != metav1.ConditionTrue { return errors.Errorf("could not find the corresponding adaptor of %s link", key) } @@ -235,46 +228,46 @@ var _ = Describe("DeviceLink controller", func() { }) -type fakeDummyAdaptor string +type fakeAdaptor string -func (a fakeDummyAdaptor) GetName() string { +func (a fakeAdaptor) GetName() string { return "adaptors.edge.cattle.io/dummy" } -func (a fakeDummyAdaptor) GetEndpoint() string { +func (a fakeAdaptor) GetEndpoint() string { return "dummy.sock" } -func (a fakeDummyAdaptor) Stop() error { +func (a fakeAdaptor) Stop() error { return nil } -func (a fakeDummyAdaptor) CreateConnection(name types.NamespacedName) (bool, error) { - return false, nil +func (a fakeAdaptor) CreateConnection(name types.NamespacedName) (overwritten bool, conn connection.Connection, err error) { + return false, fakeConnection(name), nil } -func (a fakeDummyAdaptor) DeleteConnection(name types.NamespacedName) bool { +func (a fakeAdaptor) DeleteConnection(name types.NamespacedName) bool { return false } -func (a fakeDummyAdaptor) GetConnection(name types.NamespacedName) connection.Connection { - return fakeDummyConnection(name) -} - -type fakeDummyConnection types.NamespacedName +type fakeConnection types.NamespacedName -func (c fakeDummyConnection) GetAdaptorName() string { +func (c fakeConnection) GetAdaptorName() string { return "adaptors.edge.cattle.io/dummy" } -func (c fakeDummyConnection) GetName() types.NamespacedName { +func (c fakeConnection) GetName() types.NamespacedName { return types.NamespacedName(c) } -func (c fakeDummyConnection) Stop() error { +func (c fakeConnection) Stop() error { return nil } -func (c fakeDummyConnection) Send([]byte, *metav1.TypeMeta, []byte, map[string]*api.ConnectRequestReferenceEntry) error { +func (c fakeConnection) IsStop() bool { + return false +} + +func (c fakeConnection) Send(*metav1.TypeMeta, []byte, map[string]*api.ConnectRequestReferenceEntry) error { return nil }