From 3df4bc0ad1971ab9fe71130012b0a4cecc279194 Mon Sep 17 00:00:00 2001 From: "James E. Blair" Date: Mon, 12 Apr 2021 16:38:38 -0700 Subject: [PATCH] Pass through environment to scheduler, web and launcher These components may need to have http_proxy set, so let the user pass env variables. Change-Id: I6191dd9c8ded70c715f13179c3d904e8f65e144d --- doc/source/index.rst | 7 +++++++ zuul_operator/templates/nodepool-launcher.yaml | 4 +--- zuul_operator/templates/zuul.yaml | 4 +++- zuul_operator/zuul.py | 14 ++++++++++++++ 4 files changed, 25 insertions(+), 4 deletions(-) diff --git a/doc/source/index.rst b/doc/source/index.rst index 76e2f6a..7e57bf9 100644 --- a/doc/source/index.rst +++ b/doc/source/index.rst @@ -355,6 +355,13 @@ verbatim): * ``tls.crt`` * ``tls.key`` + .. attr:: env + + A list of environment variables. This will be passed through + to the Pod specifications for the scheduler, launcher, and + web. This may be used to set http_proxy environment + variables. + .. attr:: scheduler .. attr:: config diff --git a/zuul_operator/templates/nodepool-launcher.yaml b/zuul_operator/templates/nodepool-launcher.yaml index 6dfa730..7b5ae8d 100644 --- a/zuul_operator/templates/nodepool-launcher.yaml +++ b/zuul_operator/templates/nodepool-launcher.yaml @@ -28,9 +28,7 @@ spec: containers: - name: launcher image: {{ spec.imagePrefix }}/nodepool-launcher:{{ spec.nodepoolImageVersion }} - env: - - name: KUBECONFIG - value: /etc/kubernetes/kube.config + env: {{ spec.env | zuul_to_json }} volumeMounts: - name: nodepool-config mountPath: /etc/nodepool diff --git a/zuul_operator/templates/zuul.yaml b/zuul_operator/templates/zuul.yaml index 47a8ee5..57c2e8c 100644 --- a/zuul_operator/templates/zuul.yaml +++ b/zuul_operator/templates/zuul.yaml @@ -166,6 +166,7 @@ spec: readOnly: true {%- endif %} {%- endfor %} + env: {{ spec.env | zuul_to_json }} volumes: - name: zuul-config secret: @@ -232,6 +233,7 @@ spec: - name: zookeeper-client-tls mountPath: /tls/client readOnly: true + env: {{ spec.env | zuul_to_json }} volumes: - name: zuul-config secret: @@ -365,7 +367,7 @@ spec: - name: nodepool-private-key secret: secretName: {{ executor_ssh_secret }} - {%- endif %} + {%- endif %} {%- for volume in spec.get('jobVolumes', []) %} - {{ volume.volume | zuul_to_json }} {%- endfor %} diff --git a/zuul_operator/zuul.py b/zuul_operator/zuul.py index 495e568..5ebcb99 100644 --- a/zuul_operator/zuul.py +++ b/zuul_operator/zuul.py @@ -86,6 +86,20 @@ class Zuul: self.spec.setdefault('zuulRegistryImageVersion', 'latest') self.spec.setdefault('nodepoolImageVersion', 'latest') + default_env = { + 'KUBECONFIG': '/etc/kubernetes/kube.config' + } + env = self.spec.setdefault('env', []) + for default_key, default_value in default_env.items(): + # Don't allow the user to override our defaults + for item in env: + if item.get('name') == default_key: + env.remove(item) + break + # Set our defaults + env.append({'name': default_key, + 'value': default_value}) + self.cert_manager = certmanager.CertManager( self.api, self.namespace, self.log) self.installing_cert_manager = False