Skip to content

Commit 7144328

Browse files
Merge pull request #539 from stuggi/depl_ready
Use deployment.IsReady() to validate status
2 parents 863de55 + 3d345b4 commit 7144328

File tree

9 files changed

+526
-24
lines changed

9 files changed

+526
-24
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
@@ -76,8 +76,8 @@ github.com/openshift/api v0.0.0-20240830023148-b7d0481c9094 h1:J1wuGhVxpsHykZBa6
7676
github.com/openshift/api v0.0.0-20240830023148-b7d0481c9094/go.mod h1:CxgbWAlvu2iQB0UmKTtRu1YfepRg1/vJ64n2DlIEVz4=
7777
github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20250403063905-eb287d52f38d h1:/C+ysubV00VYrqGFhQlDeQ5tUtnhIWPwQUc8MOfCEBA=
7878
github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20250403063905-eb287d52f38d/go.mod h1:IY5zp1GRhacGMvjZMUZQ0LlxWDaogIRb/4H3by1Pivk=
79-
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20250402133843-5a4c5f4fb4f1 h1:hO90JhfinKysbdrWCJugTmJbkrs1d9tR7ypg3yOD12E=
80-
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20250402133843-5a4c5f4fb4f1/go.mod h1:A9Ohw5Q90YOGhcDF4ZHkMr5RArz3phoBu9+ibbYDKG4=
79+
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20250408123225-0d9e9b82c41b h1:T+N6xOT2NP+hVp2K1xl/NV3uheVHu38CcBuW+8uOBYw=
80+
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20250408123225-0d9e9b82c41b/go.mod h1:A9Ohw5Q90YOGhcDF4ZHkMr5RArz3phoBu9+ibbYDKG4=
8181
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
8282
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
8383
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=

controllers/ironicapi_controller.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -937,8 +937,9 @@ func (r *IronicAPIReconciler) reconcileNormal(ctx context.Context, instance *iro
937937
}
938938

