Skip to content

Commit 269c641

Browse files
Set DeploymentReady to False when ReadyCount will be 0
Make sure that DeploymentReady condition is set back to False if the Deployment ReadyReplicas falls back to 0
1 parent fc03473 commit 269c641

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

controllers/placementapi_controller.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -764,9 +764,19 @@ func (r *PlacementAPIReconciler) reconcileNormal(ctx context.Context, instance *
764764
return ctrl.Result{}, err
765765
}
766766

767-
if instance.Status.ReadyCount > 0 {
767+
if instance.Status.ReadyCount > 0 || *instance.Spec.Replicas == 0 {
768768
instance.Status.Conditions.MarkTrue(condition.DeploymentReadyCondition, condition.DeploymentReadyMessage)
769+
} else {
770+
Log.Info("Deployment is not ready")
771+
instance.Status.Conditions.Set(condition.FalseCondition(
772+
condition.DeploymentReadyCondition,
773+
condition.RequestedReason,
774+
condition.SeverityInfo,
775+
condition.DeploymentReadyRunningMessage))
776+
// It is OK to return success as we are watching for StatefulSet changes
777+
return ctrl.Result{}, nil
769778
}
779+
770780
// create Deployment - end
771781

772782
Log.Info("Reconciled Service successfully")

tests/functional/placementapi_controller_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,39 @@ var _ = Describe("PlacementAPI controller", func() {
116116
})
117117
})
118118

119+
When("starts zero replicas", func() {
120+
BeforeEach(func() {
121+
spec := GetDefaultPlacementAPISpec()
122+
spec["replicas"] = 0
123+
DeferCleanup(
124+
th.DeleteInstance,
125+
CreatePlacementAPI(names.PlacementAPIName, spec),
126+
)
127+
DeferCleanup(
128+
k8sClient.Delete, ctx, CreatePlacementAPISecret(namespace, SecretName))
129+
keystoneAPIName := keystone.CreateKeystoneAPI(namespace)
130+
DeferCleanup(keystone.DeleteKeystoneAPI, keystoneAPIName)
131+
132+
})
133+
It("and deployment is Ready", func() {
134+
serviceSpec := corev1.ServiceSpec{Ports: []corev1.ServicePort{{Port: 3306}}}
135+
DeferCleanup(
136+
mariadb.DeleteDBService,
137+
mariadb.CreateDBService(namespace, "openstack", serviceSpec),
138+
)
139+
mariadb.SimulateMariaDBDatabaseCompleted(names.MariaDBDatabaseName)
140+
th.SimulateJobSuccess(names.DBSyncJobName)
141+
placement := GetPlacementAPI(names.PlacementAPIName)
142+
Expect(*(placement.Spec.Replicas)).Should(Equal(int32(0)))
143+
th.ExpectCondition(
144+
names.PlacementAPIName,
145+
ConditionGetterFunc(PlacementConditionGetter),
146+
condition.DeploymentReadyCondition,
147+
corev1.ConditionTrue,
148+
)
149+
})
150+
})
151+
119152
When("a secret is provided with missing fields", func() {
120153
BeforeEach(func() {
121154
DeferCleanup(

0 commit comments

Comments
 (0)