From d650baf75d332261d91c8e52b6bcf3ba31a1e953 Mon Sep 17 00:00:00 2001 From: Julio Chana Date: Tue, 16 Jan 2018 11:42:59 +0100 Subject: [PATCH 1/7] [DEVOPS-657] Add parameter to set if we want the antiAffinity hard --- pkg/failover/spec.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkg/failover/spec.go b/pkg/failover/spec.go index 429d877df..64b711107 100644 --- a/pkg/failover/spec.go +++ b/pkg/failover/spec.go @@ -43,6 +43,10 @@ type RedisFailoverSpec struct { // Sentinel defines its failover settings Sentinel SentinelSettings `json:"sentinel,omitempty"` + + // HardAntiAffinity defines if the PodAntiAffinity on the deployments and + // statefulsets has to be hard (it's soft by default) + HardAntiAffinity bool `json:"hardAntiAffinity,omitempty"` } // RedisFailover represents a Redis failover From 765aee091a54115a9cedfeaba219577bcf895096 Mon Sep 17 00:00:00 2001 From: Julio Chana Date: Tue, 16 Jan 2018 11:43:30 +0100 Subject: [PATCH 2/7] [DEVOPS-657] Update the resources if the antiAffinity has changed --- pkg/failover/controller.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pkg/failover/controller.go b/pkg/failover/controller.go index 4a645422d..57d3ec9b7 100644 --- a/pkg/failover/controller.go +++ b/pkg/failover/controller.go @@ -244,7 +244,7 @@ func (r *RedisFailoverController) OnUpdate(oldObj, newObj interface{}) { return } - if new.Spec.Sentinel != old.Spec.Sentinel { + if new.Spec.Sentinel != old.Spec.Sentinel || new.Spec.HardAntiAffinity != old.Spec.HardAntiAffinity { logger.Info("Updating Sentinel deployment...") logger.Debugf("OLD: \n%+v", old.Spec.Sentinel) logger.Debugf("NEW: \n%+v", new.Spec.Sentinel) @@ -252,6 +252,8 @@ func (r *RedisFailoverController) OnUpdate(oldObj, newObj interface{}) { new.Status.AppendScalingSentinelUpCondition(old.Spec.Sentinel.Replicas, new.Spec.Sentinel.Replicas) } else if old.Spec.Sentinel.Replicas > new.Spec.Sentinel.Replicas { new.Status.AppendScalingSentinelDownCondition(old.Spec.Sentinel.Replicas, new.Spec.Sentinel.Replicas) + } else if new.Spec.HardAntiAffinity != old.Spec.HardAntiAffinity { + new.Status.AppendUpdatingSentinelCondition("Change the podAntiAffinity") } else { new.Status.AppendUpdatingSentinelCondition("Change the resources/limits") } @@ -264,7 +266,8 @@ func (r *RedisFailoverController) OnUpdate(oldObj, newObj interface{}) { } logger.Info("Sentinel Deployment updated!") } - if new.Spec.Redis != old.Spec.Redis { + + if new.Spec.Redis != old.Spec.Redis || new.Spec.HardAntiAffinity != old.Spec.HardAntiAffinity { logger.Info("Updating Redis statefulset...") logger.Debugf("OLD: \n%+v", old.Spec.Redis) logger.Debugf("NEW: \n%+v", new.Spec.Redis) @@ -272,6 +275,8 @@ func (r *RedisFailoverController) OnUpdate(oldObj, newObj interface{}) { new.Status.AppendScalingRedisUpCondition(old.Spec.Redis.Replicas, new.Spec.Redis.Replicas) } else if old.Spec.Redis.Replicas > new.Spec.Redis.Replicas { new.Status.AppendScalingRedisDownCondition(old.Spec.Redis.Replicas, new.Spec.Redis.Replicas) + } else if new.Spec.HardAntiAffinity != old.Spec.HardAntiAffinity { + new.Status.AppendUpdatingSentinelCondition("Change the podAntiAffinity") } else { new.Status.AppendUpdatingRedisCondition("Change the resources/limits") } @@ -284,6 +289,7 @@ func (r *RedisFailoverController) OnUpdate(oldObj, newObj interface{}) { } logger.Info("Redis statefulset updated!") } + new.Status.SetReadyCondition() if _, err := r.Client.UpdateStatus(new); err != nil { logger.Errorf("Error updating status: %s", err) From 18a2dc59b0db68092d61d2ce1c3cd855e876a8c7 Mon Sep 17 00:00:00 2001 From: Julio Chana Date: Tue, 16 Jan 2018 11:44:08 +0100 Subject: [PATCH 3/7] [DEVOPS-657] Move the antiAffinity to a function with hard or soft option --- pkg/failover/client.go | 65 ++++++++++++++++++++++++++---------------- 1 file changed, 41 insertions(+), 24 deletions(-) diff --git a/pkg/failover/client.go b/pkg/failover/client.go index 34e5d05a7..67c46d719 100644 --- a/pkg/failover/client.go +++ b/pkg/failover/client.go @@ -429,18 +429,7 @@ func (r *RedisFailoverKubeClient) CreateSentinelDeployment(rf *RedisFailover) er Labels: labels, }, Spec: v1.PodSpec{ - Affinity: &v1.Affinity{ - PodAntiAffinity: &v1.PodAntiAffinity{ - RequiredDuringSchedulingIgnoredDuringExecution: []v1.PodAffinityTerm{ - v1.PodAffinityTerm{ - TopologyKey: hostnameTopologyKey, - LabelSelector: &metav1.LabelSelector{ - MatchLabels: labels, - }, - }, - }, - }, - }, + Affinity: createPodAntiAffinity(rf.Spec.HardAntiAffinity, labels), InitContainers: []v1.Container{ v1.Container{ Name: "sentinel-config", @@ -579,18 +568,7 @@ func (r *RedisFailoverKubeClient) CreateRedisStatefulset(rf *RedisFailover) erro Labels: labels, }, Spec: v1.PodSpec{ - Affinity: &v1.Affinity{ - PodAntiAffinity: &v1.PodAntiAffinity{ - RequiredDuringSchedulingIgnoredDuringExecution: []v1.PodAffinityTerm{ - v1.PodAffinityTerm{ - TopologyKey: hostnameTopologyKey, - LabelSelector: &metav1.LabelSelector{ - MatchLabels: labels, - }, - }, - }, - }, - }, + Affinity: createPodAntiAffinity(rf.Spec.HardAntiAffinity, labels), InitContainers: []v1.Container{ v1.Container{ Name: "redis-config", @@ -761,6 +739,7 @@ func (r *RedisFailoverKubeClient) createPodDisruptionBudget(rf *RedisFailover, n func (r *RedisFailoverKubeClient) UpdateSentinelDeployment(rf *RedisFailover) error { namespace := rf.Metadata.Namespace logger := r.logger.WithField(logNameField, rf.Metadata.Name).WithField(logNamespaceField, rf.Metadata.Namespace) + labels := generateLabels(sentinelRoleName, rf.Metadata.Name) quorum := rf.GetQuorum() replicas := rf.Spec.Sentinel.Replicas @@ -784,6 +763,7 @@ func (r *RedisFailoverKubeClient) UpdateSentinelDeployment(rf *RedisFailover) er oldSD.Spec.Template.Spec.InitContainers[0].Env = initEnv oldSD.Spec.Template.Spec.Containers[0].Image = getRedisImage(rf) oldSD.Spec.Template.Spec.Containers[0].Resources = getSentinelResources(rf.Spec) + oldSD.Spec.Template.Spec.Affinity = createPodAntiAffinity(rf.Spec.HardAntiAffinity, labels) if err := r.waitForStatefulset(r.GetRedisName(rf), namespace, rf.Spec.Redis.Replicas, logger); err != nil { return err @@ -800,6 +780,7 @@ func (r *RedisFailoverKubeClient) UpdateSentinelDeployment(rf *RedisFailover) er func (r *RedisFailoverKubeClient) UpdateRedisStatefulset(rf *RedisFailover) error { namespace := rf.Metadata.Namespace logger := r.logger.WithField(logNameField, rf.Metadata.Name).WithField(logNamespaceField, rf.Metadata.Namespace) + labels := generateLabels(redisRoleName, rf.Metadata.Name) replicas := rf.Spec.Redis.Replicas @@ -811,6 +792,7 @@ func (r *RedisFailoverKubeClient) UpdateRedisStatefulset(rf *RedisFailover) erro oldSS.Spec.Replicas = &replicas oldSS.Spec.Template.Spec.Containers[0].Resources = getRedisResources(rf.Spec) oldSS.Spec.Template.Spec.Containers[0].Image = getRedisImage(rf) + oldSS.Spec.Template.Spec.Affinity = createPodAntiAffinity(rf.Spec.HardAntiAffinity, labels) if rf.Spec.Redis.Exporter { found := false @@ -1024,3 +1006,38 @@ func createRedisExporterContainer() v1.Container { }, } } + +func createPodAntiAffinity(hard bool, labels map[string]string) *v1.Affinity { + if hard { + // Return a HARD anti-affinity (no same pods on one node) + return &v1.Affinity{ + PodAntiAffinity: &v1.PodAntiAffinity{ + RequiredDuringSchedulingIgnoredDuringExecution: []v1.PodAffinityTerm{ + v1.PodAffinityTerm{ + TopologyKey: hostnameTopologyKey, + LabelSelector: &metav1.LabelSelector{ + MatchLabels: labels, + }, + }, + }, + }, + } + } + + // Return a SOFT anti-affinity + return &v1.Affinity{ + PodAntiAffinity: &v1.PodAntiAffinity{ + PreferredDuringSchedulingIgnoredDuringExecution: []v1.WeightedPodAffinityTerm{ + v1.WeightedPodAffinityTerm{ + Weight: 100, + PodAffinityTerm: v1.PodAffinityTerm{ + TopologyKey: hostnameTopologyKey, + LabelSelector: &metav1.LabelSelector{ + MatchLabels: labels, + }, + }, + }, + }, + }, + } +} From 4e0c7493044f52eaa9e3588715e88a84c6c9d8b4 Mon Sep 17 00:00:00 2001 From: Julio Chana Date: Tue, 16 Jan 2018 11:44:31 +0100 Subject: [PATCH 4/7] [DEVOPS-657] Improve waiter checking also the number of replicas --- pkg/failover/waiter.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/failover/waiter.go b/pkg/failover/waiter.go index 2944566c9..9fcb4313d 100644 --- a/pkg/failover/waiter.go +++ b/pkg/failover/waiter.go @@ -63,7 +63,7 @@ func (r *RedisFailoverKubeClient) waitForDeployment(name string, namespace strin case <-t.C: logger.Debug("Waiting for Sentinel deployment to be fully operative") deployment, _ := r.Client.AppsV1beta1().Deployments(namespace).Get(name, metav1.GetOptions{}) - if deployment.Status.ReadyReplicas == replicas { + if deployment.Status.ReadyReplicas == replicas && deployment.Status.Replicas == replicas { return nil } case <-to: @@ -82,7 +82,7 @@ func (r *RedisFailoverKubeClient) waitForStatefulset(name string, namespace stri case <-t.C: logger.Debug("Waiting for Redis statefulset to be fully operative") statefulset, _ := r.Client.AppsV1beta1().StatefulSets(namespace).Get(name, metav1.GetOptions{}) - if statefulset.Status.ReadyReplicas == replicas { + if statefulset.Status.ReadyReplicas == replicas && statefulset.Status.Replicas == replicas { return nil } case <-to: From 928444682ea55f6078bca9e5e322cd0da2c3dae8 Mon Sep 17 00:00:00 2001 From: Julio Chana Date: Tue, 16 Jan 2018 11:44:48 +0100 Subject: [PATCH 5/7] [DEVOPS-657] Add a testing option on the Makefile --- Makefile | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index af766bfd6..ac63e885c 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ # The following are targers that do not exist in the filesystem as real files and should be always executed by make -.PHONY: default build deps-development docker-build shell run image unit-test test generate go-generate get-deps update-deps +.PHONY: default build deps-development docker-build shell run image unit-test test generate go-generate get-deps update-deps testing VERSION := 0.1.5 # Name of this service/application @@ -81,6 +81,10 @@ image: deps-development -t $(REPOSITORY):$(BRANCH) \ -f $(APP_DIR)/Dockerfile \ . + +testing: image + docker push $(REPOSITORY):$(BRANCH) + tag: git tag $(VERSION) From 61c0f1697e5466aefc67c27b9713a7590eeca679 Mon Sep 17 00:00:00 2001 From: Julio Chana Date: Tue, 16 Jan 2018 12:02:40 +0100 Subject: [PATCH 6/7] [DEVOPS-657] Add new option on readme --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 907dce672..78be2d02a 100644 --- a/README.md +++ b/README.md @@ -56,21 +56,22 @@ metadata: name: myredisfailover namespace: mynamespace spec: + hardAntiAffinity: false # Optional. Value by default. If true, the pods will not be scheduled on the same node. sentinel: - replicas: 3 # Optional. Value by default, can be set higher. - resources: # Optional. If not set, it won't be defined on created reosurces + replicas: 3 # Optional. Value by default, can be set higher. + resources: # Optional. If not set, it won't be defined on created reosurces requests: cpu: 100m limits: memory: 100Mi redis: - replicas: 3 # Optional. Value by default, can be set higher. - resources: # Optional. If not set, it won't be defined on created reosurces + replicas: 3 # Optional. Value by default, can be set higher. + resources: # Optional. If not set, it won't be defined on created reosurces requests: cpu: 100m limits: memory: 100Mi - exporter: false # Optional. False by default. Adds a redis-exporter container to export metrics. + exporter: false # Optional. False by default. Adds a redis-exporter container to export metrics. ~~~~ ## Creation pipeline @@ -125,4 +126,3 @@ You can do the following commands with make: `make update-deps` * Build the app image. `make image` - From 0ae1e780026668182c8a200229b45af9d62dab09 Mon Sep 17 00:00:00 2001 From: Julio Chana Date: Tue, 16 Jan 2018 12:58:44 +0100 Subject: [PATCH 7/7] [DEVOPS-657] Add test for new functionality --- pkg/failover/client_test.go | 242 +++++++++++++++++++++++++++++++----- 1 file changed, 212 insertions(+), 30 deletions(-) diff --git a/pkg/failover/client_test.go b/pkg/failover/client_test.go index a9a27b30e..5b48d3dce 100644 --- a/pkg/failover/client_test.go +++ b/pkg/failover/client_test.go @@ -873,6 +873,7 @@ func TestCreateSentinelDeploymentPDBError(t *testing.T) { Namespace: namespace, }, Status: v1beta1.DeploymentStatus{ + Replicas: deploymentSize, ReadyReplicas: deploymentSize, }, } @@ -927,6 +928,7 @@ func TestCreateSentinelDeploymentReplicas(t *testing.T) { Namespace: namespace, }, Status: v1beta1.DeploymentStatus{ + Replicas: deploymentSize, ReadyReplicas: deploymentSize, }, } @@ -1041,6 +1043,7 @@ func TestCreateSentinelDeploymentTimeoutError(t *testing.T) { Namespace: namespace, }, Status: v1beta1.DeploymentStatus{ + Replicas: deploymentSize, ReadyReplicas: deploymentSize, }, } @@ -1094,6 +1097,7 @@ func TestCreateSentinelDeployment(t *testing.T) { Namespace: namespace, }, Status: v1beta1.DeploymentStatus{ + Replicas: deploymentSize, ReadyReplicas: deploymentSize, }, } @@ -1312,6 +1316,7 @@ func TestCreateRedisStatefulsetPDBError(t *testing.T) { Namespace: namespace, }, Status: v1beta1.StatefulSetStatus{ + Replicas: statefulsetSize, ReadyReplicas: statefulsetSize, }, } @@ -1419,6 +1424,7 @@ func TestCreateRedisStatefulsetReplicas(t *testing.T) { Namespace: namespace, }, Status: v1beta1.StatefulSetStatus{ + Replicas: statefulsetSize, ReadyReplicas: statefulsetSize, }, } @@ -1523,6 +1529,7 @@ func TestCreateRedisStatefulsetTimeoutError(t *testing.T) { Namespace: namespace, }, Status: v1beta1.StatefulSetStatus{ + Replicas: statefulsetSize, ReadyReplicas: statefulsetSize, }, } @@ -1561,6 +1568,184 @@ func TestCreateRedisStatefulsetTimeoutError(t *testing.T) { assert.Error(err) } +func TestCreateRedisStatefulsetSoftAffinity(t *testing.T) { + assert := assert.New(t) + + // Create a faked K8S client + client := &fake.Clientset{} + + statefulsetSize := int32(3) + // Add a reactor when calling pods + client.Fake.AddReactor("get", "statefulsets", func(action k8stesting.Action) (bool, runtime.Object, error) { + // Create the statefulset to be returned with Replicas = 3 + statefulset := &v1beta1.StatefulSet{ + ObjectMeta: metav1.ObjectMeta{ + Name: redisName, + Namespace: namespace, + }, + Status: v1beta1.StatefulSetStatus{ + Replicas: statefulsetSize, + ReadyReplicas: statefulsetSize, + }, + } + + // Return the statefulset as if we where the API responding to GET statefulsets + return true, statefulset, nil + }) + + client.Fake.AddReactor("get", "poddisruptionbudgets", func(action k8stesting.Action) (bool, runtime.Object, error) { + return true, nil, errors.New("") + }) + client.Fake.AddReactor("create", "poddisruptionbudgets", func(action k8stesting.Action) (bool, runtime.Object, error) { + return true, nil, nil + }) + + expectedAffinity := &v1.Affinity{ + PodAntiAffinity: &v1.PodAntiAffinity{ + PreferredDuringSchedulingIgnoredDuringExecution: []v1.WeightedPodAffinityTerm{ + v1.WeightedPodAffinityTerm{ + Weight: 100, + PodAffinityTerm: v1.PodAffinityTerm{ + TopologyKey: "kubernetes.io/hostname", + LabelSelector: &metav1.LabelSelector{ + MatchLabels: map[string]string{ + "app": "redis-failover", + "component": "redis", + "redis": "test", + }, + }, + }, + }, + }, + }, + } + + createdAffinity := &v1.Affinity{} + + // Add a reactor when calling pods + client.Fake.AddReactor("create", "statefulsets", func(action k8stesting.Action) (bool, runtime.Object, error) { + createAction := action.(k8stesting.CreateAction) + statefulset := createAction.GetObject().(*v1beta1.StatefulSet) + createdAffinity = statefulset.Spec.Template.Spec.Affinity + + return true, nil, nil + }) + + mc := &mocks.Clock{} + mc.On("NewTicker", mock.Anything). + Once().Return(time.NewTicker(1)) + mc.On("After", mock.Anything). + Once().Return(time.After(time.Hour)) + r := failover.NewRedisFailoverKubeClient(client, mc, log.Nil) + + redisFailover := &failover.RedisFailover{ + Metadata: metav1.ObjectMeta{ + Name: name, + Namespace: namespace, + }, + Spec: failover.RedisFailoverSpec{ + Redis: failover.RedisSettings{ + Replicas: int32(3), + }, + Sentinel: failover.SentinelSettings{ + Replicas: int32(3), + }, + }, + } + + err := r.CreateRedisStatefulset(redisFailover) + assert.NoError(err) + assert.Equal(expectedAffinity, createdAffinity) +} + +func TestCreateRedisStatefulsetHardAffinity(t *testing.T) { + assert := assert.New(t) + + // Create a faked K8S client + client := &fake.Clientset{} + + statefulsetSize := int32(3) + // Add a reactor when calling pods + client.Fake.AddReactor("get", "statefulsets", func(action k8stesting.Action) (bool, runtime.Object, error) { + // Create the statefulset to be returned with Replicas = 3 + statefulset := &v1beta1.StatefulSet{ + ObjectMeta: metav1.ObjectMeta{ + Name: redisName, + Namespace: namespace, + }, + Status: v1beta1.StatefulSetStatus{ + Replicas: statefulsetSize, + ReadyReplicas: statefulsetSize, + }, + } + + // Return the statefulset as if we where the API responding to GET statefulsets + return true, statefulset, nil + }) + + client.Fake.AddReactor("get", "poddisruptionbudgets", func(action k8stesting.Action) (bool, runtime.Object, error) { + return true, nil, errors.New("") + }) + client.Fake.AddReactor("create", "poddisruptionbudgets", func(action k8stesting.Action) (bool, runtime.Object, error) { + return true, nil, nil + }) + + expectedAffinity := &v1.Affinity{ + PodAntiAffinity: &v1.PodAntiAffinity{ + RequiredDuringSchedulingIgnoredDuringExecution: []v1.PodAffinityTerm{ + v1.PodAffinityTerm{ + TopologyKey: "kubernetes.io/hostname", + LabelSelector: &metav1.LabelSelector{ + MatchLabels: map[string]string{ + "app": "redis-failover", + "component": "redis", + "redis": "test", + }, + }, + }, + }, + }, + } + + createdAffinity := &v1.Affinity{} + + // Add a reactor when calling pods + client.Fake.AddReactor("create", "statefulsets", func(action k8stesting.Action) (bool, runtime.Object, error) { + createAction := action.(k8stesting.CreateAction) + statefulset := createAction.GetObject().(*v1beta1.StatefulSet) + createdAffinity = statefulset.Spec.Template.Spec.Affinity + + return true, nil, nil + }) + + mc := &mocks.Clock{} + mc.On("NewTicker", mock.Anything). + Once().Return(time.NewTicker(1)) + mc.On("After", mock.Anything). + Once().Return(time.After(time.Hour)) + r := failover.NewRedisFailoverKubeClient(client, mc, log.Nil) + + redisFailover := &failover.RedisFailover{ + Metadata: metav1.ObjectMeta{ + Name: name, + Namespace: namespace, + }, + Spec: failover.RedisFailoverSpec{ + HardAntiAffinity: true, + Redis: failover.RedisSettings{ + Replicas: int32(3), + }, + Sentinel: failover.SentinelSettings{ + Replicas: int32(3), + }, + }, + } + + err := r.CreateRedisStatefulset(redisFailover) + assert.NoError(err) + assert.Equal(expectedAffinity, createdAffinity) +} + func TestCreateRedisStatefulset(t *testing.T) { assert := assert.New(t) @@ -1577,6 +1762,7 @@ func TestCreateRedisStatefulset(t *testing.T) { Namespace: namespace, }, Status: v1beta1.StatefulSetStatus{ + Replicas: statefulsetSize, ReadyReplicas: statefulsetSize, }, } @@ -1671,8 +1857,8 @@ func TestUpdateSentinelDeploymentError(t *testing.T) { Namespace: namespace, }, Status: v1beta1.DeploymentStatus{ - ReadyReplicas: replicas, - UpdatedReplicas: replicas, + ReadyReplicas: replicas, + Replicas: replicas, }, Spec: v1beta1.DeploymentSpec{ Template: v1.PodTemplateSpec{ @@ -1700,6 +1886,7 @@ func TestUpdateSentinelDeploymentError(t *testing.T) { Namespace: namespace, }, Status: v1beta1.StatefulSetStatus{ + Replicas: statefulsetSize, ReadyReplicas: statefulsetSize, }, } @@ -1758,8 +1945,8 @@ func TestUpdateSentinelDeploymentTimeoutError(t *testing.T) { Namespace: namespace, }, Status: v1beta1.DeploymentStatus{ - ReadyReplicas: replicas, - UpdatedReplicas: replicas, + ReadyReplicas: replicas, + Replicas: replicas, }, Spec: v1beta1.DeploymentSpec{ Template: v1.PodTemplateSpec{ @@ -1785,6 +1972,7 @@ func TestUpdateSentinelDeploymentTimeoutError(t *testing.T) { Namespace: namespace, }, Status: v1beta1.StatefulSetStatus{ + Replicas: int32(3), ReadyReplicas: int32(3), }, } @@ -1866,8 +2054,8 @@ func TestUpdateSentinelDeployment(t *testing.T) { Namespace: namespace, }, Status: v1beta1.DeploymentStatus{ - ReadyReplicas: replicas, - UpdatedReplicas: replicas, + ReadyReplicas: replicas, + Replicas: replicas, }, Spec: v1beta1.DeploymentSpec{ Template: v1.PodTemplateSpec{ @@ -1895,6 +2083,7 @@ func TestUpdateSentinelDeployment(t *testing.T) { Namespace: namespace, }, Status: v1beta1.StatefulSetStatus{ + Replicas: statefulsetSize, ReadyReplicas: statefulsetSize, }, } @@ -2012,8 +2201,8 @@ func TestUpdateRedisStatefulsetError(t *testing.T) { Namespace: namespace, }, Status: v1beta1.DeploymentStatus{ - ReadyReplicas: replicas, - UpdatedReplicas: replicas, + ReadyReplicas: replicas, + Replicas: replicas, }, } return true, deployment, nil @@ -2075,19 +2264,11 @@ func TestUpdateRedisStatefulsetWithUpdate(t *testing.T) { // Create a faked K8S client client := &fake.Clientset{} client.Fake.AddReactor("get", "statefulsets", func(action k8stesting.Action) (bool, runtime.Object, error) { - r := replicas - if called { - r = replicasUpdated - } statefulset := &v1beta1.StatefulSet{ ObjectMeta: metav1.ObjectMeta{ Name: redisName, Namespace: namespace, }, - Status: v1beta1.StatefulSetStatus{ - ReadyReplicas: r, - UpdatedReplicas: r, - }, Spec: v1beta1.StatefulSetSpec{ Template: v1.PodTemplateSpec{ Spec: v1.PodSpec{ @@ -2134,8 +2315,8 @@ func TestUpdateRedisStatefulsetWithUpdate(t *testing.T) { Namespace: namespace, }, Status: v1beta1.DeploymentStatus{ - ReadyReplicas: replicas, - UpdatedReplicas: replicas, + ReadyReplicas: replicas, + Replicas: replicas, }, } return true, deployment, nil @@ -2220,8 +2401,8 @@ func TestUpdateRedisStatefulsetWithoutUpdate(t *testing.T) { Namespace: namespace, }, Status: v1beta1.StatefulSetStatus{ - ReadyReplicas: r, - UpdatedReplicas: r, + ReadyReplicas: r, + Replicas: r, }, Spec: v1beta1.StatefulSetSpec{ Template: v1.PodTemplateSpec{ @@ -2272,8 +2453,8 @@ func TestUpdateRedisStatefulsetWithoutUpdate(t *testing.T) { Namespace: namespace, }, Status: v1beta1.DeploymentStatus{ - ReadyReplicas: replicas, - UpdatedReplicas: replicas, + ReadyReplicas: replicas, + Replicas: replicas, }, } return true, deployment, nil @@ -2343,8 +2524,8 @@ func TestUpdateRedisStatefulsetTimeoutError(t *testing.T) { Namespace: namespace, }, Status: v1beta1.StatefulSetStatus{ - ReadyReplicas: r, - UpdatedReplicas: r, + ReadyReplicas: r, + Replicas: r, }, Spec: v1beta1.StatefulSetSpec{ Template: v1.PodTemplateSpec{ @@ -2384,8 +2565,8 @@ func TestUpdateRedisStatefulsetTimeoutError(t *testing.T) { Namespace: namespace, }, Status: v1beta1.DeploymentStatus{ - ReadyReplicas: replicas, - UpdatedReplicas: replicas, + ReadyReplicas: replicas, + Replicas: replicas, }, } return true, deployment, nil @@ -2465,8 +2646,8 @@ func TestUpdateRedisStatefulset(t *testing.T) { Namespace: namespace, }, Status: v1beta1.StatefulSetStatus{ - ReadyReplicas: r, - UpdatedReplicas: r, + ReadyReplicas: r, + Replicas: r, }, Spec: v1beta1.StatefulSetSpec{ Template: v1.PodTemplateSpec{ @@ -2506,8 +2687,8 @@ func TestUpdateRedisStatefulset(t *testing.T) { Namespace: namespace, }, Status: v1beta1.DeploymentStatus{ - ReadyReplicas: replicas, - UpdatedReplicas: replicas, + ReadyReplicas: replicas, + Replicas: replicas, }, } return true, deployment, nil @@ -3158,6 +3339,7 @@ func TestCreatePDBAlreadyExists(t *testing.T) { Namespace: namespace, }, Status: v1beta1.DeploymentStatus{ + Replicas: deploymentSize, ReadyReplicas: deploymentSize, }, }