forked from tilt-dev/tilt-extensions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tiltfile
40 lines (31 loc) · 1.53 KB
/
Tiltfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
def execute_in_pod(pod_name, command, container=None, quiet=True, echo_off=False):
# k8_discoveries = decode_json(local('tilt get kd -o json', quiet=quiet, echo_off=echo_off))
# available_names = []
# for item in k8_discoveries['items']:
# if item['kind'] == 'KubernetesDiscovery':
# available_names.append(item['metadata']['name'])
# if pod_name not in available_names:
# fail('%s not found. Available pods: %s' % (pod_name, available_names))
# pods_json = decode_json(local('tilt get kd %s -ojsonpath="{.status.pods}"' % pod_name, quiet=quiet, echo_off=echo_off))
# pods_names = []
# for pod in pods_json:
# pods_names.append(pod['name'])
# pod_to_execute = pods_names[0]
# if len(pods_names) > 1:
# # use print to avoid annoying with the yellow signaling in tilt
# print('WARNING: %s multiple found. Executing in %s' % (pods_names, pod_to_execute))
# containers = []
# for pod in pods_json:
# if pod['name'] == pod_to_execute:
# for container_ in pod['containers']:
# containers.append(container_['name'])
# break
# if container and container not in containers:
# fail('%s not found in: %s' % (container, containers))
# cmd = 'kubectl exec %s' % pod_to_execute
# if container:
# cmd += ' -c %s' % container
# cmd += ' -- %s' % command
# return cmd
cmd = 'kubectl exec "$(tilt get kd %s -ojsonpath=\'{.status.pods[0].name}\')" -- %s'
return cmd % (pod_name, command)