From 72c16b93bf38d0d74b81a4a3b6a397fed73d7d73 Mon Sep 17 00:00:00 2001 From: Michalis Kargakis Date: Wed, 18 Jul 2018 10:12:41 +0200 Subject: [PATCH] UPSTREAM: 62943: set updated replicas in statefulsets --- .../statefulset/stateful_set_control.go | 12 ++++-- .../statefulset/stateful_set_control_test.go | 42 +++++++++++++++++++ 2 files changed, 50 insertions(+), 4 deletions(-) diff --git a/vendor/k8s.io/kubernetes/pkg/controller/statefulset/stateful_set_control.go b/vendor/k8s.io/kubernetes/pkg/controller/statefulset/stateful_set_control.go index b1b589860432..9634b3d8d6a0 100644 --- a/vendor/k8s.io/kubernetes/pkg/controller/statefulset/stateful_set_control.go +++ b/vendor/k8s.io/kubernetes/pkg/controller/statefulset/stateful_set_control.go @@ -297,7 +297,8 @@ func (ssc *defaultStatefulSetControl) updateStatefulSet( if isCreated(pods[i]) && !isTerminating(pods[i]) { if getPodRevision(pods[i]) == currentRevision.Name { status.CurrentReplicas++ - } else if getPodRevision(pods[i]) == updateRevision.Name { + } + if getPodRevision(pods[i]) == updateRevision.Name { status.UpdatedReplicas++ } } @@ -379,7 +380,8 @@ func (ssc *defaultStatefulSetControl) updateStatefulSet( } if getPodRevision(replicas[i]) == currentRevision.Name { status.CurrentReplicas-- - } else if getPodRevision(replicas[i]) == updateRevision.Name { + } + if getPodRevision(replicas[i]) == updateRevision.Name { status.UpdatedReplicas-- } status.Replicas-- @@ -398,7 +400,8 @@ func (ssc *defaultStatefulSetControl) updateStatefulSet( status.Replicas++ if getPodRevision(replicas[i]) == currentRevision.Name { status.CurrentReplicas++ - } else if getPodRevision(replicas[i]) == updateRevision.Name { + } + if getPodRevision(replicas[i]) == updateRevision.Name { status.UpdatedReplicas++ } @@ -479,7 +482,8 @@ func (ssc *defaultStatefulSetControl) updateStatefulSet( } if getPodRevision(condemned[target]) == currentRevision.Name { status.CurrentReplicas-- - } else if getPodRevision(condemned[target]) == updateRevision.Name { + } + if getPodRevision(condemned[target]) == updateRevision.Name { status.UpdatedReplicas-- } if monotonic { diff --git a/vendor/k8s.io/kubernetes/pkg/controller/statefulset/stateful_set_control_test.go b/vendor/k8s.io/kubernetes/pkg/controller/statefulset/stateful_set_control_test.go index d3a21577c269..6af6630c3786 100644 --- a/vendor/k8s.io/kubernetes/pkg/controller/statefulset/stateful_set_control_test.go +++ b/vendor/k8s.io/kubernetes/pkg/controller/statefulset/stateful_set_control_test.go @@ -128,6 +128,12 @@ func CreatesPods(t *testing.T, set *apps.StatefulSet, invariants invariantFunc) if set.Status.Replicas != 3 { t.Error("Failed to scale statefulset to 3 replicas") } + if set.Status.ReadyReplicas != 3 { + t.Error("Failed to set ReadyReplicas correctly") + } + if set.Status.UpdatedReplicas != 3 { + t.Error("Failed to set UpdatedReplicas correctly") + } } func ScalesUp(t *testing.T, set *apps.StatefulSet, invariants invariantFunc) { @@ -150,6 +156,12 @@ func ScalesUp(t *testing.T, set *apps.StatefulSet, invariants invariantFunc) { if set.Status.Replicas != 4 { t.Error("Failed to scale statefulset to 4 replicas") } + if set.Status.ReadyReplicas != 4 { + t.Error("Failed to set readyReplicas correctly") + } + if set.Status.UpdatedReplicas != 4 { + t.Error("Failed to set updatedReplicas correctly") + } } func ScalesDown(t *testing.T, set *apps.StatefulSet, invariants invariantFunc) { @@ -167,6 +179,12 @@ func ScalesDown(t *testing.T, set *apps.StatefulSet, invariants invariantFunc) { if set.Status.Replicas != 0 { t.Error("Failed to scale statefulset to 0 replicas") } + if set.Status.ReadyReplicas != 0 { + t.Error("Failed to set readyReplicas correctly") + } + if set.Status.UpdatedReplicas != 0 { + t.Error("Failed to set updatedReplicas correctly") + } } func ReplacesPods(t *testing.T, set *apps.StatefulSet, invariants invariantFunc) { @@ -298,6 +316,12 @@ func CreatePodFailure(t *testing.T, set *apps.StatefulSet, invariants invariantF if set.Status.Replicas != 3 { t.Error("Failed to scale StatefulSet to 3 replicas") } + if set.Status.ReadyReplicas != 3 { + t.Error("Failed to set readyReplicas correctly") + } + if set.Status.UpdatedReplicas != 3 { + t.Error("Failed to updatedReplicas correctly") + } } func UpdatePodFailure(t *testing.T, set *apps.StatefulSet, invariants invariantFunc) { @@ -318,6 +342,12 @@ func UpdatePodFailure(t *testing.T, set *apps.StatefulSet, invariants invariantF if set.Status.Replicas != 3 { t.Error("Failed to scale StatefulSet to 3 replicas") } + if set.Status.ReadyReplicas != 3 { + t.Error("Failed to set readyReplicas correctly") + } + if set.Status.UpdatedReplicas != 3 { + t.Error("Failed to set updatedReplicas correctly") + } // now mutate a pod's identity pods, err := spc.podsLister.List(labels.Everything()) @@ -357,6 +387,12 @@ func UpdateSetStatusFailure(t *testing.T, set *apps.StatefulSet, invariants inva if set.Status.Replicas != 3 { t.Error("Failed to scale StatefulSet to 3 replicas") } + if set.Status.ReadyReplicas != 3 { + t.Error("Failed to set readyReplicas to 3") + } + if set.Status.UpdatedReplicas != 3 { + t.Error("Failed to set updatedReplicas to 3") + } } func PodRecreateDeleteFailure(t *testing.T, set *apps.StatefulSet, invariants invariantFunc) { @@ -436,6 +472,12 @@ func TestStatefulSetControlScaleDownDeleteError(t *testing.T) { if set.Status.Replicas != 0 { t.Error("Failed to scale statefulset to 0 replicas") } + if set.Status.ReadyReplicas != 0 { + t.Error("Failed to set readyReplicas to 0") + } + if set.Status.UpdatedReplicas != 0 { + t.Error("Failed to set updatedReplicas to 0") + } } func TestStatefulSetControl_getSetRevisions(t *testing.T) {