Skip to content

Commit e7a4aaa

Browse files
Merge pull request #2061 from rabi/fix_failure
Improve logic to fix functional tests
2 parents cbd102e + 5c6294b commit e7a4aaa

2 files changed

Lines changed: 63 additions & 28 deletions

File tree

‎api/dataplane/v1beta1/openstackdataplanedeployment_types.go‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ import (
2323
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2424
)
2525

26+
// DefaultDeploymentRequeueTime is the default requeue interval in seconds
27+
// for spec.deploymentRequeueTime (+kubebuilder:default:=15)
28+
const DefaultDeploymentRequeueTime = 15
29+
2630
// OpenStackDataPlaneDeploymentSpec defines the desired state of OpenStackDataPlaneDeployment
2731
type OpenStackDataPlaneDeploymentSpec struct {
2832
// +kubebuilder:validation:Required

‎internal/controller/dataplane/openstackdataplanenodeset_controller.go‎

Lines changed: 59 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -404,8 +404,11 @@ func (r *OpenStackDataPlaneNodeSetReconciler) Reconcile(ctx context.Context, req
404404
instance.Status.BmhRefHash = provResult.BmhRefHash
405405
}
406406

407-
isDeploymentReady, isDeploymentRunning, isDeploymentFailed, failedDeployment, err := checkDeployment(
408-
ctx, helper, instance)
407+
deploymentStatus, err := checkDeployment(ctx, helper, instance)
408+
isDeploymentReady := deploymentStatus.ready
409+
isDeploymentRunning := deploymentStatus.running
410+
isDeploymentFailed := deploymentStatus.failed
411+
failedDeployment := deploymentStatus.failedName
409412
if !isDeploymentFailed && err != nil {
410413
instance.Status.Conditions.MarkFalse(
411414
condition.DeploymentReadyCondition,
@@ -486,23 +489,35 @@ func (r *OpenStackDataPlaneNodeSetReconciler) Reconcile(ctx context.Context, req
486489
"%s", deployErrorMsg)
487490
}
488491

492+
// Watch events can be coalesced; requeue so a stale "running" verdict self-heals.
493+
if isDeploymentRunning {
494+
return ctrl.Result{RequeueAfter: time.Second * time.Duration(deploymentStatus.requeueTime)}, nil
495+
}
496+
489497
return ctrl.Result{}, err
490498
}
491499

500+
type deploymentCheckStatus struct {
501+
ready bool
502+
running bool
503+
failed bool
504+
failedName string
505+
requeueTime int
506+
}
507+
492508
func checkDeployment(ctx context.Context, helper *helper.Helper,
493-
instance *dataplanev1.OpenStackDataPlaneNodeSet) (
494-
isNodeSetDeploymentReady bool, isNodeSetDeploymentRunning bool,
495-
isNodeSetDeploymentFailed bool, failedDeploymentName string, err error) {
509+
instance *dataplanev1.OpenStackDataPlaneNodeSet) (deploymentCheckStatus, error) {
510+
status := deploymentCheckStatus{requeueTime: dataplanev1.DefaultDeploymentRequeueTime}
496511

497512
// Get all completed deployments
498513
deployments := &dataplanev1.OpenStackDataPlaneDeploymentList{}
499514
opts := []client.ListOption{
500515
client.InNamespace(instance.Namespace),
501516
}
502-
err = helper.GetClient().List(ctx, deployments, opts...)
517+
err := helper.GetClient().List(ctx, deployments, opts...)
503518
if err != nil {
504519
helper.GetLogger().Error(err, "Unable to retrieve OpenStackDataPlaneDeployment CRs %v")
505-
return isNodeSetDeploymentReady, isNodeSetDeploymentRunning, isNodeSetDeploymentFailed, failedDeploymentName, err
520+
return status, err
506521
}
507522

508523
// Collect deployments that target this nodeset (excluding deleted ones)
@@ -517,18 +532,27 @@ func checkDeployment(ctx context.Context, helper *helper.Helper,
517532
}
518533
}
519534

520-
// Sort relevant deployments from oldest to newest, then take the last one
535+
// Sort relevant deployments from oldest to newest, then take the last one.
536+
// The latest transitioned deployment is what last acted on the node;
537+
// a missing Ready condition counts as never transitioned. Keys must
538+
// stay in a fixed sequence to preserve strict weak ordering.
521539
var latestRelevantDeployment *dataplanev1.OpenStackDataPlaneDeployment
522540
if len(relevantDeployments) > 0 {
523541
slices.SortFunc(relevantDeployments, func(a, b *dataplanev1.OpenStackDataPlaneDeployment) int {
524-
aReady := a.Status.Conditions.Get(condition.DeploymentReadyCondition)
525-
bReady := b.Status.Conditions.Get(condition.DeploymentReadyCondition)
526-
if aReady != nil && bReady != nil {
527-
if aReady.LastTransitionTime.Before(&bReady.LastTransitionTime) {
528-
return -1
529-
}
542+
var aLTT, bLTT time.Time
543+
if c := a.Status.Conditions.Get(condition.DeploymentReadyCondition); c != nil {
544+
aLTT = c.LastTransitionTime.Time
530545
}
531-
return 1
546+
if c := b.Status.Conditions.Get(condition.DeploymentReadyCondition); c != nil {
547+
bLTT = c.LastTransitionTime.Time
548+
}
549+
if c := aLTT.Compare(bLTT); c != 0 {
550+
return c
551+
}
552+
if c := a.CreationTimestamp.Compare(b.CreationTimestamp.Time); c != 0 {
553+
return c
554+
}
555+
return strings.Compare(a.Name, b.Name)
532556
})
533557
latestRelevantDeployment = relevantDeployments[len(relevantDeployments)-1]
534558
}
@@ -563,33 +587,40 @@ func checkDeployment(ctx context.Context, helper *helper.Helper,
563587
isCurrentDeploymentReady := deploymentConditions.IsTrue(dataplanev1.NodeSetDeploymentReadyCondition)
564588

565589
// Reset the vars for every deployment that affects overall state
566-
isNodeSetDeploymentReady = false
567-
isNodeSetDeploymentRunning = false
568-
isNodeSetDeploymentFailed = false
590+
status.ready = false
591+
status.running = false
592+
status.failed = false
569593

570594
if isCurrentDeploymentFailed {
571595
err = fmt.Errorf("%s", deploymentCondition.Message)
572-
failedDeploymentName = deployment.Name
573-
isNodeSetDeploymentFailed = true
596+
status.failedName = deployment.Name
597+
status.failed = true
574598
break
575599
}
576600
if isCurrentDeploymentRunning {
577-
isNodeSetDeploymentRunning = true
601+
status.running = true
602+
if deployment.Spec.DeploymentRequeueTime > 0 {
603+
status.requeueTime = deployment.Spec.DeploymentRequeueTime
604+
}
578605
}
579606

580607
if isCurrentDeploymentReady {
581-
// If the nodeset configHash does not match with what's in the deployment or
582-
// deployedBmhHash is different from current bmhRefHash.
583608
if (deployment.Status.NodeSetHashes[instance.Name] != instance.Status.ConfigHash) ||
584609
(!instance.Spec.PreProvisioned &&
585610
deployment.Status.BmhRefHashes[instance.Name] != instance.Status.BmhRefHash) {
611+
helper.GetLogger().Info("Nodeset config or BMH refs changed since deployment completed",
612+
"deployment", deployment.Name,
613+
"storedConfigHash", deployment.Status.NodeSetHashes[instance.Name],
614+
"currentConfigHash", instance.Status.ConfigHash,
615+
"storedBmhRefHash", deployment.Status.BmhRefHashes[instance.Name],
616+
"currentBmhRefHash", instance.Status.BmhRefHash)
586617
continue
587618
}
588619

589620
hasAnsibleVarsFromChanged, err := checkAnsibleVarsFromChanged(ctx, helper, instance, deployment.Status.ConfigMapHashes, deployment.Status.SecretHashes)
590621

591622
if err != nil {
592-
return isNodeSetDeploymentReady, isNodeSetDeploymentRunning, isNodeSetDeploymentFailed, failedDeploymentName, err
623+
return status, err
593624
}
594625

595626
if hasAnsibleVarsFromChanged {
@@ -599,14 +630,14 @@ func checkDeployment(ctx context.Context, helper *helper.Helper,
599630
hasCertSecretsChanged, err := checkCertSecretsChanged(ctx, helper, instance, deployment.Status.SecretHashes)
600631

601632
if err != nil {
602-
return isNodeSetDeploymentReady, isNodeSetDeploymentRunning, isNodeSetDeploymentFailed, failedDeploymentName, err
633+
return status, err
603634
}
604635

605636
if hasCertSecretsChanged {
606637
continue
607638
}
608639

609-
isNodeSetDeploymentReady = true
640+
status.ready = true
610641
for k, v := range deployment.Status.ConfigMapHashes {
611642
instance.Status.ConfigMapHashes[k] = v
612643
}
@@ -648,7 +679,7 @@ func checkDeployment(ctx context.Context, helper *helper.Helper,
648679
err := helper.GetClient().Get(ctx, name, service)
649680
if err != nil {
650681
helper.GetLogger().Error(err, "Unable to retrieve OpenStackDataPlaneService %v")
651-
return isNodeSetDeploymentReady, isNodeSetDeploymentRunning, isNodeSetDeploymentFailed, failedDeploymentName, err
682+
return status, err
652683
}
653684

654685
if service.Spec.EDPMServiceType != "update" && service.Spec.EDPMServiceType != "update-services" {
@@ -663,7 +694,7 @@ func checkDeployment(ctx context.Context, helper *helper.Helper,
663694
}
664695
}
665696

666-
return isNodeSetDeploymentReady, isNodeSetDeploymentRunning, isNodeSetDeploymentFailed, failedDeploymentName, err
697+
return status, err
667698
}
668699

669700
// SetupWithManager sets up the controller with the Manager.

0 commit comments

Comments
 (0)