Skip to content

Commit a81dd53

Browse files
author
Kenichi Omichi
committed
Fix golint failures of e2e/framework/p*.go
This fixes golint failures of - test/e2e/framework/perf_util.go - test/e2e/framework/pods.go - test/e2e/framework/profile_gatherer.go - test/e2e/framework/provider.go - test/e2e/framework/psp_util.go
1 parent 733f247 commit a81dd53

File tree

7 files changed

+63
-34
lines changed

7 files changed

+63
-34
lines changed

test/e2e/framework/framework.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ func (f *Framework) CreateNamespace(baseName string, labels map[string]string) (
407407
f.AddNamespacesToDelete(ns)
408408

409409
if err == nil && !f.SkipPrivilegedPSPBinding {
410-
CreatePrivilegedPSPBinding(f, ns.Name)
410+
createPrivilegedPSPBinding(f, ns.Name)
411411
}
412412

413413
return ns, err

test/e2e/framework/metrics_util.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ func (a *APIResponsiveness) PrintHumanReadable() string {
417417
}
418418

419419
func (a *APIResponsiveness) PrintJSON() string {
420-
return PrettyPrintJSON(ApiCallToPerfData(a))
420+
return PrettyPrintJSON(APICallToPerfData(a))
421421
}
422422

423423
func (a *APIResponsiveness) Len() int { return len(a.APICalls) }

test/e2e/framework/perf_util.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ import (
2525
// TODO(random-liu): Change the tests to actually use PerfData from the beginning instead of
2626
// translating one to the other here.
2727

28-
// currentApiCallMetricsVersion is the current apicall performance metrics version. We should
28+
// currentAPICallMetricsVersion is the current apicall performance metrics version. We should
2929
// bump up the version each time we make incompatible change to the metrics.
30-
const currentApiCallMetricsVersion = "v1"
30+
const currentAPICallMetricsVersion = "v1"
3131

32-
// ApiCallToPerfData transforms APIResponsiveness to PerfData.
33-
func ApiCallToPerfData(apicalls *APIResponsiveness) *perftype.PerfData {
34-
perfData := &perftype.PerfData{Version: currentApiCallMetricsVersion}
32+
// APICallToPerfData transforms APIResponsiveness to PerfData.
33+
func APICallToPerfData(apicalls *APIResponsiveness) *perftype.PerfData {
34+
perfData := &perftype.PerfData{Version: currentAPICallMetricsVersion}
3535
for _, apicall := range apicalls.APICalls {
3636
item := perftype.DataItem{
3737
Data: map[string]float64{
@@ -70,7 +70,7 @@ func latencyToPerfData(l LatencyMetric, name string) perftype.DataItem {
7070

7171
// PodStartupLatencyToPerfData transforms PodStartupLatency to PerfData.
7272
func PodStartupLatencyToPerfData(latency *PodStartupLatency) *perftype.PerfData {
73-
perfData := &perftype.PerfData{Version: currentApiCallMetricsVersion}
73+
perfData := &perftype.PerfData{Version: currentAPICallMetricsVersion}
7474
perfData.DataItems = append(perfData.DataItems, latencyToPerfData(latency.CreateToScheduleLatency, "create_to_schedule"))
7575
perfData.DataItems = append(perfData.DataItems, latencyToPerfData(latency.ScheduleToRunLatency, "schedule_to_run"))
7676
perfData.DataItems = append(perfData.DataItems, latencyToPerfData(latency.RunToWatchLatency, "run_to_watch"))

test/e2e/framework/pods.go

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ import (
3434
"k8s.io/kubernetes/pkg/kubelet/events"
3535
"k8s.io/kubernetes/pkg/kubelet/sysctl"
3636

37-
. "github.com/onsi/ginkgo"
38-
. "github.com/onsi/gomega"
37+
"github.com/onsi/ginkgo"
38+
"github.com/onsi/gomega"
3939
)
4040

4141
const DefaultPodDeletionTimeout = 3 * time.Minute
@@ -45,7 +45,7 @@ const DefaultPodDeletionTimeout = 3 * time.Minute
4545
// node e2e test.
4646
var ImageWhiteList sets.String
4747

48-
// Convenience method for getting a pod client interface in the framework's namespace,
48+
// PodClient is a convenience method for getting a pod client interface in the framework's namespace,
4949
// possibly applying test-suite specific transformations to the pod spec, e.g. for
5050
// node e2e pod scheduling.
5151
func (f *Framework) PodClient() *PodClient {
@@ -55,7 +55,7 @@ func (f *Framework) PodClient() *PodClient {
5555
}
5656
}
5757

58-
// Convenience method for getting a pod client interface in an alternative namespace,
58+
// PodClientNS is a convenience method for getting a pod client interface in an alternative namespace,
5959
// possibly applying test-suite specific transformations to the pod spec, e.g. for
6060
// node e2e pod scheduling.
6161
func (f *Framework) PodClientNS(namespace string) *PodClient {
@@ -65,6 +65,7 @@ func (f *Framework) PodClientNS(namespace string) *PodClient {
6565
}
6666
}
6767

68+
// PodClient is a struct for pod client.
6869
type PodClient struct {
6970
f *Framework
7071
v1core.PodInterface
@@ -96,15 +97,15 @@ func (c *PodClient) Create(pod *v1.Pod) *v1.Pod {
9697
func (c *PodClient) CreateEventually(pod *v1.Pod, opts ...interface{}) *v1.Pod {
9798
c.mungeSpec(pod)
9899
var ret *v1.Pod
99-
Eventually(func() error {
100+
gomega.Eventually(func() error {
100101
p, err := c.PodInterface.Create(pod)
101102
ret = p
102103
return err
103-
}, opts...).ShouldNot(HaveOccurred(), "Failed to create %q pod", pod.GetName())
104+
}, opts...).ShouldNot(gomega.HaveOccurred(), "Failed to create %q pod", pod.GetName())
104105
return ret
105106
}
106107

107-
// CreateSync creates a new pod according to the framework specifications in the given namespace, and waits for it to start.
108+
// CreateSyncInNamespace creates a new pod according to the framework specifications in the given namespace, and waits for it to start.
108109
func (c *PodClient) CreateSyncInNamespace(pod *v1.Pod, namespace string) *v1.Pod {
109110
p := c.Create(pod)
110111
ExpectNoError(WaitForPodNameRunningInNamespace(c.f.ClientSet, p.Name, namespace))
@@ -127,7 +128,7 @@ func (c *PodClient) CreateBatch(pods []*v1.Pod) []*v1.Pod {
127128
wg.Add(1)
128129
go func(i int, pod *v1.Pod) {
129130
defer wg.Done()
130-
defer GinkgoRecover()
131+
defer ginkgo.GinkgoRecover()
131132
ps[i] = c.CreateSync(pod)
132133
}(i, pod)
133134
}
@@ -171,8 +172,8 @@ func (c *PodClient) DeleteSyncInNamespace(name string, namespace string, options
171172
if err != nil && !errors.IsNotFound(err) {
172173
Failf("Failed to delete pod %q: %v", name, err)
173174
}
174-
Expect(WaitForPodToDisappear(c.f.ClientSet, namespace, name, labels.Everything(),
175-
2*time.Second, timeout)).To(Succeed(), "wait for pod %q to disappear", name)
175+
gomega.Expect(WaitForPodToDisappear(c.f.ClientSet, namespace, name, labels.Everything(),
176+
2*time.Second, timeout)).To(gomega.Succeed(), "wait for pod %q to disappear", name)
176177
}
177178

178179
// mungeSpec apply test-suite specific transformations to the pod spec.
@@ -181,7 +182,7 @@ func (c *PodClient) mungeSpec(pod *v1.Pod) {
181182
return
182183
}
183184

184-
Expect(pod.Spec.NodeName).To(Or(BeZero(), Equal(TestContext.NodeName)), "Test misconfigured")
185+
gomega.Expect(pod.Spec.NodeName).To(gomega.Or(gomega.BeZero(), gomega.Equal(TestContext.NodeName)), "Test misconfigured")
185186
pod.Spec.NodeName = TestContext.NodeName
186187
// Node e2e does not support the default DNSClusterFirst policy. Set
187188
// the policy to DNSDefault, which is configured per node.
@@ -204,18 +205,18 @@ func (c *PodClient) mungeSpec(pod *v1.Pod) {
204205
}
205206
// If the image policy is not PullAlways, the image must be in the white list and
206207
// pre-pulled.
207-
Expect(ImageWhiteList.Has(c.Image)).To(BeTrue(), "Image %q is not in the white list, consider adding it to CommonImageWhiteList in test/e2e/common/util.go or NodeImageWhiteList in test/e2e_node/image_list.go", c.Image)
208+
gomega.Expect(ImageWhiteList.Has(c.Image)).To(gomega.BeTrue(), "Image %q is not in the white list, consider adding it to CommonImageWhiteList in test/e2e/common/util.go or NodeImageWhiteList in test/e2e_node/image_list.go", c.Image)
208209
// Do not pull images during the tests because the images in white list should have
209210
// been prepulled.
210211
c.ImagePullPolicy = v1.PullNever
211212
}
212213
}
213214

214-
// TODO(random-liu): Move pod wait function into this file
215215
// WaitForSuccess waits for pod to succeed.
216+
// TODO(random-liu): Move pod wait function into this file
216217
func (c *PodClient) WaitForSuccess(name string, timeout time.Duration) {
217218
f := c.f
218-
Expect(WaitForPodCondition(f.ClientSet, f.Namespace.Name, name, "success or failure", timeout,
219+
gomega.Expect(WaitForPodCondition(f.ClientSet, f.Namespace.Name, name, "success or failure", timeout,
219220
func(pod *v1.Pod) (bool, error) {
220221
switch pod.Status.Phase {
221222
case v1.PodFailed:
@@ -226,13 +227,13 @@ func (c *PodClient) WaitForSuccess(name string, timeout time.Duration) {
226227
return false, nil
227228
}
228229
},
229-
)).To(Succeed(), "wait for pod %q to success", name)
230+
)).To(gomega.Succeed(), "wait for pod %q to success", name)
230231
}
231232

232233
// WaitForFailure waits for pod to fail.
233234
func (c *PodClient) WaitForFailure(name string, timeout time.Duration) {
234235
f := c.f
235-
Expect(WaitForPodCondition(f.ClientSet, f.Namespace.Name, name, "success or failure", timeout,
236+
gomega.Expect(WaitForPodCondition(f.ClientSet, f.Namespace.Name, name, "success or failure", timeout,
236237
func(pod *v1.Pod) (bool, error) {
237238
switch pod.Status.Phase {
238239
case v1.PodFailed:
@@ -243,10 +244,10 @@ func (c *PodClient) WaitForFailure(name string, timeout time.Duration) {
243244
return false, nil
244245
}
245246
},
246-
)).To(Succeed(), "wait for pod %q to fail", name)
247+
)).To(gomega.Succeed(), "wait for pod %q to fail", name)
247248
}
248249

249-
// WaitForSuccess waits for pod to succeed or an error event for that pod.
250+
// WaitForErrorEventOrSuccess waits for pod to succeed or an error event for that pod.
250251
func (c *PodClient) WaitForErrorEventOrSuccess(pod *v1.Pod) (*v1.Event, error) {
251252
var ev *v1.Event
252253
err := wait.Poll(Poll, PodStartTimeout, func() (bool, error) {
@@ -287,6 +288,7 @@ func (c *PodClient) MatchContainerOutput(name string, containerName string, expe
287288
return nil
288289
}
289290

291+
// PodIsReady returns true if the specified pod is ready. Otherwise false.
290292
func (c *PodClient) PodIsReady(name string) bool {
291293
pod, err := c.Get(name, metav1.GetOptions{})
292294
ExpectNoError(err)

test/e2e/framework/profile_gatherer.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828
)
2929

3030
const (
31-
// Default value for how long the CPU profile is gathered for.
31+
// DefaultCPUProfileSeconds is default value for how long the CPU profile is gathered for.
3232
DefaultCPUProfileSeconds = 30
3333
)
3434

@@ -168,10 +168,12 @@ func gatherProfile(componentName, profileBaseName, profileKind string) error {
168168
// that the function finishes. There's also a polling-based gatherer utility for
169169
// CPU profiles available below.
170170

171+
// GatherCPUProfile gathers CPU profile.
171172
func GatherCPUProfile(componentName string, profileBaseName string, wg *sync.WaitGroup) {
172173
GatherCPUProfileForSeconds(componentName, profileBaseName, DefaultCPUProfileSeconds, wg)
173174
}
174175

176+
// GatherCPUProfileForSeconds gathers CPU profile for specified seconds.
175177
func GatherCPUProfileForSeconds(componentName string, profileBaseName string, seconds int, wg *sync.WaitGroup) {
176178
if wg != nil {
177179
defer wg.Done()
@@ -181,6 +183,7 @@ func GatherCPUProfileForSeconds(componentName string, profileBaseName string, se
181183
}
182184
}
183185

186+
// GatherMemoryProfile gathers memory profile.
184187
func GatherMemoryProfile(componentName string, profileBaseName string, wg *sync.WaitGroup) {
185188
if wg != nil {
186189
defer wg.Done()

test/e2e/framework/provider.go

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
clientset "k8s.io/client-go/kubernetes"
2828
)
2929

30+
// Factory is a func which operates provider specific behavior.
3031
type Factory func() (ProviderInterface, error)
3132

3233
var (
@@ -112,45 +113,67 @@ type ProviderInterface interface {
112113
// which doesn't do anything.
113114
type NullProvider struct{}
114115

116+
// FrameworkBeforeEach is a base implementation which does BeforeEach.
115117
func (n NullProvider) FrameworkBeforeEach(f *Framework) {}
116-
func (n NullProvider) FrameworkAfterEach(f *Framework) {}
117118

119+
// FrameworkAfterEach is a base implementation which does AfterEach.
120+
func (n NullProvider) FrameworkAfterEach(f *Framework) {}
121+
122+
// ResizeGroup is a base implementation which resizes group.
118123
func (n NullProvider) ResizeGroup(string, int32) error {
119124
return fmt.Errorf("Provider does not support InstanceGroups")
120125
}
126+
127+
// GetGroupNodes is a base implementation which returns group nodes.
121128
func (n NullProvider) GetGroupNodes(group string) ([]string, error) {
122129
return nil, fmt.Errorf("provider does not support InstanceGroups")
123130
}
131+
132+
// DeleteNode is a base implementation which returns group size.
124133
func (n NullProvider) GroupSize(group string) (int, error) {
125134
return -1, fmt.Errorf("provider does not support InstanceGroups")
126135
}
127136

137+
// DeleteNode is a base implementation which deletes a node.
128138
func (n NullProvider) DeleteNode(node *v1.Node) error {
129139
return fmt.Errorf("provider does not support DeleteNode")
130140
}
131141

142+
// CreatePD is a base implementation which creates PD.
132143
func (n NullProvider) CreatePD(zone string) (string, error) {
133144
return "", fmt.Errorf("provider does not support volume creation")
134145
}
146+
147+
// DeletePD is a base implementation which deletes PD.
135148
func (n NullProvider) DeletePD(pdName string) error {
136149
return fmt.Errorf("provider does not support volume deletion")
137150
}
151+
152+
// CreatePVSource is a base implementation which creates PV source.
138153
func (n NullProvider) CreatePVSource(zone, diskName string) (*v1.PersistentVolumeSource, error) {
139154
return nil, fmt.Errorf("Provider not supported")
140155
}
156+
157+
// DeletePVSource is a base implementation which deletes PV source.
141158
func (n NullProvider) DeletePVSource(pvSource *v1.PersistentVolumeSource) error {
142159
return fmt.Errorf("Provider not supported")
143160
}
144161

162+
// CleanupServiceResources is a base implementation which cleans up service resources.
145163
func (n NullProvider) CleanupServiceResources(c clientset.Interface, loadBalancerName, region, zone string) {
146164
}
147165

166+
// EnsureLoadBalancerResourcesDeleted is a base implementation which ensures load balancer is deleted.
148167
func (n NullProvider) EnsureLoadBalancerResourcesDeleted(ip, portRange string) error {
149168
return nil
150169
}
170+
171+
// LoadBalancerSrcRanges is a base implementation which returns the ranges of ips used by load balancers.
151172
func (n NullProvider) LoadBalancerSrcRanges() []string {
152173
return nil
153174
}
175+
176+
// EnableAndDisableInternalLB is a base implementation which returns functions for enabling/disabling an internal LB.
154177
func (n NullProvider) EnableAndDisableInternalLB() (enable, disable func(svc *v1.Service)) {
155178
nop := func(svc *v1.Service) {}
156179
return nop, nop

test/e2e/framework/psp_util.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import (
2929
"k8s.io/apiserver/pkg/authentication/serviceaccount"
3030
"k8s.io/kubernetes/pkg/security/podsecuritypolicy/seccomp"
3131

32-
. "github.com/onsi/ginkgo"
32+
"github.com/onsi/ginkgo"
3333
)
3434

3535
const (
@@ -41,8 +41,8 @@ var (
4141
isPSPEnabled bool
4242
)
4343

44-
// Creates a PodSecurityPolicy that allows everything.
45-
func PrivilegedPSP(name string) *policy.PodSecurityPolicy {
44+
// privilegedPSP creates a PodSecurityPolicy that allows everything.
45+
func privilegedPSP(name string) *policy.PodSecurityPolicy {
4646
allowPrivilegeEscalation := true
4747
return &policy.PodSecurityPolicy{
4848
ObjectMeta: metav1.ObjectMeta{
@@ -76,6 +76,7 @@ func PrivilegedPSP(name string) *policy.PodSecurityPolicy {
7676
}
7777
}
7878

79+
// IsPodSecurityPolicyEnabled returns true if PodSecurityPolicy is enabled. Otherwise false.
7980
func IsPodSecurityPolicyEnabled(f *Framework) bool {
8081
isPSPEnabledOnce.Do(func() {
8182
psps, err := f.ClientSet.PolicyV1beta1().PodSecurityPolicies().List(metav1.ListOptions{})
@@ -97,7 +98,7 @@ var (
9798
privilegedPSPOnce sync.Once
9899
)
99100

100-
func CreatePrivilegedPSPBinding(f *Framework, namespace string) {
101+
func createPrivilegedPSPBinding(f *Framework, namespace string) {
101102
if !IsPodSecurityPolicyEnabled(f) {
102103
return
103104
}
@@ -111,7 +112,7 @@ func CreatePrivilegedPSPBinding(f *Framework, namespace string) {
111112
return
112113
}
113114

114-
psp := PrivilegedPSP(podSecurityPolicyPrivileged)
115+
psp := privilegedPSP(podSecurityPolicyPrivileged)
115116
psp, err = f.ClientSet.PolicyV1beta1().PodSecurityPolicies().Create(psp)
116117
if !apierrs.IsAlreadyExists(err) {
117118
ExpectNoError(err, "Failed to create PSP %s", podSecurityPolicyPrivileged)
@@ -135,7 +136,7 @@ func CreatePrivilegedPSPBinding(f *Framework, namespace string) {
135136
})
136137

137138
if IsRBACEnabled(f) {
138-
By(fmt.Sprintf("Binding the %s PodSecurityPolicy to the default service account in %s",
139+
ginkgo.By(fmt.Sprintf("Binding the %s PodSecurityPolicy to the default service account in %s",
139140
podSecurityPolicyPrivileged, namespace))
140141
BindClusterRoleInNamespace(f.ClientSet.RbacV1beta1(),
141142
podSecurityPolicyPrivileged,

0 commit comments

Comments
 (0)