Add container flag where is required to run the command
This commit is contained in:
parent
13093b6445
commit
8ffd1c98d2
2 changed files with 25 additions and 10 deletions
|
@ -31,11 +31,12 @@ func (f *Framework) ExecCommand(pod *v1.Pod, command string) (string, error) {
|
||||||
execErr bytes.Buffer
|
execErr bytes.Buffer
|
||||||
)
|
)
|
||||||
|
|
||||||
|
args := fmt.Sprintf("kubectl exec --namespace %v %v -- %v", pod.Namespace, pod.Name, command)
|
||||||
if len(pod.Spec.Containers) != 1 {
|
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 := exec.Command("/bin/bash", "-c", args)
|
||||||
cmd.Stdout = &execOut
|
cmd.Stdout = &execOut
|
||||||
cmd.Stderr = &execErr
|
cmd.Stderr = &execErr
|
||||||
|
|
|
@ -193,11 +193,15 @@ func (f *Framework) NginxLogs() (string, error) {
|
||||||
return "", fmt.Errorf("no nginx ingress controller pod is running")
|
return "", fmt.Errorf("no nginx ingress controller pod is running")
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(l.Items) != 1 {
|
for _, pod := range l.Items {
|
||||||
return "", fmt.Errorf("unexpected number of nginx ingress controller pod is running (%v)", len(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 {
|
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")
|
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
|
var cmd string
|
||||||
if name == "" {
|
if name == "" {
|
||||||
cmd = fmt.Sprintf("cat /etc/nginx/nginx.conf")
|
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)
|
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 {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue