From b0a4d7cdcb59e4eb093e6b3e4bdd16476da4580d Mon Sep 17 00:00:00 2001 From: Akihito INOH Date: Tue, 2 Apr 2019 14:52:24 +0900 Subject: [PATCH] Fix golint failures of e2e/framework/statefulset_utils.go This fixes golint failures of the following file: - test/e2e/framework/statefulset_utils.go This changes following file because of change function name in above file. - test/e2e/apps/statefulset.go --- test/e2e/apps/statefulset.go | 36 ++++++++--------- test/e2e/framework/statefulset_utils.go | 54 ++++++++++++------------- 2 files changed, 45 insertions(+), 45 deletions(-) diff --git a/test/e2e/apps/statefulset.go b/test/e2e/apps/statefulset.go index 2985d2df2c..12c57780d5 100644 --- a/test/e2e/apps/statefulset.go +++ b/test/e2e/apps/statefulset.go @@ -278,7 +278,7 @@ var _ = SIGDescribe("StatefulSet", func() { By("Creating a new StatefulSet") ss := framework.NewStatefulSet("ss2", ns, headlessSvcName, 3, nil, nil, labels) sst := framework.NewStatefulSetTester(c) - sst.SetHttpProbe(ss) + sst.SetHTTPProbe(ss) ss.Spec.UpdateStrategy = apps.StatefulSetUpdateStrategy{ Type: apps.RollingUpdateStatefulSetStrategyType, RollingUpdate: func() *apps.RollingUpdateStatefulSetStrategy { @@ -489,7 +489,7 @@ var _ = SIGDescribe("StatefulSet", func() { By("Creating a new StatefulSet") ss := framework.NewStatefulSet("ss2", ns, headlessSvcName, 3, nil, nil, labels) sst := framework.NewStatefulSetTester(c) - sst.SetHttpProbe(ss) + sst.SetHTTPProbe(ss) ss.Spec.UpdateStrategy = apps.StatefulSetUpdateStrategy{ Type: apps.OnDeleteStatefulSetStrategyType, } @@ -581,7 +581,7 @@ var _ = SIGDescribe("StatefulSet", func() { By("Creating stateful set " + ssName + " in namespace " + ns) ss := framework.NewStatefulSet(ssName, ns, headlessSvcName, 1, nil, nil, psLabels) sst := framework.NewStatefulSetTester(c) - sst.SetHttpProbe(ss) + sst.SetHTTPProbe(ss) ss, err = c.AppsV1().StatefulSets(ns).Create(ss) Expect(err).NotTo(HaveOccurred()) @@ -589,14 +589,14 @@ var _ = SIGDescribe("StatefulSet", func() { sst.WaitForRunningAndReady(*ss.Spec.Replicas, ss) By("Confirming that stateful set scale up will halt with unhealthy stateful pod") - sst.BreakHttpProbe(ss) + sst.BreakHTTPProbe(ss) sst.WaitForRunningAndNotReady(*ss.Spec.Replicas, ss) sst.WaitForStatusReadyReplicas(ss, 0) sst.UpdateReplicas(ss, 3) sst.ConfirmStatefulPodCount(1, ss, 10*time.Second, true) By("Scaling up stateful set " + ssName + " to 3 replicas and waiting until all of them will be running in namespace " + ns) - sst.RestoreHttpProbe(ss) + sst.RestoreHTTPProbe(ss) sst.WaitForRunningAndReady(3, ss) By("Verifying that stateful set " + ssName + " was scaled up in order") @@ -622,14 +622,14 @@ var _ = SIGDescribe("StatefulSet", func() { }) Expect(err).NotTo(HaveOccurred()) - sst.BreakHttpProbe(ss) + sst.BreakHTTPProbe(ss) sst.WaitForStatusReadyReplicas(ss, 0) sst.WaitForRunningAndNotReady(3, ss) sst.UpdateReplicas(ss, 0) sst.ConfirmStatefulPodCount(3, ss, 10*time.Second, true) By("Scaling down stateful set " + ssName + " to 0 replicas and waiting until none of pods will run in namespace" + ns) - sst.RestoreHttpProbe(ss) + sst.RestoreHTTPProbe(ss) sst.Scale(ss, 0) By("Verifying that stateful set " + ssName + " was scaled down in reverse order") @@ -662,7 +662,7 @@ var _ = SIGDescribe("StatefulSet", func() { ss := framework.NewStatefulSet(ssName, ns, headlessSvcName, 1, nil, nil, psLabels) ss.Spec.PodManagementPolicy = apps.ParallelPodManagement sst := framework.NewStatefulSetTester(c) - sst.SetHttpProbe(ss) + sst.SetHTTPProbe(ss) ss, err := c.AppsV1().StatefulSets(ns).Create(ss) Expect(err).NotTo(HaveOccurred()) @@ -670,25 +670,25 @@ var _ = SIGDescribe("StatefulSet", func() { sst.WaitForRunningAndReady(*ss.Spec.Replicas, ss) By("Confirming that stateful set scale up will not halt with unhealthy stateful pod") - sst.BreakHttpProbe(ss) + sst.BreakHTTPProbe(ss) sst.WaitForRunningAndNotReady(*ss.Spec.Replicas, ss) sst.WaitForStatusReadyReplicas(ss, 0) sst.UpdateReplicas(ss, 3) sst.ConfirmStatefulPodCount(3, ss, 10*time.Second, false) By("Scaling up stateful set " + ssName + " to 3 replicas and waiting until all of them will be running in namespace " + ns) - sst.RestoreHttpProbe(ss) + sst.RestoreHTTPProbe(ss) sst.WaitForRunningAndReady(3, ss) By("Scale down will not halt with unhealthy stateful pod") - sst.BreakHttpProbe(ss) + sst.BreakHTTPProbe(ss) sst.WaitForStatusReadyReplicas(ss, 0) sst.WaitForRunningAndNotReady(3, ss) sst.UpdateReplicas(ss, 0) sst.ConfirmStatefulPodCount(0, ss, 10*time.Second, false) By("Scaling down stateful set " + ssName + " to 0 replicas and waiting until none of pods will run in namespace" + ns) - sst.RestoreHttpProbe(ss) + sst.RestoreHTTPProbe(ss) sst.Scale(ss, 0) sst.WaitForStatusReplicas(ss, 0) }) @@ -788,7 +788,7 @@ var _ = SIGDescribe("StatefulSet", func() { By("Creating statefulset " + ssName + " in namespace " + ns) ss := framework.NewStatefulSet(ssName, ns, headlessSvcName, 1, nil, nil, labels) sst := framework.NewStatefulSetTester(c) - sst.SetHttpProbe(ss) + sst.SetHTTPProbe(ss) ss, err := c.AppsV1().StatefulSets(ns).Create(ss) Expect(err).NotTo(HaveOccurred()) sst.WaitForRunningAndReady(*ss.Spec.Replicas, ss) @@ -1083,7 +1083,7 @@ func pollReadWithTimeout(statefulPod statefulPodTester, statefulPodNumber int, k // PVCs and one using no storage. func rollbackTest(c clientset.Interface, ns string, ss *apps.StatefulSet) { sst := framework.NewStatefulSetTester(c) - sst.SetHttpProbe(ss) + sst.SetHTTPProbe(ss) ss, err := c.AppsV1().StatefulSets(ns).Create(ss) Expect(err).NotTo(HaveOccurred()) sst.WaitForRunningAndReady(*ss.Spec.Replicas, ss) @@ -1102,7 +1102,7 @@ func rollbackTest(c clientset.Interface, ns string, ss *apps.StatefulSet) { currentRevision)) } sst.SortStatefulPods(pods) - err = sst.BreakPodHttpProbe(ss, &pods.Items[1]) + err = sst.BreakPodHTTPProbe(ss, &pods.Items[1]) Expect(err).NotTo(HaveOccurred()) ss, pods = sst.WaitForPodNotReady(ss, pods.Items[1].Name) newImage := NewNginxImage @@ -1124,7 +1124,7 @@ func rollbackTest(c clientset.Interface, ns string, ss *apps.StatefulSet) { By("Updating Pods in reverse ordinal order") pods = sst.GetPodList(ss) sst.SortStatefulPods(pods) - err = sst.RestorePodHttpProbe(ss, &pods.Items[1]) + err = sst.RestorePodHTTPProbe(ss, &pods.Items[1]) Expect(err).NotTo(HaveOccurred()) ss, pods = sst.WaitForPodReady(ss, pods.Items[1].Name) ss, pods = sst.WaitForRollingUpdate(ss) @@ -1150,7 +1150,7 @@ func rollbackTest(c clientset.Interface, ns string, ss *apps.StatefulSet) { } By("Rolling back to a previous revision") - err = sst.BreakPodHttpProbe(ss, &pods.Items[1]) + err = sst.BreakPodHTTPProbe(ss, &pods.Items[1]) Expect(err).NotTo(HaveOccurred()) ss, pods = sst.WaitForPodNotReady(ss, pods.Items[1].Name) priorRevision := currentRevision @@ -1169,7 +1169,7 @@ func rollbackTest(c clientset.Interface, ns string, ss *apps.StatefulSet) { By("Rolling back update in reverse ordinal order") pods = sst.GetPodList(ss) sst.SortStatefulPods(pods) - sst.RestorePodHttpProbe(ss, &pods.Items[1]) + sst.RestorePodHTTPProbe(ss, &pods.Items[1]) ss, pods = sst.WaitForPodReady(ss, pods.Items[1].Name) ss, pods = sst.WaitForRollingUpdate(ss) Expect(ss.Status.CurrentRevision).To(Equal(priorRevision), diff --git a/test/e2e/framework/statefulset_utils.go b/test/e2e/framework/statefulset_utils.go index 24d8a39964..b03452548e 100644 --- a/test/e2e/framework/statefulset_utils.go +++ b/test/e2e/framework/statefulset_utils.go @@ -43,11 +43,11 @@ import ( ) const ( - // Poll interval for StatefulSet tests + // StatefulSetPoll is a poll interval for StatefulSet tests StatefulSetPoll = 10 * time.Second - // Timeout interval for StatefulSet operations + // StatefulSetTimeout is a timeout interval for StatefulSet operations StatefulSetTimeout = 10 * time.Minute - // Timeout for stateful pods to change state + // StatefulPodTimeout is a timeout for stateful pods to change state StatefulPodTimeout = 5 * time.Minute ) @@ -468,16 +468,15 @@ func (s *StatefulSetTester) WaitForPartitionedRollingUpdate(set *apps.StatefulSe } } return false, nil - } else { - for i := int(*set.Spec.Replicas) - 1; i >= partition; i-- { - if pods.Items[i].Labels[apps.StatefulSetRevisionLabel] != set.Status.UpdateRevision { - Logf("Waiting for Pod %s/%s to have revision %s update revision %s", - pods.Items[i].Namespace, - pods.Items[i].Name, - set.Status.UpdateRevision, - pods.Items[i].Labels[apps.StatefulSetRevisionLabel]) - return false, nil - } + } + for i := int(*set.Spec.Replicas) - 1; i >= partition; i-- { + if pods.Items[i].Labels[apps.StatefulSetRevisionLabel] != set.Status.UpdateRevision { + Logf("Waiting for Pod %s/%s to have revision %s update revision %s", + pods.Items[i].Namespace, + pods.Items[i].Name, + set.Status.UpdateRevision, + pods.Items[i].Labels[apps.StatefulSetRevisionLabel]) + return false, nil } } return true, nil @@ -485,7 +484,7 @@ func (s *StatefulSetTester) WaitForPartitionedRollingUpdate(set *apps.StatefulSe return set, pods } -// WaitForRunningAndReady waits for numStatefulPods in ss to be Running and not Ready. +// WaitForRunningAndNotReady waits for numStatefulPods in ss to be Running and not Ready. func (s *StatefulSetTester) WaitForRunningAndNotReady(numStatefulPods int32, ss *apps.StatefulSet) { s.WaitForRunning(numStatefulPods, 0, ss) } @@ -502,15 +501,15 @@ var httpProbe = &v1.Probe{ FailureThreshold: 1, } -// SetHttpProbe sets the pod template's ReadinessProbe for Nginx StatefulSet containers. -// This probe can then be controlled with BreakHttpProbe() and RestoreHttpProbe(). +// SetHTTPProbe sets the pod template's ReadinessProbe for Nginx StatefulSet containers. +// This probe can then be controlled with BreakHTTPProbe() and RestoreHTTPProbe(). // Note that this cannot be used together with PauseNewPods(). -func (s *StatefulSetTester) SetHttpProbe(ss *apps.StatefulSet) { +func (s *StatefulSetTester) SetHTTPProbe(ss *apps.StatefulSet) { ss.Spec.Template.Spec.Containers[0].ReadinessProbe = httpProbe } -// BreakHttpProbe breaks the readiness probe for Nginx StatefulSet containers in ss. -func (s *StatefulSetTester) BreakHttpProbe(ss *apps.StatefulSet) error { +// BreakHTTPProbe breaks the readiness probe for Nginx StatefulSet containers in ss. +func (s *StatefulSetTester) BreakHTTPProbe(ss *apps.StatefulSet) error { path := httpProbe.HTTPGet.Path if path == "" { return fmt.Errorf("Path expected to be not empty: %v", path) @@ -520,8 +519,8 @@ func (s *StatefulSetTester) BreakHttpProbe(ss *apps.StatefulSet) error { return s.ExecInStatefulPods(ss, cmd) } -// BreakPodHttpProbe breaks the readiness probe for Nginx StatefulSet containers in one pod. -func (s *StatefulSetTester) BreakPodHttpProbe(ss *apps.StatefulSet, pod *v1.Pod) error { +// BreakPodHTTPProbe breaks the readiness probe for Nginx StatefulSet containers in one pod. +func (s *StatefulSetTester) BreakPodHTTPProbe(ss *apps.StatefulSet, pod *v1.Pod) error { path := httpProbe.HTTPGet.Path if path == "" { return fmt.Errorf("Path expected to be not empty: %v", path) @@ -533,8 +532,8 @@ func (s *StatefulSetTester) BreakPodHttpProbe(ss *apps.StatefulSet, pod *v1.Pod) return err } -// RestoreHttpProbe restores the readiness probe for Nginx StatefulSet containers in ss. -func (s *StatefulSetTester) RestoreHttpProbe(ss *apps.StatefulSet) error { +// RestoreHTTPProbe restores the readiness probe for Nginx StatefulSet containers in ss. +func (s *StatefulSetTester) RestoreHTTPProbe(ss *apps.StatefulSet) error { path := httpProbe.HTTPGet.Path if path == "" { return fmt.Errorf("Path expected to be not empty: %v", path) @@ -544,8 +543,8 @@ func (s *StatefulSetTester) RestoreHttpProbe(ss *apps.StatefulSet) error { return s.ExecInStatefulPods(ss, cmd) } -// RestorePodHttpProbe restores the readiness probe for Nginx StatefulSet containers in pod. -func (s *StatefulSetTester) RestorePodHttpProbe(ss *apps.StatefulSet, pod *v1.Pod) error { +// RestorePodHTTPProbe restores the readiness probe for Nginx StatefulSet containers in pod. +func (s *StatefulSetTester) RestorePodHTTPProbe(ss *apps.StatefulSet, pod *v1.Pod) error { path := httpProbe.HTTPGet.Path if path == "" { return fmt.Errorf("Path expected to be not empty: %v", path) @@ -574,7 +573,7 @@ func hasPauseProbe(pod *v1.Pod) bool { // PauseNewPods adds an always-failing ReadinessProbe to the StatefulSet PodTemplate. // This causes all newly-created Pods to stay Unready until they are manually resumed // with ResumeNextPod(). -// Note that this cannot be used together with SetHttpProbe(). +// Note that this cannot be used together with SetHTTPProbe(). func (s *StatefulSetTester) PauseNewPods(ss *apps.StatefulSet) { ss.Spec.Template.Spec.Containers[0].ReadinessProbe = pauseProbe } @@ -655,7 +654,7 @@ func (s *StatefulSetTester) WaitForStatusReplicas(ss *apps.StatefulSet, expected } // CheckServiceName asserts that the ServiceName for ss is equivalent to expectedServiceName. -func (p *StatefulSetTester) CheckServiceName(ss *apps.StatefulSet, expectedServiceName string) error { +func (s *StatefulSetTester) CheckServiceName(ss *apps.StatefulSet, expectedServiceName string) error { Logf("Checking if statefulset spec.serviceName is %s", expectedServiceName) if expectedServiceName != ss.Spec.ServiceName { @@ -869,6 +868,7 @@ func (sp statefulPodsByOrdinal) Less(i, j int) bool { type updateStatefulSetFunc func(*apps.StatefulSet) +// UpdateStatefulSetWithRetries updates statfulset template with retries. func UpdateStatefulSetWithRetries(c clientset.Interface, namespace, name string, applyUpdate updateStatefulSetFunc) (statefulSet *apps.StatefulSet, err error) { statefulSets := c.AppsV1().StatefulSets(namespace) var updateErr error