Skip to content

Commit 8c6f7c1

Browse files
Merge pull request #560 from stuggi/depl_ready
Use deployment.IsReady() to validate status
2 parents 10f5f7e + f52bedc commit 8c6f7c1

File tree

6 files changed

+119
-8
lines changed

6 files changed

+119
-8
lines changed

api/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ require (
88
github.com/gophercloud/gophercloud v1.14.1
99
github.com/onsi/gomega v1.34.1
1010
github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20250403063905-eb287d52f38d
11-
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20250402133843-5a4c5f4fb4f1
11+
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20250408123225-0d9e9b82c41b
1212
github.com/openstack-k8s-operators/lib-common/modules/openstack v0.6.1-0.20250402133843-5a4c5f4fb4f1
1313
github.com/openstack-k8s-operators/lib-common/modules/storage v0.6.1-0.20250402133843-5a4c5f4fb4f1
1414
github.com/openstack-k8s-operators/lib-common/modules/test v0.6.1-0.20250402133843-5a4c5f4fb4f1

api/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ github.com/openshift/api v0.0.0-20240830023148-b7d0481c9094 h1:J1wuGhVxpsHykZBa6
8282
github.com/openshift/api v0.0.0-20240830023148-b7d0481c9094/go.mod h1:CxgbWAlvu2iQB0UmKTtRu1YfepRg1/vJ64n2DlIEVz4=
8383
github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20250403063905-eb287d52f38d h1:/C+ysubV00VYrqGFhQlDeQ5tUtnhIWPwQUc8MOfCEBA=
8484
github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20250403063905-eb287d52f38d/go.mod h1:IY5zp1GRhacGMvjZMUZQ0LlxWDaogIRb/4H3by1Pivk=
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=

controllers/keystoneapi_controller.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,7 +1128,11 @@ func (r *KeystoneAPIReconciler) reconcileNormal(
11281128
condition.DeploymentReadyRunningMessage))
11291129
return ctrlResult, nil
11301130
}
1131-
instance.Status.ReadyCount = depl.GetDeployment().Status.ReadyReplicas
1131+
1132+
deploy := depl.GetDeployment()
1133+
if deploy.Generation == deploy.Status.ObservedGeneration {
1134+
instance.Status.ReadyCount = deploy.Status.ReadyReplicas
1135+
}
11321136

