Skip to content
This repository has been archived by the owner on Sep 19, 2024. It is now read-only.

Commit

Permalink
refactor: use new condition logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Frank Mai authored and guangbochen committed Jul 6, 2020
1 parent 5d4d263 commit 2235d62
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 246 deletions.
6 changes: 1 addition & 5 deletions pkg/limb/controller/devicelink_adaptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions pkg/limb/index/devicelink_by_adaptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
185 changes: 0 additions & 185 deletions pkg/status/devicelink/condition.go

This file was deleted.

3 changes: 1 addition & 2 deletions test/e2e/usability/usability_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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())
}
5 changes: 2 additions & 3 deletions test/integration/brain/devicelink_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
9 changes: 4 additions & 5 deletions test/integration/brain/model_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
9 changes: 4 additions & 5 deletions test/integration/brain/node_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
Loading

0 comments on commit 2235d62

Please sign in to comment.