I am using a python subprocess module to execute kubectl exec command, the command is returning an error. Still I am getting a returncode of 0 and pod status of CRASHLOOPBACK state which is not valid.
Need help on fetching the correct returncode on execution of command. Executed command:
cmd = f"kubectl -n {cls.NS} exec -i {mainpod} -- sh -c \"/opt/user/data/bin/mdm -waitDb -v && /opt/user/data/bin/mdm -applySchema /etc/data/db/tables/ -v\""
result = subprocess.run(shlex.split(cmd))
Log output:
INFO : Connection Obtained - database ready
ERROR: /etc/data/db/tables/ is not a valid directory
INFO : Closed DB connection.
CompletedProcess(args=['kubectl', '-n', 'test', 'exec', '-i', 'db-pod', '--', 'sh', '-c', '/opt/user/data/bin/mdm -waitDb -v && /opt/user/data/bin/mdm -applySchema /etc/data/db/tables/ -v'], returncode=0)
How can I fetch the correct returncode in the above case?
kubectldoes not relay back the status code fromsh -ccorrectly. See also github.com/kubernetes/kubernetes/issues/26424shlex.split()it immediately seems like extra work. Trycmd = ["kubectl", "-n", cls.NS, "exec", "-i", mainpod, "--", "sh", "-c", "/opt/user/data/bin/mdm -waitDb -v && /opt/user/data/bin/mdm -applySchema /etc/data/db/tables/ -v"](maybe addstr()if your variables are not strings).