@@ -489,95 +489,115 @@ func checkDeployment(ctx context.Context, helper *helper.Helper,
489489 return isDeploymentReady , isDeploymentRunning , isDeploymentFailed , failedDeploymentName , err
490490 }
491491
492- // Sort deployments from oldest to newest by the LastTransitionTime of
493- // their DeploymentReadyCondition
494- slices .SortFunc (deployments .Items , func (a , b dataplanev1.OpenStackDataPlaneDeployment ) int {
495- aReady := a .Status .Conditions .Get (condition .DeploymentReadyCondition )
496- bReady := b .Status .Conditions .Get (condition .DeploymentReadyCondition )
497- if aReady != nil && bReady != nil {
498- if aReady .LastTransitionTime .Before (& bReady .LastTransitionTime ) {
499- return - 1
492+ // Collect deployments that target this nodeset (excluding deleted ones)
493+ var relevantDeployments []* dataplanev1.OpenStackDataPlaneDeployment
494+ for i := range deployments .Items {
495+ deployment := & deployments .Items [i ]
496+ if ! deployment .DeletionTimestamp .IsZero () {
497+ continue
498+ }
499+ if slices .Contains (deployment .Spec .NodeSets , instance .Name ) {
500+ relevantDeployments = append (relevantDeployments , deployment )
501+ }
502+ }
503+
504+ // Sort relevant deployments from oldest to newest, then take the last one
505+ var latestRelevantDeployment * dataplanev1.OpenStackDataPlaneDeployment
506+ if len (relevantDeployments ) > 0 {
507+ slices .SortFunc (relevantDeployments , func (a , b * dataplanev1.OpenStackDataPlaneDeployment ) int {
508+ aReady := a .Status .Conditions .Get (condition .DeploymentReadyCondition )
509+ bReady := b .Status .Conditions .Get (condition .DeploymentReadyCondition )
510+ if aReady != nil && bReady != nil {
511+ if aReady .LastTransitionTime .Before (& bReady .LastTransitionTime ) {
512+ return - 1
513+ }
500514 }
515+ return 1
516+ })
517+ latestRelevantDeployment = relevantDeployments [len (relevantDeployments )- 1 ]
518+ }
519+
520+ for _ , deployment := range relevantDeployments {
521+ // Always add to DeploymentStatuses (for visibility)
522+ deploymentConditions := deployment .Status .NodeSetConditions [instance .Name ]
523+ if instance .Status .DeploymentStatuses == nil {
524+ instance .Status .DeploymentStatuses = make (map [string ]condition.Conditions )
501525 }
502- return 1
503- })
526+ instance .Status .DeploymentStatuses [deployment .Name ] = deploymentConditions
504527
505- for _ , deployment := range deployments .Items {
506- if ! deployment .DeletionTimestamp .IsZero () {
528+ // Apply filtering for overall nodeset deployment state logic
529+ isLatestDeployment := latestRelevantDeployment != nil && deployment .Name == latestRelevantDeployment .Name
530+ deploymentCondition := deploymentConditions .Get (dataplanev1 .NodeSetDeploymentReadyCondition )
531+ isRunningDeployment := deploymentConditions .IsFalse (dataplanev1 .NodeSetDeploymentReadyCondition ) && ! condition .IsError (deploymentCondition )
532+
533+ // Skip processing for overall nodeset state if not running AND not latest
534+ // (This handles both completed and failed deployments that aren't the latest)
535+ if ! isRunningDeployment && ! isLatestDeployment {
507536 continue
508537 }
509- if slices .Contains (
510- deployment .Spec .NodeSets , instance .Name ) {
511-
512- // Reset the vars for every deployment
513- isDeploymentReady = false
514- isDeploymentRunning = false
515- deploymentConditions := deployment .Status .NodeSetConditions [instance .Name ]
516- if instance .Status .DeploymentStatuses == nil {
517- instance .Status .DeploymentStatuses = make (map [string ]condition.Conditions )
538+
539+ // Reset the vars for every deployment that affects overall state
540+ isDeploymentReady = false
541+ isDeploymentRunning = false
542+ if condition .IsError (deploymentCondition ) {
543+ err = fmt .Errorf ("%s" , deploymentCondition .Message )
544+ isDeploymentFailed = true
545+ failedDeploymentName = deployment .Name
546+ break
547+ } else if deploymentConditions .IsFalse (dataplanev1 .NodeSetDeploymentReadyCondition ) {
548+ isDeploymentRunning = true
549+ } else if deploymentConditions .IsTrue (dataplanev1 .NodeSetDeploymentReadyCondition ) {
550+ // If the nodeset configHash does not match with what's in the deployment or
551+ // deployedBmhHash is different from current bmhRefHash.
552+ if (deployment .Status .NodeSetHashes [instance .Name ] != instance .Status .ConfigHash ) ||
553+ (! instance .Spec .PreProvisioned &&
554+ deployment .Status .BmhRefHashes [instance .Name ] != instance .Status .BmhRefHash ) {
555+ continue
518556 }
519- instance .Status .DeploymentStatuses [deployment .Name ] = deploymentConditions
520- deploymentCondition := deploymentConditions .Get (dataplanev1 .NodeSetDeploymentReadyCondition )
521- if condition .IsError (deploymentCondition ) {
522- err = fmt .Errorf ("%s" , deploymentCondition .Message )
523- isDeploymentFailed = true
524- failedDeploymentName = deployment .Name
525- break
526- } else if deploymentConditions .IsFalse (dataplanev1 .NodeSetDeploymentReadyCondition ) {
527- isDeploymentRunning = true
528- } else if deploymentConditions .IsTrue (dataplanev1 .NodeSetDeploymentReadyCondition ) {
529- // If the nodeset configHash does not match with what's in the deployment or
530- // deployedBmhHash is different from current bmhRefHash.
531- if (deployment .Status .NodeSetHashes [instance .Name ] != instance .Status .ConfigHash ) ||
532- (! instance .Spec .PreProvisioned &&
533- deployment .Status .BmhRefHashes [instance .Name ] != instance .Status .BmhRefHash ) {
534- continue
535- }
536- isDeploymentReady = true
537- for k , v := range deployment .Status .ConfigMapHashes {
538- instance .Status .ConfigMapHashes [k ] = v
539- }
540- for k , v := range deployment .Status .SecretHashes {
541- instance .Status .SecretHashes [k ] = v
542- }
543- for k , v := range deployment .Status .ContainerImages {
544- instance .Status .ContainerImages [k ] = v
557+ isDeploymentReady = true
558+ for k , v := range deployment .Status .ConfigMapHashes {
559+ instance .Status .ConfigMapHashes [k ] = v
560+ }
561+ for k , v := range deployment .Status .SecretHashes {
562+ instance .Status .SecretHashes [k ] = v
563+ }
564+ for k , v := range deployment .Status .ContainerImages {
565+ instance .Status .ContainerImages [k ] = v
566+ }
567+ instance .Status .DeployedConfigHash = deployment .Status .NodeSetHashes [instance .Name ]
568+
569+ // Get list of services by name, either from ServicesOverride or
570+ // the NodeSet.
571+ var services []string
572+ if len (deployment .Spec .ServicesOverride ) != 0 {
573+ services = deployment .Spec .ServicesOverride
574+ } else {
575+ services = instance .Spec .Services
576+ }
577+
578+ // For each service, check if EDPMServiceType is "update" or "update-services", and
579+ // if so, copy Deployment.Status.DeployedVersion to
580+ // NodeSet.Status.DeployedVersion
581+ for _ , serviceName := range services {
582+ service := & dataplanev1.OpenStackDataPlaneService {}
583+ name := types.NamespacedName {
584+ Namespace : instance .Namespace ,
585+ Name : serviceName ,
545586 }
546- instance .Status .DeployedConfigHash = deployment .Status .NodeSetHashes [instance .Name ]
547-
548- // Get list of services by name, either from ServicesOverride or
549- // the NodeSet.
550- var services []string
551- if len (deployment .Spec .ServicesOverride ) != 0 {
552- services = deployment .Spec .ServicesOverride
553- } else {
554- services = instance .Spec .Services
587+ err := helper .GetClient ().Get (ctx , name , service )
588+ if err != nil {
589+ helper .GetLogger ().Error (err , "Unable to retrieve OpenStackDataPlaneService %v" )
590+ return isDeploymentReady , isDeploymentRunning , isDeploymentFailed , failedDeploymentName , err
555591 }
556592
557- // For each service, check if EDPMServiceType is "update" or "update-services", and
558- // if so, copy Deployment.Status.DeployedVersion to
559- // NodeSet.Status.DeployedVersion
560- for _ , serviceName := range services {
561- service := & dataplanev1.OpenStackDataPlaneService {}
562- name := types.NamespacedName {
563- Namespace : instance .Namespace ,
564- Name : serviceName ,
565- }
566- err := helper .GetClient ().Get (ctx , name , service )
567- if err != nil {
568- helper .GetLogger ().Error (err , "Unable to retrieve OpenStackDataPlaneService %v" )
569- return isDeploymentReady , isDeploymentRunning , isDeploymentFailed , failedDeploymentName , err
570- }
571-
572- if service .Spec .EDPMServiceType != "update" && service .Spec .EDPMServiceType != "update-services" {
573- continue
574- }
575-
576- // An "update" or "update-services" service Deployment has been completed, so
577- // set the NodeSet's DeployedVersion to the Deployment's
578- // DeployedVersion.
579- instance .Status .DeployedVersion = deployment .Status .DeployedVersion
593+ if service .Spec .EDPMServiceType != "update" && service .Spec .EDPMServiceType != "update-services" {
594+ continue
580595 }
596+
597+ // An "update" or "update-services" service Deployment has been completed, so
598+ // set the NodeSet's DeployedVersion to the Deployment's
599+ // DeployedVersion.
600+ instance .Status .DeployedVersion = deployment .Status .DeployedVersion
581601 }
582602 }
583603 }
0 commit comments