From 8ffd1c98d261ddb157af4a6be2717a0f58963f33 Mon Sep 17 00:00:00 2001 From: Manuel de Brito Fontes Date: Tue, 23 Jan 2018 17:09:41 -0300 Subject: [PATCH] Add container flag where is required to run the command --- test/e2e/framework/exec.go | 5 +++-- test/e2e/framework/framework.go | 30 ++++++++++++++++++++++-------- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/test/e2e/framework/exec.go b/test/e2e/framework/exec.go index aecc0170b..a3411eb73 100644 --- a/test/e2e/framework/exec.go +++ b/test/e2e/framework/exec.go @@ -31,11 +31,12 @@ func (f *Framework) ExecCommand(pod *v1.Pod, command string) (string, error) { execErr bytes.Buffer ) + args := fmt.Sprintf("kubectl exec --namespace %v %v -- %v", pod.Namespace, pod.Name, command) if len(pod.Spec.Containers) != 1 { - return "", fmt.Errorf("could not determine which container to use") + args = fmt.Sprintf("kubectl exec --namespace %v %v --container nginx-ingress-controller -- %v", pod.Namespace, pod.Name, command) } - args := fmt.Sprintf("kubectl exec -n %v %v -- %v", pod.Namespace, pod.Name, command) + log("DEBUG", "Executing command \"%v\"", args) cmd := exec.Command("/bin/bash", "-c", args) cmd.Stdout = &execOut cmd.Stderr = &execErr diff --git a/test/e2e/framework/framework.go b/test/e2e/framework/framework.go index 58cebbefb..4d1fa295d 100644 --- a/test/e2e/framework/framework.go +++ b/test/e2e/framework/framework.go @@ -193,11 +193,15 @@ func (f *Framework) NginxLogs() (string, error) { return "", fmt.Errorf("no nginx ingress controller pod is running") } - if len(l.Items) != 1 { - return "", fmt.Errorf("unexpected number of nginx ingress controller pod is running (%v)", len(l.Items)) + for _, pod := range l.Items { + if strings.HasPrefix(pod.GetName(), "nginx-ingress-controller") && + len(pod.Status.ContainerStatuses) > 0 && + pod.Status.ContainerStatuses[0].State.Running != nil { + return f.Logs(&pod) + } } - return f.Logs(&l.Items[0]) + return "", fmt.Errorf("no nginx ingress controller pod is running") } func (f *Framework) matchNginxConditions(name string, matcher func(cfg string) bool) wait.ConditionFunc { @@ -213,10 +217,6 @@ func (f *Framework) matchNginxConditions(name string, matcher func(cfg string) b return false, fmt.Errorf("no nginx ingress controller pod is running") } - if len(l.Items) != 1 { - return false, fmt.Errorf("unexpected number of nginx ingress controller pod is running (%v)", len(l.Items)) - } - var cmd string if name == "" { cmd = fmt.Sprintf("cat /etc/nginx/nginx.conf") @@ -224,7 +224,21 @@ func (f *Framework) matchNginxConditions(name string, matcher func(cfg string) b cmd = fmt.Sprintf("cat /etc/nginx/nginx.conf | awk '/## start server %v/,/## end server %v/'", name, name) } - o, err := f.ExecCommand(&l.Items[0], cmd) + var pod *v1.Pod + for _, p := range l.Items { + if strings.HasPrefix(p.GetName(), "nginx-ingress-controller") && + len(p.Status.ContainerStatuses) > 0 && + p.Status.ContainerStatuses[0].State.Running != nil { + pod = &p + break + } + } + + if pod == nil { + return false, fmt.Errorf("no nginx ingress controller pod is running") + } + + o, err := f.ExecCommand(pod, cmd) if err != nil { return false, err }