From 27dfe76156f672883adf77ff8a055ef8a064613c Mon Sep 17 00:00:00 2001 From: Trey Dockendorf Date: Fri, 28 May 2021 09:33:38 -0400 Subject: [PATCH] Expose pod port as environment variable --- lib/ood_core/job/adapters/kubernetes/templates/pod.yml.erb | 4 ++++ spec/fixtures/output/k8s/pod_yml_from_all_configs.yml | 2 ++ spec/fixtures/output/k8s/pod_yml_from_defaults.yml | 2 ++ spec/fixtures/output/k8s/pod_yml_no_configmaps.yml | 2 ++ spec/fixtures/output/k8s/pod_yml_no_init_container.yml | 2 ++ spec/fixtures/output/k8s/pod_yml_no_mounts.yml | 2 ++ spec/fixtures/output/k8s/pod_yml_no_mounts_no_configmaps.yml | 2 ++ spec/fixtures/output/k8s/pod_yml_subpath_configmap.yml | 2 ++ 8 files changed, 18 insertions(+) diff --git a/lib/ood_core/job/adapters/kubernetes/templates/pod.yml.erb b/lib/ood_core/job/adapters/kubernetes/templates/pod.yml.erb index 33d31faba..4f4ebc89d 100644 --- a/lib/ood_core/job/adapters/kubernetes/templates/pod.yml.erb +++ b/lib/ood_core/job/adapters/kubernetes/templates/pod.yml.erb @@ -52,6 +52,10 @@ spec: valueFrom: fieldRef: fieldPath: metadata.namespace + <%- unless spec.container.port.nil? -%> + - name: POD_PORT + value: "<%= spec.container.port %>" + <%- end -%> <%- spec.container.env.each_pair do |name, value| -%> - name: <%= name %> value: "<%= value %>" diff --git a/spec/fixtures/output/k8s/pod_yml_from_all_configs.yml b/spec/fixtures/output/k8s/pod_yml_from_all_configs.yml index 2ae4b5ad1..ca703ffe4 100644 --- a/spec/fixtures/output/k8s/pod_yml_from_all_configs.yml +++ b/spec/fixtures/output/k8s/pod_yml_from_all_configs.yml @@ -36,6 +36,8 @@ spec: valueFrom: fieldRef: fieldPath: metadata.namespace + - name: POD_PORT + value: "8080" - name: USER value: "testuser" - name: UID diff --git a/spec/fixtures/output/k8s/pod_yml_from_defaults.yml b/spec/fixtures/output/k8s/pod_yml_from_defaults.yml index 834a45930..932bd67a0 100644 --- a/spec/fixtures/output/k8s/pod_yml_from_defaults.yml +++ b/spec/fixtures/output/k8s/pod_yml_from_defaults.yml @@ -34,6 +34,8 @@ spec: valueFrom: fieldRef: fieldPath: metadata.namespace + - name: POD_PORT + value: "8080" - name: USER value: "testuser" - name: UID diff --git a/spec/fixtures/output/k8s/pod_yml_no_configmaps.yml b/spec/fixtures/output/k8s/pod_yml_no_configmaps.yml index f4f97f3b9..660cddb39 100644 --- a/spec/fixtures/output/k8s/pod_yml_no_configmaps.yml +++ b/spec/fixtures/output/k8s/pod_yml_no_configmaps.yml @@ -34,6 +34,8 @@ spec: valueFrom: fieldRef: fieldPath: metadata.namespace + - name: POD_PORT + value: "8080" - name: USER value: "testuser" - name: UID diff --git a/spec/fixtures/output/k8s/pod_yml_no_init_container.yml b/spec/fixtures/output/k8s/pod_yml_no_init_container.yml index b2fccad55..e8d0f3b06 100644 --- a/spec/fixtures/output/k8s/pod_yml_no_init_container.yml +++ b/spec/fixtures/output/k8s/pod_yml_no_init_container.yml @@ -34,6 +34,8 @@ spec: valueFrom: fieldRef: fieldPath: metadata.namespace + - name: POD_PORT + value: "8080" - name: USER value: "testuser" - name: UID diff --git a/spec/fixtures/output/k8s/pod_yml_no_mounts.yml b/spec/fixtures/output/k8s/pod_yml_no_mounts.yml index 7a56d51a2..0c2980ac9 100644 --- a/spec/fixtures/output/k8s/pod_yml_no_mounts.yml +++ b/spec/fixtures/output/k8s/pod_yml_no_mounts.yml @@ -34,6 +34,8 @@ spec: valueFrom: fieldRef: fieldPath: metadata.namespace + - name: POD_PORT + value: "8080" - name: USER value: "testuser" - name: UID diff --git a/spec/fixtures/output/k8s/pod_yml_no_mounts_no_configmaps.yml b/spec/fixtures/output/k8s/pod_yml_no_mounts_no_configmaps.yml index e02159634..0c82039a2 100644 --- a/spec/fixtures/output/k8s/pod_yml_no_mounts_no_configmaps.yml +++ b/spec/fixtures/output/k8s/pod_yml_no_mounts_no_configmaps.yml @@ -34,6 +34,8 @@ spec: valueFrom: fieldRef: fieldPath: metadata.namespace + - name: POD_PORT + value: "8080" - name: USER value: "testuser" - name: UID diff --git a/spec/fixtures/output/k8s/pod_yml_subpath_configmap.yml b/spec/fixtures/output/k8s/pod_yml_subpath_configmap.yml index b779622b6..16626d9a5 100644 --- a/spec/fixtures/output/k8s/pod_yml_subpath_configmap.yml +++ b/spec/fixtures/output/k8s/pod_yml_subpath_configmap.yml @@ -34,6 +34,8 @@ spec: valueFrom: fieldRef: fieldPath: metadata.namespace + - name: POD_PORT + value: "8080" - name: USER value: "testuser" - name: UID