From 632d4546449039d44b35bc65be75bbbe58606b5f Mon Sep 17 00:00:00 2001 From: Rabi Mishra Date: Sun, 4 Oct 2026 09:00:45 +0530 Subject: [PATCH] Track failure per nodeset A failed service job (backoff limit exceeded) stalls whole deployment and reconcile returned before the other nodeSets could be advanced, so their in-flight jobs were never collected and their remaining services never started. InitConditions() wipes NodeSetConditions every pass and the AEE job backing the failure is garbage collected once its TTL expires, so once it is gone the failure can no longer be derived. Signed-off-by: Rabi Mishra --- ...ack.org_openstackdataplanedeployments.yaml | 8 + .../openstackdataplanedeployment_types.go | 5 + .../v1beta1/zz_generated.deepcopy.go | 7 + bindata/crds/crds.yaml | 8 + ...ack.org_openstackdataplanedeployments.yaml | 8 + ...openstackdataplanedeployment_controller.go | 112 ++++-- ...tackdataplanedeployment_controller_test.go | 345 ++++++++++++++++++ 7 files changed, 463 insertions(+), 30 deletions(-) diff --git a/api/bases/dataplane.openstack.org_openstackdataplanedeployments.yaml b/api/bases/dataplane.openstack.org_openstackdataplanedeployments.yaml index b5db86a344..126a0a476c 100644 --- a/api/bases/dataplane.openstack.org_openstackdataplanedeployments.yaml +++ b/api/bases/dataplane.openstack.org_openstackdataplanedeployments.yaml @@ -236,6 +236,14 @@ spec: deployedVersion: description: DeployedVersion type: string + failedNodeSets: + additionalProperties: + type: string + description: |- + FailedNodeSets maps a nodeSet name to the message of the permanent failure + that terminated it. Terminality cannot live in the conditions because the AEE + job backing the failure is garbage collected once the deployment settles. + type: object nodeSetConditions: additionalProperties: description: Conditions provide observations of the operational diff --git a/api/dataplane/v1beta1/openstackdataplanedeployment_types.go b/api/dataplane/v1beta1/openstackdataplanedeployment_types.go index cea6e562be..062e23f1eb 100644 --- a/api/dataplane/v1beta1/openstackdataplanedeployment_types.go +++ b/api/dataplane/v1beta1/openstackdataplanedeployment_types.go @@ -112,6 +112,11 @@ type OpenStackDataPlaneDeploymentStatus struct { // NodeSetConditions NodeSetConditions map[string]condition.Conditions `json:"nodeSetConditions,omitempty" optional:"true"` + // FailedNodeSets maps a nodeSet name to the message of the permanent failure + // that terminated it. Terminality cannot live in the conditions because the AEE + // job backing the failure is garbage collected once the deployment settles. + FailedNodeSets map[string]string `json:"failedNodeSets,omitempty" optional:"true"` + // AnsibleEEHashes AnsibleEEHashes map[string]string `json:"ansibleEEHashes,omitempty" optional:"true"` diff --git a/api/dataplane/v1beta1/zz_generated.deepcopy.go b/api/dataplane/v1beta1/zz_generated.deepcopy.go index 05c763fb03..845ca049f2 100644 --- a/api/dataplane/v1beta1/zz_generated.deepcopy.go +++ b/api/dataplane/v1beta1/zz_generated.deepcopy.go @@ -451,6 +451,13 @@ func (in *OpenStackDataPlaneDeploymentStatus) DeepCopyInto(out *OpenStackDataPla (*out)[key] = outVal } } + if in.FailedNodeSets != nil { + in, out := &in.FailedNodeSets, &out.FailedNodeSets + *out = make(map[string]string, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } if in.AnsibleEEHashes != nil { in, out := &in.AnsibleEEHashes, &out.AnsibleEEHashes *out = make(map[string]string, len(*in)) diff --git a/bindata/crds/crds.yaml b/bindata/crds/crds.yaml index 9953ed6ee9..27ade07679 100644 --- a/bindata/crds/crds.yaml +++ b/bindata/crds/crds.yaml @@ -20863,6 +20863,14 @@ spec: deployedVersion: description: DeployedVersion type: string + failedNodeSets: + additionalProperties: + type: string + description: |- + FailedNodeSets maps a nodeSet name to the message of the permanent failure + that terminated it. Terminality cannot live in the conditions because the AEE + job backing the failure is garbage collected once the deployment settles. + type: object nodeSetConditions: additionalProperties: description: Conditions provide observations of the operational diff --git a/config/crd/bases/dataplane.openstack.org_openstackdataplanedeployments.yaml b/config/crd/bases/dataplane.openstack.org_openstackdataplanedeployments.yaml index b5db86a344..126a0a476c 100644 --- a/config/crd/bases/dataplane.openstack.org_openstackdataplanedeployments.yaml +++ b/config/crd/bases/dataplane.openstack.org_openstackdataplanedeployments.yaml @@ -236,6 +236,14 @@ spec: deployedVersion: description: DeployedVersion type: string + failedNodeSets: + additionalProperties: + type: string + description: |- + FailedNodeSets maps a nodeSet name to the message of the permanent failure + that terminated it. Terminality cannot live in the conditions because the AEE + job backing the failure is garbage collected once the deployment settles. + type: object nodeSetConditions: additionalProperties: description: Conditions provide observations of the operational diff --git a/internal/controller/dataplane/openstackdataplanedeployment_controller.go b/internal/controller/dataplane/openstackdataplanedeployment_controller.go index 050b53f5be..771f123500 100644 --- a/internal/controller/dataplane/openstackdataplanedeployment_controller.go +++ b/internal/controller/dataplane/openstackdataplanedeployment_controller.go @@ -113,18 +113,10 @@ func (r *OpenStackDataPlaneDeploymentReconciler) Reconcile(ctx context.Context, return ctrl.Result{}, nil } - // If the deployment has failed with backoff limit exceeded, do not reconcile - // even if nodesets or other watched resources change. The deployment is in a - // terminal failure state and should not be retried. - if instance.Status.Conditions != nil { - deploymentCondition := instance.Status.Conditions.Get(condition.DeploymentReadyCondition) - if deploymentCondition != nil && - deploymentCondition.Severity == condition.SeverityError && - deploymentCondition.Reason == condition.JobReasonBackoffLimitExceeded { - Log.Info("Deployment has failed with backoff limit exceeded, skipping reconciliation", - "deployment", instance.Name) - return ctrl.Result{}, nil - } + if terminalFailure(instance) { + Log.Info("Deployment is terminal, skipping reconciliation", + "deployment", instance.Name) + return ctrl.Result{}, nil } // initialize status if Conditions is nil, but do not reset if it already @@ -255,7 +247,10 @@ func (r *OpenStackDataPlaneDeploymentReconciler) Reconcile(ctx context.Context, haveError := false deploymentErrMsg := "" var servicePlan *deployment.ServicePlan - backoffLimitReached := false + var finishedNodeSets []dataplanev1.OpenStackDataPlaneNodeSet + if instance.Status.FailedNodeSets == nil { + instance.Status.FailedNodeSets = map[string]string{} + } if servicePlan, err = deployment.DedupeServices(ctx, helper, nodeSets.Items, instance.Spec.ServicesOverride); err != nil { @@ -383,6 +378,21 @@ func (r *OpenStackDataPlaneDeploymentReconciler) Reconcile(ctx context.Context, for i := range nodeSets.Items { nodeSet := &nodeSets.Items[i] + if failure, ok := instance.Status.FailedNodeSets[nodeSet.Name]; ok { + Log.Info("NodeSet already terminated by a permanent failure", "nodeSet", nodeSet.Name) + nsConditions := instance.Status.NodeSetConditions[nodeSet.Name] + nsConditions.MarkFalse( + dataplanev1.NodeSetDeploymentReadyCondition, + condition.JobReasonBackoffLimitExceeded, + condition.SeverityError, + "%s", failure) + instance.Status.NodeSetConditions[nodeSet.Name] = nsConditions + haveError = true + deploymentErrMsg = appendDeploymentErrMsg(deploymentErrMsg, + fmt.Sprintf("nodeSet: %s error: %s", nodeSet.Name, failure)) + continue + } + Log.Info("Deploying NodeSet", "nodeSet", nodeSet.Name) Log.Info("Set Status.Deployed to false", "instance", instance) instance.Status.Deployed = false @@ -413,14 +423,12 @@ func (r *OpenStackDataPlaneDeploymentReconciler) Reconcile(ctx context.Context, util.LogErrorForObject(helper, err, fmt.Sprintf("OpenStackDeployment error for NodeSet %s", nodeSet.Name), instance) Log.Info("Set NodeSetDeploymentReadyCondition false", "nodeSet", nodeSet.Name) haveError = true - errMsg := fmt.Sprintf("nodeSet: %s error: %s", nodeSet.Name, err.Error()) - if len(deploymentErrMsg) == 0 { - deploymentErrMsg = errMsg - } else { - deploymentErrMsg = fmt.Sprintf("%s & %s", deploymentErrMsg, errMsg) + deploymentErrMsg = appendDeploymentErrMsg(deploymentErrMsg, + fmt.Sprintf("nodeSet: %s error: %s", nodeSet.Name, err.Error())) + if nsConditions.Get(dataplanev1.NodeSetDeploymentReadyCondition) != nil && + nsConditions.Get(dataplanev1.NodeSetDeploymentReadyCondition).Reason == condition.JobReasonBackoffLimitExceeded { + instance.Status.FailedNodeSets[nodeSet.Name] = err.Error() } - errorReason := nsConditions.Get(dataplanev1.NodeSetDeploymentReadyCondition).Reason - backoffLimitReached = errorReason == condition.JobReasonBackoffLimitExceeded } if deployResult != nil { @@ -431,16 +439,26 @@ func (r *OpenStackDataPlaneDeploymentReconciler) Reconcile(ctx context.Context, nsConditions.MarkTrue( dataplanev1.NodeSetDeploymentReadyCondition, condition.DeploymentReadyMessage) - instance.Status.NodeSetHashes[nodeSet.Name] = nodeSet.Status.ConfigHash - instance.Status.BmhRefHashes[nodeSet.Name] = nodeSet.Status.BmhRefHash + finishedNodeSets = append(finishedNodeSets, *nodeSet) + } + } + + // A nodeSet that finished alongside a failure must still get its hashes, or the + // NodeSet controller re-deploys it because its inputs look changed. + if len(finishedNodeSets) > 0 { + err = r.setHashes(ctx, helper, instance, + dataplanev1.OpenStackDataPlaneNodeSetList{Items: finishedNodeSets}) + if err != nil { + return ctrl.Result{}, err } } if haveError { + settled := terminalFailure(instance) var reason condition.Reason reason = condition.ErrorReason severity := condition.SeverityWarning - if backoffLimitReached { + if settled { reason = condition.JobReasonBackoffLimitExceeded severity = condition.SeverityError } @@ -450,7 +468,7 @@ func (r *OpenStackDataPlaneDeploymentReconciler) Reconcile(ctx context.Context, severity, condition.DeploymentReadyErrorMessage, deploymentErrMsg) - if backoffLimitReached { + if settled { return ctrl.Result{}, nil } return ctrl.Result{}, fmt.Errorf("%s", deploymentErrMsg) @@ -468,10 +486,6 @@ func (r *OpenStackDataPlaneDeploymentReconciler) Reconcile(ctx context.Context, if version != nil { instance.Status.DeployedVersion = version.Spec.TargetVersion } - err = r.setHashes(ctx, helper, instance, *nodeSets) - if err != nil { - Log.Error(err, "Error setting service hashes") - } return ctrl.Result{}, nil } @@ -600,14 +614,19 @@ func (r *OpenStackDataPlaneDeploymentReconciler) setHashes( } for _, nodeSet := range nodeSets.Items { - instance.Status.NodeSetHashes[nodeSet.Name] = nodeSet.Status.ConfigHash - err = setNodeSetAnsibleVarsFromHashes(ctx, helper, &nodeSet, instance.Status.ConfigMapHashes, instance.Status.SecretHashes) if err != nil { return err } } + // Split from the loop above: terminalFailure reads a NodeSetHashes entry as proof + // the nodeSet's input hashes are recorded, so nothing above may fail after it. + for _, nodeSet := range nodeSets.Items { + instance.Status.NodeSetHashes[nodeSet.Name] = nodeSet.Status.ConfigHash + instance.Status.BmhRefHashes[nodeSet.Name] = nodeSet.Status.BmhRefHash + } + return nil } @@ -703,6 +722,39 @@ func (r *OpenStackDataPlaneDeploymentReconciler) listNodeSets(ctx context.Contex return &nodeSets, err } +// terminalFailure reports whether the deployment has a permanently failed +// nodeSet and nothing left to wait for. A nodeSet still in flight keeps this +// false even when another one already failed. Deployments that failed before +// FailedNodeSets existed carry the failure only on the top-level condition, so +// honor it as well: their backing jobs are garbage collected and must not be +// recreated. +func terminalFailure(instance *dataplanev1.OpenStackDataPlaneDeployment) bool { + if c := instance.Status.Conditions.Get(condition.DeploymentReadyCondition); c != nil && + c.Severity == condition.SeverityError && + c.Reason == condition.JobReasonBackoffLimitExceeded { + return true + } + if len(instance.Spec.NodeSets) == 0 || len(instance.Status.FailedNodeSets) == 0 { + return false + } + for _, nodeSet := range instance.Spec.NodeSets { + if _, failed := instance.Status.FailedNodeSets[nodeSet]; failed { + continue + } + if _, done := instance.Status.NodeSetHashes[nodeSet]; !done { + return false + } + } + return true +} + +func appendDeploymentErrMsg(current string, errMsg string) string { + if len(current) == 0 { + return errMsg + } + return fmt.Sprintf("%s & %s", current, errMsg) +} + func setNodeSetAnsibleVarsFromHashes( ctx context.Context, helper *helper.Helper, diff --git a/test/functional/dataplane/openstackdataplanedeployment_controller_test.go b/test/functional/dataplane/openstackdataplanedeployment_controller_test.go index 18a23eef15..ab0862670c 100644 --- a/test/functional/dataplane/openstackdataplanedeployment_controller_test.go +++ b/test/functional/dataplane/openstackdataplanedeployment_controller_test.go @@ -20,6 +20,7 @@ import ( "k8s.io/apimachinery/pkg/types" "k8s.io/utils/ptr" + "sigs.k8s.io/controller-runtime/pkg/client" ) var _ = Describe("Dataplane Deployment Test", func() { @@ -508,6 +509,195 @@ var _ = Describe("Dataplane Deployment Test", func() { }) }) + When("A dataplaneDeployment has two NodeSets and a service job permanently fails", func() { + var alphaNodeSetName types.NamespacedName + var betaNodeSetName types.NamespacedName + var alphaNodeName types.NamespacedName + var betaNodeName types.NamespacedName + var dataSourceSecretName types.NamespacedName + + nodeSetSpec := func(nodeName types.NamespacedName, ansibleVarsFrom []interface{}) map[string]interface{} { + ansible := map[string]interface{}{"ansibleUser": "cloud-user"} + if ansibleVarsFrom != nil { + ansible["ansibleVarsFrom"] = ansibleVarsFrom + } + return map[string]interface{}{ + "preProvisioned": false, + "services": []string{"foo-service"}, + "nodeTemplate": map[string]interface{}{ + "ansibleSSHPrivateKeySecret": "dataplane-ansible-ssh-private-key-secret", + "ansible": ansible, + }, + "nodes": map[string]interface{}{ + nodeName.Name: map[string]interface{}{ + "hostname": nodeName.Name, + "networks": []map[string]interface{}{{ + "name": "CtlPlane", + "subnetName": "subnet1", + }, + }, + }, + }, + "baremetalSetTemplate": map[string]interface{}{ + "baremetalHosts": map[string]interface{}{"ctlPlaneIP": map[string]interface{}{}}, + "deploymentSSHSecret": "dataplane-ansible-ssh-private-key-secret", + "ctlplaneInterface": "172.20.12.1", + }, + "tlsEnabled": true, + } + } + + jobName := func(nodeSetName types.NamespacedName) types.NamespacedName { + name, _ := dataplaneutil.GetAnsibleExecutionNameAndLabels( + GetService(dataplaneServiceName), dataplaneDeploymentName.Name, nodeSetName.Name) + return types.NamespacedName{Name: name, Namespace: namespace} + } + + failJob := func(nodeSetName types.NamespacedName, withJobFailedCondition bool) { + Eventually(func(g Gomega) { + job := GetAnsibleee(jobName(nodeSetName)) + job.Status.StartTime = ptr.To(metav1.Now()) + job.Status.Failed = DefaultBackoffLimit + 1 + if withJobFailedCondition { + job.Status.Conditions = []batchv1.JobCondition{ + { + Type: batchv1.JobFailureTarget, + Status: corev1.ConditionTrue, + Reason: "BackoffLimitExceeded", + Message: "simulated backoff limit exceeded", + }, + { + Type: batchv1.JobFailed, + Status: corev1.ConditionTrue, + Reason: string(condition.JobReasonBackoffLimitExceeded), + Message: "simulated backoff limit exceeded", + }, + } + } + g.Expect(th.K8sClient.Status().Update(th.Ctx, job)).To(Succeed()) + }, th.Timeout, th.Interval).Should(Succeed()) + } + + succeedJob := func(nodeSetName types.NamespacedName) { + Eventually(func(g Gomega) { + job := GetAnsibleee(jobName(nodeSetName)) + job.Status.Succeeded = 1 + g.Expect(th.K8sClient.Status().Update(th.Ctx, job)).To(Succeed()) + }, th.Timeout, th.Interval).Should(Succeed()) + } + + nodeSetCondition := func(deployment *dataplanev1.OpenStackDataPlaneDeployment, name string) *condition.Condition { + nsConditions := deployment.Status.NodeSetConditions[name] + return nsConditions.Get(dataplanev1.NodeSetDeploymentReadyCondition) + } + + BeforeEach(func() { + CreateSSHSecret(dataplaneSSHSecretName) + CreateCABundleSecret(caBundleSecretName) + + alphaNodeSetName = types.NamespacedName{Name: "alpha-nodeset", Namespace: namespace} + betaNodeSetName = types.NamespacedName{Name: "beta-nodeset", Namespace: namespace} + alphaNodeName = types.NamespacedName{Name: "alpha-nodeset-node-1", Namespace: namespace} + betaNodeName = types.NamespacedName{Name: "beta-nodeset-node-1", Namespace: namespace} + dataSourceSecretName = types.NamespacedName{Name: "beta-datasource", Namespace: namespace} + + CreateDataplaneService(dataplaneServiceName, false) + DeferCleanup(th.DeleteService, dataplaneServiceName) + + DeferCleanup(th.DeleteInstance, CreateNetConfig(dataplaneNetConfigName, DefaultNetConfigSpec())) + DeferCleanup(th.DeleteInstance, CreateDNSMasq(dnsMasqName, DefaultDNSMasqSpec())) + SimulateDNSMasqComplete(dnsMasqName) + + DeferCleanup(th.DeleteInstance, th.CreateSecret(dataSourceSecretName, map[string][]byte{ + "fake_keys": []byte("blih"), + })) + + DeferCleanup(th.DeleteInstance, CreateDataplaneNodeSet(alphaNodeSetName, nodeSetSpec(alphaNodeName, nil))) + DeferCleanup(th.DeleteInstance, CreateDataplaneNodeSet(betaNodeSetName, nodeSetSpec(betaNodeName, []interface{}{ + map[string]interface{}{"secretRef": map[string]interface{}{"name": dataSourceSecretName.Name}}, + }))) + + SimulateIPSetComplete(alphaNodeName) + SimulateIPSetComplete(betaNodeName) + SimulateDNSDataComplete(alphaNodeSetName) + SimulateDNSDataComplete(betaNodeSetName) + + Eventually(func(g Gomega) { + // OpenStackBaremetalSet has the same name as OpenStackDataPlaneNodeSet + for _, name := range []types.NamespacedName{alphaNodeSetName, betaNodeSetName} { + baremetalSet := baremetalv1.OpenStackBaremetalSet{} + g.Expect(th.K8sClient.Get(th.Ctx, name, &baremetalSet)).To(Succeed()) + baremetalSet.Status.Conditions.MarkTrue(condition.ReadyCondition, condition.ReadyMessage) + g.Expect(th.K8sClient.Status().Update(th.Ctx, &baremetalSet)).To(Succeed()) + } + }, th.Timeout, th.Interval).Should(Succeed()) + + DeferCleanup(th.DeleteInstance, CreateDataplaneDeployment(dataplaneDeploymentName, map[string]interface{}{ + "nodeSets": []string{alphaNodeSetName.Name, betaNodeSetName.Name}, + })) + }) + + It("should complete the healthy nodeSet and terminate only the failed one", func() { + failJob(alphaNodeSetName, true) + + Eventually(func(g Gomega) { + deployment := GetDataplaneDeployment(dataplaneDeploymentName) + g.Expect(deployment.Status.FailedNodeSets).To(HaveKey(alphaNodeSetName.Name)) + // beta is still in flight, so the deployment is not settled yet + deploymentCondition := deployment.Status.Conditions.Get(condition.DeploymentReadyCondition) + g.Expect(deploymentCondition).ToNot(BeNil()) + g.Expect(string(deploymentCondition.Severity)).To(Equal(string(condition.SeverityWarning))) + }, th.Timeout, th.Interval).Should(Succeed()) + + succeedJob(betaNodeSetName) + + Eventually(func(g Gomega) { + deployment := GetDataplaneDeployment(dataplaneDeploymentName) + deploymentCondition := deployment.Status.Conditions.Get(condition.DeploymentReadyCondition) + g.Expect(deploymentCondition).ToNot(BeNil()) + g.Expect(deploymentCondition.Status).To(Equal(corev1.ConditionFalse)) + g.Expect(string(deploymentCondition.Reason)).To(Equal(string(condition.JobReasonBackoffLimitExceeded))) + g.Expect(string(deploymentCondition.Severity)).To(Equal(string(condition.SeverityError))) + g.Expect(deployment.Status.Deployed).To(BeFalse()) + }, th.Timeout, th.Interval).Should(Succeed()) + + deployment := GetDataplaneDeployment(dataplaneDeploymentName) + Expect(nodeSetCondition(deployment, alphaNodeSetName.Name)).ToNot(BeNil()) + Expect(string(nodeSetCondition(deployment, alphaNodeSetName.Name).Reason)).To(Equal(string(condition.JobReasonBackoffLimitExceeded))) + Expect(nodeSetCondition(deployment, betaNodeSetName.Name)).ToNot(BeNil()) + Expect(nodeSetCondition(deployment, betaNodeSetName.Name).Status).To(Equal(corev1.ConditionTrue)) + + Expect(deployment.Status.NodeSetHashes).To(HaveKeyWithValue(betaNodeSetName.Name, GetDataplaneNodeSet(betaNodeSetName).Status.ConfigHash)) + Expect(deployment.Status.NodeSetHashes).ToNot(HaveKey(alphaNodeSetName.Name)) + Expect(deployment.Status.SecretHashes).To(HaveKey(dataSourceSecretName.Name)) + }) + + It("should not treat a failure without a JobFailed condition as terminal", func() { + failJob(alphaNodeSetName, false) + failJob(betaNodeSetName, false) + + Eventually(func(g Gomega) { + deployment := GetDataplaneDeployment(dataplaneDeploymentName) + g.Expect(deployment.Status.FailedNodeSets).To(BeEmpty()) + deploymentCondition := deployment.Status.Conditions.Get(condition.DeploymentReadyCondition) + g.Expect(deploymentCondition).ToNot(BeNil()) + g.Expect(string(deploymentCondition.Reason)).To(Equal(string(condition.ErrorReason))) + g.Expect(string(deploymentCondition.Severity)).To(Equal(string(condition.SeverityWarning))) + g.Expect(deployment.Status.Deployed).To(BeFalse()) + }, th.Timeout, th.Interval).Should(Succeed()) + + Consistently(func(g Gomega) { + deployment := GetDataplaneDeployment(dataplaneDeploymentName) + g.Expect(deployment.Status.FailedNodeSets).To(BeEmpty()) + deploymentCondition := deployment.Status.Conditions.Get(condition.DeploymentReadyCondition) + g.Expect(deploymentCondition).ToNot(BeNil()) + g.Expect(string(deploymentCondition.Reason)).To(Equal(string(condition.ErrorReason))) + g.Expect(string(deploymentCondition.Severity)).To(Equal(string(condition.SeverityWarning))) + g.Expect(deployment.Status.Deployed).To(BeFalse()) + }, "5s", "1s").Should(Succeed()) + }) + }) + When("A dataplaneDeployment is created with a missing nodeset", func() { BeforeEach(func() { CreateSSHSecret(dataplaneSSHSecretName) @@ -1828,6 +2018,10 @@ var _ = Describe("Dataplane Deployment Test", func() { condition.DeploymentReadyErrorMessage, "Simulated backoff limit exceeded for testing") + deployment.Status.FailedNodeSets = map[string]string{ + dataplaneNodeSetName.Name: "Simulated backoff limit exceeded for testing", + } + deployment.Status.Deployed = false g.Expect(th.K8sClient.Status().Update(th.Ctx, deployment)).To(Succeed()) @@ -1892,6 +2086,74 @@ var _ = Describe("Dataplane Deployment Test", func() { corev1.ConditionFalse, ) }) + + It("should not re-deploy a pre-existing failed deployment that has no FailedNodeSets", func() { + // This deployment predates FailedNodeSets, so its terminal status is set manually. + Eventually(func(g Gomega) { + deployment := GetDataplaneDeployment(dataplaneDeploymentName) + g.Expect(deployment.Status.ObservedGeneration).To(Equal(deployment.Generation)) + }, th.Timeout, th.Interval).Should(Succeed()) + + Eventually(func(g Gomega) { + deployment := GetDataplaneDeployment(dataplaneDeploymentName) + if deployment.Status.NodeSetConditions == nil { + deployment.Status.NodeSetConditions = make(map[string]condition.Conditions) + } + deployment.Status.Conditions.MarkFalse( + condition.DeploymentReadyCondition, + condition.JobReasonBackoffLimitExceeded, + condition.SeverityError, + condition.DeploymentReadyErrorMessage, + "Simulated backoff limit exceeded for testing") + deployment.Status.FailedNodeSets = nil + deployment.Status.Deployed = false + g.Expect(th.K8sClient.Status().Update(th.Ctx, deployment)).To(Succeed()) + }, th.Timeout, th.Interval).Should(Succeed()) + + deployment := GetDataplaneDeployment(dataplaneDeploymentName) + originalGeneration := deployment.Status.ObservedGeneration + deploymentCondition := deployment.Status.Conditions.Get(condition.DeploymentReadyCondition) + Expect(deploymentCondition).ToNot(BeNil()) + originalTransitionTime := deploymentCondition.LastTransitionTime + + // Simulate TTL garbage collection of the AEE jobs. + Eventually(func(g Gomega) { + jobList := &batchv1.JobList{} + g.Expect(th.K8sClient.List(th.Ctx, jobList, + client.InNamespace(namespace), + client.MatchingLabels{"openstackdataplanenodeset": dataplaneNodeSetName.Name})).To(Succeed()) + for i := range jobList.Items { + g.Expect(th.K8sClient.Delete(th.Ctx, &jobList.Items[i])).To(Succeed()) + } + }, th.Timeout, th.Interval).Should(Succeed()) + + Eventually(func(g Gomega) { + deployment := GetDataplaneDeployment(dataplaneDeploymentName) + if deployment.Annotations == nil { + deployment.Annotations = make(map[string]string) + } + deployment.Annotations["test-annotation"] = "trigger-reconcile" + g.Expect(th.K8sClient.Update(th.Ctx, deployment)).To(Succeed()) + }, th.Timeout, th.Interval).Should(Succeed()) + + Consistently(func(g Gomega) { + deployment := GetDataplaneDeployment(dataplaneDeploymentName) + g.Expect(deployment.Status.ObservedGeneration).To(Equal(originalGeneration)) + g.Expect(deployment.Status.FailedNodeSets).To(BeEmpty()) + g.Expect(deployment.Status.Deployed).To(BeFalse()) + c := deployment.Status.Conditions.Get(condition.DeploymentReadyCondition) + g.Expect(c).ToNot(BeNil()) + g.Expect(string(c.Severity)).To(Equal(string(condition.SeverityError))) + g.Expect(string(c.Reason)).To(Equal(string(condition.JobReasonBackoffLimitExceeded))) + g.Expect(c.LastTransitionTime).To(Equal(originalTransitionTime)) + + jobList := &batchv1.JobList{} + g.Expect(th.K8sClient.List(th.Ctx, jobList, + client.InNamespace(namespace), + client.MatchingLabels{"openstackdataplanenodeset": dataplaneNodeSetName.Name})).To(Succeed()) + g.Expect(jobList.Items).To(BeEmpty()) + }, "5s", "1s").Should(Succeed()) + }) }) When("A dataplaneDeployment is created with useParallelExecution true and services with dependsOn", func() { @@ -2161,6 +2423,89 @@ var _ = Describe("Dataplane Deployment Test", func() { }) }) + When("A deployment scoped service job exceeds its backoff limit", func() { + var gfailDeploymentName types.NamespacedName + var gfailAlphaName types.NamespacedName + var gfailBetaName types.NamespacedName + + BeforeEach(func() { + gfailDeploymentName = types.NamespacedName{Name: "global-fail-deployment", Namespace: namespace} + gfailAlphaName = types.NamespacedName{Name: "global-fail-alpha", Namespace: namespace} + gfailBetaName = types.NamespacedName{Name: "global-fail-beta", Namespace: namespace} + CreateSSHSecret(dataplaneSSHSecretName) + CreateCABundleSecret(caBundleSecretName) + + DeferCleanup(th.DeleteInstance, CreateDataPlaneServiceFromSpec( + types.NamespacedName{Name: "svc-global-fail", Namespace: namespace}, + map[string]interface{}{"edpmServiceType": "svc-global-fail", "deployOnAllNodeSets": true})) + + DeferCleanup(th.DeleteInstance, CreateNetConfig(dataplaneNetConfigName, DefaultNetConfigSpec())) + DeferCleanup(th.DeleteInstance, CreateDNSMasq(dnsMasqName, DefaultDNSMasqSpec())) + SimulateDNSMasqComplete(dnsMasqName) + + for idx, nodeSetName := range []types.NamespacedName{gfailAlphaName, gfailBetaName} { + DeferCleanup(th.DeleteInstance, CreateDataplaneNodeSet( + nodeSetName, BarrierNodeSetSpec(nodeSetName.Name, []string{"svc-global-fail"}, + fmt.Sprintf("192.168.122.%d", 110+idx)))) + SimulateIPSetComplete(types.NamespacedName{ + Name: fmt.Sprintf("%s-node-1", nodeSetName.Name), Namespace: namespace}) + SimulateDNSDataComplete(nodeSetName) + } + + DeferCleanup(th.DeleteInstance, CreateDataplaneDeployment(gfailDeploymentName, + map[string]interface{}{ + "nodeSets": []string{gfailAlphaName.Name, gfailBetaName.Name}, + })) + }) + + It("should terminate every nodeset listing the deployment scoped service", func() { + globalJobName := types.NamespacedName{ + Name: fmt.Sprintf("svc-global-fail-%s", gfailDeploymentName.Name), + Namespace: namespace, + } + + Eventually(func(g Gomega) { + job := GetAnsibleee(globalJobName) + job.Status.StartTime = ptr.To(metav1.Now()) + job.Status.Failed = DefaultBackoffLimit + 1 + job.Status.Conditions = []batchv1.JobCondition{ + { + Type: batchv1.JobFailureTarget, + Status: corev1.ConditionTrue, + Reason: "BackoffLimitExceeded", + Message: "simulated backoff limit exceeded", + }, + { + Type: batchv1.JobFailed, + Status: corev1.ConditionTrue, + Reason: string(condition.JobReasonBackoffLimitExceeded), + Message: "simulated backoff limit exceeded", + }, + } + g.Expect(k8sClient.Status().Update(ctx, job)).To(Succeed()) + }, timeout, interval).Should(Succeed()) + + Eventually(func(g Gomega) { + deployment := GetDataplaneDeployment(gfailDeploymentName) + g.Expect(deployment.Status.FailedNodeSets).To(HaveKey(gfailAlphaName.Name)) + g.Expect(deployment.Status.FailedNodeSets).To(HaveKey(gfailBetaName.Name)) + g.Expect(deployment.Status.NodeSetHashes).To(BeEmpty()) + deploymentCondition := deployment.Status.Conditions.Get(condition.DeploymentReadyCondition) + g.Expect(deploymentCondition).ToNot(BeNil()) + g.Expect(deploymentCondition.Status).To(Equal(corev1.ConditionFalse)) + g.Expect(string(deploymentCondition.Reason)).To(Equal(string(condition.JobReasonBackoffLimitExceeded))) + g.Expect(string(deploymentCondition.Severity)).To(Equal(string(condition.SeverityError))) + g.Expect(deployment.Status.Deployed).To(BeFalse()) + }, timeout, interval).Should(Succeed()) + + Consistently(func(g Gomega) { + deployment := GetDataplaneDeployment(gfailDeploymentName) + g.Expect(deployment.Status.FailedNodeSets).To(HaveLen(2)) + g.Expect(deployment.Status.Deployed).To(BeFalse()) + }, "5s", interval).Should(Succeed()) + }) + }) + When("A nodeset does not list the deployment scoped service", func() { var freeDeploymentName types.NamespacedName var freeAlphaName types.NamespacedName