Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify e2e/kubectl tests to import e2elog.Logf #77486

Merged
merged 1 commit into from
May 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions test/e2e/kubectl/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ go_library(
"//test/e2e/framework:go_default_library",
"//test/e2e/framework/auth:go_default_library",
"//test/e2e/framework/job:go_default_library",
"//test/e2e/framework/log:go_default_library",
"//test/e2e/framework/testfiles:go_default_library",
"//test/e2e/scheduling:go_default_library",
"//test/utils:go_default_library",
Expand Down
51 changes: 26 additions & 25 deletions test/e2e/kubectl/kubectl.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ import (
"k8s.io/kubernetes/test/e2e/framework"
"k8s.io/kubernetes/test/e2e/framework/auth"
jobutil "k8s.io/kubernetes/test/e2e/framework/job"
e2elog "k8s.io/kubernetes/test/e2e/framework/log"
"k8s.io/kubernetes/test/e2e/framework/testfiles"
"k8s.io/kubernetes/test/e2e/scheduling"
testutils "k8s.io/kubernetes/test/utils"
Expand Down Expand Up @@ -140,7 +141,7 @@ func runKubectlRetryOrDie(args ...string) string {
}
// Expect no errors to be present after retries are finished
// Copied from framework #ExecOrDie
framework.Logf("stdout: %q", output)
e2elog.Logf("stdout: %q", output)
framework.ExpectNoError(err)
return output
}
Expand Down Expand Up @@ -234,7 +235,7 @@ var _ = SIGDescribe("Kubectl client", func() {
debugDiscovery := func() {
home := os.Getenv("HOME")
if len(home) == 0 {
framework.Logf("no $HOME envvar set")
e2elog.Logf("no $HOME envvar set")
return
}

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

data, readError := ioutil.ReadFile(path)
if readError != nil {
framework.Logf("%s error: %v", path, readError)
e2elog.Logf("%s error: %v", path, readError)
} else {
framework.Logf("%s content: %s", path, string(data))
e2elog.Logf("%s content: %s", path, string(data))
}
return nil
})
framework.Logf("scanned %s for discovery docs: %v", home, err)
e2elog.Logf("scanned %s for discovery docs: %v", home, err)
}

framework.KubeDescribe("Update Demo", func() {
Expand Down Expand Up @@ -348,7 +349,7 @@ var _ = SIGDescribe("Kubectl client", func() {
})
ginkgo.By("creating all guestbook components")
forEachGBFile(func(contents string) {
framework.Logf(contents)
e2elog.Logf(contents)
framework.RunKubectlOrDieInput(contents, "create", "-f", "-", fmt.Sprintf("--namespace=%v", ns))
})

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

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

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

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

Expand All @@ -709,7 +710,7 @@ metadata:

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

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

ginkgo.By("creating Redis RC")

framework.Logf("namespace %v", ns)
e2elog.Logf("namespace %v", ns)
framework.RunKubectlOrDieInput(controllerJSON, "create", "-f", "-", nsFlag)

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

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

uidToPort := framework.GetContainerPortsByPodUID(endpoints)
if len(uidToPort) == 0 {
framework.Logf("No endpoint found, retrying")
e2elog.Logf("No endpoint found, retrying")
return false, nil
}
if len(uidToPort) > 1 {
Expand Down Expand Up @@ -2070,21 +2071,21 @@ func curl(url string) (string, error) {
}

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

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

framework.Logf("Verifying that added entry can be retrieved.")
e2elog.Logf("Verifying that added entry can be retrieved.")
if !waitForGuestbookResponse(c, "get", "", `{"data": "TestEntry"}`, guestbookResponseTimeout, ns) {
framework.Failf("Entry to guestbook wasn't correctly added in %v seconds.", guestbookResponseTimeout.Seconds())
}
Expand All @@ -2097,7 +2098,7 @@ func waitForGuestbookResponse(c clientset.Interface, cmd, arg, expectedResponse
if err == nil && res == expectedResponse {
return true
}
framework.Logf("Failed to get response from guestbook. err: %v, response: %s", err, res)
e2elog.Logf("Failed to get response from guestbook. err: %v, response: %s", err, res)
}
return false
}
Expand Down Expand Up @@ -2192,7 +2193,7 @@ func getUDData(jpgExpected string, ns string) func(clientset.Interface, string)

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

ctx, cancel := context.WithTimeout(context.Background(), framework.SingleCallTimeout)
defer cancel()
Expand All @@ -2212,12 +2213,12 @@ func getUDData(jpgExpected string, ns string) func(clientset.Interface, string)
}
return err
}
framework.Logf("got data: %s", body)
e2elog.Logf("got data: %s", body)
var data updateDemoData
if err := json.Unmarshal(body, &data); err != nil {
return err
}
framework.Logf("Unmarshalled json jpg/img => %s , expecting %s .", data, jpgExpected)
e2elog.Logf("Unmarshalled json jpg/img => %s , expecting %s .", data, jpgExpected)
if strings.Contains(data.Image, jpgExpected) {
return nil
}
Expand Down
15 changes: 8 additions & 7 deletions test/e2e/kubectl/portforward.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@ import (
"time"

"golang.org/x/net/websocket"
"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/kubernetes/test/e2e/framework"
e2elog "k8s.io/kubernetes/test/e2e/framework/log"
testutils "k8s.io/kubernetes/test/utils"
imageutils "k8s.io/kubernetes/test/utils/image"

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

// try to wait for a clean exit
Expand All @@ -154,12 +155,12 @@ func (c *portForwardCommand) Stop() {
// success
return
}
framework.Logf("error waiting for kubectl port-forward to exit: %v", err)
e2elog.Logf("error waiting for kubectl port-forward to exit: %v", err)
case <-expired.C:
framework.Logf("timed out waiting for kubectl port-forward to exit")
e2elog.Logf("timed out waiting for kubectl port-forward to exit")
}

framework.Logf("trying to forcibly kill kubectl port-forward")
e2elog.Logf("trying to forcibly kill kubectl port-forward")
framework.TryKill(c.cmd)
}

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

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