Skip to content

Commit 3b5bedd

Browse files
author
Jiatong Wang
committed
Modify e2e/kubectl tests to import e2elog.Log
Signed-off-by: Jiatong Wang <[email protected]>
1 parent df3e59f commit 3b5bedd

File tree

3 files changed

+35
-32
lines changed

3 files changed

+35
-32
lines changed

test/e2e/kubectl/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ go_library(
3333
"//test/e2e/framework:go_default_library",
3434
"//test/e2e/framework/auth:go_default_library",
3535
"//test/e2e/framework/job:go_default_library",
36+
"//test/e2e/framework/log:go_default_library",
3637
"//test/e2e/framework/testfiles:go_default_library",
3738
"//test/e2e/scheduling:go_default_library",
3839
"//test/utils:go_default_library",

test/e2e/kubectl/kubectl.go

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ import (
6060
"k8s.io/kubernetes/test/e2e/framework"
6161
"k8s.io/kubernetes/test/e2e/framework/auth"
6262
jobutil "k8s.io/kubernetes/test/e2e/framework/job"
63+
e2elog "k8s.io/kubernetes/test/e2e/framework/log"
6364
"k8s.io/kubernetes/test/e2e/framework/testfiles"
6465
"k8s.io/kubernetes/test/e2e/scheduling"
6566
testutils "k8s.io/kubernetes/test/utils"
@@ -140,7 +141,7 @@ func runKubectlRetryOrDie(args ...string) string {
140141
}
141142
// Expect no errors to be present after retries are finished
142143
// Copied from framework #ExecOrDie
143-
framework.Logf("stdout: %q", output)
144+
e2elog.Logf("stdout: %q", output)
144145
framework.ExpectNoError(err)
145146
return output
146147
}
@@ -234,7 +235,7 @@ var _ = SIGDescribe("Kubectl client", func() {
234235
debugDiscovery := func() {
235236
home := os.Getenv("HOME")
236237
if len(home) == 0 {
237-
framework.Logf("no $HOME envvar set")
238+
e2elog.Logf("no $HOME envvar set")
238239
return
239240
}
240241

@@ -250,17 +251,17 @@ var _ = SIGDescribe("Kubectl client", func() {
250251
if len(parts) != 3 || parts[1] != "v1" || parts[2] != "serverresources.json" {
251252
return nil
252253
}
253-
framework.Logf("%s modified at %s (current time: %s)", path, info.ModTime(), time.Now())
254+
e2elog.Logf("%s modified at %s (current time: %s)", path, info.ModTime(), time.Now())
254255

255256
data, readError := ioutil.ReadFile(path)
256257
if readError != nil {
257-
framework.Logf("%s error: %v", path, readError)
258+
e2elog.Logf("%s error: %v", path, readError)
258259
} else {
259-
framework.Logf("%s content: %s", path, string(data))
260+
e2elog.Logf("%s content: %s", path, string(data))
260261
}
261262
return nil
262263
})
263-
framework.Logf("scanned %s for discovery docs: %v", home, err)
264+
e2elog.Logf("scanned %s for discovery docs: %v", home, err)
264265
}
265266

266267
framework.KubeDescribe("Update Demo", func() {
@@ -348,7 +349,7 @@ var _ = SIGDescribe("Kubectl client", func() {
348349
})
349350
ginkgo.By("creating all guestbook components")
350351
forEachGBFile(func(contents string) {
351-
framework.Logf(contents)
352+
e2elog.Logf(contents)
352353
framework.RunKubectlOrDieInput(contents, "create", "-f", "-", fmt.Sprintf("--namespace=%v", ns))
353354
})
354355

@@ -604,7 +605,7 @@ var _ = SIGDescribe("Kubectl client", func() {
604605
ginkgo.By("curling local port output")
605606
localAddr := fmt.Sprintf("http://localhost:%d", cmd.port)
606607
body, err := curl(localAddr)
607-
framework.Logf("got: %s", body)
608+
e2elog.Logf("got: %s", body)
608609
if err != nil {
609610
framework.Failf("Failed http.Get of forwarded port (%s): %v", localAddr, err)
610611
}
@@ -639,7 +640,7 @@ var _ = SIGDescribe("Kubectl client", func() {
639640
inClusterHost := strings.TrimSpace(framework.RunHostCmdOrDie(ns, simplePodName, "printenv KUBERNETES_SERVICE_HOST"))
640641
inClusterPort := strings.TrimSpace(framework.RunHostCmdOrDie(ns, simplePodName, "printenv KUBERNETES_SERVICE_PORT"))
641642

642-
framework.Logf("copying %s to the %s pod", kubectlPath, simplePodName)
643+
e2elog.Logf("copying %s to the %s pod", kubectlPath, simplePodName)
643644
framework.RunKubectlOrDie("cp", kubectlPath, ns+"/"+simplePodName+":/tmp/")
644645

645646
// Build a kubeconfig file that will make use of the injected ca and token,
@@ -669,7 +670,7 @@ users:
669670
user:
670671
tokenFile: /var/run/secrets/kubernetes.io/serviceaccount/token
671672
`), os.FileMode(0755)))
672-
framework.Logf("copying override kubeconfig to the %s pod", simplePodName)
673+
e2elog.Logf("copying override kubeconfig to the %s pod", simplePodName)
673674
framework.RunKubectlOrDie("cp", filepath.Join(tmpDir, overrideKubeconfigName), ns+"/"+simplePodName+":/tmp/")
674675

675676
framework.ExpectNoError(ioutil.WriteFile(filepath.Join(tmpDir, "invalid-configmap-with-namespace.yaml"), []byte(`
@@ -685,7 +686,7 @@ apiVersion: v1
685686
metadata:
686687
name: "configmap without namespace and invalid name"
687688
`), os.FileMode(0755)))
688-
framework.Logf("copying configmap manifests to the %s pod", simplePodName)
689+
e2elog.Logf("copying configmap manifests to the %s pod", simplePodName)
689690
framework.RunKubectlOrDie("cp", filepath.Join(tmpDir, "invalid-configmap-with-namespace.yaml"), ns+"/"+simplePodName+":/tmp/")
690691
framework.RunKubectlOrDie("cp", filepath.Join(tmpDir, "invalid-configmap-without-namespace.yaml"), ns+"/"+simplePodName+":/tmp/")
691692

@@ -709,7 +710,7 @@ metadata:
709710

710711
ginkgo.By("trying to use kubectl with invalid token")
711712
_, err = framework.RunHostCmd(ns, simplePodName, "/tmp/kubectl get pods --token=invalid --v=7 2>&1")
712-
framework.Logf("got err %v", err)
713+
e2elog.Logf("got err %v", err)
713714
gomega.Expect(err).To(gomega.HaveOccurred())
714715
gomega.Expect(err).To(gomega.ContainSubstring("Using in-cluster namespace"))
715716
gomega.Expect(err).To(gomega.ContainSubstring("Using in-cluster configuration"))
@@ -718,7 +719,7 @@ metadata:
718719

719720
ginkgo.By("trying to use kubectl with invalid server")
720721
_, err = framework.RunHostCmd(ns, simplePodName, "/tmp/kubectl get pods --server=invalid --v=6 2>&1")
721-
framework.Logf("got err %v", err)
722+
e2elog.Logf("got err %v", err)
722723
gomega.Expect(err).To(gomega.HaveOccurred())
723724
gomega.Expect(err).To(gomega.ContainSubstring("Unable to connect to the server"))
724725
gomega.Expect(err).To(gomega.ContainSubstring("GET http://invalid/api"))
@@ -1059,22 +1060,22 @@ metadata:
10591060

10601061
ginkgo.By("creating Redis RC")
10611062

1062-
framework.Logf("namespace %v", ns)
1063+
e2elog.Logf("namespace %v", ns)
10631064
framework.RunKubectlOrDieInput(controllerJSON, "create", "-f", "-", nsFlag)
10641065

10651066
// It may take a while for the pods to get registered in some cases, wait to be sure.
10661067
ginkgo.By("Waiting for Redis master to start.")
10671068
waitForOrFailWithDebug(1)
10681069
forEachPod(func(pod v1.Pod) {
1069-
framework.Logf("wait on redis-master startup in %v ", ns)
1070+
e2elog.Logf("wait on redis-master startup in %v ", ns)
10701071
framework.LookForStringInLog(ns, pod.Name, "redis-master", "The server is now ready to accept connections", framework.PodStartTimeout)
10711072
})
10721073
validateService := func(name string, servicePort int, timeout time.Duration) {
10731074
err := wait.Poll(framework.Poll, timeout, func() (bool, error) {
10741075
endpoints, err := c.CoreV1().Endpoints(ns).Get(name, metav1.GetOptions{})
10751076
if err != nil {
10761077
// log the real error
1077-
framework.Logf("Get endpoints failed (interval %v): %v", framework.Poll, err)
1078+
e2elog.Logf("Get endpoints failed (interval %v): %v", framework.Poll, err)
10781079

10791080
// if the error is API not found or could not find default credentials or TLS handshake timeout, try again
10801081
if apierrs.IsNotFound(err) ||
@@ -1087,7 +1088,7 @@ metadata:
10871088

10881089
uidToPort := framework.GetContainerPortsByPodUID(endpoints)
10891090
if len(uidToPort) == 0 {
1090-
framework.Logf("No endpoint found, retrying")
1091+
e2elog.Logf("No endpoint found, retrying")
10911092
return false, nil
10921093
}
10931094
if len(uidToPort) > 1 {
@@ -2070,21 +2071,21 @@ func curl(url string) (string, error) {
20702071
}
20712072

20722073
func validateGuestbookApp(c clientset.Interface, ns string) {
2073-
framework.Logf("Waiting for all frontend pods to be Running.")
2074+
e2elog.Logf("Waiting for all frontend pods to be Running.")
20742075
label := labels.SelectorFromSet(labels.Set(map[string]string{"tier": "frontend", "app": "guestbook"}))
20752076
err := testutils.WaitForPodsWithLabelRunning(c, ns, label)
20762077
framework.ExpectNoError(err)
2077-
framework.Logf("Waiting for frontend to serve content.")
2078+
e2elog.Logf("Waiting for frontend to serve content.")
20782079
if !waitForGuestbookResponse(c, "get", "", `{"data": ""}`, guestbookStartupTimeout, ns) {
20792080
framework.Failf("Frontend service did not start serving content in %v seconds.", guestbookStartupTimeout.Seconds())
20802081
}
20812082

2082-
framework.Logf("Trying to add a new entry to the guestbook.")
2083+
e2elog.Logf("Trying to add a new entry to the guestbook.")
20832084
if !waitForGuestbookResponse(c, "set", "TestEntry", `{"message": "Updated"}`, guestbookResponseTimeout, ns) {
20842085
framework.Failf("Cannot added new entry in %v seconds.", guestbookResponseTimeout.Seconds())
20852086
}
20862087

2087-
framework.Logf("Verifying that added entry can be retrieved.")
2088+
e2elog.Logf("Verifying that added entry can be retrieved.")
20882089
if !waitForGuestbookResponse(c, "get", "", `{"data": "TestEntry"}`, guestbookResponseTimeout, ns) {
20892090
framework.Failf("Entry to guestbook wasn't correctly added in %v seconds.", guestbookResponseTimeout.Seconds())
20902091
}
@@ -2097,7 +2098,7 @@ func waitForGuestbookResponse(c clientset.Interface, cmd, arg, expectedResponse
20972098
if err == nil && res == expectedResponse {
20982099
return true
20992100
}
2100-
framework.Logf("Failed to get response from guestbook. err: %v, response: %s", err, res)
2101+
e2elog.Logf("Failed to get response from guestbook. err: %v, response: %s", err, res)
21012102
}
21022103
return false
21032104
}
@@ -2192,7 +2193,7 @@ func getUDData(jpgExpected string, ns string) func(clientset.Interface, string)
21922193

21932194
// getUDData validates data.json in the update-demo (returns nil if data is ok).
21942195
return func(c clientset.Interface, podID string) error {
2195-
framework.Logf("validating pod %s", podID)
2196+
e2elog.Logf("validating pod %s", podID)
21962197

21972198
ctx, cancel := context.WithTimeout(context.Background(), framework.SingleCallTimeout)
21982199
defer cancel()
@@ -2212,12 +2213,12 @@ func getUDData(jpgExpected string, ns string) func(clientset.Interface, string)
22122213
}
22132214
return err
22142215
}
2215-
framework.Logf("got data: %s", body)
2216+
e2elog.Logf("got data: %s", body)
22162217
var data updateDemoData
22172218
if err := json.Unmarshal(body, &data); err != nil {
22182219
return err
22192220
}
2220-
framework.Logf("Unmarshalled json jpg/img => %s , expecting %s .", data, jpgExpected)
2221+
e2elog.Logf("Unmarshalled json jpg/img => %s , expecting %s .", data, jpgExpected)
22212222
if strings.Contains(data.Image, jpgExpected) {
22222223
return nil
22232224
}

test/e2e/kubectl/portforward.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,11 @@ import (
3232
"time"
3333

3434
"golang.org/x/net/websocket"
35-
"k8s.io/api/core/v1"
35+
v1 "k8s.io/api/core/v1"
3636
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3737
"k8s.io/apimachinery/pkg/util/wait"
3838
"k8s.io/kubernetes/test/e2e/framework"
39+
e2elog "k8s.io/kubernetes/test/e2e/framework/log"
3940
testutils "k8s.io/kubernetes/test/utils"
4041
imageutils "k8s.io/kubernetes/test/utils/image"
4142

@@ -136,7 +137,7 @@ type portForwardCommand struct {
136137
func (c *portForwardCommand) Stop() {
137138
// SIGINT signals that kubectl port-forward should gracefully terminate
138139
if err := c.cmd.Process.Signal(syscall.SIGINT); err != nil {
139-
framework.Logf("error sending SIGINT to kubectl port-forward: %v", err)
140+
e2elog.Logf("error sending SIGINT to kubectl port-forward: %v", err)
140141
}
141142

142143
// try to wait for a clean exit
@@ -154,12 +155,12 @@ func (c *portForwardCommand) Stop() {
154155
// success
155156
return
156157
}
157-
framework.Logf("error waiting for kubectl port-forward to exit: %v", err)
158+
e2elog.Logf("error waiting for kubectl port-forward to exit: %v", err)
158159
case <-expired.C:
159-
framework.Logf("timed out waiting for kubectl port-forward to exit")
160+
e2elog.Logf("timed out waiting for kubectl port-forward to exit")
160161
}
161162

162-
framework.Logf("trying to forcibly kill kubectl port-forward")
163+
e2elog.Logf("trying to forcibly kill kubectl port-forward")
163164
framework.TryKill(c.cmd)
164165
}
165166

@@ -169,7 +170,7 @@ func runPortForward(ns, podName string, port int) *portForwardCommand {
169170
// This is somewhat ugly but is the only way to retrieve the port that was picked
170171
// by the port-forward command. We don't want to hard code the port as we have no
171172
// way of guaranteeing we can pick one that isn't in use, particularly on Jenkins.
172-
framework.Logf("starting port-forward command and streaming output")
173+
e2elog.Logf("starting port-forward command and streaming output")
173174
portOutput, _, err := framework.StartCmdAndStreamOutput(cmd)
174175
if err != nil {
175176
framework.Failf("Failed to start port-forward command: %v", err)
@@ -178,7 +179,7 @@ func runPortForward(ns, podName string, port int) *portForwardCommand {
178179
buf := make([]byte, 128)
179180

180181
var n int
181-
framework.Logf("reading from `kubectl port-forward` command's stdout")
182+
e2elog.Logf("reading from `kubectl port-forward` command's stdout")
182183
if n, err = portOutput.Read(buf); err != nil {
183184
framework.Failf("Failed to read from kubectl port-forward stdout: %v", err)
184185
}

0 commit comments

Comments
 (0)