Use namespace flag passed to RunKubectl* methods

This commit is contained in:
Maciej Szulik 2020-09-08 10:26:10 +02:00
parent 4fd93ff852
commit eec4a04c2d
No known key found for this signature in database
GPG Key ID: F15E55D276FA84C4
11 changed files with 116 additions and 145 deletions

View File

@ -981,18 +981,16 @@ func (z *zookeeperTester) deploy(ns string) *appsv1.StatefulSet {
func (z *zookeeperTester) write(statefulPodIndex int, kv map[string]string) {
name := fmt.Sprintf("%v-%d", z.ss.Name, statefulPodIndex)
ns := fmt.Sprintf("--namespace=%v", z.ss.Namespace)
for k, v := range kv {
cmd := fmt.Sprintf("/opt/zookeeper/bin/zkCli.sh create /%v %v", k, v)
framework.Logf(framework.RunKubectlOrDie(z.ss.Namespace, "exec", ns, name, "--", "/bin/sh", "-c", cmd))
framework.Logf(framework.RunKubectlOrDie(z.ss.Namespace, "exec", name, "--", "/bin/sh", "-c", cmd))
}
}
func (z *zookeeperTester) read(statefulPodIndex int, key string) string {
name := fmt.Sprintf("%v-%d", z.ss.Name, statefulPodIndex)
ns := fmt.Sprintf("--namespace=%v", z.ss.Namespace)
cmd := fmt.Sprintf("/opt/zookeeper/bin/zkCli.sh get /%v", key)
return lastLine(framework.RunKubectlOrDie(z.ss.Namespace, "exec", ns, name, "--", "/bin/sh", "-c", cmd))
return lastLine(framework.RunKubectlOrDie(z.ss.Namespace, "exec", name, "--", "/bin/sh", "-c", cmd))
}
type mysqlGaleraTester struct {
@ -1009,7 +1007,7 @@ func (m *mysqlGaleraTester) mysqlExec(cmd, ns, podName string) string {
// TODO: Find a readiness probe for mysql that guarantees writes will
// succeed and ditch retries. Current probe only reads, so there's a window
// for a race.
return kubectlExecWithRetries(ns, fmt.Sprintf("--namespace=%v", ns), "exec", podName, "--", "/bin/sh", "-c", cmd)
return kubectlExecWithRetries(ns, "exec", podName, "--", "/bin/sh", "-c", cmd)
}
func (m *mysqlGaleraTester) deploy(ns string) *appsv1.StatefulSet {
@ -1049,7 +1047,7 @@ func (m *redisTester) name() string {
func (m *redisTester) redisExec(cmd, ns, podName string) string {
cmd = fmt.Sprintf("/opt/redis/redis-cli -h %v %v", podName, cmd)
return framework.RunKubectlOrDie(ns, fmt.Sprintf("--namespace=%v", ns), "exec", podName, "--", "/bin/sh", "-c", cmd)
return framework.RunKubectlOrDie(ns, "exec", podName, "--", "/bin/sh", "-c", cmd)
}
func (m *redisTester) deploy(ns string) *appsv1.StatefulSet {
@ -1080,7 +1078,7 @@ func (c *cockroachDBTester) name() string {
func (c *cockroachDBTester) cockroachDBExec(cmd, ns, podName string) string {
cmd = fmt.Sprintf("/cockroach/cockroach sql --insecure --host %s.cockroachdb -e \"%v\"", podName, cmd)
return framework.RunKubectlOrDie(ns, fmt.Sprintf("--namespace=%v", ns), "exec", podName, "--", "/bin/sh", "-c", cmd)
return framework.RunKubectlOrDie(ns, "exec", podName, "--", "/bin/sh", "-c", cmd)
}
func (c *cockroachDBTester) deploy(ns string) *appsv1.StatefulSet {

View File

@ -68,10 +68,9 @@ var _ = framework.KubeDescribe("[Feature:Example]", func() {
test := "test/fixtures/doc-yaml/user-guide/liveness"
execYaml := readFile(test, "exec-liveness.yaml.in")
httpYaml := readFile(test, "http-liveness.yaml.in")
nsFlag := fmt.Sprintf("--namespace=%v", ns)
framework.RunKubectlOrDieInput(ns, execYaml, "create", "-f", "-", nsFlag)
framework.RunKubectlOrDieInput(ns, httpYaml, "create", "-f", "-", nsFlag)
framework.RunKubectlOrDieInput(ns, execYaml, "create", "-f", "-")
framework.RunKubectlOrDieInput(ns, httpYaml, "create", "-f", "-")
// Since both containers start rapidly, we can easily run this test in parallel.
var wg sync.WaitGroup
@ -117,12 +116,11 @@ var _ = framework.KubeDescribe("[Feature:Example]", func() {
secretYaml := readFile(test, "secret.yaml")
podYaml := readFile(test, "secret-pod.yaml.in")
nsFlag := fmt.Sprintf("--namespace=%v", ns)
podName := "secret-test-pod"
ginkgo.By("creating secret and pod")
framework.RunKubectlOrDieInput(ns, secretYaml, "create", "-f", "-", nsFlag)
framework.RunKubectlOrDieInput(ns, podYaml, "create", "-f", "-", nsFlag)
framework.RunKubectlOrDieInput(ns, secretYaml, "create", "-f", "-")
framework.RunKubectlOrDieInput(ns, podYaml, "create", "-f", "-")
err := e2epod.WaitForPodNoLongerRunningInNamespace(c, podName, ns)
framework.ExpectNoError(err)
@ -136,11 +134,10 @@ var _ = framework.KubeDescribe("[Feature:Example]", func() {
ginkgo.It("should create a pod that prints his name and namespace", func() {
test := "test/fixtures/doc-yaml/user-guide/downward-api"
podYaml := readFile(test, "dapi-pod.yaml.in")
nsFlag := fmt.Sprintf("--namespace=%v", ns)
podName := "dapi-test-pod"
ginkgo.By("creating the pod")
framework.RunKubectlOrDieInput(ns, podYaml, "create", "-f", "-", nsFlag)
framework.RunKubectlOrDieInput(ns, podYaml, "create", "-f", "-")
err := e2epod.WaitForPodNoLongerRunningInNamespace(c, podName, ns)
framework.ExpectNoError(err)

View File

@ -460,10 +460,10 @@ func (j *TestJig) CreateIngress(manifestPath, ns string, ingAnnotations map[stri
}
j.Logger.Infof("creating replication controller")
framework.RunKubectlOrDieInput(ns, read("rc.yaml"), "create", "-f", "-", fmt.Sprintf("--namespace=%v", ns))
framework.RunKubectlOrDieInput(ns, read("rc.yaml"), "create", "-f", "-")
j.Logger.Infof("creating service")
framework.RunKubectlOrDieInput(ns, read("svc.yaml"), "create", "-f", "-", fmt.Sprintf("--namespace=%v", ns))
framework.RunKubectlOrDieInput(ns, read("svc.yaml"), "create", "-f", "-")
if len(svcAnnotations) > 0 {
svcList, err := j.Client.CoreV1().Services(ns).List(context.TODO(), metav1.ListOptions{})
framework.ExpectNoError(err)
@ -476,7 +476,7 @@ func (j *TestJig) CreateIngress(manifestPath, ns string, ingAnnotations map[stri
if exists("secret.yaml") {
j.Logger.Infof("creating secret")
framework.RunKubectlOrDieInput(ns, read("secret.yaml"), "create", "-f", "-", fmt.Sprintf("--namespace=%v", ns))
framework.RunKubectlOrDieInput(ns, read("secret.yaml"), "create", "-f", "-")
}
j.Logger.Infof("Parsing ingress from %v", filepath.Join(manifestPath, "ing.yaml"))
@ -569,7 +569,7 @@ func (j *TestJig) runUpdate(ing *networkingv1beta1.Ingress) (*networkingv1beta1.
func DescribeIng(ns string) {
framework.Logf("\nOutput of kubectl describe ing:\n")
desc, _ := framework.RunKubectl(
ns, "describe", "ing", fmt.Sprintf("--namespace=%v", ns))
ns, "describe", "ing")
framework.Logf(desc)
}
@ -1034,7 +1034,7 @@ func (cont *NginxIngressController) Init() {
}
framework.Logf("initializing nginx ingress controller")
framework.RunKubectlOrDieInput(cont.Ns, read("rc.yaml"), "create", "-f", "-", fmt.Sprintf("--namespace=%v", cont.Ns))
framework.RunKubectlOrDieInput(cont.Ns, read("rc.yaml"), "create", "-f", "-")
rc, err := cont.Client.CoreV1().ReplicationControllers(cont.Ns).Get(context.TODO(), "nginx-ingress-controller", metav1.GetOptions{})
framework.ExpectNoError(err)

View File

@ -86,6 +86,9 @@ func (tk *TestKubeconfig) KubectlCmd(args ...string) *exec.Cmd {
fmt.Sprintf("--client-key=%s", filepath.Join(tk.CertDir, "kubecfg.key")))
}
}
if tk.Namespace != "" {
defaultArgs = append(defaultArgs, fmt.Sprintf("--namespace=%s", tk.Namespace))
}
kubectlArgs := append(defaultArgs, args...)
//We allow users to specify path to kubectl, so you can test either "kubectl" or "cluster/kubectl.sh"

View File

@ -1064,13 +1064,13 @@ func NodeHasTaint(c clientset.Interface, nodeName string, taint *v1.Taint) (bool
// RunHostCmd runs the given cmd in the context of the given pod using `kubectl exec`
// inside of a shell.
func RunHostCmd(ns, name, cmd string) (string, error) {
return RunKubectl(ns, "exec", fmt.Sprintf("--namespace=%v", ns), name, "--", "/bin/sh", "-x", "-c", cmd)
return RunKubectl(ns, "exec", name, "--", "/bin/sh", "-x", "-c", cmd)
}
// RunHostCmdWithFullOutput runs the given cmd in the context of the given pod using `kubectl exec`
// inside of a shell. It will also return the command's stderr.
func RunHostCmdWithFullOutput(ns, name, cmd string) (string, string, error) {
return RunKubectlWithFullOutput(ns, "exec", fmt.Sprintf("--namespace=%v", ns), name, "--", "/bin/sh", "-x", "-c", cmd)
return RunKubectlWithFullOutput(ns, "exec", name, "--", "/bin/sh", "-x", "-c", cmd)
}
// RunHostCmdOrDie calls RunHostCmd and dies on error.
@ -1148,7 +1148,7 @@ func AllNodesReady(c clientset.Interface, timeout time.Duration) error {
// LookForStringInLog looks for the given string in the log of a specific pod container
func LookForStringInLog(ns, podName, container, expectedString string, timeout time.Duration) (result string, err error) {
return lookForString(expectedString, timeout, func() string {
return RunKubectlOrDie(ns, "logs", podName, container, fmt.Sprintf("--namespace=%v", ns))
return RunKubectlOrDie(ns, "logs", podName, container)
})
}
@ -1274,7 +1274,7 @@ func GetAllMasterAddresses(c clientset.Interface) []string {
// CreateEmptyFileOnPod creates empty file at given path on the pod.
// TODO(alejandrox1): move to subpkg pod once kubectl methods have been refactored.
func CreateEmptyFileOnPod(namespace string, podName string, filePath string) error {
_, err := RunKubectl(namespace, "exec", fmt.Sprintf("--namespace=%s", namespace), podName, "--", "/bin/sh", "-c", fmt.Sprintf("touch %s", filePath))
_, err := RunKubectl(namespace, "exec", podName, "--", "/bin/sh", "-c", fmt.Sprintf("touch %s", filePath))
return err
}
@ -1282,10 +1282,10 @@ func CreateEmptyFileOnPod(namespace string, podName string, filePath string) err
func DumpDebugInfo(c clientset.Interface, ns string) {
sl, _ := c.CoreV1().Pods(ns).List(context.TODO(), metav1.ListOptions{LabelSelector: labels.Everything().String()})
for _, s := range sl.Items {
desc, _ := RunKubectl(ns, "describe", "po", s.Name, fmt.Sprintf("--namespace=%v", ns))
desc, _ := RunKubectl(ns, "describe", "po", s.Name)
Logf("\nOutput of kubectl describe %v:\n%v", s.Name, desc)
l, _ := RunKubectl(ns, "logs", s.Name, fmt.Sprintf("--namespace=%v", ns), "--tail=100")
l, _ := RunKubectl(ns, "logs", s.Name, "--tail=100")
Logf("\nLast 100 log lines of %v:\n%v", s.Name, l)
}
}

View File

@ -322,7 +322,7 @@ var _ = SIGDescribe("Kubectl client", func() {
defer cleanupKubectlInputs(nautilus, ns, updateDemoSelector)
ginkgo.By("creating a replication controller")
framework.RunKubectlOrDieInput(ns, nautilus, "create", "-f", "-", fmt.Sprintf("--namespace=%v", ns))
framework.RunKubectlOrDieInput(ns, nautilus, "create", "-f", "-")
validateController(c, nautilusImage, 2, "update-demo", updateDemoSelector, getUDData("nautilus.jpg", ns), ns)
})
@ -335,15 +335,15 @@ var _ = SIGDescribe("Kubectl client", func() {
defer cleanupKubectlInputs(nautilus, ns, updateDemoSelector)
ginkgo.By("creating a replication controller")
framework.RunKubectlOrDieInput(ns, nautilus, "create", "-f", "-", fmt.Sprintf("--namespace=%v", ns))
framework.RunKubectlOrDieInput(ns, nautilus, "create", "-f", "-")
validateController(c, nautilusImage, 2, "update-demo", updateDemoSelector, getUDData("nautilus.jpg", ns), ns)
ginkgo.By("scaling down the replication controller")
debugDiscovery()
framework.RunKubectlOrDie(ns, "scale", "rc", "update-demo-nautilus", "--replicas=1", "--timeout=5m", fmt.Sprintf("--namespace=%v", ns))
framework.RunKubectlOrDie(ns, "scale", "rc", "update-demo-nautilus", "--replicas=1", "--timeout=5m")
validateController(c, nautilusImage, 1, "update-demo", updateDemoSelector, getUDData("nautilus.jpg", ns), ns)
ginkgo.By("scaling up the replication controller")
debugDiscovery()
framework.RunKubectlOrDie(ns, "scale", "rc", "update-demo-nautilus", "--replicas=2", "--timeout=5m", fmt.Sprintf("--namespace=%v", ns))
framework.RunKubectlOrDie(ns, "scale", "rc", "update-demo-nautilus", "--replicas=2", "--timeout=5m")
validateController(c, nautilusImage, 2, "update-demo", updateDemoSelector, getUDData("nautilus.jpg", ns), ns)
})
})
@ -380,7 +380,7 @@ var _ = SIGDescribe("Kubectl client", func() {
ginkgo.By("creating all guestbook components")
forEachGBFile(func(contents string) {
framework.Logf(contents)
framework.RunKubectlOrDieInput(ns, contents, "create", "-f", "-", fmt.Sprintf("--namespace=%v", ns))
framework.RunKubectlOrDieInput(ns, contents, "create", "-f", "-")
})
ginkgo.By("validating guestbook app")
@ -393,7 +393,7 @@ var _ = SIGDescribe("Kubectl client", func() {
ginkgo.BeforeEach(func() {
ginkgo.By(fmt.Sprintf("creating the pod from %v", podYaml))
podYaml = commonutils.SubstituteImageName(string(readTestFileOrDie("pod-with-readiness-probe.yaml.in")))
framework.RunKubectlOrDieInput(ns, podYaml, "create", "-f", "-", fmt.Sprintf("--namespace=%v", ns))
framework.RunKubectlOrDieInput(ns, podYaml, "create", "-f", "-")
framework.ExpectEqual(e2epod.CheckPodsRunningReady(c, ns, []string{simplePodName}, framework.PodStartTimeout), true)
})
ginkgo.AfterEach(func() {
@ -402,7 +402,7 @@ var _ = SIGDescribe("Kubectl client", func() {
ginkgo.It("should support exec", func() {
ginkgo.By("executing a command in the container")
execOutput := framework.RunKubectlOrDie(ns, "exec", fmt.Sprintf("--namespace=%v", ns), simplePodName, "echo", "running", "in", "container")
execOutput := framework.RunKubectlOrDie(ns, "exec", simplePodName, "echo", "running", "in", "container")
if e, a := "running in container", strings.TrimSpace(execOutput); e != a {
framework.Failf("Unexpected kubectl exec output. Wanted %q, got %q", e, a)
}
@ -412,11 +412,11 @@ var _ = SIGDescribe("Kubectl client", func() {
for i := 0; i < len(veryLongData); i++ {
veryLongData[i] = 'a'
}
execOutput = framework.RunKubectlOrDie(ns, "exec", fmt.Sprintf("--namespace=%v", ns), simplePodName, "echo", string(veryLongData))
execOutput = framework.RunKubectlOrDie(ns, "exec", simplePodName, "echo", string(veryLongData))
framework.ExpectEqual(string(veryLongData), strings.TrimSpace(execOutput), "Unexpected kubectl exec output")
ginkgo.By("executing a command in the container with noninteractive stdin")
execOutput = framework.NewKubectlCommand(ns, "exec", fmt.Sprintf("--namespace=%v", ns), "-i", simplePodName, "cat").
execOutput = framework.NewKubectlCommand(ns, "exec", "-i", simplePodName, "cat").
WithStdinData("abcd1234").
ExecOrDie(ns)
if e, a := "abcd1234", execOutput; e != a {
@ -432,7 +432,7 @@ var _ = SIGDescribe("Kubectl client", func() {
defer closer.Close()
ginkgo.By("executing a command in the container with pseudo-interactive stdin")
execOutput = framework.NewKubectlCommand(ns, "exec", fmt.Sprintf("--namespace=%v", ns), "-i", simplePodName, "sh").
execOutput = framework.NewKubectlCommand(ns, "exec", "-i", simplePodName, "sh").
WithStdinReader(r).
ExecOrDie(ns)
if e, a := "hi", strings.TrimSpace(execOutput); e != a {
@ -442,7 +442,7 @@ var _ = SIGDescribe("Kubectl client", func() {
ginkgo.It("should support exec using resource/name", func() {
ginkgo.By("executing a command in the container")
execOutput := framework.RunKubectlOrDie(ns, "exec", fmt.Sprintf("--namespace=%v", ns), simplePodResourceName, "echo", "running", "in", "container")
execOutput := framework.RunKubectlOrDie(ns, "exec", simplePodResourceName, "echo", "running", "in", "container")
if e, a := "running in container", strings.TrimSpace(execOutput); e != a {
framework.Failf("Unexpected kubectl exec output. Wanted %q, got %q", e, a)
}
@ -509,30 +509,28 @@ var _ = SIGDescribe("Kubectl client", func() {
})
ginkgo.It("should return command exit codes", func() {
nsFlag := fmt.Sprintf("--namespace=%v", ns)
ginkgo.By("execing into a container with a successful command")
_, err := framework.NewKubectlCommand(ns, nsFlag, "exec", "httpd", "--", "/bin/sh", "-c", "exit 0").Exec()
_, err := framework.NewKubectlCommand(ns, "exec", "httpd", "--", "/bin/sh", "-c", "exit 0").Exec()
framework.ExpectNoError(err)
ginkgo.By("execing into a container with a failing command")
_, err = framework.NewKubectlCommand(ns, nsFlag, "exec", "httpd", "--", "/bin/sh", "-c", "exit 42").Exec()
_, err = framework.NewKubectlCommand(ns, "exec", "httpd", "--", "/bin/sh", "-c", "exit 42").Exec()
ee, ok := err.(uexec.ExitError)
framework.ExpectEqual(ok, true)
framework.ExpectEqual(ee.ExitStatus(), 42)
ginkgo.By("running a successful command")
_, err = framework.NewKubectlCommand(ns, nsFlag, "run", "-i", "--image="+busyboxImage, "--restart=Never", "success", "--", "/bin/sh", "-c", "exit 0").Exec()
_, err = framework.NewKubectlCommand(ns, "run", "-i", "--image="+busyboxImage, "--restart=Never", "success", "--", "/bin/sh", "-c", "exit 0").Exec()
framework.ExpectNoError(err)
ginkgo.By("running a failing command")
_, err = framework.NewKubectlCommand(ns, nsFlag, "run", "-i", "--image="+busyboxImage, "--restart=Never", "failure-1", "--", "/bin/sh", "-c", "exit 42").Exec()
_, err = framework.NewKubectlCommand(ns, "run", "-i", "--image="+busyboxImage, "--restart=Never", "failure-1", "--", "/bin/sh", "-c", "exit 42").Exec()
ee, ok = err.(uexec.ExitError)
framework.ExpectEqual(ok, true)
framework.ExpectEqual(ee.ExitStatus(), 42)
ginkgo.By("running a failing command without --restart=Never")
_, err = framework.NewKubectlCommand(ns, nsFlag, "run", "-i", "--image="+busyboxImage, "--restart=OnFailure", "failure-2", "--", "/bin/sh", "-c", "cat && exit 42").
_, err = framework.NewKubectlCommand(ns, "run", "-i", "--image="+busyboxImage, "--restart=OnFailure", "failure-2", "--", "/bin/sh", "-c", "cat && exit 42").
WithStdinData("abcd1234").
Exec()
ee, ok = err.(uexec.ExitError)
@ -542,7 +540,7 @@ var _ = SIGDescribe("Kubectl client", func() {
}
ginkgo.By("running a failing command without --restart=Never, but with --rm")
_, err = framework.NewKubectlCommand(ns, nsFlag, "run", "-i", "--image="+busyboxImage, "--restart=OnFailure", "--rm", "failure-3", "--", "/bin/sh", "-c", "cat && exit 42").
_, err = framework.NewKubectlCommand(ns, "run", "-i", "--image="+busyboxImage, "--restart=OnFailure", "--rm", "failure-3", "--", "/bin/sh", "-c", "cat && exit 42").
WithStdinData("abcd1234").
Exec()
ee, ok = err.(uexec.ExitError)
@ -553,18 +551,16 @@ var _ = SIGDescribe("Kubectl client", func() {
e2epod.WaitForPodToDisappear(f.ClientSet, ns, "failure-3", labels.Everything(), 2*time.Second, wait.ForeverTestTimeout)
ginkgo.By("running a failing command with --leave-stdin-open")
_, err = framework.NewKubectlCommand(ns, nsFlag, "run", "-i", "--image="+busyboxImage, "--restart=Never", "failure-4", "--leave-stdin-open", "--", "/bin/sh", "-c", "exit 42").
_, err = framework.NewKubectlCommand(ns, "run", "-i", "--image="+busyboxImage, "--restart=Never", "failure-4", "--leave-stdin-open", "--", "/bin/sh", "-c", "exit 42").
WithStdinData("abcd1234").
Exec()
framework.ExpectNoError(err)
})
ginkgo.It("should support inline execution and attach", func() {
nsFlag := fmt.Sprintf("--namespace=%v", ns)
ginkgo.By("executing a command with run and attach with stdin")
// We wait for a non-empty line so we know kubectl has attached
runOutput := framework.NewKubectlCommand(ns, nsFlag, "run", "run-test", "--image="+busyboxImage, "--restart=OnFailure", "--attach=true", "--stdin", "--", "sh", "-c", "while [ -z \"$s\" ]; do read s; sleep 1; done; echo read:$s && cat && echo 'stdin closed'").
runOutput := framework.NewKubectlCommand(ns, "run", "run-test", "--image="+busyboxImage, "--restart=OnFailure", "--attach=true", "--stdin", "--", "sh", "-c", "while [ -z \"$s\" ]; do read s; sleep 1; done; echo read:$s && cat && echo 'stdin closed'").
WithStdinData("value\nabcd1234").
ExecOrDie(ns)
gomega.Expect(runOutput).To(gomega.ContainSubstring("read:value"))
@ -579,7 +575,7 @@ var _ = SIGDescribe("Kubectl client", func() {
// "stdin closed", but hasn't exited yet.
// We wait 10 seconds before printing to give time to kubectl to attach
// to the container, this does not solve the race though.
runOutput = framework.NewKubectlCommand(ns, fmt.Sprintf("--namespace=%v", ns), "run", "run-test-2", "--image="+busyboxImage, "--restart=OnFailure", "--attach=true", "--leave-stdin-open=true", "--", "sh", "-c", "sleep 10; cat && echo 'stdin closed'").
runOutput = framework.NewKubectlCommand(ns, "run", "run-test-2", "--image="+busyboxImage, "--restart=OnFailure", "--attach=true", "--leave-stdin-open=true", "--", "sh", "-c", "sleep 10; cat && echo 'stdin closed'").
WithStdinData("abcd1234").
ExecOrDie(ns)
gomega.Expect(runOutput).ToNot(gomega.ContainSubstring("abcd1234"))
@ -588,7 +584,7 @@ var _ = SIGDescribe("Kubectl client", func() {
gomega.Expect(c.CoreV1().Pods(ns).Delete(context.TODO(), "run-test-2", metav1.DeleteOptions{})).To(gomega.BeNil())
ginkgo.By("executing a command with run and attach with stdin with open stdin should remain running")
runOutput = framework.NewKubectlCommand(ns, nsFlag, "run", "run-test-3", "--image="+busyboxImage, "--restart=OnFailure", "--attach=true", "--leave-stdin-open=true", "--stdin", "--", "sh", "-c", "cat && echo 'stdin closed'").
runOutput = framework.NewKubectlCommand(ns, "run", "run-test-3", "--image="+busyboxImage, "--restart=OnFailure", "--attach=true", "--leave-stdin-open=true", "--stdin", "--", "sh", "-c", "cat && echo 'stdin closed'").
WithStdinData("abcd1234\n").
ExecOrDie(ns)
gomega.Expect(runOutput).ToNot(gomega.ContainSubstring("stdin closed"))
@ -605,7 +601,7 @@ var _ = SIGDescribe("Kubectl client", func() {
if !e2epod.CheckPodsRunningReady(c, ns, []string{runTestPod.Name}, 1*time.Second) {
framework.Failf("Pod %q of Job %q should still be running", runTestPod.Name, "run-test-3")
}
logOutput := framework.RunKubectlOrDie(ns, nsFlag, "logs", runTestPod.Name)
logOutput := framework.RunKubectlOrDie(ns, "logs", runTestPod.Name)
gomega.Expect(logOutput).ToNot(gomega.ContainSubstring("stdin closed"))
return strings.Contains(logOutput, "abcd1234"), nil
})
@ -615,17 +611,16 @@ var _ = SIGDescribe("Kubectl client", func() {
})
ginkgo.It("should contain last line of the log", func() {
nsFlag := fmt.Sprintf("--namespace=%v", ns)
podName := "run-log-test"
ginkgo.By("executing a command with run")
framework.RunKubectlOrDie(ns, "run", podName, "--image="+busyboxImage, "--restart=OnFailure", nsFlag, "--", "sh", "-c", "sleep 10; seq 100 | while read i; do echo $i; sleep 0.01; done; echo EOF")
framework.RunKubectlOrDie(ns, "run", podName, "--image="+busyboxImage, "--restart=OnFailure", "--", "sh", "-c", "sleep 10; seq 100 | while read i; do echo $i; sleep 0.01; done; echo EOF")
if !e2epod.CheckPodsRunningReadyOrSucceeded(c, ns, []string{podName}, framework.PodStartTimeout) {
framework.Failf("Pod for run-log-test was not ready")
}
logOutput := framework.RunKubectlOrDie(ns, nsFlag, "logs", "-f", "run-log-test")
logOutput := framework.RunKubectlOrDie(ns, "logs", "-f", "run-log-test")
gomega.Expect(logOutput).To(gomega.ContainSubstring("EOF"))
})
@ -807,12 +802,11 @@ metadata:
ginkgo.It("should apply a new configuration to an existing RC", func() {
controllerJSON := commonutils.SubstituteImageName(string(readTestFileOrDie(agnhostControllerFilename)))
nsFlag := fmt.Sprintf("--namespace=%v", ns)
ginkgo.By("creating Agnhost RC")
framework.RunKubectlOrDieInput(ns, controllerJSON, "create", "-f", "-", nsFlag)
framework.RunKubectlOrDieInput(ns, controllerJSON, "create", "-f", "-")
ginkgo.By("applying a modified configuration")
stdin := modifyReplicationControllerConfiguration(controllerJSON)
framework.NewKubectlCommand(ns, "apply", "-f", "-", nsFlag).
framework.NewKubectlCommand(ns, "apply", "-f", "-").
WithStdinReader(stdin).
ExecOrDie(ns)
ginkgo.By("checking the result")
@ -820,19 +814,18 @@ metadata:
})
ginkgo.It("should reuse port when apply to an existing SVC", func() {
serviceJSON := readTestFileOrDie(agnhostServiceFilename)
nsFlag := fmt.Sprintf("--namespace=%v", ns)
ginkgo.By("creating Agnhost SVC")
framework.RunKubectlOrDieInput(ns, string(serviceJSON[:]), "create", "-f", "-", nsFlag)
framework.RunKubectlOrDieInput(ns, string(serviceJSON[:]), "create", "-f", "-")
ginkgo.By("getting the original port")
originalNodePort := framework.RunKubectlOrDie(ns, "get", "service", "agnhost-primary", nsFlag, "-o", "jsonpath={.spec.ports[0].port}")
originalNodePort := framework.RunKubectlOrDie(ns, "get", "service", "agnhost-primary", "-o", "jsonpath={.spec.ports[0].port}")
ginkgo.By("applying the same configuration")
framework.RunKubectlOrDieInput(ns, string(serviceJSON[:]), "apply", "-f", "-", nsFlag)
framework.RunKubectlOrDieInput(ns, string(serviceJSON[:]), "apply", "-f", "-")
ginkgo.By("getting the port after applying configuration")
currentNodePort := framework.RunKubectlOrDie(ns, "get", "service", "agnhost-primary", nsFlag, "-o", "jsonpath={.spec.ports[0].port}")
currentNodePort := framework.RunKubectlOrDie(ns, "get", "service", "agnhost-primary", "-o", "jsonpath={.spec.ports[0].port}")
ginkgo.By("checking the result")
if originalNodePort != currentNodePort {
@ -844,23 +837,22 @@ metadata:
deployment1Yaml := commonutils.SubstituteImageName(string(readTestFileOrDie(httpdDeployment1Filename)))
deployment2Yaml := commonutils.SubstituteImageName(string(readTestFileOrDie(httpdDeployment2Filename)))
deployment3Yaml := commonutils.SubstituteImageName(string(readTestFileOrDie(httpdDeployment3Filename)))
nsFlag := fmt.Sprintf("--namespace=%v", ns)
ginkgo.By("deployment replicas number is 2")
framework.RunKubectlOrDieInput(ns, deployment1Yaml, "apply", "-f", "-", nsFlag)
framework.RunKubectlOrDieInput(ns, deployment1Yaml, "apply", "-f", "-")
ginkgo.By("check the last-applied matches expectations annotations")
output := framework.RunKubectlOrDieInput(ns, deployment1Yaml, "apply", "view-last-applied", "-f", "-", nsFlag, "-o", "json")
output := framework.RunKubectlOrDieInput(ns, deployment1Yaml, "apply", "view-last-applied", "-f", "-", "-o", "json")
requiredString := "\"replicas\": 2"
if !strings.Contains(output, requiredString) {
framework.Failf("Missing %s in kubectl view-last-applied", requiredString)
}
ginkgo.By("apply file doesn't have replicas")
framework.RunKubectlOrDieInput(ns, deployment2Yaml, "apply", "set-last-applied", "-f", "-", nsFlag)
framework.RunKubectlOrDieInput(ns, deployment2Yaml, "apply", "set-last-applied", "-f", "-")
ginkgo.By("check last-applied has been updated, annotations doesn't have replicas")
output = framework.RunKubectlOrDieInput(ns, deployment1Yaml, "apply", "view-last-applied", "-f", "-", nsFlag, "-o", "json")
output = framework.RunKubectlOrDieInput(ns, deployment1Yaml, "apply", "view-last-applied", "-f", "-", "-o", "json")
requiredString = "\"replicas\": 2"
if strings.Contains(output, requiredString) {
framework.Failf("Presenting %s in kubectl view-last-applied", requiredString)
@ -869,13 +861,13 @@ metadata:
ginkgo.By("scale set replicas to 3")
httpdDeploy := "httpd-deployment"
debugDiscovery()
framework.RunKubectlOrDie(ns, "scale", "deployment", httpdDeploy, "--replicas=3", nsFlag)
framework.RunKubectlOrDie(ns, "scale", "deployment", httpdDeploy, "--replicas=3")
ginkgo.By("apply file doesn't have replicas but image changed")
framework.RunKubectlOrDieInput(ns, deployment3Yaml, "apply", "-f", "-", nsFlag)
framework.RunKubectlOrDieInput(ns, deployment3Yaml, "apply", "-f", "-")
ginkgo.By("verify replicas still is 3 and image has been updated")
output = framework.RunKubectlOrDieInput(ns, deployment3Yaml, "get", "-f", "-", nsFlag, "-o", "json")
output = framework.RunKubectlOrDieInput(ns, deployment3Yaml, "get", "-f", "-", "-o", "json")
requiredItems := []string{"\"replicas\": 3", imageutils.GetE2EImage(imageutils.Httpd)}
for _, item := range requiredItems {
if !strings.Contains(output, item) {
@ -925,16 +917,15 @@ metadata:
framework.ConformanceIt("should check if kubectl can dry-run update Pods", func() {
ginkgo.By("running the image " + httpdImage)
podName := "e2e-test-httpd-pod"
nsFlag := fmt.Sprintf("--namespace=%v", ns)
framework.RunKubectlOrDie(ns, "run", podName, "--image="+httpdImage, "--labels=run="+podName, nsFlag)
framework.RunKubectlOrDie(ns, "run", podName, "--image="+httpdImage, "--labels=run="+podName)
ginkgo.By("replace the image in the pod with server-side dry-run")
podJSON := framework.RunKubectlOrDie(ns, "get", "pod", podName, "-o", "json", nsFlag)
podJSON := framework.RunKubectlOrDie(ns, "get", "pod", podName, "-o", "json")
podJSON = strings.Replace(podJSON, httpdImage, busyboxImage, 1)
if !strings.Contains(podJSON, busyboxImage) {
framework.Failf("Failed replacing image from %s to %s in:\n%s\n", httpdImage, busyboxImage, podJSON)
}
framework.RunKubectlOrDieInput(ns, podJSON, "replace", "-f", "-", "--dry-run", "server", nsFlag)
framework.RunKubectlOrDieInput(ns, podJSON, "replace", "-f", "-", "--dry-run", "server")
ginkgo.By("verifying the pod " + podName + " has the right image " + httpdImage)
pod, err := c.CoreV1().Pods(ns).Get(context.TODO(), podName, metav1.GetOptions{})
@ -946,7 +937,7 @@ metadata:
framework.Failf("Failed creating pod with expected image %s", httpdImage)
}
framework.RunKubectlOrDie(ns, "delete", "pods", podName, nsFlag)
framework.RunKubectlOrDie(ns, "delete", "pods", podName)
})
})
@ -1112,16 +1103,15 @@ metadata:
controllerJSON := commonutils.SubstituteImageName(string(readTestFileOrDie(agnhostControllerFilename)))
serviceJSON := readTestFileOrDie(agnhostServiceFilename)
nsFlag := fmt.Sprintf("--namespace=%v", ns)
framework.RunKubectlOrDieInput(ns, controllerJSON, "create", "-f", "-", nsFlag)
framework.RunKubectlOrDieInput(ns, string(serviceJSON[:]), "create", "-f", "-", nsFlag)
framework.RunKubectlOrDieInput(ns, controllerJSON, "create", "-f", "-")
framework.RunKubectlOrDieInput(ns, string(serviceJSON[:]), "create", "-f", "-")
ginkgo.By("Waiting for Agnhost primary to start.")
waitForOrFailWithDebug(1)
// Pod
forEachPod(func(pod v1.Pod) {
output := framework.RunKubectlOrDie(ns, "describe", "pod", pod.Name, nsFlag)
output := framework.RunKubectlOrDie(ns, "describe", "pod", pod.Name)
requiredStrings := [][]string{
{"Name:", "agnhost-primary-"},
{"Namespace:", ns},
@ -1152,10 +1142,10 @@ metadata:
{"Pod Template:"},
{"Image:", agnhostImage},
{"Events:"}}
checkKubectlOutputWithRetry(ns, requiredStrings, "describe", "rc", "agnhost-primary", nsFlag)
checkKubectlOutputWithRetry(ns, requiredStrings, "describe", "rc", "agnhost-primary")
// Service
output := framework.RunKubectlOrDie(ns, "describe", "service", "agnhost-primary", nsFlag)
output := framework.RunKubectlOrDie(ns, "describe", "service", "agnhost-primary")
requiredStrings = [][]string{
{"Name:", "agnhost-primary"},
{"Namespace:", ns},
@ -1208,9 +1198,8 @@ metadata:
ginkgo.It("should check if kubectl describe prints relevant information for cronjob", func() {
ginkgo.By("creating a cronjob")
nsFlag := fmt.Sprintf("--namespace=%v", ns)
cronjobYaml := commonutils.SubstituteImageName(string(readTestFileOrDie("busybox-cronjob.yaml")))
framework.RunKubectlOrDieInput(ns, cronjobYaml, "create", "-f", "-", nsFlag)
framework.RunKubectlOrDieInput(ns, cronjobYaml, "create", "-f", "-")
ginkgo.By("waiting for cronjob to start.")
err := wait.PollImmediate(time.Second, time.Minute, func() (bool, error) {
@ -1223,7 +1212,7 @@ metadata:
framework.ExpectNoError(err)
ginkgo.By("verifying kubectl describe prints")
output := framework.RunKubectlOrDie(ns, "describe", "cronjob", "cronjob-test", nsFlag)
output := framework.RunKubectlOrDie(ns, "describe", "cronjob", "cronjob-test")
requiredStrings := [][]string{
{"Name:", "cronjob-test"},
{"Namespace:", ns},
@ -1251,14 +1240,13 @@ metadata:
*/
framework.ConformanceIt("should create services for rc ", func() {
controllerJSON := commonutils.SubstituteImageName(string(readTestFileOrDie(agnhostControllerFilename)))
nsFlag := fmt.Sprintf("--namespace=%v", ns)
agnhostPort := 6379
ginkgo.By("creating Agnhost RC")
framework.Logf("namespace %v", ns)
framework.RunKubectlOrDieInput(ns, controllerJSON, "create", "-f", "-", nsFlag)
framework.RunKubectlOrDieInput(ns, controllerJSON, "create", "-f", "-")
// It may take a while for the pods to get registered in some cases, wait to be sure.
ginkgo.By("Waiting for Agnhost primary to start.")
@ -1316,12 +1304,12 @@ metadata:
}
ginkgo.By("exposing RC")
framework.RunKubectlOrDie(ns, "expose", "rc", "agnhost-primary", "--name=rm2", "--port=1234", fmt.Sprintf("--target-port=%d", agnhostPort), nsFlag)
framework.RunKubectlOrDie(ns, "expose", "rc", "agnhost-primary", "--name=rm2", "--port=1234", fmt.Sprintf("--target-port=%d", agnhostPort))
e2enetwork.WaitForService(c, ns, "rm2", true, framework.Poll, framework.ServiceStartTimeout)
validateService("rm2", 1234, framework.ServiceStartTimeout)
ginkgo.By("exposing service")
framework.RunKubectlOrDie(ns, "expose", "service", "rm2", "--name=rm3", "--port=2345", fmt.Sprintf("--target-port=%d", agnhostPort), nsFlag)
framework.RunKubectlOrDie(ns, "expose", "service", "rm2", "--name=rm3", "--port=2345", fmt.Sprintf("--target-port=%d", agnhostPort))
e2enetwork.WaitForService(c, ns, "rm3", true, framework.Poll, framework.ServiceStartTimeout)
validateService("rm3", 2345, framework.ServiceStartTimeout)
})
@ -1329,12 +1317,10 @@ metadata:
ginkgo.Describe("Kubectl label", func() {
var podYaml string
var nsFlag string
ginkgo.BeforeEach(func() {
ginkgo.By("creating the pod")
podYaml = commonutils.SubstituteImageName(string(readTestFileOrDie("pause-pod.yaml.in")))
nsFlag = fmt.Sprintf("--namespace=%v", ns)
framework.RunKubectlOrDieInput(ns, podYaml, "create", "-f", "-", nsFlag)
framework.RunKubectlOrDieInput(ns, podYaml, "create", "-f", "-")
framework.ExpectEqual(e2epod.CheckPodsRunningReady(c, ns, []string{pausePodName}, framework.PodStartTimeout), true)
})
ginkgo.AfterEach(func() {
@ -1351,17 +1337,17 @@ metadata:
labelValue := "testing-label-value"
ginkgo.By("adding the label " + labelName + " with value " + labelValue + " to a pod")
framework.RunKubectlOrDie(ns, "label", "pods", pausePodName, labelName+"="+labelValue, nsFlag)
framework.RunKubectlOrDie(ns, "label", "pods", pausePodName, labelName+"="+labelValue)
ginkgo.By("verifying the pod has the label " + labelName + " with the value " + labelValue)
output := framework.RunKubectlOrDie(ns, "get", "pod", pausePodName, "-L", labelName, nsFlag)
output := framework.RunKubectlOrDie(ns, "get", "pod", pausePodName, "-L", labelName)
if !strings.Contains(output, labelValue) {
framework.Failf("Failed updating label " + labelName + " to the pod " + pausePodName)
}
ginkgo.By("removing the label " + labelName + " of a pod")
framework.RunKubectlOrDie(ns, "label", "pods", pausePodName, labelName+"-", nsFlag)
framework.RunKubectlOrDie(ns, "label", "pods", pausePodName, labelName+"-")
ginkgo.By("verifying the pod doesn't have the label " + labelName)
output = framework.RunKubectlOrDie(ns, "get", "pod", pausePodName, "-L", labelName, nsFlag)
output = framework.RunKubectlOrDie(ns, "get", "pod", pausePodName, "-L", labelName)
if strings.Contains(output, labelValue) {
framework.Failf("Failed removing label " + labelName + " of the pod " + pausePodName)
}
@ -1370,12 +1356,10 @@ metadata:
ginkgo.Describe("Kubectl copy", func() {
var podYaml string
var nsFlag string
ginkgo.BeforeEach(func() {
ginkgo.By("creating the pod")
nsFlag = fmt.Sprintf("--namespace=%v", ns)
podYaml = commonutils.SubstituteImageName(string(readTestFileOrDie("busybox-pod.yaml")))
framework.RunKubectlOrDieInput(ns, podYaml, "create", "-f", "-", nsFlag)
framework.RunKubectlOrDieInput(ns, podYaml, "create", "-f", "-")
framework.ExpectEqual(e2epod.CheckPodsRunningReady(c, ns, []string{busyboxPodName}, framework.PodStartTimeout), true)
})
ginkgo.AfterEach(func() {
@ -1396,7 +1380,7 @@ metadata:
}
ginkgo.By("specifying a remote filepath " + podSource + " on the pod")
framework.RunKubectlOrDie(ns, "cp", podSource, tempDestination.Name(), nsFlag)
framework.RunKubectlOrDie(ns, "cp", podSource, tempDestination.Name())
ginkgo.By("verifying that the contents of the remote file " + podSource + " have been copied to a local file " + tempDestination.Name())
localData, err := ioutil.ReadAll(tempDestination)
if err != nil {
@ -1409,17 +1393,15 @@ metadata:
})
ginkgo.Describe("Kubectl logs", func() {
var nsFlag string
podName := "logs-generator"
containerName := "logs-generator"
ginkgo.BeforeEach(func() {
ginkgo.By("creating an pod")
nsFlag = fmt.Sprintf("--namespace=%v", ns)
// Agnhost image generates logs for a total of 100 lines over 20s.
framework.RunKubectlOrDie(ns, "run", podName, "--image="+agnhostImage, nsFlag, "--restart=Never", "--", "logs-generator", "--log-lines-total", "100", "--run-duration", "20s")
framework.RunKubectlOrDie(ns, "run", podName, "--image="+agnhostImage, "--restart=Never", "--", "logs-generator", "--log-lines-total", "100", "--run-duration", "20s")
})
ginkgo.AfterEach(func() {
framework.RunKubectlOrDie(ns, "delete", "pod", podName, nsFlag)
framework.RunKubectlOrDie(ns, "delete", "pod", podName)
})
/*
@ -1450,19 +1432,19 @@ metadata:
framework.ExpectNoError(err)
ginkgo.By("limiting log lines")
out := framework.RunKubectlOrDie(ns, "logs", podName, containerName, nsFlag, "--tail=1")
out := framework.RunKubectlOrDie(ns, "logs", podName, containerName, "--tail=1")
framework.Logf("got output %q", out)
gomega.Expect(len(out)).NotTo(gomega.BeZero())
framework.ExpectEqual(len(lines(out)), 1)
ginkgo.By("limiting log bytes")
out = framework.RunKubectlOrDie(ns, "logs", podName, containerName, nsFlag, "--limit-bytes=1")
out = framework.RunKubectlOrDie(ns, "logs", podName, containerName, "--limit-bytes=1")
framework.Logf("got output %q", out)
framework.ExpectEqual(len(lines(out)), 1)
framework.ExpectEqual(len(out), 1)
ginkgo.By("exposing timestamps")
out = framework.RunKubectlOrDie(ns, "logs", podName, containerName, nsFlag, "--tail=1", "--timestamps")
out = framework.RunKubectlOrDie(ns, "logs", podName, containerName, "--tail=1", "--timestamps")
framework.Logf("got output %q", out)
l := lines(out)
framework.ExpectEqual(len(l), 1)
@ -1479,9 +1461,9 @@ metadata:
// because the granularity is only 1 second and
// it could end up rounding the wrong way.
time.Sleep(2500 * time.Millisecond) // ensure that startup logs on the node are seen as older than 1s
recentOut := framework.RunKubectlOrDie(ns, "logs", podName, containerName, nsFlag, "--since=1s")
recentOut := framework.RunKubectlOrDie(ns, "logs", podName, containerName, "--since=1s")
recent := len(strings.Split(recentOut, "\n"))
olderOut := framework.RunKubectlOrDie(ns, "logs", podName, containerName, nsFlag, "--since=24h")
olderOut := framework.RunKubectlOrDie(ns, "logs", podName, containerName, "--since=24h")
older := len(strings.Split(olderOut, "\n"))
gomega.Expect(recent).To(gomega.BeNumerically("<", older), "expected recent(%v) to be less than older(%v)\nrecent lines:\n%v\nolder lines:\n%v\n", recent, older, recentOut, olderOut)
})
@ -1495,14 +1477,13 @@ metadata:
*/
framework.ConformanceIt("should add annotations for pods in rc ", func() {
controllerJSON := commonutils.SubstituteImageName(string(readTestFileOrDie(agnhostControllerFilename)))
nsFlag := fmt.Sprintf("--namespace=%v", ns)
ginkgo.By("creating Agnhost RC")
framework.RunKubectlOrDieInput(ns, controllerJSON, "create", "-f", "-", nsFlag)
framework.RunKubectlOrDieInput(ns, controllerJSON, "create", "-f", "-")
ginkgo.By("Waiting for Agnhost primary to start.")
waitForOrFailWithDebug(1)
ginkgo.By("patching all pods")
forEachPod(func(pod v1.Pod) {
framework.RunKubectlOrDie(ns, "patch", "pod", pod.Name, nsFlag, "-p", "{\"metadata\":{\"annotations\":{\"x\":\"y\"}}}")
framework.RunKubectlOrDie(ns, "patch", "pod", pod.Name, "-p", "{\"metadata\":{\"annotations\":{\"x\":\"y\"}}}")
})
ginkgo.By("checking annotations")
@ -1539,16 +1520,14 @@ metadata:
})
ginkgo.Describe("Kubectl run pod", func() {
var nsFlag string
var podName string
ginkgo.BeforeEach(func() {
nsFlag = fmt.Sprintf("--namespace=%v", ns)
podName = "e2e-test-httpd-pod"
})
ginkgo.AfterEach(func() {
framework.RunKubectlOrDie(ns, "delete", "pods", podName, nsFlag)
framework.RunKubectlOrDie(ns, "delete", "pods", podName)
})
/*
@ -1558,7 +1537,7 @@ metadata:
*/
framework.ConformanceIt("should create a pod from an image when restart is Never ", func() {
ginkgo.By("running the image " + httpdImage)
framework.RunKubectlOrDie(ns, "run", podName, "--restart=Never", "--image="+httpdImage, nsFlag)
framework.RunKubectlOrDie(ns, "run", podName, "--restart=Never", "--image="+httpdImage)
ginkgo.By("verifying the pod " + podName + " was created")
pod, err := c.CoreV1().Pods(ns).Get(context.TODO(), podName, metav1.GetOptions{})
if err != nil {
@ -1575,16 +1554,14 @@ metadata:
})
ginkgo.Describe("Kubectl replace", func() {
var nsFlag string
var podName string
ginkgo.BeforeEach(func() {
nsFlag = fmt.Sprintf("--namespace=%v", ns)
podName = "e2e-test-httpd-pod"
})
ginkgo.AfterEach(func() {
framework.RunKubectlOrDie(ns, "delete", "pods", podName, nsFlag)
framework.RunKubectlOrDie(ns, "delete", "pods", podName)
})
/*
@ -1594,7 +1571,7 @@ metadata:
*/
framework.ConformanceIt("should update a single-container pod's image ", func() {
ginkgo.By("running the image " + httpdImage)
framework.RunKubectlOrDie(ns, "run", podName, "--image="+httpdImage, "--labels=run="+podName, nsFlag)
framework.RunKubectlOrDie(ns, "run", podName, "--image="+httpdImage, "--labels=run="+podName)
ginkgo.By("verifying the pod " + podName + " is running")
label := labels.SelectorFromSet(labels.Set(map[string]string{"run": podName}))
@ -1604,14 +1581,14 @@ metadata:
}
ginkgo.By("verifying the pod " + podName + " was created")
podJSON := framework.RunKubectlOrDie(ns, "get", "pod", podName, nsFlag, "-o", "json")
podJSON := framework.RunKubectlOrDie(ns, "get", "pod", podName, "-o", "json")
if !strings.Contains(podJSON, podName) {
framework.Failf("Failed to find pod %s in [%s]", podName, podJSON)
}
ginkgo.By("replace the image in the pod")
podJSON = strings.Replace(podJSON, httpdImage, busyboxImage, 1)
framework.RunKubectlOrDieInput(ns, podJSON, "replace", "-f", "-", nsFlag)
framework.RunKubectlOrDieInput(ns, podJSON, "replace", "-f", "-")
ginkgo.By("verifying the pod " + podName + " has the right image " + busyboxImage)
pod, err := c.CoreV1().Pods(ns).Get(context.TODO(), podName, metav1.GetOptions{})
@ -1791,11 +1768,10 @@ metadata:
ginkgo.Describe("Kubectl create quota", func() {
ginkgo.It("should create a quota without scopes", func() {
nsFlag := fmt.Sprintf("--namespace=%v", ns)
quotaName := "million"
ginkgo.By("calling kubectl quota")
framework.RunKubectlOrDie(ns, "create", "quota", quotaName, "--hard=pods=1000000,services=1000000", nsFlag)
framework.RunKubectlOrDie(ns, "create", "quota", quotaName, "--hard=pods=1000000,services=1000000")
ginkgo.By("verifying that the quota was created")
quota, err := c.CoreV1().ResourceQuotas(ns).Get(context.TODO(), quotaName, metav1.GetOptions{})
@ -1820,11 +1796,10 @@ metadata:
})
ginkgo.It("should create a quota with scopes", func() {
nsFlag := fmt.Sprintf("--namespace=%v", ns)
quotaName := "scopes"
ginkgo.By("calling kubectl quota")
framework.RunKubectlOrDie(ns, "create", "quota", quotaName, "--hard=pods=1000000", "--scopes=BestEffort,NotTerminating", nsFlag)
framework.RunKubectlOrDie(ns, "create", "quota", quotaName, "--hard=pods=1000000", "--scopes=BestEffort,NotTerminating")
ginkgo.By("verifying that the quota was created")
quota, err := c.CoreV1().ResourceQuotas(ns).Get(context.TODO(), quotaName, metav1.GetOptions{})
@ -1848,11 +1823,10 @@ metadata:
})
ginkgo.It("should reject quota with invalid scopes", func() {
nsFlag := fmt.Sprintf("--namespace=%v", ns)
quotaName := "scopes"
ginkgo.By("calling kubectl quota")
out, err := framework.RunKubectl(ns, "create", "quota", quotaName, "--hard=hard=pods=1000000", "--scopes=Foo", nsFlag)
out, err := framework.RunKubectl(ns, "create", "quota", quotaName, "--hard=hard=pods=1000000", "--scopes=Foo")
if err == nil {
framework.Failf("Expected kubectl to fail, but it succeeded: %s", out)
}
@ -2158,19 +2132,18 @@ func startLocalProxy() (srv *httptest.Server, logs *bytes.Buffer) {
// createApplyCustomResource asserts that given CustomResource be created and applied
// without being rejected by client-side validation
func createApplyCustomResource(resource, namespace, name string, crd *crd.TestCrd) error {
ns := fmt.Sprintf("--namespace=%v", namespace)
ginkgo.By("successfully create CR")
if _, err := framework.RunKubectlInput(namespace, resource, ns, "create", "--validate=true", "-f", "-"); err != nil {
return fmt.Errorf("failed to create CR %s in namespace %s: %v", resource, ns, err)
if _, err := framework.RunKubectlInput(namespace, resource, "create", "--validate=true", "-f", "-"); err != nil {
return fmt.Errorf("failed to create CR %s in namespace %s: %v", resource, namespace, err)
}
if _, err := framework.RunKubectl(namespace, ns, "delete", crd.Crd.Spec.Names.Plural, name); err != nil {
if _, err := framework.RunKubectl(namespace, "delete", crd.Crd.Spec.Names.Plural, name); err != nil {
return fmt.Errorf("failed to delete CR %s: %v", name, err)
}
ginkgo.By("successfully apply CR")
if _, err := framework.RunKubectlInput(namespace, resource, ns, "apply", "--validate=true", "-f", "-"); err != nil {
return fmt.Errorf("failed to apply CR %s in namespace %s: %v", resource, ns, err)
if _, err := framework.RunKubectlInput(namespace, resource, "apply", "--validate=true", "-f", "-"); err != nil {
return fmt.Errorf("failed to apply CR %s in namespace %s: %v", resource, namespace, err)
}
if _, err := framework.RunKubectl(namespace, ns, "delete", crd.Crd.Spec.Names.Plural, name); err != nil {
if _, err := framework.RunKubectl(namespace, "delete", crd.Crd.Spec.Names.Plural, name); err != nil {
return fmt.Errorf("failed to delete CR %s: %v", name, err)
}
return nil
@ -2205,7 +2178,7 @@ func validateController(c clientset.Interface, containerImage string, replicas i
ginkgo.By(fmt.Sprintf("waiting for all containers in %s pods to come up.", testname)) //testname should be selector
waitLoop:
for start := time.Now(); time.Since(start) < framework.PodStartTimeout; time.Sleep(5 * time.Second) {
getPodsOutput := framework.RunKubectlOrDie(ns, "get", "pods", "-o", "template", getPodsTemplate, "-l", testname, fmt.Sprintf("--namespace=%v", ns))
getPodsOutput := framework.RunKubectlOrDie(ns, "get", "pods", "-o", "template", getPodsTemplate, "-l", testname)
pods := strings.Fields(getPodsOutput)
if numPods := len(pods); numPods != replicas {
ginkgo.By(fmt.Sprintf("Replicas for %s: expected=%d actual=%d", testname, replicas, numPods))
@ -2213,13 +2186,13 @@ waitLoop:
}
var runningPods []string
for _, podID := range pods {
running := framework.RunKubectlOrDie(ns, "get", "pods", podID, "-o", "template", getContainerStateTemplate, fmt.Sprintf("--namespace=%v", ns))
running := framework.RunKubectlOrDie(ns, "get", "pods", podID, "-o", "template", getContainerStateTemplate)
if running != "true" {
framework.Logf("%s is created but not running", podID)
continue waitLoop
}
currentImage := framework.RunKubectlOrDie(ns, "get", "pods", podID, "-o", "template", getImageTemplate, fmt.Sprintf("--namespace=%v", ns))
currentImage := framework.RunKubectlOrDie(ns, "get", "pods", podID, "-o", "template", getImageTemplate)
currentImage = trimDockerRegistry(currentImage)
if currentImage != containerImage {
framework.Logf("%s is created but running wrong image; expected: %s, actual: %s", podID, containerImage, currentImage)

View File

@ -1077,5 +1077,5 @@ func podContainerExec(pod *v1.Pod, containerIndex int, command string) (string,
shell = "/bin/sh"
option = "-c"
}
return framework.RunKubectl(pod.Namespace, "exec", fmt.Sprintf("--namespace=%s", pod.Namespace), pod.Name, "--container", pod.Spec.Containers[containerIndex].Name, "--", shell, option, command)
return framework.RunKubectl(pod.Namespace, "exec", pod.Name, "--container", pod.Spec.Containers[containerIndex].Name, "--", shell, option, command)
}

View File

@ -358,7 +358,7 @@ func getVSpherePodSpecWithVolumePaths(volumePaths []string, keyValuelabel map[st
func verifyFilesExistOnVSphereVolume(namespace string, podName string, filePaths ...string) {
for _, filePath := range filePaths {
_, err := framework.RunKubectl(namespace, "exec", fmt.Sprintf("--namespace=%s", namespace), podName, "--", "/bin/ls", filePath)
_, err := framework.RunKubectl(namespace, "exec", podName, "--", "/bin/ls", filePath)
framework.ExpectNoError(err, fmt.Sprintf("failed to verify file: %q on the pod: %q", filePath, podName))
}
}
@ -815,7 +815,7 @@ func expectFilesToBeAccessible(namespace string, pods []*v1.Pod, filePaths []str
// writeContentToPodFile writes the given content to the specified file.
func writeContentToPodFile(namespace, podName, filePath, content string) error {
_, err := framework.RunKubectl(namespace, "exec", fmt.Sprintf("--namespace=%s", namespace), podName,
_, err := framework.RunKubectl(namespace, "exec", podName,
"--", "/bin/sh", "-c", fmt.Sprintf("echo '%s' > %s", content, filePath))
return err
}
@ -823,7 +823,7 @@ func writeContentToPodFile(namespace, podName, filePath, content string) error {
// expectFileContentToMatch checks if a given file contains the specified
// content, else fails.
func expectFileContentToMatch(namespace, podName, filePath, content string) {
_, err := framework.RunKubectl(namespace, "exec", fmt.Sprintf("--namespace=%s", namespace), podName,
_, err := framework.RunKubectl(namespace, "exec", podName,
"--", "/bin/sh", "-c", fmt.Sprintf("grep '%s' %s", content, filePath))
framework.ExpectNoError(err, fmt.Sprintf("failed to match content of file: %q on the pod: %q", filePath, podName))
}

View File

@ -65,7 +65,7 @@ func cassandraKubectlCreate(ns, file string) {
framework.Fail(err.Error())
}
input := string(data)
framework.RunKubectlOrDieInput(ns, input, "create", "-f", "-", fmt.Sprintf("--namespace=%s", ns))
framework.RunKubectlOrDieInput(ns, input, "create", "-f", "-")
}
// Setup creates a Cassandra StatefulSet and a PDB. It also brings up a tester

View File

@ -64,7 +64,7 @@ func kubectlCreate(ns, file string) {
framework.Fail(err.Error())
}
input := string(data)
framework.RunKubectlOrDieInput(ns, input, "create", "-f", "-", fmt.Sprintf("--namespace=%s", ns))
framework.RunKubectlOrDieInput(ns, input, "create", "-f", "-")
}
// Setup creates etcd statefulset and then verifies that the etcd is writable.

View File

@ -66,7 +66,7 @@ func mysqlKubectlCreate(ns, file string) {
framework.Fail(err.Error())
}
input := string(data)
framework.RunKubectlOrDieInput(ns, input, "create", "-f", "-", fmt.Sprintf("--namespace=%s", ns))
framework.RunKubectlOrDieInput(ns, input, "create", "-f", "-")
}
func (t *MySQLUpgradeTest) getServiceIP(f *framework.Framework, ns, svcName string) string {