From 670335e2cf202e9edd9d0e7d54ec81892a0e0940 Mon Sep 17 00:00:00 2001 From: Christian Schwede Date: Thu, 7 Mar 2024 17:50:26 +0100 Subject: [PATCH] Fix status update if zero replicas deployed If the SwiftStorage instance is created with replicas=0 - for example to adopt an existing dataplane - the network attachments will never be created due to no running pods. This resulted in a wrong status. --- controllers/swiftstorage_controller.go | 40 +++++++++++++++----------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/controllers/swiftstorage_controller.go b/controllers/swiftstorage_controller.go index 8ae56368..acc05416 100644 --- a/controllers/swiftstorage_controller.go +++ b/controllers/swiftstorage_controller.go @@ -250,29 +250,35 @@ func (r *SwiftStorageReconciler) Reconcile(ctx context.Context, req ctrl.Request return ctrlResult, nil } - // verify if network attachment matches expectations - networkReady, networkAttachmentStatus, err := networkattachment.VerifyNetworkStatusFromAnnotation(ctx, helper, instance.Spec.NetworkAttachments, serviceLabels, instance.Status.ReadyCount) - if err != nil { - return ctrl.Result{}, err - } + // replicas=0 is a common setting before dataplane adoption. However, + // networkReady will never become true in that case and status will + // report an error where none is + if *instance.Spec.Replicas > 0 { + // verify if network attachment matches expectations + networkReady, networkAttachmentStatus, err := networkattachment.VerifyNetworkStatusFromAnnotation(ctx, helper, instance.Spec.NetworkAttachments, serviceLabels, instance.Status.ReadyCount) + if err != nil { + return ctrl.Result{}, err + } - instance.Status.NetworkAttachments = networkAttachmentStatus - if networkReady { - instance.Status.Conditions.MarkTrue(condition.NetworkAttachmentsReadyCondition, condition.NetworkAttachmentsReadyMessage) - } else { - err := fmt.Errorf("not all pods have interfaces with ips as configured in NetworkAttachments: %s", instance.Spec.NetworkAttachments) - instance.Status.Conditions.Set(condition.FalseCondition( - condition.NetworkAttachmentsReadyCondition, - condition.ErrorReason, - condition.SeverityWarning, - condition.NetworkAttachmentsReadyErrorMessage, - err.Error())) + instance.Status.NetworkAttachments = networkAttachmentStatus + if networkReady { + instance.Status.Conditions.MarkTrue(condition.NetworkAttachmentsReadyCondition, condition.NetworkAttachmentsReadyMessage) + } else { + err := fmt.Errorf("not all pods have interfaces with ips as configured in NetworkAttachments: %s", instance.Spec.NetworkAttachments) + instance.Status.Conditions.Set(condition.FalseCondition( + condition.NetworkAttachmentsReadyCondition, + condition.ErrorReason, + condition.SeverityWarning, + condition.NetworkAttachmentsReadyErrorMessage, + err.Error())) - return ctrl.Result{}, err + return ctrl.Result{}, err + } } instance.Status.ReadyCount = sset.GetStatefulSet().Status.ReadyReplicas if instance.Status.ReadyCount == *instance.Spec.Replicas { + // When the cluster is attached to an external network, create DNS record for every // cluster member so it can be resolved from outside cluster (edpm nodes) podList, err := pod.GetPodListWithLabel(ctx, helper, instance.Namespace, serviceLabels)