Skip to content

Commit a3a67a9

Browse files
Merge pull request #542 from stuggi/OSPRH-14472-fr2
[18.0-fr2] Use deployment.IsReady() to validate status
2 parents 116a1b1 + 9b65479 commit a3a67a9

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.5.1-0.20250301104950-9a202ca63f62
9-
github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20250228124213-cd63da392f97
9+
github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20250414142358-93cd2db6b160
1010
k8s.io/api v0.29.14
1111
k8s.io/apimachinery v0.29.14
1212
k8s.io/client-go v0.29.14

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.5.1-0.20250301104950-9a202ca63f62 h1:0NgCmg03wFjZEltZyHLWalTsUxOg1b7WFNlOZ4APPek=
7878
github.com/openstack-k8s-operators/infra-operator/apis v0.5.1-0.20250301104950-9a202ca63f62/go.mod h1:JgcmYJyyMKfArK8ulZnbls0L01qt8Dq6s5LH8TZH63A=
79-
github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20250228124213-cd63da392f97 h1:3LC66vrXJzGMV/eCdvImosOEL2Cgc2KFJIm2YhfTG3w=
80-
github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20250228124213-cd63da392f97/go.mod h1:rgpcv2tLD+/vudXx/gpIQSTuRpk4GOxHx84xwfvQalM=
79+
github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20250414142358-93cd2db6b160 h1:7l70xtCoyyz6kjMTSBdL4+4yUhZBrAVWLLzB7w+yhD4=
80+
github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20250414142358-93cd2db6b160/go.mod h1:rgpcv2tLD+/vudXx/gpIQSTuRpk4GOxHx84xwfvQalM=
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.5.1-0.20250301104950-9a202ca63f62
1212
github.com/openstack-k8s-operators/ironic-operator/api v0.0.0-00010101000000-000000000000
1313
github.com/openstack-k8s-operators/keystone-operator/api v0.5.1-0.20250302110733-25e75aecd56f
14-
github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20250228124213-cd63da392f97
14+
github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20250414142358-93cd2db6b160
1515
github.com/openstack-k8s-operators/lib-common/modules/test v0.5.1-0.20250228124213-cd63da392f97
1616
github.com/openstack-k8s-operators/mariadb-operator/api v0.5.1-0.20250227120618-381cb0be1059
1717
k8s.io/api v0.29.14

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.5.1-0.20250301104950-9
8282
github.com/openstack-k8s-operators/infra-operator/apis v0.5.1-0.20250301104950-9a202ca63f62/go.mod h1:JgcmYJyyMKfArK8ulZnbls0L01qt8Dq6s5LH8TZH63A=
8383
github.com/openstack-k8s-operators/keystone-operator/api v0.5.1-0.20250302110733-25e75aecd56f h1:t5cA25n+Y53dgWAOObgWRwC5ABdi++u82mjAFCRMFKo=
8484
github.com/openstack-k8s-operators/keystone-operator/api v0.5.1-0.20250302110733-25e75aecd56f/go.mod h1:5eUEjRPFyDhyJTdKz9xfeNP1OMFiJWy4ejb4tidD6ds=
85-
github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20250228124213-cd63da392f97 h1:3LC66vrXJzGMV/eCdvImosOEL2Cgc2KFJIm2YhfTG3w=
86-
github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20250228124213-cd63da392f97/go.mod h1:rgpcv2tLD+/vudXx/gpIQSTuRpk4GOxHx84xwfvQalM=
85+
github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20250414142358-93cd2db6b160 h1:7l70xtCoyyz6kjMTSBdL4+4yUhZBrAVWLLzB7w+yhD4=
86+
github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20250414142358-93cd2db6b160/go.mod h1:rgpcv2tLD+/vudXx/gpIQSTuRpk4GOxHx84xwfvQalM=
8787
github.com/openstack-k8s-operators/lib-common/modules/openstack v0.5.1-0.20250228124213-cd63da392f97 h1:2m8xt9k3FWcnzmq5SxplT0t6v8vvH7LZq3UWK17ygak=
8888
github.com/openstack-k8s-operators/lib-common/modules/openstack v0.5.1-0.20250228124213-cd63da392f97/go.mod h1:tfMa+ochq7Dyilq9hQr2CEPfPtsj6IUgMmMqi4CWDmo=
8989
github.com/openstack-k8s-operators/lib-common/modules/test v0.5.1-0.20250228124213-cd63da392f97 h1:2f6Fl2chkacLkElCtEtCFygtuVhEq3YuUvZbfiEBDZ8=

0 commit comments

Comments
 (0)