Skip to content

Commit 007bf56

Browse files
SimonBaeumerludydoo
authored andcommitted
Fix updater test to use existing fields from deployment's status field
1 parent af75988 commit 007bf56

File tree

3 files changed

+20
-17
lines changed

3 files changed

+20
-17
lines changed

pkg/reconciler/internal/updater/updater.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ import (
2828
"k8s.io/client-go/util/retry"
2929
"sigs.k8s.io/controller-runtime/pkg/client"
3030

31-
"github.com/operator-framework/helm-operator/pkg/extensions"
3231
"github.com/operator-framework/helm-operator-plugins/internal/sdk/controllerutil"
32+
"github.com/operator-framework/helm-operator-plugins/pkg/extensions"
3333
"github.com/operator-framework/helm-operator-plugins/pkg/internal/status"
3434
)
3535

pkg/reconciler/internal/updater/updater_test.go

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ import (
3232
"github.com/operator-framework/helm-operator-plugins/pkg/reconciler/internal/conditions"
3333
)
3434

35-
const testFinalizer = "testFinalizer"
35+
const (
36+
testFinalizer = "testFinalizer"
37+
availableReplicasStatus = int64(3)
38+
replicasStatus = int64(5)
39+
)
3640

3741
var _ = Describe("Updater", func() {
3842
var (
@@ -96,12 +100,12 @@ var _ = Describe("Updater", func() {
96100
It("should support a mix of standard and custom status updates", func() {
97101
u.UpdateStatus(EnsureCondition(conditions.Deployed(corev1.ConditionTrue, "", "")))
98102
u.UpdateStatusCustom(func(uSt *unstructured.Unstructured) bool {
99-
Expect(unstructured.SetNestedMap(uSt.Object, map[string]interface{}{"bar": "baz"}, "foo")).To(Succeed())
103+
Expect(unstructured.SetNestedField(uSt.Object, replicasStatus, "replicas")).To(Succeed())
100104
return true
101105
})
102106
u.UpdateStatus(EnsureCondition(conditions.Irreconcilable(corev1.ConditionFalse, "", "")))
103107
u.UpdateStatusCustom(func(uSt *unstructured.Unstructured) bool {
104-
Expect(unstructured.SetNestedField(uSt.Object, "quux", "foo", "qux")).To(Succeed())
108+
Expect(unstructured.SetNestedField(uSt.Object, availableReplicasStatus, "availableReplicas")).To(Succeed())
105109
return true
106110
})
107111
u.UpdateStatus(EnsureCondition(conditions.Initialized(corev1.ConditionTrue, "", "")))
@@ -113,20 +117,20 @@ var _ = Describe("Updater", func() {
113117
Expect(found).To(BeFalse())
114118
Expect(err).To(Not(HaveOccurred()))
115119

116-
val, found, err := unstructured.NestedString(obj.Object, "status", "foo", "bar")
117-
Expect(val).To(Equal("baz"))
120+
val, found, err := unstructured.NestedInt64(obj.Object, "status", "replicas")
121+
Expect(val).To(Equal(replicasStatus))
118122
Expect(found).To(BeTrue())
119123
Expect(err).To(Not(HaveOccurred()))
120124

121-
val, found, err = unstructured.NestedString(obj.Object, "status", "foo", "qux")
122-
Expect(val).To(Equal("quux"))
125+
val, found, err = unstructured.NestedInt64(obj.Object, "status", "availableReplicas")
126+
Expect(val).To(Equal(availableReplicasStatus))
123127
Expect(found).To(BeTrue())
124128
Expect(err).To(Not(HaveOccurred()))
125129
})
126130

127131
It("should preserve any custom status across multiple apply calls", func() {
128132
u.UpdateStatusCustom(func(uSt *unstructured.Unstructured) bool {
129-
Expect(unstructured.SetNestedMap(uSt.Object, map[string]interface{}{"bar": "baz"}, "foo")).To(Succeed())
133+
Expect(unstructured.SetNestedField(uSt.Object, int64(5), "replicas")).To(Succeed())
130134
return true
131135
})
132136
Expect(u.Apply(context.TODO(), obj)).To(Succeed())
@@ -137,8 +141,8 @@ var _ = Describe("Updater", func() {
137141
Expect(found).To(BeFalse())
138142
Expect(err).To(Not(HaveOccurred()))
139143

140-
val, found, err := unstructured.NestedString(obj.Object, "status", "foo", "bar")
141-
Expect(val).To(Equal("baz"))
144+
val, found, err := unstructured.NestedInt64(obj.Object, "status", "replicas")
145+
Expect(val).To(Equal(replicasStatus))
142146
Expect(found).To(BeTrue())
143147
Expect(err).To(Succeed())
144148

@@ -152,8 +156,8 @@ var _ = Describe("Updater", func() {
152156
Expect(found).To(BeFalse())
153157
Expect(err).To(Not(HaveOccurred()))
154158

155-
val, found, err = unstructured.NestedString(obj.Object, "status", "foo", "bar")
156-
Expect(val).To(Equal("baz"))
159+
val, found, err = unstructured.NestedInt64(obj.Object, "status", "replicas")
160+
Expect(val).To(Equal(replicasStatus))
157161
Expect(found).To(BeTrue())
158162
Expect(err).To(Succeed())
159163
})

pkg/reconciler/reconciler.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,21 +44,20 @@ import (
4444
"sigs.k8s.io/controller-runtime/pkg/controller"
4545
"sigs.k8s.io/controller-runtime/pkg/handler"
4646
"sigs.k8s.io/controller-runtime/pkg/predicate"
47-
"sigs.k8s.io/controller-runtime/pkg/predicate"
4847
ctrlpredicate "sigs.k8s.io/controller-runtime/pkg/predicate"
4948
"sigs.k8s.io/controller-runtime/pkg/source"
5049

5150
"github.com/operator-framework/helm-operator-plugins/internal/sdk/controllerutil"
5251
"github.com/operator-framework/helm-operator-plugins/pkg/annotation"
5352
helmclient "github.com/operator-framework/helm-operator-plugins/pkg/client"
53+
"github.com/operator-framework/helm-operator-plugins/pkg/extensions"
5454
"github.com/operator-framework/helm-operator-plugins/pkg/hook"
5555
"github.com/operator-framework/helm-operator-plugins/pkg/reconciler/internal/conditions"
5656
"github.com/operator-framework/helm-operator-plugins/pkg/reconciler/internal/diff"
5757
internalhook "github.com/operator-framework/helm-operator-plugins/pkg/reconciler/internal/hook"
5858
"github.com/operator-framework/helm-operator-plugins/pkg/reconciler/internal/updater"
5959
internalvalues "github.com/operator-framework/helm-operator-plugins/pkg/reconciler/internal/values"
6060
"github.com/operator-framework/helm-operator-plugins/pkg/values"
61-
"github.com/joelanford/helm-operator/pkg/extensions"
6261
)
6362

6463
const uninstallFinalizer = "uninstall-helm-release"
@@ -82,10 +81,10 @@ type Reconciler struct {
8281
selectorPredicate predicate.Predicate
8382
overrideValues map[string]string
8483
skipDependentWatches bool
85-
extraWatches []watchDescription
84+
extraWatches []watchDescription
8685
maxConcurrentReconciles int
8786
reconcilePeriod time.Duration
88-
markFailedAfter time.Duration
87+
markFailedAfter time.Duration
8988
maxHistory int
9089
skipPrimaryGVKSchemeRegistration bool
9190
controllerSetupFuncs []ControllerSetupFunc

0 commit comments

Comments
 (0)