Skip to content

Commit 149db63

Browse files
committed
Use deployment.IsReady() to validate status
Changes to use the common IsReady() func to validate a deployment is fully up as requested and e.g. no update rollout in progress. During a minor update this has seen to already report/mark the condition ready, even the deployment is still in progress, or the replacement pod failed. Jira: OSPRH-14472 Depends-On: openstack-k8s-operators/lib-common#616 Signed-off-by: Martin Schuppert <[email protected]>
1 parent 7682008 commit 149db63

File tree

9 files changed

+434
-12
lines changed

9 files changed

+434
-12
lines changed

api/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ require (
66
github.com/onsi/ginkgo/v2 v2.20.1
77
github.com/onsi/gomega v1.34.1
88
github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20250403063905-eb287d52f38d
9-
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20250402133843-5a4c5f4fb4f1
9+
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20250408123225-0d9e9b82c41b
1010
k8s.io/api v0.29.15
1111
k8s.io/apimachinery v0.29.15
1212
k8s.io/client-go v0.29.15

api/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ github.com/onsi/gomega v1.34.1 h1:EUMJIKUjM8sKjYbtxQI9A4z2o+rruxnzNvpknOXie6k=
7474
github.com/onsi/gomega v1.34.1/go.mod h1:kU1QgUvBDLXBJq618Xvm2LUX6rSAfRaFRTcdOeDLwwY=
7575
github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20250403063905-eb287d52f38d h1:/C+ysubV00VYrqGFhQlDeQ5tUtnhIWPwQUc8MOfCEBA=
7676
github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20250403063905-eb287d52f38d/go.mod h1:IY5zp1GRhacGMvjZMUZQ0LlxWDaogIRb/4H3by1Pivk=
77-
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20250402133843-5a4c5f4fb4f1 h1:hO90JhfinKysbdrWCJugTmJbkrs1d9tR7ypg3yOD12E=
78-
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20250402133843-5a4c5f4fb4f1/go.mod h1:A9Ohw5Q90YOGhcDF4ZHkMr5RArz3phoBu9+ibbYDKG4=
77+
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20250408123225-0d9e9b82c41b h1:T+N6xOT2NP+hVp2K1xl/NV3uheVHu38CcBuW+8uOBYw=
78+
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20250408123225-0d9e9b82c41b/go.mod h1:A9Ohw5Q90YOGhcDF4ZHkMr5RArz3phoBu9+ibbYDKG4=
7979
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
8080
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
8181
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=

controllers/barbicanapi_controller.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -835,7 +835,11 @@ func (r *BarbicanAPIReconciler) reconcileNormal(ctx context.Context, instance *b
835835
condition.DeploymentReadyRunningMessage))
836836
return ctrlResult, nil
837837
}
838-
instance.Status.ReadyCount = depl.GetDeployment().Status.ReadyReplicas
838+
839+
deploy := depl.GetDeployment()
840+
if deploy.Generation == deploy.Status.ObservedGeneration {
841+
instance.Status.ReadyCount = deploy.Status.ReadyReplicas
842+
}
839843

840844
// verify if network attachment matches expectations
841845
networkReady, networkAttachmentStatus, err := nad.VerifyNetworkStatusFromAnnotation(ctx, helper, instance.Spec.NetworkAttachments, serviceLabels, instance.Status.ReadyCount)
@@ -857,8 +861,20 @@ func (r *BarbicanAPIReconciler) reconcileNormal(ctx context.Context, instance *b
857861
return ctrl.Result{}, err
858862
}
859863

860-
if instance.Status.ReadyCount > 0 {
864+
// Mark the Deployment as Ready only if the number of Replicas is equals
865+
// to the Deployed instances (ReadyCount), and the the Status.Replicas
866+
// match Status.ReadyReplicas. If a deployment update is in progress,
867+
// Replicas > ReadyReplicas.
868+
// In addition, make sure the controller sees the last Generation
869+
// by comparing it with the ObservedGeneration.
870+
if deployment.IsReady(deploy) {
861871
instance.Status.Conditions.MarkTrue(condition.DeploymentReadyCondition, condition.DeploymentReadyMessage)
872+
} else {
873+
instance.Status.Conditions.Set(condition.FalseCondition(
874+
condition.DeploymentReadyCondition,
875+
condition.RequestedReason,
876+
condition.SeverityInfo,
877+
condition.DeploymentReadyRunningMessage))
862878
}
863879
// create Deployment - end
864880

controllers/barbicankeystonelistener_controller.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,11 @@ func (r *BarbicanKeystoneListenerReconciler) reconcileNormal(ctx context.Context
594594
condition.DeploymentReadyRunningMessage))
595595
return ctrlResult, nil
596596
}
597-
instance.Status.ReadyCount = depl.GetDeployment().Status.ReadyReplicas
597+
598+
deploy := depl.GetDeployment()
599+
if deploy.Generation == deploy.Status.ObservedGeneration {
600+
instance.Status.ReadyCount = deploy.Status.ReadyReplicas
601+
}
598602

599603
// verify if network attachment matches expectations
600604
networkReady, networkAttachmentStatus, err := nad.VerifyNetworkStatusFromAnnotation(ctx, helper, instance.Spec.NetworkAttachments, serviceLabels, instance.Status.ReadyCount)
@@ -616,8 +620,20 @@ func (r *BarbicanKeystoneListenerReconciler) reconcileNormal(ctx context.Context
616620
return ctrl.Result{}, err
617621
}
618622

