Skip to content

Commit 65e6e46

Browse files
author
Kenichi Omichi
committed
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.
1 parent 9518d52 commit 65e6e46

File tree

2 files changed

+22
-18
lines changed

2 files changed

+22
-18
lines changed

test/e2e/framework/deployment_util.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
"fmt"
2222
"time"
2323

24-
. "github.com/onsi/ginkgo"
24+
"github.com/onsi/ginkgo"
2525

2626
apps "k8s.io/api/apps/v1"
2727
"k8s.io/api/core/v1"
@@ -30,19 +30,18 @@ import (
3030
"k8s.io/apimachinery/pkg/util/wait"
3131
"k8s.io/apimachinery/pkg/watch"
3232
clientset "k8s.io/client-go/kubernetes"
33-
scaleclient "k8s.io/client-go/scale"
3433
watchtools "k8s.io/client-go/tools/watch"
35-
appsinternal "k8s.io/kubernetes/pkg/apis/apps"
3634
deploymentutil "k8s.io/kubernetes/pkg/controller/deployment/util"
3735
testutils "k8s.io/kubernetes/test/utils"
3836
imageutils "k8s.io/kubernetes/test/utils/image"
3937
)
4038

39+
// UpdateDeploymentWithRetries updates the specified deployment with retries.
4140
func UpdateDeploymentWithRetries(c clientset.Interface, namespace, name string, applyUpdate testutils.UpdateDeploymentFunc) (*apps.Deployment, error) {
4241
return testutils.UpdateDeploymentWithRetries(c, namespace, name, applyUpdate, Logf, Poll, pollShortTimeout)
4342
}
4443

