From 65e6e46515112921f79a99f36ca8d8c318f1ddb9 Mon Sep 17 00:00:00 2001 From: Kenichi Omichi Date: Mon, 25 Mar 2019 20:10:02 +0000 Subject: [PATCH] Fix golint failures of e2e/framework/[d-e]*.go This fixes golint failures on the following files: - test/e2e/framework/deployment_util.go - test/e2e/framework/exec_util.go Cleanup: - ScaleDeployment() was not used at all, so let's remove it. - ExecCommandInPod() and ExecCommandInPodWithFullOutput() were called in the framework only, so let's make them local. --- test/e2e/framework/deployment_util.go | 23 ++++++++++++----------- test/e2e/framework/exec_util.go | 17 ++++++++++------- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/test/e2e/framework/deployment_util.go b/test/e2e/framework/deployment_util.go index a525d47ecc6..6c96c9a681f 100644 --- a/test/e2e/framework/deployment_util.go +++ b/test/e2e/framework/deployment_util.go @@ -21,7 +21,7 @@ import ( "fmt" "time" - . "github.com/onsi/ginkgo" + "github.com/onsi/ginkgo" apps "k8s.io/api/apps/v1" "k8s.io/api/core/v1" @@ -30,19 +30,18 @@ import ( "k8s.io/apimachinery/pkg/util/wait" "k8s.io/apimachinery/pkg/watch" clientset "k8s.io/client-go/kubernetes" - scaleclient "k8s.io/client-go/scale" watchtools "k8s.io/client-go/tools/watch" - appsinternal "k8s.io/kubernetes/pkg/apis/apps" deploymentutil "k8s.io/kubernetes/pkg/controller/deployment/util" testutils "k8s.io/kubernetes/test/utils" imageutils "k8s.io/kubernetes/test/utils/image" ) +// UpdateDeploymentWithRetries updates the specified deployment with retries. func UpdateDeploymentWithRetries(c clientset.Interface, namespace, name string, applyUpdate testutils.UpdateDeploymentFunc) (*apps.Deployment, error) { return testutils.UpdateDeploymentWithRetries(c, namespace, name, applyUpdate, Logf, Poll, pollShortTimeout) } -// Waits for the deployment to clean up old rcs. +// WaitForDeploymentOldRSsNum waits for the deployment to clean up old rcs. func WaitForDeploymentOldRSsNum(c clientset.Interface, ns, deploymentName string, desiredRSNum int) error { var oldRSs []*apps.ReplicaSet var d *apps.Deployment @@ -71,10 +70,12 @@ func logReplicaSetsOfDeployment(deployment *apps.Deployment, allOldRSs []*apps.R testutils.LogReplicaSetsOfDeployment(deployment, allOldRSs, newRS, Logf) } +// WaitForObservedDeployment waits for the specified deployment generation. func WaitForObservedDeployment(c clientset.Interface, ns, deploymentName string, desiredGeneration int64) error { return testutils.WaitForObservedDeployment(c, ns, deploymentName, desiredGeneration) } +// WaitForDeploymentWithCondition waits for the specified deployment condition. func WaitForDeploymentWithCondition(c clientset.Interface, ns, deploymentName, reason string, condType apps.DeploymentConditionType) error { return testutils.WaitForDeploymentWithCondition(c, ns, deploymentName, reason, condType, Logf, Poll, pollLongTimeout) } @@ -86,6 +87,7 @@ func WaitForDeploymentRevisionAndImage(c clientset.Interface, ns, deploymentName return testutils.WaitForDeploymentRevisionAndImage(c, ns, deploymentName, revision, image, Logf, Poll, pollLongTimeout) } +// NewDeployment returns a deployment spec with the specified argument. func NewDeployment(deploymentName string, replicas int32, podLabels map[string]string, imageName, image string, strategyType apps.DeploymentStrategyType) *apps.Deployment { zero := int64(0) return &apps.Deployment{ @@ -117,14 +119,14 @@ func NewDeployment(deploymentName string, replicas int32, podLabels map[string]s } } -// Waits for the deployment to complete, and don't check if rolling update strategy is broken. +// WaitForDeploymentComplete waits for the deployment to complete, and don't check if rolling update strategy is broken. // Rolling update strategy is used only during a rolling update, and can be violated in other situations, // such as shortly after a scaling event or the deployment is just created. func WaitForDeploymentComplete(c clientset.Interface, d *apps.Deployment) error { return testutils.WaitForDeploymentComplete(c, d, Logf, Poll, pollLongTimeout) } -// Waits for the deployment to complete, and check rolling update strategy isn't broken at any times. +// WaitForDeploymentCompleteAndCheckRolling waits for the deployment to complete, and check rolling update strategy isn't broken at any times. // Rolling update strategy should not be broken during a rolling update. func WaitForDeploymentCompleteAndCheckRolling(c clientset.Interface, d *apps.Deployment) error { return testutils.WaitForDeploymentCompleteAndCheckRolling(c, d, Logf, Poll, pollLongTimeout) @@ -184,12 +186,9 @@ func WatchRecreateDeployment(c clientset.Interface, d *apps.Deployment) error { return err } -func ScaleDeployment(clientset clientset.Interface, scalesGetter scaleclient.ScalesGetter, ns, name string, size uint, wait bool) error { - return ScaleResource(clientset, scalesGetter, ns, name, size, wait, appsinternal.Kind("Deployment"), appsinternal.Resource("deployments")) -} - +// RunDeployment runs a delopyment with the specified config. func RunDeployment(config testutils.DeploymentConfig) error { - By(fmt.Sprintf("creating deployment %s in namespace %s", config.Name, config.Namespace)) + ginkgo.By(fmt.Sprintf("creating deployment %s in namespace %s", config.Name, config.Namespace)) config.NodeDumpFunc = DumpNodeDebugInfo config.ContainerDumpFunc = LogFailedContainers return testutils.RunDeployment(config) @@ -199,6 +198,7 @@ func logPodsOfDeployment(c clientset.Interface, deployment *apps.Deployment, rsL testutils.LogPodsOfDeployment(c, deployment, rsList, Logf) } +// WaitForDeploymentRevision waits for becoming the target revision of a delopyment. func WaitForDeploymentRevision(c clientset.Interface, d *apps.Deployment, targetRevision string) error { err := wait.PollImmediate(Poll, pollLongTimeout, func() (bool, error) { deployment, err := c.AppsV1().Deployments(d.Namespace).Get(d.Name, metav1.GetOptions{}) @@ -219,6 +219,7 @@ func CheckDeploymentRevisionAndImage(c clientset.Interface, ns, deploymentName, return testutils.CheckDeploymentRevisionAndImage(c, ns, deploymentName, revision, image) } +// CreateDeployment creates a deployment. func CreateDeployment(client clientset.Interface, replicas int32, podLabels map[string]string, nodeSelector map[string]string, namespace string, pvclaims []*v1.PersistentVolumeClaim, command string) (*apps.Deployment, error) { deploymentSpec := MakeDeployment(replicas, podLabels, nodeSelector, namespace, pvclaims, false, command) deployment, err := client.AppsV1().Deployments(namespace).Create(deploymentSpec) diff --git a/test/e2e/framework/exec_util.go b/test/e2e/framework/exec_util.go index 730ddc67cb2..15252c707d0 100644 --- a/test/e2e/framework/exec_util.go +++ b/test/e2e/framework/exec_util.go @@ -28,7 +28,7 @@ import ( "k8s.io/client-go/tools/remotecommand" "k8s.io/kubernetes/pkg/api/legacyscheme" - . "github.com/onsi/gomega" + "github.com/onsi/gomega" ) // ExecOptions passed to ExecWithOptions @@ -107,30 +107,33 @@ func (f *Framework) ExecCommandInContainer(podName, containerName string, cmd .. return stdout } +// ExecShellInContainer executes the specified command on the pod's container. func (f *Framework) ExecShellInContainer(podName, containerName string, cmd string) string { return f.ExecCommandInContainer(podName, containerName, "/bin/sh", "-c", cmd) } -func (f *Framework) ExecCommandInPod(podName string, cmd ...string) string { +func (f *Framework) execCommandInPod(podName string, cmd ...string) string { pod, err := f.PodClient().Get(podName, metav1.GetOptions{}) ExpectNoError(err, "failed to get pod") - Expect(pod.Spec.Containers).NotTo(BeEmpty()) + gomega.Expect(pod.Spec.Containers).NotTo(gomega.BeEmpty()) return f.ExecCommandInContainer(podName, pod.Spec.Containers[0].Name, cmd...) } -func (f *Framework) ExecCommandInPodWithFullOutput(podName string, cmd ...string) (string, string, error) { +func (f *Framework) execCommandInPodWithFullOutput(podName string, cmd ...string) (string, string, error) { pod, err := f.PodClient().Get(podName, metav1.GetOptions{}) ExpectNoError(err, "failed to get pod") - Expect(pod.Spec.Containers).NotTo(BeEmpty()) + gomega.Expect(pod.Spec.Containers).NotTo(gomega.BeEmpty()) return f.ExecCommandInContainerWithFullOutput(podName, pod.Spec.Containers[0].Name, cmd...) } +// ExecShellInPod executes the specified command on the pod. func (f *Framework) ExecShellInPod(podName string, cmd string) string { - return f.ExecCommandInPod(podName, "/bin/sh", "-c", cmd) + return f.execCommandInPod(podName, "/bin/sh", "-c", cmd) } +// ExecShellInPodWithFullOutput executes the specified command on the pod with returing return stdout, stderr and error. func (f *Framework) ExecShellInPodWithFullOutput(podName string, cmd string) (string, string, error) { - return f.ExecCommandInPodWithFullOutput(podName, "/bin/sh", "-c", cmd) + return f.execCommandInPodWithFullOutput(podName, "/bin/sh", "-c", cmd) } func execute(method string, url *url.URL, config *restclient.Config, stdin io.Reader, stdout, stderr io.Writer, tty bool) error {