diff --git a/lib/galaxy/jobs/runners/kubernetes.py b/lib/galaxy/jobs/runners/kubernetes.py index 917bb5e54009..79a1b13a0c05 100644 --- a/lib/galaxy/jobs/runners/kubernetes.py +++ b/lib/galaxy/jobs/runners/kubernetes.py @@ -20,6 +20,7 @@ ) from galaxy.jobs.runners.util.pykube_util import ( deduplicate_entries, + DEFAULT_INGRESS_API_VERSION, DEFAULT_JOB_API_VERSION, delete_ingress, delete_job, @@ -110,6 +111,7 @@ def __init__(self, app, nworkers, **kwargs): k8s_interactivetools_ingress_annotations=dict(map=str), k8s_interactivetools_ingress_class=dict(map=str, default=None), k8s_interactivetools_tls_secret=dict(map=str, default=None), + k8s_ingress_api_version=dict(map=str, default=DEFAULT_INGRESS_API_VERSION), ) if "runner_param_specs" not in kwargs: @@ -250,6 +252,7 @@ def __configure_port_routing(self, ajs): service = Service(self._pykube_api, k8s_service_obj) service.create() ingress = Ingress(self._pykube_api, k8s_ingress_obj) + ingress.version = self.runner_params.get("k8s_ingress_api_version") ingress.create() def __get_overridable_params(self, job_wrapper, param_key): @@ -430,6 +433,54 @@ def __get_k8s_service_spec(self, ajs): } return k8s_spec_template + def __get_k8s_ingress_rules_spec(self, ajs, entry_points): + """This represents the template for the "rules" portion of the Ingress spec.""" + if "v1beta1" in self.runner_params.get("k8s_ingress_api_version"): + rules_spec = [ + { + "host": ep["domain"], + "http": { + "paths": [ + { + "backend": { + "serviceName": self.__get_k8s_job_name( + self.__produce_k8s_job_prefix(), ajs.job_wrapper + ), + "servicePort": int(ep["tool_port"]), + }, + "path": ep.get("entry_path", "/"), + "pathType": "Prefix", + } + ] + }, + } + for ep in entry_points + ] + else: + rules_spec = [ + { + "host": ep["domain"], + "http": { + "paths": [ + { + "backend": { + "service": { + "name": self.__get_k8s_job_name( + self.__produce_k8s_job_prefix(), ajs.job_wrapper + ), + "port": {"number": int(ep["tool_port"])}, + } + }, + "path": ep.get("entry_path", "/"), + "pathType": "ImplementationSpecific", + } + ] + }, + } + for ep in entry_points + ] + return rules_spec + def __get_k8s_ingress_spec(self, ajs): """The k8s spec template is nothing but a Ingress spec, except that it is nested and does not have an apiversion nor kind.""" @@ -467,30 +518,7 @@ def __get_k8s_ingress_spec(self, ajs): }, "annotations": {"app.galaxyproject.org/tool_id": ajs.job_wrapper.tool.id}, }, - "spec": { - "rules": [ - { - "host": ep["domain"], - "http": { - "paths": [ - { - "backend": { - "service": { - "name": self.__get_k8s_job_name( - self.__produce_k8s_job_prefix(), ajs.job_wrapper - ), - "port": {"number": int(ep["tool_port"])}, - } - }, - "path": ep.get("entry_path", "/"), - "pathType": "Prefix", - } - ] - }, - } - for ep in entry_points - ], - }, + "spec": {"rules": self.__get_k8s_ingress_rules_spec(ajs, entry_points)}, } default_ingress_class = self.runner_params.get("k8s_interactivetools_ingress_class") if default_ingress_class: