Skip to content

Commit a431a05

Browse files
authored
[improvement] Remove severity levels from CAPLs logic (#589)
1 parent 8e21d69 commit a431a05

8 files changed

+76
-84
lines changed

internal/controller/linodecluster_controller.go

+18-12
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,9 @@ func (r *LinodeClusterReconciler) reconcile(
154154
// Handle deleted clusters
155155
if !clusterScope.LinodeCluster.DeletionTimestamp.IsZero() {
156156
if err := r.reconcileDelete(ctx, logger, clusterScope); err != nil {
157-
if !reconciler.HasConditionSeverity(clusterScope.LinodeCluster, clusterv1.ReadyCondition, clusterv1.ConditionSeverityError) {
157+
if !reconciler.HasStaleCondition(clusterScope.LinodeCluster,
158+
clusterv1.ReadyCondition,
159+
reconciler.DefaultTimeout(r.ReconcileTimeout, reconciler.DefaultClusterControllerReconcileTimeout)) {
158160
logger.Info("re-queuing cluster/nb deletion")
159161
return ctrl.Result{RequeueAfter: reconciler.DefaultClusterControllerReconcileDelay}, nil
160162
}
@@ -176,7 +178,9 @@ func (r *LinodeClusterReconciler) reconcile(
176178
// Create
177179
if clusterScope.LinodeCluster.Spec.ControlPlaneEndpoint.Host == "" {
178180
if err := r.reconcileCreate(ctx, logger, clusterScope); err != nil {
179-
if !reconciler.HasConditionSeverity(clusterScope.LinodeCluster, clusterv1.ReadyCondition, clusterv1.ConditionSeverityError) {
181+
if !reconciler.HasStaleCondition(clusterScope.LinodeCluster,
182+
clusterv1.ReadyCondition,
183+
reconciler.DefaultTimeout(r.ReconcileTimeout, reconciler.DefaultClusterControllerReconcileTimeout)) {
180184
logger.Info("re-queuing cluster/load-balancer creation")
181185
return ctrl.Result{RequeueAfter: reconciler.DefaultClusterControllerReconcileDelay}, nil
182186
}
@@ -207,7 +211,7 @@ func (r *LinodeClusterReconciler) performPreflightChecks(ctx context.Context, lo
207211
if !reconciler.ConditionTrue(clusterScope.LinodeCluster, ConditionPreflightLinodeVPCReady) {
208212
res, err := r.reconcilePreflightLinodeVPCCheck(ctx, logger, clusterScope)
209213
if err != nil || !res.IsZero() {
210-
conditions.MarkFalse(clusterScope.LinodeCluster, ConditionPreflightLinodeVPCReady, "linode vpc not yet available", clusterv1.ConditionSeverityError, "")
214+
conditions.MarkFalse(clusterScope.LinodeCluster, ConditionPreflightLinodeVPCReady, "linode vpc not yet available", "", "")
211215
return res, err
212216
}
213217
}
@@ -218,7 +222,7 @@ func (r *LinodeClusterReconciler) performPreflightChecks(ctx context.Context, lo
218222
if !reconciler.ConditionTrue(clusterScope.LinodeCluster, ConditionPreflightLinodeNBFirewallReady) {
219223
res, err := r.reconcilePreflightLinodeFirewallCheck(ctx, logger, clusterScope)
220224
if err != nil || !res.IsZero() {
221-
conditions.MarkFalse(clusterScope.LinodeCluster, ConditionPreflightLinodeNBFirewallReady, "linode firewall not yet available", clusterv1.ConditionSeverityError, "")
225+
conditions.MarkFalse(clusterScope.LinodeCluster, ConditionPreflightLinodeNBFirewallReady, "linode firewall not yet available", "", "")
222226
return res, err
223227
}
224228
}
@@ -245,9 +249,10 @@ func (r *LinodeClusterReconciler) reconcilePreflightLinodeFirewallCheck(ctx cont
245249
err := clusterScope.Client.Get(ctx, objectKey, linodeFirewall)
246250
if err != nil {
247251
logger.Error(err, "Failed to fetch LinodeFirewall")
248-
if reconciler.RecordDecayingCondition(clusterScope.LinodeCluster,
249-
ConditionPreflightLinodeNBFirewallReady, string(cerrs.CreateClusterError), err.Error(),
252+
if reconciler.HasStaleCondition(clusterScope.LinodeCluster,
253+
ConditionPreflightLinodeNBFirewallReady,
250254
reconciler.DefaultTimeout(r.ReconcileTimeout, reconciler.DefaultClusterControllerReconcileTimeout)) {
255+
conditions.MarkFalse(clusterScope.LinodeCluster, ConditionPreflightLinodeNBFirewallReady, string(cerrs.CreateClusterError), "", "%s", err.Error())
251256
return ctrl.Result{}, err
252257
}
253258
return ctrl.Result{RequeueAfter: reconciler.DefaultClusterControllerReconcileDelay}, nil
@@ -276,9 +281,10 @@ func (r *LinodeClusterReconciler) reconcilePreflightLinodeVPCCheck(ctx context.C
276281
}
277282
if err := clusterScope.Client.Get(ctx, client.ObjectKeyFromObject(&linodeVPC), &linodeVPC); err != nil {
278283
logger.Error(err, "Failed to fetch LinodeVPC")
279-
if reconciler.RecordDecayingCondition(clusterScope.LinodeCluster,
280-
ConditionPreflightLinodeVPCReady, string(cerrs.CreateClusterError), err.Error(),
284+
if reconciler.HasStaleCondition(clusterScope.LinodeCluster,
285+
ConditionPreflightLinodeVPCReady,
281286
reconciler.DefaultTimeout(r.ReconcileTimeout, reconciler.DefaultClusterControllerReconcileTimeout)) {
287+
conditions.MarkFalse(clusterScope.LinodeCluster, ConditionPreflightLinodeVPCReady, string(cerrs.CreateClusterError), "", "%s", err.Error())
282288
return ctrl.Result{}, err
283289
}
284290
return ctrl.Result{RequeueAfter: reconciler.DefaultClusterControllerReconcileDelay}, nil
@@ -294,7 +300,7 @@ func setFailureReason(clusterScope *scope.ClusterScope, failureReason cerrs.Clus
294300
clusterScope.LinodeCluster.Status.FailureReason = util.Pointer(failureReason)
295301
clusterScope.LinodeCluster.Status.FailureMessage = util.Pointer(err.Error())
296302

297-
reconciler.RecordDecayingCondition(clusterScope.LinodeCluster, clusterv1.ReadyCondition, string(failureReason), err.Error(), reconciler.DefaultTimeout(lcr.ReconcileTimeout, reconciler.DefaultClusterControllerReconcileTimeout))
303+
conditions.MarkFalse(clusterScope.LinodeCluster, clusterv1.ReadyCondition, string(failureReason), "", "%s", err.Error())
298304

299305
lcr.Recorder.Event(clusterScope.LinodeCluster, corev1.EventTypeWarning, string(failureReason), err.Error())
300306
}
@@ -323,14 +329,14 @@ func (r *LinodeClusterReconciler) reconcileDelete(ctx context.Context, logger lo
323329
switch {
324330
case clusterScope.LinodeCluster.Spec.Network.LoadBalancerType == "external":
325331
logger.Info("LoadBalacing managed externally, nothing to do.")
326-
conditions.MarkFalse(clusterScope.LinodeCluster, clusterv1.ReadyCondition, clusterv1.DeletedReason, clusterv1.ConditionSeverityInfo, "Deletion in progress")
332+
conditions.MarkFalse(clusterScope.LinodeCluster, clusterv1.ReadyCondition, clusterv1.DeletedReason, "", "%s", "Deletion in progress")
327333
r.Recorder.Event(clusterScope.LinodeCluster, corev1.EventTypeWarning, "LoadBalacing managed externally", "LoadBalacing managed externally, nothing to do.")
328334

329335
case clusterScope.LinodeCluster.Spec.Network.LoadBalancerType == lbTypeDNS:
330336
if err := removeMachineFromDNS(ctx, logger, clusterScope); err != nil {
331337
return fmt.Errorf("remove machine from loadbalancer: %w", err)
332338
}
333-
conditions.MarkFalse(clusterScope.LinodeCluster, clusterv1.ReadyCondition, clusterv1.DeletedReason, clusterv1.ConditionSeverityInfo, "Load balancing for Type DNS deleted")
339+
conditions.MarkFalse(clusterScope.LinodeCluster, clusterv1.ReadyCondition, clusterv1.DeletedReason, "", "%s", "Load balancing for Type DNS deleted")
334340
r.Recorder.Event(clusterScope.LinodeCluster, corev1.EventTypeNormal, clusterv1.DeletedReason, "Load balancing for Type DNS deleted")
335341

336342
case clusterScope.LinodeCluster.Spec.Network.LoadBalancerType == "NodeBalancer" && clusterScope.LinodeCluster.Spec.Network.NodeBalancerID == nil:
@@ -349,7 +355,7 @@ func (r *LinodeClusterReconciler) reconcileDelete(ctx context.Context, logger lo
349355
return err
350356
}
351357

352-
conditions.MarkFalse(clusterScope.LinodeCluster, clusterv1.ReadyCondition, clusterv1.DeletedReason, clusterv1.ConditionSeverityInfo, "Load balancer for Type NodeBalancer deleted")
358+
conditions.MarkFalse(clusterScope.LinodeCluster, clusterv1.ReadyCondition, clusterv1.DeletedReason, "", "%s", "Load balancer for Type NodeBalancer deleted")
353359
r.Recorder.Event(clusterScope.LinodeCluster, corev1.EventTypeNormal, clusterv1.DeletedReason, "Load balancer for Type NodeBalancer deleted")
354360

355361
clusterScope.LinodeCluster.Spec.Network.NodeBalancerID = nil

internal/controller/linodefirewall_controller.go

+5-16
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ func (r *LinodeFirewallReconciler) reconcile(
112112
if err != nil {
113113
fwScope.LinodeFirewall.Status.FailureReason = util.Pointer(failureReason)
114114
fwScope.LinodeFirewall.Status.FailureMessage = util.Pointer(err.Error())
115-
conditions.MarkFalse(fwScope.LinodeFirewall, clusterv1.ReadyCondition, string(failureReason), clusterv1.ConditionSeverityError, "%s", err.Error())
115+
conditions.MarkFalse(fwScope.LinodeFirewall, clusterv1.ReadyCondition, string(failureReason), "", "%s", err.Error())
116116
r.Recorder.Event(fwScope.LinodeFirewall, corev1.EventTypeWarning, string(failureReason), err.Error())
117117
}
118118

@@ -154,34 +154,23 @@ func (r *LinodeFirewallReconciler) reconcile(
154154
failureReason = infrav1alpha2.CreateFirewallError
155155
if err = fwScope.AddCredentialsRefFinalizer(ctx); err != nil {
156156
logger.Error(err, "failed to update credentials secret")
157-
reconciler.RecordDecayingCondition(
158-
fwScope.LinodeFirewall,
159-
clusterv1.ReadyCondition,
160-
string(failureReason),
161-
err.Error(),
162-
reconciler.DefaultTimeout(r.ReconcileTimeout, reconciler.DefaultFWControllerReconcileTimeout),
163-
)
157+
conditions.MarkFalse(fwScope.LinodeFirewall, clusterv1.ReadyCondition, string(failureReason), "", "%s", err.Error())
164158
r.Recorder.Event(fwScope.LinodeFirewall, corev1.EventTypeWarning, string(failureReason), err.Error())
165159

166160
return ctrl.Result{}, nil
167161
}
168162
}
169163
if err = reconcileFirewall(ctx, r.Client, fwScope, logger); err != nil {
170164
logger.Error(err, fmt.Sprintf("failed to %s Firewall", action))
171-
reconciler.RecordDecayingCondition(
172-
fwScope.LinodeFirewall,
173-
clusterv1.ReadyCondition,
174-
string(failureReason),
175-
err.Error(),
176-
reconciler.DefaultTimeout(r.ReconcileTimeout, reconciler.DefaultFWControllerReconcileTimeout),
177-
)
165+
conditions.MarkFalse(fwScope.LinodeFirewall, clusterv1.ReadyCondition, string(failureReason), "", "%s", err.Error())
178166
r.Recorder.Event(fwScope.LinodeFirewall, corev1.EventTypeWarning, string(failureReason), err.Error())
179167

180168
switch {
181169
case errors.Is(err, errTooManyIPs):
182170
// Cannot reconcile firewall with too many ips, wait for an update to the spec
183171
return ctrl.Result{}, nil
184-
case util.IsRetryableError(err) && !reconciler.HasConditionSeverity(fwScope.LinodeFirewall, clusterv1.ReadyCondition, clusterv1.ConditionSeverityError):
172+
case util.IsRetryableError(err) && !reconciler.HasStaleCondition(fwScope.LinodeFirewall, clusterv1.ReadyCondition,
173+
reconciler.DefaultTimeout(r.ReconcileTimeout, reconciler.DefaultFWControllerReconcileTimeout)):
185174
logger.Info(fmt.Sprintf("re-queuing Firewall %s", action))
186175

187176
return ctrl.Result{RequeueAfter: reconciler.DefaultFWControllerReconcilerDelay}, nil

0 commit comments

Comments
 (0)