11331137
// verify if network attachment matches expectations
11341138
networkReady, networkAttachmentStatus, err := nad.VerifyNetworkStatusFromAnnotation(
@@ -1154,7 +1158,13 @@ func (r *KeystoneAPIReconciler) reconcileNormal(
11541158
return ctrl.Result{}, err
11551159
}
11561160

1157-
if instance.Status.ReadyCount > 0 {
1161+
// Mark the Deployment as Ready only if the number of Replicas is equals
1162+
// to the Deployed instances (ReadyCount), and the the Status.Replicas
1163+
// match Status.ReadyReplicas. If a deployment update is in progress,
1164+
// Replicas > ReadyReplicas.
1165+
// In addition, make sure the controller sees the last Generation
1166+
// by comparing it with the ObservedGeneration.
1167+
if deployment.IsReady(deploy) {
11581168
instance.Status.Conditions.MarkTrue(condition.DeploymentReadyCondition, condition.DeploymentReadyMessage)
11591169
} else {
11601170
instance.Status.Conditions.Set(condition.FalseCondition(

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ require (
1010
github.com/onsi/gomega v1.34.1
1111
github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20250403063905-eb287d52f38d
1212
github.com/openstack-k8s-operators/keystone-operator/api v0.3.1-0.20240213125925-e40975f3db7e
13-
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20250402133843-5a4c5f4fb4f1
13+
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20250408123225-0d9e9b82c41b
1414
github.com/openstack-k8s-operators/lib-common/modules/openstack v0.6.1-0.20250402133843-5a4c5f4fb4f1
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

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ github.com/openshift/api v0.0.0-20240830023148-b7d0481c9094 h1:J1wuGhVxpsHykZBa6
8080
github.com/openshift/api v0.0.0-20240830023148-b7d0481c9094/go.mod h1:CxgbWAlvu2iQB0UmKTtRu1YfepRg1/vJ64n2DlIEVz4=
8181
github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20250403063905-eb287d52f38d h1:/C+ysubV00VYrqGFhQlDeQ5tUtnhIWPwQUc8MOfCEBA=
8282
github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20250403063905-eb287d52f38d/go.mod h1:IY5zp1GRhacGMvjZMUZQ0LlxWDaogIRb/4H3by1Pivk=
83-
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20250402133843-5a4c5f4fb4f1 h1:hO90JhfinKysbdrWCJugTmJbkrs1d9tR7ypg3yOD12E=
84-
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20250402133843-5a4c5f4fb4f1/go.mod h1:A9Ohw5Q90YOGhcDF4ZHkMr5RArz3phoBu9+ibbYDKG4=
83+
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20250408123225-0d9e9b82c41b h1:T+N6xOT2NP+hVp2K1xl/NV3uheVHu38CcBuW+8uOBYw=
84+
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20250408123225-0d9e9b82c41b/go.mod h1:A9Ohw5Q90YOGhcDF4ZHkMr5RArz3phoBu9+ibbYDKG4=
8585
github.com/openstack-k8s-operators/lib-common/modules/openstack v0.6.1-0.20250402133843-5a4c5f4fb4f1 h1:QlwUTGaUrl0Z6ozC7u0UNdgB3L6k/b60jsq2u8w482k=
8686
github.com/openstack-k8s-operators/lib-common/modules/openstack v0.6.1-0.20250402133843-5a4c5f4fb4f1/go.mod h1:fesgTbs2j30Fhw2hebXkPgbeAIqG0Yk2oaeOklAInZg=
8787
github.com/openstack-k8s-operators/lib-common/modules/storage v0.6.1-0.20250402133843-5a4c5f4fb4f1 h1:KcltUDbUA0sjtf6bV60L7GDpC0pmokhtdK3579yytS4=

tests/functional/keystoneapi_controller_test.go

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,107 @@ var _ = Describe("Keystone controller", func() {
699699
})
700700
})
701701

702+
When("Deployment rollout is progressing", func() {
703+
BeforeEach(func() {
704+
DeferCleanup(
705+
k8sClient.Delete, ctx, CreateKeystoneMessageBusSecret(namespace, "rabbitmq-secret"))
706+
DeferCleanup(th.DeleteInstance, CreateKeystoneAPI(keystoneAPIName, GetDefaultKeystoneAPISpec()))
707+
DeferCleanup(
708+
k8sClient.Delete, ctx, CreateKeystoneAPISecret(namespace, SecretName))
709+
DeferCleanup(infra.DeleteMemcached, infra.CreateMemcached(namespace, "memcached", memcachedSpec))
710+
DeferCleanup(
711+
mariadb.DeleteDBService,
712+
mariadb.CreateDBService(
713+
namespace,
714+
GetKeystoneAPI(keystoneAPIName).Spec.DatabaseInstance,
715+
corev1.ServiceSpec{
716+
Ports: []corev1.ServicePort{{Port: 3306}},
717+
},
718+
),
719+
)
720+
mariadb.SimulateMariaDBAccountCompleted(keystoneAccountName)
721+
mariadb.SimulateMariaDBDatabaseCompleted(keystoneDatabaseName)
722+
infra.SimulateTransportURLReady(types.NamespacedName{
723+
Name: fmt.Sprintf("%s-keystone-transport", keystoneAPIName.Name),
724+
Namespace: namespace,
725+
})
726+
infra.SimulateMemcachedReady(types.NamespacedName{
727+
Name: "memcached",
728+
Namespace: namespace,
729+
})
730+
th.SimulateJobSuccess(dbSyncJobName)
731+
th.SimulateJobSuccess(bootstrapJobName)
732+
th.SimulateDeploymentProgressing(deploymentName)
733+
})
734+
735+
It("shows the deployment progressing in DeploymentReadyCondition", func() {
736+
th.ExpectConditionWithDetails(
737+
keystoneAPIName,
738+
ConditionGetterFunc(KeystoneConditionGetter),
739+
condition.DeploymentReadyCondition,
740+
corev1.ConditionFalse,
741+
condition.RequestedReason,
742+
condition.DeploymentReadyRunningMessage,
743+
)
744+
th.ExpectCondition(
745+
keystoneAPIName,
746+
ConditionGetterFunc(KeystoneConditionGetter),
747+
condition.ReadyCondition,
748+
corev1.ConditionFalse,
749+
)
750+
})
751+
752+
It("still shows the deployment progressing in DeploymentReadyCondition when rollout hits ProgressDeadlineExceeded", func() {
753+
th.SimulateDeploymentProgressDeadlineExceeded(deploymentName)
754+
th.ExpectConditionWithDetails(
755+
keystoneAPIName,
756+
ConditionGetterFunc(KeystoneConditionGetter),
757+
condition.DeploymentReadyCondition,
758+
corev1.ConditionFalse,
759+
condition.RequestedReason,
760+
condition.DeploymentReadyRunningMessage,
761+
)
762+
th.ExpectCondition(
763+
keystoneAPIName,
764+
ConditionGetterFunc(KeystoneConditionGetter),
765+
condition.ReadyCondition,
766+
corev1.ConditionFalse,
767+
)
768+
})
769+
770+
It("reaches Ready when deployment rollout finished", func() {
771+
th.ExpectConditionWithDetails(
772+
keystoneAPIName,
773+
ConditionGetterFunc(KeystoneConditionGetter),
774+
condition.DeploymentReadyCondition,
775+
corev1.ConditionFalse,
776+
condition.RequestedReason,
777+
condition.DeploymentReadyRunningMessage,
778+
)
779+
th.ExpectCondition(
780+
keystoneAPIName,
781+
ConditionGetterFunc(KeystoneConditionGetter),
782+
condition.ReadyCondition,
783+
corev1.ConditionFalse,
784+
)
785+
786+
th.SimulateDeploymentReplicaReady(deploymentName)
787+
th.ExpectCondition(
788+
keystoneAPIName,
789+
ConditionGetterFunc(KeystoneConditionGetter),
790+
condition.DeploymentReadyCondition,
791+
corev1.ConditionTrue,
792+
)
793+
794+
th.ExpectCondition(
795+
keystoneAPIName,
796+
ConditionGetterFunc(KeystoneConditionGetter),
797+
condition.ReadyCondition,
798+
corev1.ConditionTrue,
799+
)
800+
})
801+
})
802+
702803
When("A KeystoneAPI is created with service override", func() {
703804
BeforeEach(func() {
704805
spec := GetDefaultKeystoneAPISpec()

0 commit comments

Comments
 (0)