45-
// Waits for the deployment to clean up old rcs.
44+
// WaitForDeploymentOldRSsNum waits for the deployment to clean up old rcs.
4645
func WaitForDeploymentOldRSsNum(c clientset.Interface, ns, deploymentName string, desiredRSNum int) error {
4746
var oldRSs []*apps.ReplicaSet
4847
var d *apps.Deployment
@@ -71,10 +70,12 @@ func logReplicaSetsOfDeployment(deployment *apps.Deployment, allOldRSs []*apps.R
7170
testutils.LogReplicaSetsOfDeployment(deployment, allOldRSs, newRS, Logf)
7271
}
7372

73+
// WaitForObservedDeployment waits for the specified deployment generation.
7474
func WaitForObservedDeployment(c clientset.Interface, ns, deploymentName string, desiredGeneration int64) error {
7575
return testutils.WaitForObservedDeployment(c, ns, deploymentName, desiredGeneration)
7676
}
7777

78+
// WaitForDeploymentWithCondition waits for the specified deployment condition.
7879
func WaitForDeploymentWithCondition(c clientset.Interface, ns, deploymentName, reason string, condType apps.DeploymentConditionType) error {
7980
return testutils.WaitForDeploymentWithCondition(c, ns, deploymentName, reason, condType, Logf, Poll, pollLongTimeout)
8081
}
@@ -86,6 +87,7 @@ func WaitForDeploymentRevisionAndImage(c clientset.Interface, ns, deploymentName
8687
return testutils.WaitForDeploymentRevisionAndImage(c, ns, deploymentName, revision, image, Logf, Poll, pollLongTimeout)
8788
}
8889

90+
// NewDeployment returns a deployment spec with the specified argument.
8991
func NewDeployment(deploymentName string, replicas int32, podLabels map[string]string, imageName, image string, strategyType apps.DeploymentStrategyType) *apps.Deployment {
9092
zero := int64(0)
9193
return &apps.Deployment{
@@ -117,14 +119,14 @@ func NewDeployment(deploymentName string, replicas int32, podLabels map[string]s
117119
}
118120
}
119121

120-
// Waits for the deployment to complete, and don't check if rolling update strategy is broken.
122+
// WaitForDeploymentComplete waits for the deployment to complete, and don't check if rolling update strategy is broken.
121123
// Rolling update strategy is used only during a rolling update, and can be violated in other situations,
122124
// such as shortly after a scaling event or the deployment is just created.
123125
func WaitForDeploymentComplete(c clientset.Interface, d *apps.Deployment) error {
124126
return testutils.WaitForDeploymentComplete(c, d, Logf, Poll, pollLongTimeout)
125127
}
126128

127-
// Waits for the deployment to complete, and check rolling update strategy isn't broken at any times.
129+
// WaitForDeploymentCompleteAndCheckRolling waits for the deployment to complete, and check rolling update strategy isn't broken at any times.
128130
// Rolling update strategy should not be broken during a rolling update.
129131
func WaitForDeploymentCompleteAndCheckRolling(c clientset.Interface, d *apps.Deployment) error {
130132
return testutils.WaitForDeploymentCompleteAndCheckRolling(c, d, Logf, Poll, pollLongTimeout)
@@ -184,12 +186,9 @@ func WatchRecreateDeployment(c clientset.Interface, d *apps.Deployment) error {
184186
return err
185187
}
186188

187-
func ScaleDeployment(clientset clientset.Interface, scalesGetter scaleclient.ScalesGetter, ns, name string, size uint, wait bool) error {
188-
return ScaleResource(clientset, scalesGetter, ns, name, size, wait, appsinternal.Kind("Deployment"), appsinternal.Resource("deployments"))
189-
}
190-
189+
// RunDeployment runs a delopyment with the specified config.
191190
func RunDeployment(config testutils.DeploymentConfig) error {
192-
By(fmt.Sprintf("creating deployment %s in namespace %s", config.Name, config.Namespace))
191+
ginkgo.By(fmt.Sprintf("creating deployment %s in namespace %s", config.Name, config.Namespace))
193192
config.NodeDumpFunc = DumpNodeDebugInfo
194193
config.ContainerDumpFunc = LogFailedContainers
195194
return testutils.RunDeployment(config)
@@ -199,6 +198,7 @@ func logPodsOfDeployment(c clientset.Interface, deployment *apps.Deployment, rsL
199198
testutils.LogPodsOfDeployment(c, deployment, rsList, Logf)
200199
}
201200

201+
// WaitForDeploymentRevision waits for becoming the target revision of a delopyment.
202202
func WaitForDeploymentRevision(c clientset.Interface, d *apps.Deployment, targetRevision string) error {
203203
err := wait.PollImmediate(Poll, pollLongTimeout, func() (bool, error) {
204204
deployment, err := c.AppsV1().Deployments(d.Namespace).Get(d.Name, metav1.GetOptions{})
@@ -219,6 +219,7 @@ func CheckDeploymentRevisionAndImage(c clientset.Interface, ns, deploymentName,
219219
return testutils.CheckDeploymentRevisionAndImage(c, ns, deploymentName, revision, image)
220220
}
221221

222+
// CreateDeployment creates a deployment.
222223
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) {
223224
deploymentSpec := MakeDeployment(replicas, podLabels, nodeSelector, namespace, pvclaims, false, command)
224225
deployment, err := client.AppsV1().Deployments(namespace).Create(deploymentSpec)

test/e2e/framework/exec_util.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828
"k8s.io/client-go/tools/remotecommand"
2929
"k8s.io/kubernetes/pkg/api/legacyscheme"
3030

31-
. "github.com/onsi/gomega"
31+
"github.com/onsi/gomega"
3232
)
3333

3434
// ExecOptions passed to ExecWithOptions
@@ -107,30 +107,33 @@ func (f *Framework) ExecCommandInContainer(podName, containerName string, cmd ..
107107
return stdout
108108
}
109109

110+
// ExecShellInContainer executes the specified command on the pod's container.
110111
func (f *Framework) ExecShellInContainer(podName, containerName string, cmd string) string {
111112
return f.ExecCommandInContainer(podName, containerName, "/bin/sh", "-c", cmd)
112113
}
113114

114-
func (f *Framework) ExecCommandInPod(podName string, cmd ...string) string {
115+
func (f *Framework) execCommandInPod(podName string, cmd ...string) string {
115116
pod, err := f.PodClient().Get(podName, metav1.GetOptions{})
116117
ExpectNoError(err, "failed to get pod")
117-
Expect(pod.Spec.Containers).NotTo(BeEmpty())
118+
gomega.Expect(pod.Spec.Containers).NotTo(gomega.BeEmpty())
118119
return f.ExecCommandInContainer(podName, pod.Spec.Containers[0].Name, cmd...)
119120
}
120121

121-
func (f *Framework) ExecCommandInPodWithFullOutput(podName string, cmd ...string) (string, string, error) {
122+
func (f *Framework) execCommandInPodWithFullOutput(podName string, cmd ...string) (string, string, error) {
122123
pod, err := f.PodClient().Get(podName, metav1.GetOptions{})
123124
ExpectNoError(err, "failed to get pod")
124-
Expect(pod.Spec.Containers).NotTo(BeEmpty())
125+
gomega.Expect(pod.Spec.Containers).NotTo(gomega.BeEmpty())
125126
return f.ExecCommandInContainerWithFullOutput(podName, pod.Spec.Containers[0].Name, cmd...)
126127
}
127128

129+
// ExecShellInPod executes the specified command on the pod.
128130
func (f *Framework) ExecShellInPod(podName string, cmd string) string {
129-
return f.ExecCommandInPod(podName, "/bin/sh", "-c", cmd)
131+
return f.execCommandInPod(podName, "/bin/sh", "-c", cmd)
130132
}
131133

134+
// ExecShellInPodWithFullOutput executes the specified command on the pod with returing return stdout, stderr and error.
132135
func (f *Framework) ExecShellInPodWithFullOutput(podName string, cmd string) (string, string, error) {
133-
return f.ExecCommandInPodWithFullOutput(podName, "/bin/sh", "-c", cmd)
136+
return f.execCommandInPodWithFullOutput(podName, "/bin/sh", "-c", cmd)
134137
}
135138

136139
func execute(method string, url *url.URL, config *restclient.Config, stdin io.Reader, stdout, stderr io.Writer, tty bool) error {

0 commit comments

Comments
 (0)