Skip to content

Commit dd2b2d5

Browse files
author
Rahul Sharma
committed
avoid resetting condition with severity error to severity warning during next reconcile
1 parent 3b20368 commit dd2b2d5

File tree

5 files changed

+25
-19
lines changed

5 files changed

+25
-19
lines changed

internal/controller/linodecluster_controller_test.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,21 @@ var _ = Describe("cluster-lifecycle", Ordered, Label("cluster", "cluster-lifecyc
114114

115115
ctlrSuite.Run(
116116
OneOf(
117+
Path(
118+
Call("vpc present but not ready", func(ctx context.Context, mck Mock) {
119+
Expect(k8sClient.Create(ctx, &linodeVPC)).To(Succeed())
120+
linodeVPC.Status.Ready = false
121+
k8sClient.Status().Update(ctx, &linodeVPC)
122+
}),
123+
OneOf(
124+
Path(Result("", func(ctx context.Context, mck Mock) {
125+
reconciler.Client = k8sClient
126+
_, err := reconciler.reconcile(ctx, cScope, mck.Logger())
127+
Expect(err).NotTo(HaveOccurred())
128+
Expect(rec.ConditionTrue(&linodeCluster, ConditionPreflightLinodeVPCReady)).To(BeFalse())
129+
})),
130+
),
131+
),
117132
Path(
118133
Call("firewall doesn't exist", func(ctx context.Context, mck Mock) {
119134
cScope.LinodeCluster.Spec.NodeBalancerFirewallRef = &corev1.ObjectReference{Name: "firewalltest"}
@@ -151,21 +166,6 @@ var _ = Describe("cluster-lifecycle", Ordered, Label("cluster", "cluster-lifecyc
151166
})),
152167
),
153168
),
154-
Path(
155-
Call("vpc present but not ready", func(ctx context.Context, mck Mock) {
156-
Expect(k8sClient.Create(ctx, &linodeVPC)).To(Succeed())
157-
linodeVPC.Status.Ready = false
158-
k8sClient.Status().Update(ctx, &linodeVPC)
159-
}),
160-
OneOf(
161-
Path(Result("", func(ctx context.Context, mck Mock) {
162-
reconciler.Client = k8sClient
163-
_, err := reconciler.reconcile(ctx, cScope, mck.Logger())
164-
Expect(err).NotTo(HaveOccurred())
165-
Expect(rec.ConditionTrue(&linodeCluster, ConditionPreflightLinodeVPCReady)).To(BeFalse())
166-
})),
167-
),
168-
),
169169
Path(
170170
Call("cluster is not created because there was an error creating nb", func(ctx context.Context, mck Mock) {
171171
cScope.LinodeClient = mck.LinodeClient

internal/controller/linodefirewall_controller_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ import (
2525
"github.com/linode/linodego"
2626
"go.uber.org/mock/gomock"
2727
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
28+
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
29+
"sigs.k8s.io/cluster-api/util/conditions"
2830
"sigs.k8s.io/cluster-api/util/patch"
2931
"sigs.k8s.io/controller-runtime/pkg/client"
3032

@@ -169,6 +171,7 @@ var _ = Describe("lifecycle", Ordered, Label("firewalls", "lifecycle"), func() {
169171
}),
170172
OneOf(
171173
Path(Result("update requeues for update rules error", func(ctx context.Context, mck Mock) {
174+
conditions.MarkFalse(fwScope.LinodeFirewall, clusterv1.ReadyCondition, "test", clusterv1.ConditionSeverityWarning, "%s", "test")
172175
mck.LinodeClient.EXPECT().UpdateFirewallRules(ctx, 1, gomock.Any()).Return(nil, &linodego.Error{Code: http.StatusInternalServerError})
173176
res, err := reconciler.reconcile(ctx, mck.Logger(), &fwScope)
174177
Expect(err).NotTo(HaveOccurred())

internal/controller/linodemachine_controller_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ var _ = Describe("create", Label("machine", "create"), func() {
630630

631631
Expect(rutil.ConditionTrue(&linodeMachine, ConditionPreflightMetadataSupportConfigured)).To(BeTrue())
632632
Expect(rutil.ConditionTrue(&linodeMachine, ConditionPreflightCreated)).To(BeFalse())
633-
Expect(conditions.Get(&linodeMachine, ConditionPreflightCreated).Severity).To(Equal(clusterv1.ConditionSeverityError))
633+
Expect(conditions.Get(&linodeMachine, ConditionPreflightCreated).Severity).To(Equal(clusterv1.ConditionSeverityWarning))
634634
Expect(conditions.Get(&linodeMachine, ConditionPreflightCreated).Message).To(ContainSubstring("time is up"))
635635
})
636636
})

internal/controller/linodevpc_controller_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ import (
2626
apierrors "k8s.io/apimachinery/pkg/api/errors"
2727
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2828
"k8s.io/utils/ptr"
29+
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
30+
"sigs.k8s.io/cluster-api/util/conditions"
2931
"sigs.k8s.io/cluster-api/util/patch"
3032
"sigs.k8s.io/controller-runtime/pkg/client"
3133

@@ -163,6 +165,7 @@ var _ = Describe("lifecycle", Ordered, Label("vpc", "lifecycle"), func() {
163165
}),
164166
OneOf(
165167
Path(Result("update requeues", func(ctx context.Context, mck Mock) {
168+
conditions.MarkFalse(vpcScope.LinodeVPC, clusterv1.ReadyCondition, "test", clusterv1.ConditionSeverityWarning, "%s", "test")
166169
res, err := reconciler.reconcile(ctx, mck.Logger(), &vpcScope)
167170
Expect(err).NotTo(HaveOccurred())
168171
Expect(res.RequeueAfter).To(Equal(rec.DefaultVPCControllerReconcileDelay))

util/reconciler/conditions.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,12 @@ func HasConditionSeverity(from conditions.Getter, typ clusterv1.ConditionType, s
3131
}
3232

3333
func RecordDecayingCondition(to conditions.Setter, typ clusterv1.ConditionType, reason, message string, timeout time.Duration) bool {
34-
conditions.MarkFalse(to, typ, reason, clusterv1.ConditionSeverityWarning, "%s", message)
35-
3634
if HasStaleCondition(to, typ, timeout) {
3735
conditions.MarkFalse(to, typ, reason, clusterv1.ConditionSeverityError, "%s", message)
3836
return true
3937
}
4038

39+
conditions.MarkFalse(to, typ, reason, clusterv1.ConditionSeverityWarning, "%s", message)
4140
return false
4241
}
4342

@@ -47,5 +46,6 @@ func HasStaleCondition(from conditions.Getter, typ clusterv1.ConditionType, time
4746
return false
4847
}
4948

50-
return time.Now().After(cond.LastTransitionTime.Add(timeout))
49+
// if severity is already set to error, it was a stale condition
50+
return cond.Severity == clusterv1.ConditionSeverityError || time.Now().After(cond.LastTransitionTime.Add(timeout))
5151
}

0 commit comments

Comments
 (0)