Skip to content

Commit

Permalink
refactor: use FindStatusCondition from apimachinery meta in test
Browse files Browse the repository at this point in the history
Changes:
- Instead of two loops, use `apimeta.FindStatusCondition` to check if
  the stalled condition is has the same properties after a
  reconciliation loop.
- regenerate `zz_generated.deepcopy.go`.
- return `nil` in test where the value is not used.

Signed-off-by: Balazs Nadasdi <balazs@weave.works>
  • Loading branch information
yitsushi committed Nov 24, 2023
1 parent 8c4ef45 commit 88eff5a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 18 deletions.
20 changes: 20 additions & 0 deletions api/v1alpha2/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 9 additions & 18 deletions controllers/tc000243_remediation_retry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/fluxcd/pkg/apis/meta"
sourcev1 "github.com/fluxcd/source-controller/api/v1"
infrav1 "github.com/weaveworks/tf-controller/api/v1alpha2"
apimeta "k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
)
Expand Down Expand Up @@ -168,25 +169,15 @@ spec:
return k8sClient.Get(ctx, helloWorldTFKey, &recheckHelloWorldTF)
}, timeout, interval).Should(Succeed())

var retryCondition *metav1.Condition
for _, cond := range recheckHelloWorldTF.Status.Conditions {
if cond.Type == meta.StalledCondition && cond.Reason == infrav1.RetryLimitReachedReason {
retryCondition = &cond
break
}
}
var originalRetryCondition *metav1.Condition
for _, cond := range createdHelloWorldTF.Status.Conditions {
if cond.Type == meta.StalledCondition && cond.Reason == infrav1.RetryLimitReachedReason {
originalRetryCondition = &cond
break
}
}
originalCondition := apimeta.FindStatusCondition(createdHelloWorldTF.Status.Conditions, meta.StalledCondition)
recheckCondition := apimeta.FindStatusCondition(recheckHelloWorldTF.Status.Conditions, meta.StalledCondition)

g.Expect(retryCondition).ToNot(BeNil(), "Terraform resource should have retry limit reached status condition")
g.Expect(originalRetryCondition).ToNot(BeNil(), "Terraform resource should have retry limit reached status condition")
g.Expect(recheckCondition).ToNot(BeNil(), "Terraform resource should have retry limit reached status condition")
g.Expect(originalCondition).ToNot(BeNil(), "Terraform resource should have retry limit reached status condition")
g.Expect(originalCondition.Reason).To(Equal(infrav1.RetryLimitReachedReason))
g.Expect(originalCondition.Reason).To(Equal(recheckCondition.Reason))
g.Expect(recheckHelloWorldTF.Status.ReconciliationFailures).To(Equal(createdHelloWorldTF.Status.ReconciliationFailures))
g.Expect(retryCondition.ObservedGeneration).To(Equal(originalRetryCondition.ObservedGeneration))
g.Expect(recheckCondition.ObservedGeneration).To(Equal(originalCondition.ObservedGeneration))
g.Expect(recheckHelloWorldTF.Status.LastAttemptedRevision).To(Equal(testRepo.Status.Artifact.Revision))

It("should restart retry count")
Expand Down Expand Up @@ -220,6 +211,6 @@ spec:
}
}
}
return createdHelloWorldTF.Status
return nil
}, timeout, interval).Should(Equal(expected))
}

0 comments on commit 88eff5a

Please sign in to comment.