Skip to content

Commit 6b31883

Browse files
author
allegroai
committed
Fix queue resolution when no queue is passed
1 parent e48b475 commit 6b31883

File tree

1 file changed

+59
-29
lines changed

1 file changed

+59
-29
lines changed

examples/k8s_glue_example.py

Lines changed: 59 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -13,65 +13,86 @@ def parse_args():
1313
group = parser.add_mutually_exclusive_group()
1414

1515
parser.add_argument(
16-
"--queue", type=str, help="Queues to pull tasks from. If multiple queues, use comma separated list, e.g. 'queue1,queue2'",
16+
"--queue",
17+
type=str,
18+
help="Queues to pull tasks from. If multiple queues, use comma separated list, e.g. 'queue1,queue2'",
1719
)
1820
group.add_argument(
19-
"--ports-mode", action='store_true', default=False,
21+
"--ports-mode",
22+
action="store_true",
23+
default=False,
2024
help="Ports-Mode will add a label to the pod which can be used as service, in order to expose ports"
2125
"Should not be used with max-pods"
2226
)
2327
parser.add_argument(
24-
"--num-of-services", type=int, default=20,
25-
help="Specify the number of k8s services to be used. Use only with ports-mode."
28+
"--num-of-services",
29+
type=int,
30+
default=20,
31+
help="Specify the number of k8s services to be used. Use only with ports-mode.",
2632
)
2733
parser.add_argument(
28-
"--base-port", type=int,
34+
"--base-port",
35+
type=int,
2936
help="Used in conjunction with ports-mode, specifies the base port exposed by the services. "
3037
"For pod #X, the port will be <base-port>+X. Note that pod number is calculated based on base-pod-num"
3138
"e.g. if base-port=20000 and base-pod-num=3, the port for the first pod will be 20003"
3239
)
3340
parser.add_argument(
34-
"--base-pod-num", type=int, default=1,
41+
"--base-pod-num",
42+
type=int,
43+
default=1,
3544
help="Used in conjunction with ports-mode and base-port, specifies the base pod number to be used by the "
3645
"service (default: %(default)s)"
3746
)
3847
parser.add_argument(
39-
"--gateway-address", type=str, default=None,
40-
help="Used in conjunction with ports-mode, specify the external address of the k8s ingress / ELB"
48+
"--gateway-address",
49+
type=str,
50+
default=None,
51+
help="Used in conjunction with ports-mode, specify the external address of the k8s ingress / ELB",
4152
)
4253
parser.add_argument(
43-
"--pod-clearml-conf", type=str,
44-
help="Configuration file to be used by the pod itself (if not provided, current configuration is used)"
54+
"--pod-clearml-conf",
55+
type=str,
56+
help="Configuration file to be used by the pod itself (if not provided, current configuration is used)",
4557
)
4658
parser.add_argument(
47-
"--overrides-yaml", type=str,
48-
help="YAML file containing pod overrides to be used when launching a new pod"
59+
"--overrides-yaml", type=str, help="YAML file containing pod overrides to be used when launching a new pod"
4960
)
5061
parser.add_argument(
51-
"--template-yaml", type=str,
62+
"--template-yaml",
63+
type=str,
5264
help="YAML file containing pod template. If provided pod will be scheduled with kubectl apply "
5365
"and overrides are ignored, otherwise it will be scheduled with kubectl run"
5466
)
5567
parser.add_argument(
56-
"--ssh-server-port", type=int, default=0,
57-
help="If non-zero, every pod will also start an SSH server on the selected port (default: zero, not active)"
68+
"--ssh-server-port",
69+
type=int,
70+
default=0,
71+
help="If non-zero, every pod will also start an SSH server on the selected port (default: zero, not active)",
5872
)
5973
parser.add_argument(
60-
"--namespace", type=str,
61-
help="Specify the namespace in which pods will be created (default: %(default)s)", default="clearml"
74+
"--namespace",
75+
type=str,
76+
help="Specify the namespace in which pods will be created (default: %(default)s)",
77+
default="clearml",
6278
)
6379
group.add_argument(
64-
"--max-pods", type=int,
80+
"--max-pods",
81+
type=int,
6582
help="Limit the maximum number of pods that this service can run at the same time."
6683
"Should not be used with ports-mode"
6784
)
6885
parser.add_argument(
69-
"--use-owner-token", action="store_true", default=False,
70-
help="Generate and use task owner token for the execution of each task"
86+
"--use-owner-token",
87+
action="store_true",
88+
default=False,
89+
help="Generate and use task owner token for the execution of each task",
7190
)
7291
parser.add_argument(
73-
"--create-queue", action="store_true", default=False,
74-
help="Create the queue if it does not exist (default: %(default)s)"
92+
"--create-queue",
93+
action="store_true",
94+
default=False,
95+
help="Create the queue if it does not exist (default: %(default)s)",
7596
)
7697
return parser.parse_args()
7798

@@ -81,23 +102,32 @@ def main():
81102

82103
user_props_cb = None
83104
if args.ports_mode and args.base_port:
105+
84106
def k8s_user_props_cb(pod_number=0):
85107
user_prop = {"k8s-pod-port": args.base_port + pod_number}
86108
if args.gateway_address:
87109
user_prop["k8s-gateway-address"] = args.gateway_address
88110
return user_prop
111+
89112
user_props_cb = k8s_user_props_cb
90113

91114
k8s = K8sIntegration(
92-
ports_mode=args.ports_mode, num_of_services=args.num_of_services, base_pod_num=args.base_pod_num,
93-
user_props_cb=user_props_cb, overrides_yaml=args.overrides_yaml, clearml_conf_file=args.pod_clearml_conf,
94-
template_yaml=args.template_yaml, extra_bash_init_script=K8sIntegration.get_ssh_server_bash(
95-
ssh_port_number=args.ssh_server_port) if args.ssh_server_port else None,
96-
namespace=args.namespace, max_pods_limit=args.max_pods or None,
115+
ports_mode=args.ports_mode,
116+
num_of_services=args.num_of_services,
117+
base_pod_num=args.base_pod_num,
118+
user_props_cb=user_props_cb,
119+
overrides_yaml=args.overrides_yaml,
120+
clearml_conf_file=args.pod_clearml_conf,
121+
template_yaml=args.template_yaml,
122+
extra_bash_init_script=K8sIntegration.get_ssh_server_bash(ssh_port_number=args.ssh_server_port)
123+
if args.ssh_server_port
124+
else None,
125+
namespace=args.namespace,
126+
max_pods_limit=args.max_pods or None,
97127
)
98-
args.queue = [q.strip() for q in args.queue.split(",") if q.strip()]
128+
queue = [q.strip() for q in args.queue.split(",") if q.strip()] if args.queue else None
99129

100-
k8s.k8s_daemon(args.queue, use_owner_token=args.use_owner_token, create_queue=args.create_queue)
130+
k8s.k8s_daemon(queue, use_owner_token=args.use_owner_token, create_queue=args.create_queue)
101131

102132

103133
if __name__ == "__main__":

0 commit comments

Comments
 (0)