Skip to content

Commit

Permalink
Fix updater test to use existing fields from deployment's status field
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonBaeumer committed May 6, 2022
1 parent a8d57a5 commit 3764c49
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 17 deletions.
2 changes: 1 addition & 1 deletion pkg/reconciler/internal/updater/updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ import (
"k8s.io/client-go/util/retry"
"sigs.k8s.io/controller-runtime/pkg/client"

"github.com/operator-framework/helm-operator/pkg/extensions"
"github.com/operator-framework/helm-operator-plugins/internal/sdk/controllerutil"
"github.com/operator-framework/helm-operator-plugins/pkg/extensions"
"github.com/operator-framework/helm-operator-plugins/pkg/internal/status"
)

Expand Down
28 changes: 16 additions & 12 deletions pkg/reconciler/internal/updater/updater_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ import (
"github.com/operator-framework/helm-operator-plugins/pkg/reconciler/internal/conditions"
)

const testFinalizer = "testFinalizer"
const (
testFinalizer = "testFinalizer"
availableReplicasStatus = int64(3)
replicasStatus = int64(5)
)

var _ = Describe("Updater", func() {
var (
Expand Down Expand Up @@ -90,12 +94,12 @@ var _ = Describe("Updater", func() {
It("should support a mix of standard and custom status updates", func() {
u.UpdateStatus(EnsureCondition(conditions.Deployed(corev1.ConditionTrue, "", "")))
u.UpdateStatusCustom(func(uSt *unstructured.Unstructured) bool {
Expect(unstructured.SetNestedMap(uSt.Object, map[string]interface{}{"bar": "baz"}, "foo")).To(Succeed())
Expect(unstructured.SetNestedField(uSt.Object, replicasStatus, "replicas")).To(Succeed())
return true
})
u.UpdateStatus(EnsureCondition(conditions.Irreconcilable(corev1.ConditionFalse, "", "")))
u.UpdateStatusCustom(func(uSt *unstructured.Unstructured) bool {
Expect(unstructured.SetNestedField(uSt.Object, "quux", "foo", "qux")).To(Succeed())
Expect(unstructured.SetNestedField(uSt.Object, availableReplicasStatus, "availableReplicas")).To(Succeed())
return true
})
u.UpdateStatus(EnsureCondition(conditions.Initialized(corev1.ConditionTrue, "", "")))
Expand All @@ -107,20 +111,20 @@ var _ = Describe("Updater", func() {
Expect(found).To(BeFalse())
Expect(err).To(Not(HaveOccurred()))

val, found, err := unstructured.NestedString(obj.Object, "status", "foo", "bar")
Expect(val).To(Equal("baz"))
val, found, err := unstructured.NestedInt64(obj.Object, "status", "replicas")
Expect(val).To(Equal(replicasStatus))
Expect(found).To(BeTrue())
Expect(err).To(Not(HaveOccurred()))

val, found, err = unstructured.NestedString(obj.Object, "status", "foo", "qux")
Expect(val).To(Equal("quux"))
val, found, err = unstructured.NestedInt64(obj.Object, "status", "availableReplicas")
Expect(val).To(Equal(availableReplicasStatus))
Expect(found).To(BeTrue())
Expect(err).To(Not(HaveOccurred()))
})

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

val, found, err := unstructured.NestedString(obj.Object, "status", "foo", "bar")
Expect(val).To(Equal("baz"))
val, found, err := unstructured.NestedInt64(obj.Object, "status", "replicas")
Expect(val).To(Equal(replicasStatus))
Expect(found).To(BeTrue())
Expect(err).To(Succeed())

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

val, found, err = unstructured.NestedString(obj.Object, "status", "foo", "bar")
Expect(val).To(Equal("baz"))
val, found, err = unstructured.NestedInt64(obj.Object, "status", "replicas")
Expect(val).To(Equal(replicasStatus))
Expect(found).To(BeTrue())
Expect(err).To(Succeed())
})
Expand Down
7 changes: 3 additions & 4 deletions pkg/reconciler/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,19 @@ import (
"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/predicate"
"sigs.k8s.io/controller-runtime/pkg/predicate"
ctrlpredicate "sigs.k8s.io/controller-runtime/pkg/predicate"
"sigs.k8s.io/controller-runtime/pkg/source"

"github.com/operator-framework/helm-operator-plugins/internal/sdk/controllerutil"
"github.com/operator-framework/helm-operator-plugins/pkg/annotation"
helmclient "github.com/operator-framework/helm-operator-plugins/pkg/client"
"github.com/operator-framework/helm-operator-plugins/pkg/extensions"
"github.com/operator-framework/helm-operator-plugins/pkg/hook"
"github.com/operator-framework/helm-operator-plugins/pkg/reconciler/internal/conditions"
internalhook "github.com/operator-framework/helm-operator-plugins/pkg/reconciler/internal/hook"
"github.com/operator-framework/helm-operator-plugins/pkg/reconciler/internal/updater"
internalvalues "github.com/operator-framework/helm-operator-plugins/pkg/reconciler/internal/values"
"github.com/operator-framework/helm-operator-plugins/pkg/values"
"github.com/joelanford/helm-operator/pkg/extensions"
)

const uninstallFinalizer = "uninstall-helm-release"
Expand All @@ -80,10 +79,10 @@ type Reconciler struct {
selectorPredicate predicate.Predicate
overrideValues map[string]string
skipDependentWatches bool
extraWatches []watchDescription
extraWatches []watchDescription
maxConcurrentReconciles int
reconcilePeriod time.Duration
markFailedAfter time.Duration
markFailedAfter time.Duration
maxHistory int
skipPrimaryGVKSchemeRegistration bool

Expand Down

0 comments on commit 3764c49

Please sign in to comment.