Skip to content

Commit

Permalink
[improvement] Remove severity levels from CAPLs logic (#589)
Browse files Browse the repository at this point in the history
  • Loading branch information
komer3 authored Dec 13, 2024
1 parent 8e21d69 commit a431a05
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 84 deletions.
30 changes: 18 additions & 12 deletions internal/controller/linodecluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,9 @@ func (r *LinodeClusterReconciler) reconcile(
// Handle deleted clusters
if !clusterScope.LinodeCluster.DeletionTimestamp.IsZero() {
if err := r.reconcileDelete(ctx, logger, clusterScope); err != nil {
if !reconciler.HasConditionSeverity(clusterScope.LinodeCluster, clusterv1.ReadyCondition, clusterv1.ConditionSeverityError) {
if !reconciler.HasStaleCondition(clusterScope.LinodeCluster,
clusterv1.ReadyCondition,
reconciler.DefaultTimeout(r.ReconcileTimeout, reconciler.DefaultClusterControllerReconcileTimeout)) {
logger.Info("re-queuing cluster/nb deletion")
return ctrl.Result{RequeueAfter: reconciler.DefaultClusterControllerReconcileDelay}, nil
}
Expand All @@ -176,7 +178,9 @@ func (r *LinodeClusterReconciler) reconcile(
// Create
if clusterScope.LinodeCluster.Spec.ControlPlaneEndpoint.Host == "" {
if err := r.reconcileCreate(ctx, logger, clusterScope); err != nil {
if !reconciler.HasConditionSeverity(clusterScope.LinodeCluster, clusterv1.ReadyCondition, clusterv1.ConditionSeverityError) {
if !reconciler.HasStaleCondition(clusterScope.LinodeCluster,
clusterv1.ReadyCondition,
reconciler.DefaultTimeout(r.ReconcileTimeout, reconciler.DefaultClusterControllerReconcileTimeout)) {
logger.Info("re-queuing cluster/load-balancer creation")
return ctrl.Result{RequeueAfter: reconciler.DefaultClusterControllerReconcileDelay}, nil
}
Expand Down Expand Up @@ -207,7 +211,7 @@ func (r *LinodeClusterReconciler) performPreflightChecks(ctx context.Context, lo
if !reconciler.ConditionTrue(clusterScope.LinodeCluster, ConditionPreflightLinodeVPCReady) {
res, err := r.reconcilePreflightLinodeVPCCheck(ctx, logger, clusterScope)
if err != nil || !res.IsZero() {
conditions.MarkFalse(clusterScope.LinodeCluster, ConditionPreflightLinodeVPCReady, "linode vpc not yet available", clusterv1.ConditionSeverityError, "")
conditions.MarkFalse(clusterScope.LinodeCluster, ConditionPreflightLinodeVPCReady, "linode vpc not yet available", "", "")
return res, err
}
}
Expand All @@ -218,7 +222,7 @@ func (r *LinodeClusterReconciler) performPreflightChecks(ctx context.Context, lo
if !reconciler.ConditionTrue(clusterScope.LinodeCluster, ConditionPreflightLinodeNBFirewallReady) {
res, err := r.reconcilePreflightLinodeFirewallCheck(ctx, logger, clusterScope)
if err != nil || !res.IsZero() {
conditions.MarkFalse(clusterScope.LinodeCluster, ConditionPreflightLinodeNBFirewallReady, "linode firewall not yet available", clusterv1.ConditionSeverityError, "")
conditions.MarkFalse(clusterScope.LinodeCluster, ConditionPreflightLinodeNBFirewallReady, "linode firewall not yet available", "", "")
return res, err
}
}
Expand All @@ -245,9 +249,10 @@ func (r *LinodeClusterReconciler) reconcilePreflightLinodeFirewallCheck(ctx cont
err := clusterScope.Client.Get(ctx, objectKey, linodeFirewall)
if err != nil {
logger.Error(err, "Failed to fetch LinodeFirewall")
if reconciler.RecordDecayingCondition(clusterScope.LinodeCluster,
ConditionPreflightLinodeNBFirewallReady, string(cerrs.CreateClusterError), err.Error(),
if reconciler.HasStaleCondition(clusterScope.LinodeCluster,
ConditionPreflightLinodeNBFirewallReady,
reconciler.DefaultTimeout(r.ReconcileTimeout, reconciler.DefaultClusterControllerReconcileTimeout)) {
conditions.MarkFalse(clusterScope.LinodeCluster, ConditionPreflightLinodeNBFirewallReady, string(cerrs.CreateClusterError), "", "%s", err.Error())
return ctrl.Result{}, err
}
return ctrl.Result{RequeueAfter: reconciler.DefaultClusterControllerReconcileDelay}, nil
Expand Down Expand Up @@ -276,9 +281,10 @@ func (r *LinodeClusterReconciler) reconcilePreflightLinodeVPCCheck(ctx context.C
}
if err := clusterScope.Client.Get(ctx, client.ObjectKeyFromObject(&linodeVPC), &linodeVPC); err != nil {
logger.Error(err, "Failed to fetch LinodeVPC")
if reconciler.RecordDecayingCondition(clusterScope.LinodeCluster,
ConditionPreflightLinodeVPCReady, string(cerrs.CreateClusterError), err.Error(),
if reconciler.HasStaleCondition(clusterScope.LinodeCluster,
ConditionPreflightLinodeVPCReady,
reconciler.DefaultTimeout(r.ReconcileTimeout, reconciler.DefaultClusterControllerReconcileTimeout)) {
conditions.MarkFalse(clusterScope.LinodeCluster, ConditionPreflightLinodeVPCReady, string(cerrs.CreateClusterError), "", "%s", err.Error())
return ctrl.Result{}, err
}
return ctrl.Result{RequeueAfter: reconciler.DefaultClusterControllerReconcileDelay}, nil
Expand All @@ -294,7 +300,7 @@ func setFailureReason(clusterScope *scope.ClusterScope, failureReason cerrs.Clus
clusterScope.LinodeCluster.Status.FailureReason = util.Pointer(failureReason)
clusterScope.LinodeCluster.Status.FailureMessage = util.Pointer(err.Error())

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

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

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

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

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

clusterScope.LinodeCluster.Spec.Network.NodeBalancerID = nil
Expand Down
21 changes: 5 additions & 16 deletions internal/controller/linodefirewall_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func (r *LinodeFirewallReconciler) reconcile(
if err != nil {
fwScope.LinodeFirewall.Status.FailureReason = util.Pointer(failureReason)
fwScope.LinodeFirewall.Status.FailureMessage = util.Pointer(err.Error())
conditions.MarkFalse(fwScope.LinodeFirewall, clusterv1.ReadyCondition, string(failureReason), clusterv1.ConditionSeverityError, "%s", err.Error())
conditions.MarkFalse(fwScope.LinodeFirewall, clusterv1.ReadyCondition, string(failureReason), "", "%s", err.Error())
r.Recorder.Event(fwScope.LinodeFirewall, corev1.EventTypeWarning, string(failureReason), err.Error())
}

Expand Down Expand Up @@ -154,34 +154,23 @@ func (r *LinodeFirewallReconciler) reconcile(
failureReason = infrav1alpha2.CreateFirewallError
if err = fwScope.AddCredentialsRefFinalizer(ctx); err != nil {
logger.Error(err, "failed to update credentials secret")
reconciler.RecordDecayingCondition(
fwScope.LinodeFirewall,
clusterv1.ReadyCondition,
string(failureReason),
err.Error(),
reconciler.DefaultTimeout(r.ReconcileTimeout, reconciler.DefaultFWControllerReconcileTimeout),
)
conditions.MarkFalse(fwScope.LinodeFirewall, clusterv1.ReadyCondition, string(failureReason), "", "%s", err.Error())
r.Recorder.Event(fwScope.LinodeFirewall, corev1.EventTypeWarning, string(failureReason), err.Error())

return ctrl.Result{}, nil
}
}
if err = reconcileFirewall(ctx, r.Client, fwScope, logger); err != nil {
logger.Error(err, fmt.Sprintf("failed to %s Firewall", action))
reconciler.RecordDecayingCondition(
fwScope.LinodeFirewall,
clusterv1.ReadyCondition,
string(failureReason),
err.Error(),
reconciler.DefaultTimeout(r.ReconcileTimeout, reconciler.DefaultFWControllerReconcileTimeout),
)
conditions.MarkFalse(fwScope.LinodeFirewall, clusterv1.ReadyCondition, string(failureReason), "", "%s", err.Error())
r.Recorder.Event(fwScope.LinodeFirewall, corev1.EventTypeWarning, string(failureReason), err.Error())

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

return ctrl.Result{RequeueAfter: reconciler.DefaultFWControllerReconcilerDelay}, nil
Expand Down
Loading

0 comments on commit a431a05

Please sign in to comment.