939939
// Only check readiness if controller sees the last version of the CR
940-
if depl.GetDeployment().Generation == depl.GetDeployment().Status.ObservedGeneration {
941-
instance.Status.ReadyCount = depl.GetDeployment().Status.ReadyReplicas
940+
deploy := depl.GetDeployment()
941+
if deploy.Generation == deploy.Status.ObservedGeneration {
942+
instance.Status.ReadyCount = deploy.Status.ReadyReplicas
942943

943944
// verify if network attachment matches expectations
944945
networkReady, networkAttachmentStatus, err := nad.VerifyNetworkStatusFromAnnotation(ctx, helper, instance.Spec.NetworkAttachments, serviceLabels, instance.Status.ReadyCount)
@@ -960,8 +961,18 @@ func (r *IronicAPIReconciler) reconcileNormal(ctx context.Context, instance *iro
960961
return ctrl.Result{}, err
961962
}
962963

963-
if instance.Status.ReadyCount == *instance.Spec.Replicas {
964+
// Mark the Deployment as Ready only if the number of Replicas is equals
965+
// to the Deployed instances (ReadyCount), and the the Status.Replicas
966+
// match Status.ReadyReplicas. If a deployment update is in progress,
967+
// Replicas > ReadyReplicas.
968+
if deployment.IsReady(deploy) {
964969
instance.Status.Conditions.MarkTrue(condition.DeploymentReadyCondition, condition.DeploymentReadyMessage)
970+
} else {
971+
instance.Status.Conditions.Set(condition.FalseCondition(
972+
condition.DeploymentReadyCondition,
973+
condition.RequestedReason,
974+
condition.SeverityInfo,
975+
condition.DeploymentReadyRunningMessage))
965976
}
966977
}
967978
// create Deployment - end

controllers/ironicconductor_controller.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -756,8 +756,9 @@ func (r *IronicConductorReconciler) reconcileNormal(ctx context.Context, instanc
756756
}
757757

758758
// Only check readiness if controller sees the last version of the CR
759-
if ss.GetStatefulSet().Generation == ss.GetStatefulSet().Status.ObservedGeneration {
760-
instance.Status.ReadyCount = ss.GetStatefulSet().Status.ReadyReplicas
759+
deploy := ss.GetStatefulSet()
760+
if deploy.Generation == deploy.Status.ObservedGeneration {
761+
instance.Status.ReadyCount = deploy.Status.ReadyReplicas
761762

762763
// verify if network attachment matches expectations
763764
networkReady, networkAttachmentStatus, err := nad.VerifyNetworkStatusFromAnnotation(ctx, helper, instance.Spec.NetworkAttachments, serviceLabels, instance.Status.ReadyCount)
@@ -779,8 +780,18 @@ func (r *IronicConductorReconciler) reconcileNormal(ctx context.Context, instanc
779780
return ctrl.Result{}, err
780781
}
781782

782-
if instance.Status.ReadyCount == *instance.Spec.Replicas {
783+
// Mark the Deployment as Ready only if the number of Replicas is equals
784+
// to the Deployed instances (ReadyCount), and the the Status.Replicas
785+
// match Status.ReadyReplicas. If a deployment update is in progress,
786+
// Replicas > ReadyReplicas.
787+
if statefulset.IsReady(deploy) {
783788
instance.Status.Conditions.MarkTrue(condition.DeploymentReadyCondition, condition.DeploymentReadyMessage)
789+
} else {
790+
instance.Status.Conditions.Set(condition.FalseCondition(
791+
condition.DeploymentReadyCondition,
792+
condition.RequestedReason,
793+
condition.SeverityInfo,
794+
condition.DeploymentReadyRunningMessage))
784795
}
785796
}
786797

controllers/ironicinspector_controller.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -710,8 +710,9 @@ func (r *IronicInspectorReconciler) reconcileStatefulSet(
710710
}
711711

712712
// Only check readiness if controller sees the last version of the CR
713-
if ss.GetStatefulSet().Generation == ss.GetStatefulSet().Status.ObservedGeneration {
714-
instance.Status.ReadyCount = ss.GetStatefulSet().Status.ReadyReplicas
713+
deploy := ss.GetStatefulSet()
714+
if deploy.Generation == deploy.Status.ObservedGeneration {
715+
instance.Status.ReadyCount = deploy.Status.ReadyReplicas
715716

716717
// verify if network attachment matches expectations
717718
networkReady, networkAttachmentStatus, err := nad.VerifyNetworkStatusFromAnnotation(ctx, helper, instance.Spec.NetworkAttachments, serviceLabels, instance.Status.ReadyCount)
@@ -733,11 +734,20 @@ func (r *IronicInspectorReconciler) reconcileStatefulSet(
733734

734735
return ctrl.Result{}, err
735736
}
736-
if instance.Status.ReadyCount == *instance.Spec.Replicas {
737-
instance.Status.Conditions.MarkTrue(
738-
condition.DeploymentReadyCondition,
739-
condition.DeploymentReadyMessage)
737+
738+
// Mark the Deployment as Ready only if the number of Replicas is equals
739+
// to the Deployed instances (ReadyCount), and the the Status.Replicas
740+
// match Status.ReadyReplicas. If a deployment update is in progress,
741+
// Replicas > ReadyReplicas.
742+
if statefulset.IsReady(deploy) {
743+
instance.Status.Conditions.MarkTrue(condition.DeploymentReadyCondition, condition.DeploymentReadyMessage)
740744
} else {
745+
instance.Status.Conditions.Set(condition.FalseCondition(
746+
condition.DeploymentReadyCondition,
747+
condition.RequestedReason,
748+
condition.SeverityInfo,
749+
condition.DeploymentReadyRunningMessage))
750+
741751
return ctrl.Result{RequeueAfter: time.Second * 10}, nil
742752
}
743753
}

controllers/ironicneutronagent_controller.go

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -517,8 +517,8 @@ func (r *IronicNeutronAgentReconciler) reconcileDeployment(
517517
serviceLabels,
518518
topology,
519519
)
520-
deployment := deployment.NewDeployment(deplomentDef, 5)
521-
ctrlResult, err := deployment.CreateOrPatch(ctx, helper)
520+
depl := deployment.NewDeployment(deplomentDef, 5)
521+
ctrlResult, err := depl.CreateOrPatch(ctx, helper)
522522
if err != nil {
523523
instance.Status.Conditions.Set(condition.FalseCondition(
524524
condition.DeploymentReadyCondition,
@@ -537,11 +537,22 @@ func (r *IronicNeutronAgentReconciler) reconcileDeployment(
537537
}
538538

539539
// Only check ReadyCount if controller sees the last version of the CR
540-
if deployment.GetDeployment().Generation == deployment.GetDeployment().Status.ObservedGeneration {
541-
instance.Status.ReadyCount = deployment.GetDeployment().Status.ReadyReplicas
542-
543-
if instance.Status.ReadyCount == *instance.Spec.Replicas {
540+
deploy := depl.GetDeployment()
541+
if deploy.Generation == deploy.Status.ObservedGeneration {
542+
instance.Status.ReadyCount = deploy.Status.ReadyReplicas
543+
544+
// Mark the Deployment as Ready only if the number of Replicas is equals
545+
// to the Deployed instances (ReadyCount), and the the Status.Replicas
546+
// match Status.ReadyReplicas. If a deployment update is in progress,
547+
// Replicas > ReadyReplicas.
548+
if deployment.IsReady(deploy) {
544549
instance.Status.Conditions.MarkTrue(condition.DeploymentReadyCondition, condition.DeploymentReadyMessage)
550+
} else {
551+
instance.Status.Conditions.Set(condition.FalseCondition(
552+
condition.DeploymentReadyCondition,
553+
condition.RequestedReason,
554+
condition.SeverityInfo,
555+
condition.DeploymentReadyRunningMessage))
545556
}
546557
}
547558

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/infra-operator/apis v0.6.1-0.20250403063905-eb287d52f38d
1212
github.com/openstack-k8s-operators/ironic-operator/api v0.0.0-00010101000000-000000000000
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/test v0.6.1-0.20250402133843-5a4c5f4fb4f1
1616
github.com/openstack-k8s-operators/mariadb-operator/api v0.6.0
1717
k8s.io/api v0.29.15

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)