mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-12-18 02:50:30 +00:00
e2e: add execCommandInDaemonsetPod()
execCommandInDaemonsetPod() executes commands inside given container of a daemonset pod on a particular node. Signed-off-by: Rakshith R <rar@redhat.com>
This commit is contained in:
parent
915437b314
commit
e2dc8439e4
37
e2e/pod.go
37
e2e/pod.go
@ -123,6 +123,43 @@ func getCommandInPodOpts(f *framework.Framework, c, ns string, opt *metav1.ListO
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// execCommandInDaemonsetPod executes commands inside given container of a daemonset pod on a particular node.
|
||||||
|
func execCommandInDaemonsetPod(f *framework.Framework, c, daemonsetName, nodeName, containerName, ns string) (string, string, error) {
|
||||||
|
selector, err := getDaemonSetLabelSelector(f, ns, daemonsetName)
|
||||||
|
if err != nil {
|
||||||
|
return "", "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
opt := &metav1.ListOptions{
|
||||||
|
LabelSelector: selector,
|
||||||
|
}
|
||||||
|
pods, err := listPods(f, ns, opt)
|
||||||
|
if err != nil {
|
||||||
|
return "", "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
podName := ""
|
||||||
|
for i := range pods {
|
||||||
|
if pods[i].Spec.NodeName == nodeName {
|
||||||
|
podName = pods[i].Name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if podName == "" {
|
||||||
|
return "", "", fmt.Errorf("%s daemonset pod on node %s in namespace %s not found", daemonsetName, nodeName, ns)
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd := []string{"/bin/sh", "-c", c}
|
||||||
|
podOpt := framework.ExecOptions{
|
||||||
|
Command: cmd,
|
||||||
|
Namespace: ns,
|
||||||
|
PodName: podName,
|
||||||
|
ContainerName: containerName,
|
||||||
|
CaptureStdout: true,
|
||||||
|
CaptureStderr: true,
|
||||||
|
}
|
||||||
|
return f.ExecWithOptions(podOpt)
|
||||||
|
}
|
||||||
|
|
||||||
// listPods returns slice of pods matching given ListOptions and namespace.
|
// listPods returns slice of pods matching given ListOptions and namespace.
|
||||||
func listPods(f *framework.Framework, ns string, opt *metav1.ListOptions) ([]v1.Pod, error) {
|
func listPods(f *framework.Framework, ns string, opt *metav1.ListOptions) ([]v1.Pod, error) {
|
||||||
podList, err := f.PodClientNS(ns).List(context.TODO(), *opt)
|
podList, err := f.PodClientNS(ns).List(context.TODO(), *opt)
|
||||||
|
Loading…
Reference in New Issue
Block a user