in troubleshooting/create_snapshot.py [0:0]
def get_kubectl_list(object_type, kubeconfig, timeout, namespace=None,
object_name='', jsonpath="{.items[*].metadata.name}"):
cmd = 'kubectl get {obj_type} {kubeconfig_arg} ' \
'--request-timeout {timeout} ' \
'-o jsonpath="{jsonpath}" {obj_name}'. \
format(kubeconfig_arg=kubeconfig,
jsonpath=jsonpath,
timeout=timeout,
obj_type=object_type, obj_name=object_name)
if namespace:
cmd = "{} -n {}".format(cmd, namespace)
backoff_timer = 1
backoff_count = 0
print("Executing: {}... ".format(cmd), end='')
while True:
if backoff_count > BACKOFF_LIMIT:
print('[ FAIL ]')
return
process = subprocess.run(cmd, shell=True,
capture_output=True)
if not process.returncode:
print("[ DONE ]")
obj_list = process.stdout.decode().strip().split(' ')
if '' in obj_list:
obj_list.remove('')
return obj_list
print("\nCommand failed, trying again in {}s. ' \
'Error output: {}".format(backoff_timer, process.stderr))
time.sleep(backoff_timer)
backoff_timer *= 2
backoff_count += 1