From 2e63bad5a3964d2818b4575a9d82b886930e7d29 Mon Sep 17 00:00:00 2001 From: Navid Shaikh Date: Mon, 8 Feb 2021 10:47:41 +0530 Subject: [PATCH] Fix golint errors in test/e2e/common - Add comments for exported types - Replace Uid with UID --- test/e2e/common/container.go | 21 ++++++++++++++++++--- test/e2e/common/container_probe.go | 3 +++ test/e2e/common/empty_dir.go | 18 +++++++++--------- test/e2e/common/kubelet_etc_hosts.go | 1 + 4 files changed, 31 insertions(+), 12 deletions(-) diff --git a/test/e2e/common/container.go b/test/e2e/common/container.go index cd5a2be9e90..59ef844cb12 100644 --- a/test/e2e/common/container.go +++ b/test/e2e/common/container.go @@ -30,10 +30,13 @@ import ( ) const ( + // ContainerStatusRetryTimeout represents polling threshold before giving up to get the container status ContainerStatusRetryTimeout = time.Minute * 5 + // ContainerStatusPollInterval represents duration between polls to get the container status ContainerStatusPollInterval = time.Second * 1 ) +// ConformanceContainer defines the types for running container conformance test cases // One pod one container type ConformanceContainer struct { Container v1.Container @@ -46,6 +49,7 @@ type ConformanceContainer struct { PodSecurityContext *v1.PodSecurityContext } +// Create creates the defined conformance container func (cc *ConformanceContainer) Create() { cc.podName = cc.Container.Name + string(uuid.NewUUID()) imagePullSecrets := []v1.LocalObjectReference{} @@ -69,10 +73,12 @@ func (cc *ConformanceContainer) Create() { cc.PodClient.Create(pod) } +// Delete deletes the defined conformance container func (cc *ConformanceContainer) Delete() error { return cc.PodClient.Delete(context.TODO(), cc.podName, *metav1.NewDeleteOptions(0)) } +// IsReady returns whether this container is ready and error if any func (cc *ConformanceContainer) IsReady() (bool, error) { pod, err := cc.PodClient.Get(context.TODO(), cc.podName, metav1.GetOptions{}) if err != nil { @@ -81,6 +87,7 @@ func (cc *ConformanceContainer) IsReady() (bool, error) { return podutil.IsPodReady(pod), nil } +// GetPhase returns the phase of the pod lifecycle and error if any func (cc *ConformanceContainer) GetPhase() (v1.PodPhase, error) { pod, err := cc.PodClient.Get(context.TODO(), cc.podName, metav1.GetOptions{}) if err != nil { @@ -89,6 +96,7 @@ func (cc *ConformanceContainer) GetPhase() (v1.PodPhase, error) { return pod.Status.Phase, nil } +// GetStatus returns the details of the current status of this container and error if any func (cc *ConformanceContainer) GetStatus() (v1.ContainerStatus, error) { pod, err := cc.PodClient.Get(context.TODO(), cc.podName, metav1.GetOptions{}) if err != nil { @@ -101,6 +109,7 @@ func (cc *ConformanceContainer) GetStatus() (v1.ContainerStatus, error) { return statuses[0], nil } +// Present returns whether this pod is present and error if any func (cc *ConformanceContainer) Present() (bool, error) { _, err := cc.PodClient.Get(context.TODO(), cc.podName, metav1.GetOptions{}) if err == nil { @@ -112,15 +121,21 @@ func (cc *ConformanceContainer) Present() (bool, error) { return false, err } +// ContainerState represents different states of its lifecycle type ContainerState string const ( - ContainerStateWaiting ContainerState = "Waiting" - ContainerStateRunning ContainerState = "Running" + // ContainerStateWaiting represents 'Waiting' container state + ContainerStateWaiting ContainerState = "Waiting" + // ContainerStateRunning represents 'Running' container state + ContainerStateRunning ContainerState = "Running" + // ContainerStateTerminated represents 'Terminated' container state ContainerStateTerminated ContainerState = "Terminated" - ContainerStateUnknown ContainerState = "Unknown" + // ContainerStateUnknown represents 'Unknown' container state + ContainerStateUnknown ContainerState = "Unknown" ) +// GetContainerState returns current state the container represents among its lifecyle func GetContainerState(state v1.ContainerState) ContainerState { if state.Waiting != nil { return ContainerStateWaiting diff --git a/test/e2e/common/container_probe.go b/test/e2e/common/container_probe.go index aa790c62450..791996fba58 100644 --- a/test/e2e/common/container_probe.go +++ b/test/e2e/common/container_probe.go @@ -420,6 +420,7 @@ var _ = framework.KubeDescribe("Probing container", func() { }) }) +// GetContainerStartedTime returns the time when the given container started and error if any func GetContainerStartedTime(p *v1.Pod, containerName string) (time.Time, error) { for _, status := range p.Status.ContainerStatuses { if status.Name != containerName { @@ -433,6 +434,7 @@ func GetContainerStartedTime(p *v1.Pod, containerName string) (time.Time, error) return time.Time{}, fmt.Errorf("cannot find container named %q", containerName) } +// GetTransitionTimeForReadyCondition returns the time when the given pod became ready and error if any func GetTransitionTimeForReadyCondition(p *v1.Pod) (time.Time, error) { for _, cond := range p.Status.Conditions { if cond.Type == v1.PodReady { @@ -570,6 +572,7 @@ func (b webserverProbeBuilder) build() *v1.Probe { return probe } +// RunLivenessTest verifies the number of restarts for pod with given expected number of restarts func RunLivenessTest(f *framework.Framework, pod *v1.Pod, expectNumRestarts int, timeout time.Duration) { podClient := f.PodClient() ns := f.Namespace.Name diff --git a/test/e2e/common/empty_dir.go b/test/e2e/common/empty_dir.go index 29b5199370c..9a00f1fef98 100644 --- a/test/e2e/common/empty_dir.go +++ b/test/e2e/common/empty_dir.go @@ -39,7 +39,7 @@ const ( ) var ( - nonRootUid = int64(1001) + nonRootUID = int64(1001) ) var _ = ginkgo.Describe("[sig-storage] EmptyDir volumes", func() { @@ -57,11 +57,11 @@ var _ = ginkgo.Describe("[sig-storage] EmptyDir volumes", func() { }) ginkgo.It("new files should be created with FSGroup ownership when container is non-root", func() { - doTestSetgidFSGroup(f, nonRootUid, v1.StorageMediumMemory) + doTestSetgidFSGroup(f, nonRootUID, v1.StorageMediumMemory) }) ginkgo.It("nonexistent volume subPath should have the correct mode and owner using FSGroup", func() { - doTestSubPathFSGroup(f, nonRootUid, v1.StorageMediumMemory) + doTestSubPathFSGroup(f, nonRootUID, v1.StorageMediumMemory) }) ginkgo.It("files with FSGroup ownership should support (root,0644,tmpfs)", func() { @@ -124,7 +124,7 @@ var _ = ginkgo.Describe("[sig-storage] EmptyDir volumes", func() { This test is marked LinuxOnly since Windows does not support setting specific file permissions, or running as UID / GID, or the medium = 'Memory'. */ framework.ConformanceIt("should support (non-root,0644,tmpfs) [LinuxOnly] [NodeConformance]", func() { - doTest0644(f, nonRootUid, v1.StorageMediumMemory) + doTest0644(f, nonRootUID, v1.StorageMediumMemory) }) /* @@ -134,7 +134,7 @@ var _ = ginkgo.Describe("[sig-storage] EmptyDir volumes", func() { This test is marked LinuxOnly since Windows does not support setting specific file permissions, or running as UID / GID, or the medium = 'Memory'. */ framework.ConformanceIt("should support (non-root,0666,tmpfs) [LinuxOnly] [NodeConformance]", func() { - doTest0666(f, nonRootUid, v1.StorageMediumMemory) + doTest0666(f, nonRootUID, v1.StorageMediumMemory) }) /* @@ -144,7 +144,7 @@ var _ = ginkgo.Describe("[sig-storage] EmptyDir volumes", func() { This test is marked LinuxOnly since Windows does not support setting specific file permissions, or running as UID / GID, or the medium = 'Memory'. */ framework.ConformanceIt("should support (non-root,0777,tmpfs) [LinuxOnly] [NodeConformance]", func() { - doTest0777(f, nonRootUid, v1.StorageMediumMemory) + doTest0777(f, nonRootUID, v1.StorageMediumMemory) }) /* @@ -194,7 +194,7 @@ var _ = ginkgo.Describe("[sig-storage] EmptyDir volumes", func() { This test is marked LinuxOnly since Windows does not support setting specific file permissions, or running as UID / GID. */ framework.ConformanceIt("should support (non-root,0644,default) [LinuxOnly] [NodeConformance]", func() { - doTest0644(f, nonRootUid, v1.StorageMediumDefault) + doTest0644(f, nonRootUID, v1.StorageMediumDefault) }) /* @@ -204,7 +204,7 @@ var _ = ginkgo.Describe("[sig-storage] EmptyDir volumes", func() { This test is marked LinuxOnly since Windows does not support setting specific file permissions, or running as UID / GID. */ framework.ConformanceIt("should support (non-root,0666,default) [LinuxOnly] [NodeConformance]", func() { - doTest0666(f, nonRootUid, v1.StorageMediumDefault) + doTest0666(f, nonRootUID, v1.StorageMediumDefault) }) /* @@ -214,7 +214,7 @@ var _ = ginkgo.Describe("[sig-storage] EmptyDir volumes", func() { This test is marked LinuxOnly since Windows does not support setting specific file permissions, or running as UID / GID. */ framework.ConformanceIt("should support (non-root,0777,default) [LinuxOnly] [NodeConformance]", func() { - doTest0777(f, nonRootUid, v1.StorageMediumDefault) + doTest0777(f, nonRootUID, v1.StorageMediumDefault) }) /* diff --git a/test/e2e/common/kubelet_etc_hosts.go b/test/e2e/common/kubelet_etc_hosts.go index 701fbd78f3c..a9eabadf651 100644 --- a/test/e2e/common/kubelet_etc_hosts.go +++ b/test/e2e/common/kubelet_etc_hosts.go @@ -36,6 +36,7 @@ const ( etcHostsOriginalPath = "/etc/hosts-original" ) +// KubeletManagedHostConfig defines the types for running managed etc hosts test cases type KubeletManagedHostConfig struct { hostNetworkPod *v1.Pod pod *v1.Pod