619-
if instance.Status.ReadyCount > 0 {
623+
// Mark the Deployment as Ready only if the number of Replicas is equals
624+
// to the Deployed instances (ReadyCount), and the the Status.Replicas
625+
// match Status.ReadyReplicas. If a deployment update is in progress,
626+
// Replicas > ReadyReplicas.
627+
// In addition, make sure the controller sees the last Generation
628+
// by comparing it with the ObservedGeneration.
629+
if deployment.IsReady(deploy) {
620630
instance.Status.Conditions.MarkTrue(condition.DeploymentReadyCondition, condition.DeploymentReadyMessage)
631+
} else {
632+
instance.Status.Conditions.Set(condition.FalseCondition(
633+
condition.DeploymentReadyCondition,
634+
condition.RequestedReason,
635+
condition.SeverityInfo,
636+
condition.DeploymentReadyRunningMessage))
621637
}
622638
// create Deployment - end
623639

controllers/barbicanworker_controller.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,11 @@ func (r *BarbicanWorkerReconciler) reconcileNormal(ctx context.Context, instance
592592
condition.DeploymentReadyRunningMessage))
593593
return ctrlResult, nil
594594
}
595-
instance.Status.ReadyCount = depl.GetDeployment().Status.ReadyReplicas
595+
596+
deploy := depl.GetDeployment()
597+
if deploy.Generation == deploy.Status.ObservedGeneration {
598+
instance.Status.ReadyCount = deploy.Status.ReadyReplicas
599+
}
596600

597601
// verify if network attachment matches expectations
598602
networkReady, networkAttachmentStatus, err := nad.VerifyNetworkStatusFromAnnotation(ctx, helper, instance.Spec.NetworkAttachments, serviceLabels, instance.Status.ReadyCount)
@@ -614,8 +618,20 @@ func (r *BarbicanWorkerReconciler) reconcileNormal(ctx context.Context, instance
614618
return ctrl.Result{}, err
615619
}
616620

617-
if instance.Status.ReadyCount > 0 {
621+
// Mark the Deployment as Ready only if the number of Replicas is equals
622+
// to the Deployed instances (ReadyCount), and the the Status.Replicas
623+
// match Status.ReadyReplicas. If a deployment update is in progress,
624+
// Replicas > ReadyReplicas.
625+
// In addition, make sure the controller sees the last Generation
626+
// by comparing it with the ObservedGeneration.
627+
if deployment.IsReady(deploy) {
618628
instance.Status.Conditions.MarkTrue(condition.DeploymentReadyCondition, condition.DeploymentReadyMessage)
629+
} else {
630+
instance.Status.Conditions.Set(condition.FalseCondition(
631+
condition.DeploymentReadyCondition,
632+
condition.RequestedReason,
633+
condition.SeverityInfo,
634+
condition.DeploymentReadyRunningMessage))
619635
}
620636
// create Deployment - end
621637

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ require (
1111
github.com/openstack-k8s-operators/barbican-operator/api v0.0.0-00010101000000-000000000000
1212
github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20250403063905-eb287d52f38d
1313
github.com/openstack-k8s-operators/keystone-operator/api v0.6.1-0.20250406092234-10f5f7e5b5a9
14-
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20250402133843-5a4c5f4fb4f1
14+
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20250408123225-0d9e9b82c41b
1515
github.com/openstack-k8s-operators/lib-common/modules/storage v0.6.1-0.20250402133843-5a4c5f4fb4f1
1616
github.com/openstack-k8s-operators/lib-common/modules/test v0.6.1-0.20250402133843-5a4c5f4fb4f1
1717
github.com/openstack-k8s-operators/mariadb-operator/api v0.5.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20250403063905-e
8282
github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20250403063905-eb287d52f38d/go.mod h1:IY5zp1GRhacGMvjZMUZQ0LlxWDaogIRb/4H3by1Pivk=
8383
github.com/openstack-k8s-operators/keystone-operator/api v0.6.1-0.20250406092234-10f5f7e5b5a9 h1:Q1yMkuwIOCtGQJDsKYAbspJU5b6emRvoKw5VyPXfiak=
8484
github.com/openstack-k8s-operators/keystone-operator/api v0.6.1-0.20250406092234-10f5f7e5b5a9/go.mod h1:klMsoleakNm0dfNR9ePkL5pNZQsIyx4WMLaHDKIkTt4=
85-
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20250402133843-5a4c5f4fb4f1 h1:hO90JhfinKysbdrWCJugTmJbkrs1d9tR7ypg3yOD12E=
86-
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20250402133843-5a4c5f4fb4f1/go.mod h1:A9Ohw5Q90YOGhcDF4ZHkMr5RArz3phoBu9+ibbYDKG4=
85+
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20250408123225-0d9e9b82c41b h1:T+N6xOT2NP+hVp2K1xl/NV3uheVHu38CcBuW+8uOBYw=
86+
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20250408123225-0d9e9b82c41b/go.mod h1:A9Ohw5Q90YOGhcDF4ZHkMr5RArz3phoBu9+ibbYDKG4=
8787
github.com/openstack-k8s-operators/lib-common/modules/openstack v0.6.1-0.20250402133843-5a4c5f4fb4f1 h1:QlwUTGaUrl0Z6ozC7u0UNdgB3L6k/b60jsq2u8w482k=
8888
github.com/openstack-k8s-operators/lib-common/modules/openstack v0.6.1-0.20250402133843-5a4c5f4fb4f1/go.mod h1:fesgTbs2j30Fhw2hebXkPgbeAIqG0Yk2oaeOklAInZg=
8989
github.com/openstack-k8s-operators/lib-common/modules/storage v0.6.1-0.20250402133843-5a4c5f4fb4f1 h1:KcltUDbUA0sjtf6bV60L7GDpC0pmokhtdK3579yytS4=

0 commit comments

Comments
 (0)