Skip to content

Commit 3764c49

Browse files
committed
Fix updater test to use existing fields from deployment's status field
1 parent a8d57a5 commit 3764c49

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
@@ -26,8 +26,8 @@ import (
2626
"k8s.io/client-go/util/retry"
2727
"sigs.k8s.io/controller-runtime/pkg/client"
2828

29-
"github.com/operator-framework/helm-operator/pkg/extensions"
3029
"github.com/operator-framework/helm-operator-plugins/internal/sdk/controllerutil"
30+
"github.com/operator-framework/helm-operator-plugins/pkg/extensions"
3131
"github.com/operator-framework/helm-operator-plugins/pkg/internal/status"
3232
)
3333

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 (
@@ -90,12 +94,12 @@ var _ = Describe("Updater", func() {
9094
It("should support a mix of standard and custom status updates", func() {
9195
u.UpdateStatus(EnsureCondition(conditions.Deployed(corev1.ConditionTrue, "", "")))
9296
u.UpdateStatusCustom(func(uSt *unstructured.Unstructured) bool {
93-
Expect(unstructured.SetNestedMap(uSt.Object, map[string]interface{}{"bar": "baz"}, "foo")).To(Succeed())
97+
Expect(unstructured.SetNestedField(uSt.Object, replicasStatus, "replicas")).To(Succeed())
9498
return true
9599
})
96100
u.UpdateStatus(EnsureCondition(conditions.Irreconcilable(corev1.ConditionFalse, "", "")))
97101
u.UpdateStatusCustom(func(uSt *unstructured.Unstructured) bool {
98-
Expect(unstructured.SetNestedField(uSt.Object, "quux", "foo", "qux")).To(Succeed())
102+
Expect(unstructured.SetNestedField(uSt.Object, availableReplicasStatus, "availableReplicas")).To(Succeed())
99103
return true
100104
})
101105
u.UpdateStatus(EnsureCondition(conditions.Initialized(corev1.ConditionTrue, "", "")))
@@ -107,20 +111,20 @@ var _ = Describe("Updater", func() {
107111
Expect(found).To(BeFalse())
108112
Expect(err).To(Not(HaveOccurred()))
109113

110-
val, found, err := unstructured.NestedString(obj.Object, "status", "foo", "bar")
111-
Expect(val).To(Equal("baz"))
114+
val, found, err := unstructured.NestedInt64(obj.Object, "status", "replicas")
115+
Expect(val).To(Equal(replicasStatus))
112116
Expect(found).To(BeTrue())
113117
Expect(err).To(Not(HaveOccurred()))
114118

115-
val, found, err = unstructured.NestedString(obj.Object, "status", "foo", "qux")
116-
Expect(val).To(Equal("quux"))
119+
val, found, err = unstructured.NestedInt64(obj.Object, "status", "availableReplicas")
120+
Expect(val).To(Equal(availableReplicasStatus))
117121
Expect(found).To(BeTrue())
118122
Expect(err).To(Not(HaveOccurred()))
119123
})
120124

121125
It("should preserve any custom status across multiple apply calls", func() {
122126
u.UpdateStatusCustom(func(uSt *unstructured.Unstructured) bool {
123-
Expect(unstructured.SetNestedMap(uSt.Object, map[string]interface{}{"bar": "baz"}, "foo")).To(Succeed())
127+
Expect(unstructured.SetNestedField(uSt.Object, int64(5), "replicas")).To(Succeed())
124128
return true
125129
})
126130
Expect(u.Apply(context.TODO(), obj)).To(Succeed())
@@ -131,8 +135,8 @@ var _ = Describe("Updater", func() {
131135
Expect(found).To(BeFalse())
132136
Expect(err).To(Not(HaveOccurred()))
133137

134-
val, found, err := unstructured.NestedString(obj.Object, "status", "foo", "bar")
135-
Expect(val).To(Equal("baz"))
138+
val, found, err := unstructured.NestedInt64(obj.Object, "status", "replicas")
139+
Expect(val).To(Equal(replicasStatus))
136140
Expect(found).To(BeTrue())
137141
Expect(err).To(Succeed())
138142

@@ -146,8 +150,8 @@ var _ = Describe("Updater", func() {
146150
Expect(found).To(BeFalse())
147151
Expect(err).To(Not(HaveOccurred()))
148152

149-
val, found, err = unstructured.NestedString(obj.Object, "status", "foo", "bar")
150-
Expect(val).To(Equal("baz"))
153+
val, found, err = unstructured.NestedInt64(obj.Object, "status", "replicas")
154+
Expect(val).To(Equal(replicasStatus))
151155
Expect(found).To(BeTrue())
152156
Expect(err).To(Succeed())
153157
})

pkg/reconciler/reconciler.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,20 +43,19 @@ import (
4343
"sigs.k8s.io/controller-runtime/pkg/controller"
4444
"sigs.k8s.io/controller-runtime/pkg/handler"
4545
"sigs.k8s.io/controller-runtime/pkg/predicate"
46-
"sigs.k8s.io/controller-runtime/pkg/predicate"
4746
ctrlpredicate "sigs.k8s.io/controller-runtime/pkg/predicate"
4847
"sigs.k8s.io/controller-runtime/pkg/source"
4948

5049
"github.com/operator-framework/helm-operator-plugins/internal/sdk/controllerutil"
5150
"github.com/operator-framework/helm-operator-plugins/pkg/annotation"
5251
helmclient "github.com/operator-framework/helm-operator-plugins/pkg/client"
52+
"github.com/operator-framework/helm-operator-plugins/pkg/extensions"
5353
"github.com/operator-framework/helm-operator-plugins/pkg/hook"
5454
"github.com/operator-framework/helm-operator-plugins/pkg/reconciler/internal/conditions"
5555
internalhook "github.com/operator-framework/helm-operator-plugins/pkg/reconciler/internal/hook"
5656
"github.com/operator-framework/helm-operator-plugins/pkg/reconciler/internal/updater"
5757
internalvalues "github.com/operator-framework/helm-operator-plugins/pkg/reconciler/internal/values"
5858
"github.com/operator-framework/helm-operator-plugins/pkg/values"
59-
"github.com/joelanford/helm-operator/pkg/extensions"
6059
)
6160

6261
const uninstallFinalizer = "uninstall-helm-release"
@@ -80,10 +79,10 @@ type Reconciler struct {
8079
selectorPredicate predicate.Predicate
8180
overrideValues map[string]string
8281
skipDependentWatches bool
83-
extraWatches []watchDescription
82+
extraWatches []watchDescription
8483
maxConcurrentReconciles int
8584
reconcilePeriod time.Duration
86-
markFailedAfter time.Duration
85+
markFailedAfter time.Duration
8786
maxHistory int
8887
skipPrimaryGVKSchemeRegistration bool
8988

0 commit comments

Comments
 (0)