STX command with key-add options - TTY error in automated environments

The issue was:

- The "-t" flag from kubectl commands, which was forcing TTY allocation even in automated/scripted environments. This flag is unnecessary in such contexts and causes the error when no interactive terminal is available.

Closes-Bug: 2118938

Test Plan: Running STX control keys-add in a automated proccess(non-iterative) without errors

PASS: Running in an interactive environment works fine
PASS: Running in an automated environment now works

Change-Id: Iec8a15739f3d272c451ab6181d852df48ee2b387
Signed-off-by: Ladislau Felisbino <Ladislau.Felisbino@windriver.com>
This commit is contained in:
Ladislau Felisbino
2025-07-10 17:59:58 -03:00
committed by Ladislau
parent fbf2c3a312
commit b9c8a03781
2 changed files with 11 additions and 7 deletions

View File

@@ -212,7 +212,9 @@ class KubeHelper(object):
def generatePrefixCommand(self, podname, command, enableuser, interactive=False):
'''Generate the command executed in the host'''
prefix_exec_cmd = self.config.kubectl() + ' exec -ti '
tty_flag = ' -ti ' if os.isatty(1) else ' -i '
prefix_exec_cmd = self.config.kubectl() + ' exec ' + tty_flag
builder_exec_cmd = prefix_exec_cmd + podname
prefix_bash_cmd = ' -- bash -l -c '
prefix_bash_with_user_cmd = ' -- bash -l -c \'sudo -u ${MYUNAME} \

View File

@@ -31,6 +31,8 @@ from stx import utils # pylint: disable=E0611
helmchartdir = 'stx/stx-build-tools-chart/stx-builder'
tty_flag = ' -ti ' if os.isatty(1) else ' -i '
class HandleControlTask(object):
'''Handle the task for the control sub-command'''
@@ -57,7 +59,7 @@ class HandleControlTask(object):
while count:
podname = self.k8s.get_pod_name(pulpname)
if podname:
cmd = self.config.kubectl() + ' exec -ti '
cmd = self.config.kubectl() + ' exec ' + tty_flag
cmd = cmd + podname + remote_cmd
subprocess.call(cmd, shell=True)
count = 0
@@ -393,11 +395,11 @@ stx-pkgbuilder/configmap/')
pod_name = self.k8s.get_pod_name(buildername)
if pod_name:
# Prepare and run commands:
# kubectl exec -ti [pod_name_builder] -- mkdir /home/[user_name]/.ssh
# kubectl exec -ti [pod_name_builder] -- mkdir /root/.ssh
# kubectl exec -i(or -it if is a TTY) [pod_name_builder] -- mkdir /home/[user_name]/.ssh
# kubectl exec -i(or -it if is a TTY) [pod_name_builder] -- mkdir /root/.ssh
# kubectl cp [key] [pod_name_builder]:/home/[user_name]/.ssh
# kubectl cp [key] [pod_name_builder]:/root/.ssh
main_cmd = ' exec -ti '
main_cmd = ' exec ' + tty_flag
remote_cmd = ' -- mkdir /home/' + username + '/.ssh'
self.run_pod_cmd(pod_name, main_cmd, remote_cmd)
remote_cmd = ' -- mkdir /root/.ssh'
@@ -415,9 +417,9 @@ no builder container is available!')
pod_name = self.k8s.get_pod_name(latname)
if pod_name:
# Prepare and run commands:
# kubectl exec -ti [pod_name_lat] -- mkdir /root/.ssh
# kubectl exec -i(or -it if is a TTY) [pod_name_lat] -- mkdir /root/.ssh
# kubectl cp [key] [pod_name_lat]:/root/.ssh
main_cmd = ' exec -ti '
main_cmd = ' exec ' + tty_flag
remote_cmd = ' -- mkdir /root/.ssh'
self.run_pod_cmd(pod_name, main_cmd, remote_cmd)
main_cmd = ' cp ' + args.key + ' '