@@ -113,18 +113,10 @@ func (r *OpenStackDataPlaneDeploymentReconciler) Reconcile(ctx context.Context,
113113 return ctrl.Result {}, nil
114114 }
115115
116- // If the deployment has failed with backoff limit exceeded, do not reconcile
117- // even if nodesets or other watched resources change. The deployment is in a
118- // terminal failure state and should not be retried.
119- if instance .Status .Conditions != nil {
120- deploymentCondition := instance .Status .Conditions .Get (condition .DeploymentReadyCondition )
121- if deploymentCondition != nil &&
122- deploymentCondition .Severity == condition .SeverityError &&
123- deploymentCondition .Reason == condition .JobReasonBackoffLimitExceeded {
124- Log .Info ("Deployment has failed with backoff limit exceeded, skipping reconciliation" ,
125- "deployment" , instance .Name )
126- return ctrl.Result {}, nil
127- }
116+ if terminalFailure (instance ) {
117+ Log .Info ("Deployment is terminal, skipping reconciliation" ,
118+ "deployment" , instance .Name )
119+ return ctrl.Result {}, nil
128120 }
129121
130122 // initialize status if Conditions is nil, but do not reset if it already
@@ -255,7 +247,10 @@ func (r *OpenStackDataPlaneDeploymentReconciler) Reconcile(ctx context.Context,
255247 haveError := false
256248 deploymentErrMsg := ""
257249 var servicePlan * deployment.ServicePlan
258- backoffLimitReached := false
250+ var finishedNodeSets []dataplanev1.OpenStackDataPlaneNodeSet
251+ if instance .Status .FailedNodeSets == nil {
252+ instance .Status .FailedNodeSets = map [string ]string {}
253+ }
259254
260255 if servicePlan , err = deployment .DedupeServices (ctx , helper , nodeSets .Items ,
261256 instance .Spec .ServicesOverride ); err != nil {
@@ -383,6 +378,21 @@ func (r *OpenStackDataPlaneDeploymentReconciler) Reconcile(ctx context.Context,
383378 for i := range nodeSets .Items {
384379 nodeSet := & nodeSets .Items [i ]
385380
381+ if failure , ok := instance .Status .FailedNodeSets [nodeSet .Name ]; ok {
382+ Log .Info ("NodeSet already terminated by a permanent failure" , "nodeSet" , nodeSet .Name )
383+ nsConditions := instance .Status .NodeSetConditions [nodeSet .Name ]
384+ nsConditions .MarkFalse (
385+ dataplanev1 .NodeSetDeploymentReadyCondition ,
386+ condition .JobReasonBackoffLimitExceeded ,
387+ condition .SeverityError ,
388+ "%s" , failure )
389+ instance .Status .NodeSetConditions [nodeSet .Name ] = nsConditions
390+ haveError = true
391+ deploymentErrMsg = appendDeploymentErrMsg (deploymentErrMsg ,
392+ fmt .Sprintf ("nodeSet: %s error: %s" , nodeSet .Name , failure ))
393+ continue
394+ }
395+
386396 Log .Info ("Deploying NodeSet" , "nodeSet" , nodeSet .Name )
387397 Log .Info ("Set Status.Deployed to false" , "instance" , instance )
388398 instance .Status .Deployed = false
@@ -413,14 +423,12 @@ func (r *OpenStackDataPlaneDeploymentReconciler) Reconcile(ctx context.Context,
413423 util .LogErrorForObject (helper , err , fmt .Sprintf ("OpenStackDeployment error for NodeSet %s" , nodeSet .Name ), instance )
414424 Log .Info ("Set NodeSetDeploymentReadyCondition false" , "nodeSet" , nodeSet .Name )
415425 haveError = true
416- errMsg := fmt . Sprintf ( "nodeSet: %s error: %s" , nodeSet . Name , err . Error ())
417- if len ( deploymentErrMsg ) == 0 {
418- deploymentErrMsg = errMsg
419- } else {
420- deploymentErrMsg = fmt . Sprintf ( "%s & %s" , deploymentErrMsg , errMsg )
426+ deploymentErrMsg = appendDeploymentErrMsg ( deploymentErrMsg ,
427+ fmt . Sprintf ( "nodeSet: %s error: %s" , nodeSet . Name , err . Error ()))
428+ if nsConditions . Get ( dataplanev1 . NodeSetDeploymentReadyCondition ) != nil &&
429+ nsConditions . Get ( dataplanev1 . NodeSetDeploymentReadyCondition ). Reason == condition . JobReasonBackoffLimitExceeded {
430+ instance . Status . FailedNodeSets [ nodeSet . Name ] = err . Error ( )
421431 }
422- errorReason := nsConditions .Get (dataplanev1 .NodeSetDeploymentReadyCondition ).Reason
423- backoffLimitReached = errorReason == condition .JobReasonBackoffLimitExceeded
424432 }
425433
426434 if deployResult != nil {
@@ -433,14 +441,26 @@ func (r *OpenStackDataPlaneDeploymentReconciler) Reconcile(ctx context.Context,
433441 condition .DeploymentReadyMessage )
434442 instance .Status .NodeSetHashes [nodeSet .Name ] = nodeSet .Status .ConfigHash
435443 instance .Status .BmhRefHashes [nodeSet .Name ] = nodeSet .Status .BmhRefHash
444+ finishedNodeSets = append (finishedNodeSets , * nodeSet )
445+ }
446+ }
447+
448+ // A nodeSet that finished alongside a failure must still get its hashes, or the
449+ // NodeSet controller re-deploys it because its inputs look changed.
450+ if len (finishedNodeSets ) > 0 {
451+ err = r .setHashes (ctx , helper , instance ,
452+ dataplanev1.OpenStackDataPlaneNodeSetList {Items : finishedNodeSets })
453+ if err != nil {
454+ Log .Error (err , "Error setting service hashes" )
436455 }
437456 }
438457
439458 if haveError {
459+ settled := terminalFailure (instance )
440460 var reason condition.Reason
441461 reason = condition .ErrorReason
442462 severity := condition .SeverityWarning
443- if backoffLimitReached {
463+ if settled {
444464 reason = condition .JobReasonBackoffLimitExceeded
445465 severity = condition .SeverityError
446466 }
@@ -450,7 +470,7 @@ func (r *OpenStackDataPlaneDeploymentReconciler) Reconcile(ctx context.Context,
450470 severity ,
451471 condition .DeploymentReadyErrorMessage ,
452472 deploymentErrMsg )
453- if backoffLimitReached {
473+ if settled {
454474 return ctrl.Result {}, nil
455475 }
456476 return ctrl.Result {}, fmt .Errorf ("%s" , deploymentErrMsg )
@@ -468,10 +488,6 @@ func (r *OpenStackDataPlaneDeploymentReconciler) Reconcile(ctx context.Context,
468488 if version != nil {
469489 instance .Status .DeployedVersion = version .Spec .TargetVersion
470490 }
471- err = r .setHashes (ctx , helper , instance , * nodeSets )
472- if err != nil {
473- Log .Error (err , "Error setting service hashes" )
474- }
475491 return ctrl.Result {}, nil
476492}
477493
@@ -703,6 +719,39 @@ func (r *OpenStackDataPlaneDeploymentReconciler) listNodeSets(ctx context.Contex
703719 return & nodeSets , err
704720}
705721
722+ // terminalFailure reports whether the deployment has a permanently failed
723+ // nodeSet and nothing left to wait for. A nodeSet still in flight keeps this
724+ // false even when another one already failed. Deployments that failed before
725+ // FailedNodeSets existed carry the failure only on the top-level condition, so
726+ // honor it as well: their backing jobs are garbage collected and must not be
727+ // recreated.
728+ func terminalFailure (instance * dataplanev1.OpenStackDataPlaneDeployment ) bool {
729+ if c := instance .Status .Conditions .Get (condition .DeploymentReadyCondition ); c != nil &&
730+ c .Severity == condition .SeverityError &&
731+ c .Reason == condition .JobReasonBackoffLimitExceeded {
732+ return true
733+ }
734+ if len (instance .Spec .NodeSets ) == 0 || len (instance .Status .FailedNodeSets ) == 0 {
735+ return false
736+ }
737+ for _ , nodeSet := range instance .Spec .NodeSets {
738+ if _ , failed := instance .Status .FailedNodeSets [nodeSet ]; failed {
739+ continue
740+ }
741+ if _ , done := instance .Status .NodeSetHashes [nodeSet ]; ! done {
742+ return false
743+ }
744+ }
745+ return true
746+ }
747+
748+ func appendDeploymentErrMsg (current string , errMsg string ) string {
749+ if len (current ) == 0 {
750+ return errMsg
751+ }
752+ return fmt .Sprintf ("%s & %s" , current , errMsg )
753+ }
754+
706755func setNodeSetAnsibleVarsFromHashes (
707756 ctx context.Context ,
708757 helper * helper.Helper ,
0 commit comments