@@ -13,65 +13,86 @@ def parse_args():
13
13
group = parser .add_mutually_exclusive_group ()
14
14
15
15
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'" ,
17
19
)
18
20
group .add_argument (
19
- "--ports-mode" , action = 'store_true' , default = False ,
21
+ "--ports-mode" ,
22
+ action = "store_true" ,
23
+ default = False ,
20
24
help = "Ports-Mode will add a label to the pod which can be used as service, in order to expose ports"
21
25
"Should not be used with max-pods"
22
26
)
23
27
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." ,
26
32
)
27
33
parser .add_argument (
28
- "--base-port" , type = int ,
34
+ "--base-port" ,
35
+ type = int ,
29
36
help = "Used in conjunction with ports-mode, specifies the base port exposed by the services. "
30
37
"For pod #X, the port will be <base-port>+X. Note that pod number is calculated based on base-pod-num"
31
38
"e.g. if base-port=20000 and base-pod-num=3, the port for the first pod will be 20003"
32
39
)
33
40
parser .add_argument (
34
- "--base-pod-num" , type = int , default = 1 ,
41
+ "--base-pod-num" ,
42
+ type = int ,
43
+ default = 1 ,
35
44
help = "Used in conjunction with ports-mode and base-port, specifies the base pod number to be used by the "
36
45
"service (default: %(default)s)"
37
46
)
38
47
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" ,
41
52
)
42
53
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)" ,
45
57
)
46
58
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"
49
60
)
50
61
parser .add_argument (
51
- "--template-yaml" , type = str ,
62
+ "--template-yaml" ,
63
+ type = str ,
52
64
help = "YAML file containing pod template. If provided pod will be scheduled with kubectl apply "
53
65
"and overrides are ignored, otherwise it will be scheduled with kubectl run"
54
66
)
55
67
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)" ,
58
72
)
59
73
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" ,
62
78
)
63
79
group .add_argument (
64
- "--max-pods" , type = int ,
80
+ "--max-pods" ,
81
+ type = int ,
65
82
help = "Limit the maximum number of pods that this service can run at the same time."
66
83
"Should not be used with ports-mode"
67
84
)
68
85
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" ,
71
90
)
72
91
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)" ,
75
96
)
76
97
return parser .parse_args ()
77
98
@@ -81,23 +102,32 @@ def main():
81
102
82
103
user_props_cb = None
83
104
if args .ports_mode and args .base_port :
105
+
84
106
def k8s_user_props_cb (pod_number = 0 ):
85
107
user_prop = {"k8s-pod-port" : args .base_port + pod_number }
86
108
if args .gateway_address :
87
109
user_prop ["k8s-gateway-address" ] = args .gateway_address
88
110
return user_prop
111
+
89
112
user_props_cb = k8s_user_props_cb
90
113
91
114
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 ,
97
127
)
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
99
129
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 )
101
131
102
132
103
133
if __name__ == "__main__" :
0 commit comments