Home > Software engineering >  is there a way to run a command in a pod when you exec into it using robot framework?
is there a way to run a command in a pod when you exec into it using robot framework?

Time:10-26

I am able to exec into a pod , and in that pod i will also like to run a stolonctl command at the same time into the pod i just exec into. Here is an example of what i will like to achieve. I tried using the first command first and then tried to see if i write the second command if it will work based on the first but it didnt.

Special execution command ${cluster_name} kubectl exec -it pod -c container ${cluster_name} -- /bin/bash then in the bash i want to also run this stolonctl --cluster-name [cluster_name] --store-backend [store_backend] --store-endpoints kubernetes status i want to be able to achieve something like this in robot. be able to do something similar to ls in the pod

controlplane $ kubectl run --image=nginx web --restart=Never
pod/web created
controlplane $ kubectl get po
NAME   READY   STATUS              RESTARTS   AGE
web    0/1     ContainerCreating   0          4s
controlplane $ kubectl exec -it web -- /bin/bash
root@web:/# ls
bin   dev                  docker-entrypoint.sh  home  lib64  mnt  proc  run   srv  tmp  var
boot  docker-entrypoint.d  etc                   lib   media  opt  root  sbin  sys  usr

CodePudding user response:

You don't need to open a bash in the container first. You can run the stolonctl command directly:

$ kubectl exec -it pod -c container ${cluster_name} -- stolonctl --cluster-name [cluster_name] --store-backend [store_backend] --store-endpoints kubernetes status

CodePudding user response:

You may execute your command without starting a shell, using something like this:

kubectl exec  $pod -c $container -- \
    stolonctl --custer-name $clustername and-any-other-options

Or, if for some reason, you need your shell (eg: evaluating env vars in your command line, if you need pipes, &&, ||, ...), you could warp this in /bin/sh, eg:

kubectl exec  $pod -c $container -- /bin/sh -c \
    "stolonctl --custer-name $clustername and-any-other-options"

Not being familiar with that robotframework, I'm not sure if that helps you ... I guess you would have to use the Process library

  • Related