2020-10-20 11:17:30 +00:00
|
|
|
"""
|
|
|
|
This example assumes you have preconfigured services with selectors in the form of
|
|
|
|
"ai.allegro.agent.serial=pod-<number>" and a targetPort of 10022.
|
|
|
|
The K8sIntegration component will label each pod accordingly.
|
|
|
|
"""
|
|
|
|
from argparse import ArgumentParser
|
|
|
|
|
|
|
|
from trains_agent.glue.k8s import K8sIntegration
|
|
|
|
|
|
|
|
|
|
|
|
def parse_args():
|
|
|
|
parser = ArgumentParser()
|
|
|
|
parser.add_argument(
|
|
|
|
"--queue", type=str, help="Queue to pull tasks from"
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
"--ports-mode", action='store_true', default=False,
|
|
|
|
help="Ports-mode will add a label to the pod which can be used in services in order to expose ports"
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
"--num-of-services", type=int, default=20,
|
|
|
|
help="Specify the number of k8s services to be used. Use only with ports-mode."
|
|
|
|
)
|
2020-10-20 20:48:02 +00:00
|
|
|
parser.add_argument(
|
|
|
|
"--base-port", type=int,
|
|
|
|
help="If using ports-mode, specifies the base port exposed by the services."
|
|
|
|
"For pod #X, the port will be <base-port>+X"
|
|
|
|
)
|
2020-10-21 16:04:38 +00:00
|
|
|
parser.add_argument(
|
|
|
|
"--pod-trains-conf", type=str,
|
|
|
|
help="Configuration file to be used by the pod itself (if not provided, current configuration is used)"
|
|
|
|
)
|
2020-10-22 15:09:56 +00:00
|
|
|
parser.add_argument(
|
|
|
|
"--overrides-yaml", type=str,
|
|
|
|
help="YAML file containing pod overrides to be used when launching a new pod"
|
|
|
|
)
|
2020-10-22 22:28:22 +00:00
|
|
|
parser.add_argument(
|
|
|
|
"--template-yaml", type=str,
|
|
|
|
help="YAML file containing pod template. If provided pod will be scheduled with kubectl apply "
|
|
|
|
"and overrides are ignored, otherwise it will be scheduled with kubectl run"
|
|
|
|
)
|
2020-10-20 11:17:30 +00:00
|
|
|
return parser.parse_args()
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
args = parse_args()
|
2020-10-20 20:48:02 +00:00
|
|
|
|
|
|
|
user_props_cb = None
|
|
|
|
if args.ports_mode and args.base_port:
|
|
|
|
def user_props_cb(pod_number):
|
|
|
|
return {"k8s-pod-port": args.base_port + pod_number}
|
|
|
|
|
2020-10-21 16:04:38 +00:00
|
|
|
k8s = K8sIntegration(
|
|
|
|
ports_mode=args.ports_mode, num_of_services=args.num_of_services, user_props_cb=user_props_cb,
|
2020-11-11 14:31:25 +00:00
|
|
|
overrides_yaml=args.overrides_yaml, trains_conf_file=args.pod_trains_conf, template_yaml=args.template_yaml,
|
|
|
|
extra_bash_init_script=K8sIntegration.get_ssh_server_bash(ssh_port_number=10022)
|
|
|
|
)
|
2020-10-20 11:17:30 +00:00
|
|
|
k8s.k8s_daemon(args.queue)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|