Skip to content

Commit 8df10e6

Browse files
committed
Improve logic to fix functional tests
- latest-deployment sort returned 1 on equal/missing Ready transition times and same-second transitions would pick an arbitrary "latest". Tie-break on creationTimestamp, then name. - nodeset controller is purely event-driven; coalesced watch events left a stale "running" verdict unreconciled until timeout. Requeue after 15s while a deployment is running - log the previously silent config-hash mismatch so a stuck nodeset is diagnosable from logs Signed-off-by: rabi <ramishra@redhat.com>
1 parent e22415e commit 8df10e6

2 files changed

Lines changed: 24 additions & 6 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: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,11 @@ func (r *OpenStackDataPlaneNodeSetReconciler) Reconcile(ctx context.Context, req
486486
"%s", deployErrorMsg)
487487
}
488488

489+
// Watch events can be coalesced; requeue so a stale "running" verdict self-heals.
490+
if isDeploymentRunning {
491+
return ctrl.Result{RequeueAfter: time.Second * time.Duration(dataplanev1.DefaultDeploymentRequeueTime)}, nil
492+
}
493+
489494
return ctrl.Result{}, err
490495
}
491496

@@ -517,18 +522,23 @@ func checkDeployment(ctx context.Context, helper *helper.Helper,
517522
}
518523
}
519524

520-
// Sort relevant deployments from oldest to newest, then take the last one
525+
// Sort relevant deployments from oldest to newest, then take the last one.
526+
// The latest transitioned deployment is what last acted on the node;
527+
// tie-break on creationTimestamp then name for determinism.
521528
var latestRelevantDeployment *dataplanev1.OpenStackDataPlaneDeployment
522529
if len(relevantDeployments) > 0 {
523530
slices.SortFunc(relevantDeployments, func(a, b *dataplanev1.OpenStackDataPlaneDeployment) int {
524531
aReady := a.Status.Conditions.Get(condition.DeploymentReadyCondition)
525532
bReady := b.Status.Conditions.Get(condition.DeploymentReadyCondition)
526533
if aReady != nil && bReady != nil {
527-
if aReady.LastTransitionTime.Before(&bReady.LastTransitionTime) {
528-
return -1
534+
if c := aReady.LastTransitionTime.Compare(bReady.LastTransitionTime.Time); c != 0 {
535+
return c
529536
}
530537
}
531-
return 1
538+
if c := a.CreationTimestamp.Compare(b.CreationTimestamp.Time); c != 0 {
539+
return c
540+
}
541+
return strings.Compare(a.Name, b.Name)
532542
})
533543
latestRelevantDeployment = relevantDeployments[len(relevantDeployments)-1]
534544
}
@@ -578,11 +588,15 @@ func checkDeployment(ctx context.Context, helper *helper.Helper,
578588
}
579589

580590
if isCurrentDeploymentReady {
581-
// If the nodeset configHash does not match with what's in the deployment or
582-
// deployedBmhHash is different from current bmhRefHash.
583591
if (deployment.Status.NodeSetHashes[instance.Name] != instance.Status.ConfigHash) ||
584592
(!instance.Spec.PreProvisioned &&
585593
deployment.Status.BmhRefHashes[instance.Name] != instance.Status.BmhRefHash) {
594+
helper.GetLogger().Info("Nodeset config or BMH refs changed since deployment completed",
595+
"deployment", deployment.Name,
596+
"storedConfigHash", deployment.Status.NodeSetHashes[instance.Name],
597+
"currentConfigHash", instance.Status.ConfigHash,
598+
"storedBmhRefHash", deployment.Status.BmhRefHashes[instance.Name],
599+
"currentBmhRefHash", instance.Status.BmhRefHash)
586600
continue
587601
}
588602

0 commit comments

Comments
 (0)