Skip to content

Commit f3ca66a

Browse files
authored
Merge pull request kubernetes#76745 from atoato88/fix-golint-e2e-framework-util-go-part4
Fix golint failures of e2e/framework/util.go - part4
2 parents f980370 + 97fe60e commit f3ca66a

File tree

1 file changed

+33
-10
lines changed

1 file changed

+33
-10
lines changed

test/e2e/framework/util.go

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3683,6 +3683,7 @@ func ParseKVLines(output, key string) string {
36833683
return ""
36843684
}
36853685

3686+
// RestartKubeProxy restarts kube-proxy on the given host.
36863687
func RestartKubeProxy(host string) error {
36873688
// TODO: Make it work for all providers.
36883689
if !ProviderIs("gce", "gke", "aws") {
@@ -3719,6 +3720,7 @@ func RestartKubeProxy(host string) error {
37193720
return nil
37203721
}
37213722

3723+
// RestartKubelet restarts kubelet on the given host.
37223724
func RestartKubelet(host string) error {
37233725
// TODO: Make it work for all providers and distros.
37243726
supportedProviders := []string{"gce", "aws", "vsphere"}
@@ -3762,6 +3764,7 @@ func RestartKubelet(host string) error {
37623764
return nil
37633765
}
37643766

3767+
// WaitForKubeletUp waits for the kubelet on the given host to be up.
37653768
func WaitForKubeletUp(host string) error {
37663769
cmd := "curl http://localhost:" + strconv.Itoa(ports.KubeletReadOnlyPort) + "/healthz"
37673770
for start := time.Now(); time.Since(start) < time.Minute; time.Sleep(5 * time.Second) {
@@ -3776,6 +3779,7 @@ func WaitForKubeletUp(host string) error {
37763779
return fmt.Errorf("waiting for kubelet timed out")
37773780
}
37783781

3782+
// RestartApiserver restarts the kube-apiserver.
37793783
func RestartApiserver(cs clientset.Interface) error {
37803784
// TODO: Make it work for all providers.
37813785
if !ProviderIs("gce", "gke", "aws") {
@@ -3819,6 +3823,7 @@ func sshRestartMaster() error {
38193823
return nil
38203824
}
38213825

3826+
// WaitForApiserverUp waits for the kube-apiserver to be up.
38223827
func WaitForApiserverUp(c clientset.Interface) error {
38233828
for start := time.Now(); time.Since(start) < time.Minute; time.Sleep(5 * time.Second) {
38243829
body, err := c.CoreV1().RESTClient().Get().AbsPath("/healthz").Do().Raw()
@@ -3865,6 +3870,7 @@ func getApiserverRestartCount(c clientset.Interface) (int32, error) {
38653870
return -1, fmt.Errorf("Failed to find kube-apiserver container in pod")
38663871
}
38673872

3873+
// RestartControllerManager restarts the kube-controller-manager.
38683874
func RestartControllerManager() error {
38693875
// TODO: Make it work for all providers and distros.
38703876
if !ProviderIs("gce", "aws") {
@@ -3883,6 +3889,7 @@ func RestartControllerManager() error {
38833889
return nil
38843890
}
38853891

3892+
// WaitForControllerManagerUp waits for the kube-controller-manager to be up.
38863893
func WaitForControllerManagerUp() error {
38873894
cmd := "curl http://localhost:" + strconv.Itoa(ports.InsecureKubeControllerManagerPort) + "/healthz"
38883895
for start := time.Now(); time.Since(start) < time.Minute; time.Sleep(5 * time.Second) {
@@ -3986,11 +3993,12 @@ func WaitForReadyNodes(c clientset.Interface, size int, timeout time.Duration) e
39863993
return err
39873994
}
39883995

3996+
// GenerateMasterRegexp returns a regex for matching master node name.
39893997
func GenerateMasterRegexp(prefix string) string {
39903998
return prefix + "(-...)?"
39913999
}
39924000

3993-
// waitForMasters waits until the cluster has the desired number of ready masters in it.
4001+
// WaitForMasters waits until the cluster has the desired number of ready masters in it.
39944002
func WaitForMasters(masterPrefix string, c clientset.Interface, size int, timeout time.Duration) error {
39954003
for start := time.Now(); time.Since(start) < timeout; time.Sleep(20 * time.Second) {
39964004
nodes, err := c.CoreV1().Nodes().List(metav1.ListOptions{})
@@ -4099,21 +4107,21 @@ func OpenWebSocketForURL(url *url.URL, config *restclient.Config, protocols []st
40994107
return websocket.DialConfig(cfg)
41004108
}
41014109

4102-
// Looks for the given string in the log of a specific pod container
4110+
// LookForStringInLog looks for the given string in the log of a specific pod container
41034111
func LookForStringInLog(ns, podName, container, expectedString string, timeout time.Duration) (result string, err error) {
41044112
return LookForString(expectedString, timeout, func() string {
41054113
return RunKubectlOrDie("logs", podName, container, fmt.Sprintf("--namespace=%v", ns))
41064114
})
41074115
}
41084116

4109-
// Looks for the given string in a file in a specific pod container
4117+
// LookForStringInFile looks for the given string in a file in a specific pod container
41104118
func LookForStringInFile(ns, podName, container, file, expectedString string, timeout time.Duration) (result string, err error) {
41114119
return LookForString(expectedString, timeout, func() string {
41124120
return RunKubectlOrDie("exec", podName, "-c", container, fmt.Sprintf("--namespace=%v", ns), "--", "cat", file)
41134121
})
41144122
}
41154123

4116-
// Looks for the given string in the output of a command executed in a specific pod container
4124+
// LookForStringInPodExec looks for the given string in the output of a command executed in a specific pod container
41174125
func LookForStringInPodExec(ns, podName string, command []string, expectedString string, timeout time.Duration) (result string, err error) {
41184126
return LookForString(expectedString, timeout, func() string {
41194127
// use the first container
@@ -4123,7 +4131,7 @@ func LookForStringInPodExec(ns, podName string, command []string, expectedString
41234131
})
41244132
}
41254133

4126-
// Looks for the given string in the output of fn, repeatedly calling fn until
4134+
// LookForString looks for the given string in the output of fn, repeatedly calling fn until
41274135
// the timeout is reached or the string is found. Returns last log and possibly
41284136
// error if the string was not found.
41294137
func LookForString(expectedString string, timeout time.Duration, fn func() string) (result string, err error) {
@@ -4179,7 +4187,7 @@ func GetNodePortURL(client clientset.Interface, ns, name string, svcPort int) (s
41794187
return "", err
41804188
}
41814189
if len(nodes.Items) == 0 {
4182-
return "", fmt.Errorf("Unable to list nodes in cluster.")
4190+
return "", fmt.Errorf("Unable to list nodes in cluster")
41834191
}
41844192
for _, node := range nodes.Items {
41854193
for _, address := range node.Status.Addresses {
@@ -4193,6 +4201,7 @@ func GetNodePortURL(client clientset.Interface, ns, name string, svcPort int) (s
41934201
return "", fmt.Errorf("Failed to find external address for service %v", name)
41944202
}
41954203

4204+
// GetPodLogs returns the logs of the specified container (namespace/pod/container).
41964205
// TODO(random-liu): Change this to be a member function of the framework.
41974206
func GetPodLogs(c clientset.Interface, namespace, podName, containerName string) (string, error) {
41984207
return getPodLogsInternal(c, namespace, podName, containerName, false)
@@ -4216,7 +4225,7 @@ func getPodLogsInternal(c clientset.Interface, namespace, podName, containerName
42164225
return "", err
42174226
}
42184227
if err == nil && strings.Contains(string(logs), "Internal Error") {
4219-
return "", fmt.Errorf("Fetched log contains \"Internal Error\": %q.", string(logs))
4228+
return "", fmt.Errorf("Fetched log contains \"Internal Error\": %q", string(logs))
42204229
}
42214230
return string(logs), err
42224231
}
@@ -4227,6 +4236,7 @@ func EnsureLoadBalancerResourcesDeleted(ip, portRange string) error {
42274236
return TestContext.CloudConfig.Provider.EnsureLoadBalancerResourcesDeleted(ip, portRange)
42284237
}
42294238

4239+
// BlockNetwork blocks network between the given from value and the given to value.
42304240
// The following helper functions can block/unblock network from source
42314241
// host to destination host by manipulating iptable rules.
42324242
// This function assumes it can ssh to the source host.
@@ -4254,6 +4264,7 @@ func BlockNetwork(from string, to string) {
42544264
}
42554265
}
42564266

4267+
// UnblockNetwork unblocks network between the given from value and the given to value.
42574268
func UnblockNetwork(from string, to string) {
42584269
Logf("Unblock network traffic from %s to %s", from, to)
42594270
iptablesRule := fmt.Sprintf("OUTPUT --destination %s --jump REJECT", to)
@@ -4341,10 +4352,13 @@ func getKubeletPods(c clientset.Interface, node, resource string) (*v1.PodList,
43414352
return result, nil
43424353
}
43434354

4355+
// PingCommand is the type to hold ping command.
43444356
type PingCommand string
43454357

43464358
const (
4359+
// IPv4PingCommand is a ping command for IPv4.
43474360
IPv4PingCommand PingCommand = "ping"
4361+
// IPv6PingCommand is a ping command for IPv6.
43484362
IPv6PingCommand PingCommand = "ping6"
43494363
)
43504364

@@ -4428,6 +4442,7 @@ func parseSystemdServices(services string) string {
44284442
return strings.TrimSpace(strings.Replace(services, ",", " ", -1))
44294443
}
44304444

4445+
// GetPodsInNamespace returns the pods in the given namespace.
44314446
func GetPodsInNamespace(c clientset.Interface, ns string, ignoreLabels map[string]string) ([]*v1.Pod, error) {
44324447
pods, err := c.CoreV1().Pods(ns).List(metav1.ListOptions{})
44334448
if err != nil {
@@ -4561,6 +4576,7 @@ func GetMasterAndWorkerNodesOrDie(c clientset.Interface) (sets.String, *v1.NodeL
45614576
return masters, nodes
45624577
}
45634578

4579+
// ListNamespaceEvents lists the events in the given namespace.
45644580
func ListNamespaceEvents(c clientset.Interface, ns string) error {
45654581
ls, err := c.CoreV1().Events(ns).List(metav1.ListOptions{})
45664582
if err != nil {
@@ -4583,6 +4599,7 @@ type E2ETestNodePreparer struct {
45834599
nodeToAppliedStrategy map[string]testutils.PrepareNodeStrategy
45844600
}
45854601

4602+
// NewE2ETestNodePreparer returns a new instance of E2ETestNodePreparer.
45864603
func NewE2ETestNodePreparer(client clientset.Interface, countToStrategy []testutils.CountToStrategy) testutils.TestNodePreparer {
45874604
return &E2ETestNodePreparer{
45884605
client: client,
@@ -4591,14 +4608,15 @@ func NewE2ETestNodePreparer(client clientset.Interface, countToStrategy []testut
45914608
}
45924609
}
45934610

4611+
// PrepareNodes prepares nodes in the cluster.
45944612
func (p *E2ETestNodePreparer) PrepareNodes() error {
45954613
nodes := GetReadySchedulableNodesOrDie(p.client)
45964614
numTemplates := 0
45974615
for _, v := range p.countToStrategy {
45984616
numTemplates += v.Count
45994617
}
46004618
if numTemplates > len(nodes.Items) {
4601-
return fmt.Errorf("Can't prepare Nodes. Got more templates than existing Nodes.")
4619+
return fmt.Errorf("Can't prepare Nodes. Got more templates than existing Nodes")
46024620
}
46034621
index := 0
46044622
sum := 0
@@ -4615,6 +4633,7 @@ func (p *E2ETestNodePreparer) PrepareNodes() error {
46154633
return nil
46164634
}
46174635

4636+
// CleanupNodes cleanups nodes in the cluster.
46184637
func (p *E2ETestNodePreparer) CleanupNodes() error {
46194638
var encounteredError error
46204639
nodes := GetReadySchedulableNodesOrDie(p.client)
@@ -4758,12 +4777,13 @@ func PollURL(route, host string, timeout time.Duration, interval time.Duration,
47584777
return !expectUnreachable, nil
47594778
})
47604779
if pollErr != nil {
4761-
return fmt.Errorf("Failed to execute a successful GET within %v, Last response body for %v, host %v:\n%v\n\n%v\n",
4780+
return fmt.Errorf("Failed to execute a successful GET within %v, Last response body for %v, host %v:\n%v\n\n%v",
47624781
timeout, route, host, lastBody, pollErr)
47634782
}
47644783
return nil
47654784
}
47664785

4786+
// DescribeIng describes information of ingress by running kubectl describe ing.
47674787
func DescribeIng(ns string) {
47684788
Logf("\nOutput of kubectl describe ing:\n")
47694789
desc, _ := RunKubectl(
@@ -4792,12 +4812,13 @@ func (f *Framework) NewTestPod(name string, requests v1.ResourceList, limits v1.
47924812
}
47934813
}
47944814

4795-
// create empty file at given path on the pod.
4815+
// CreateEmptyFileOnPod creates empty file at given path on the pod.
47964816
func CreateEmptyFileOnPod(namespace string, podName string, filePath string) error {
47974817
_, err := RunKubectl("exec", fmt.Sprintf("--namespace=%s", namespace), podName, "--", "/bin/sh", "-c", fmt.Sprintf("touch %s", filePath))
47984818
return err
47994819
}
48004820

4821+
// PrintSummaries prints summaries of tests.
48014822
func PrintSummaries(summaries []TestDataSummary, testBaseName string) {
48024823
now := time.Now()
48034824
for i := range summaries {
@@ -4834,6 +4855,7 @@ func PrintSummaries(summaries []TestDataSummary, testBaseName string) {
48344855
}
48354856
}
48364857

4858+
// DumpDebugInfo dumps debug info of tests.
48374859
func DumpDebugInfo(c clientset.Interface, ns string) {
48384860
sl, _ := c.CoreV1().Pods(ns).List(metav1.ListOptions{LabelSelector: labels.Everything().String()})
48394861
for _, s := range sl.Items {
@@ -4924,6 +4946,7 @@ func WaitForPersistentVolumeClaimDeleted(c clientset.Interface, ns string, pvcNa
49244946
return fmt.Errorf("PersistentVolumeClaim %s is not removed from the system within %v", pvcName, timeout)
49254947
}
49264948

4949+
// GetClusterZones returns the values of zone label collected from all nodes.
49274950
func GetClusterZones(c clientset.Interface) (sets.String, error) {
49284951
nodes, err := c.CoreV1().Nodes().List(metav1.ListOptions{})
49294952
if err != nil {

0 commit comments

Comments
 (0)