Skip to content

Commit

Permalink
Add Generation test
Browse files Browse the repository at this point in the history
  • Loading branch information
burmanm committed Sep 5, 2022
1 parent 467153d commit 2673975
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 3 additions & 1 deletion controllers/control/cassandratask_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -508,13 +508,15 @@ var _ = Describe("CassandraTask controller tests", func() {

Expect(k8sClient.Get(context.TODO(), taskKey, task)).To(Succeed())
Expect(task.Status.CompletionTime).To(BeNil())

// Imitate statefulset_controller
Expect(k8sClient.Get(context.TODO(), stsKey, &sts)).Should(Succeed())
sts.Status.UpdatedReplicas = sts.Status.Replicas
sts.Status.ReadyReplicas = sts.Status.Replicas
sts.Status.CurrentReplicas = sts.Status.Replicas
sts.Status.UpdateRevision = "1"
sts.Status.CurrentRevision = sts.Status.UpdateRevision
sts.Status.ObservedGeneration = sts.GetObjectMeta().GetGeneration()

Expect(k8sClient.Status().Update(context.TODO(), &sts)).Should(Succeed())

Expand Down Expand Up @@ -559,7 +561,6 @@ var _ = Describe("CassandraTask controller tests", func() {
Expect(inflight).To(BeNumerically("<=", 1))

for _, sts := range stsAll.Items {
// TODO Verify that the restart wasn't set to all StS at once
if _, found := sts.Spec.Template.ObjectMeta.Annotations[api.RestartedAtAnnotation]; found {
// Imitate statefulset_controller
if sts.Status.UpdateRevision != "1" {
Expand All @@ -568,6 +569,7 @@ var _ = Describe("CassandraTask controller tests", func() {
sts.Status.CurrentReplicas = sts.Status.Replicas
sts.Status.UpdateRevision = "1"
sts.Status.CurrentRevision = sts.Status.UpdateRevision
sts.Status.ObservedGeneration = sts.GetObjectMeta().GetGeneration()

Expect(k8sClient.Status().Update(context.TODO(), &sts)).Should(Succeed())
}
Expand Down
3 changes: 2 additions & 1 deletion controllers/control/jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ func (r *CassandraTaskReconciler) restartSts(ctx context.Context, sts []appsv1.S
if status.CurrentRevision == status.UpdateRevision &&
status.UpdatedReplicas == status.Replicas &&
status.CurrentReplicas == status.Replicas &&
status.ReadyReplicas == status.Replicas {
status.ReadyReplicas == status.Replicas &&
status.ObservedGeneration == st.GetObjectMeta().GetGeneration() {
// This one has been updated, move on to the next one
continue
}
Expand Down

0 comments on commit 2673975

Please sign in to comment.