From b5237095628be3a02a35da047b1021e629f4e4ba Mon Sep 17 00:00:00 2001 From: Caio Almeida Date: Wed, 8 Dec 2021 15:21:55 -0300 Subject: [PATCH] feat(ui): extra envs Resolves #40 --- templates/deployment.yaml | 9 ++++++--- test/linter/test.sh | 16 ++++++++++++++++ test/unit/deployment.yaml | 22 ++++++++++++++++++++++ values.schema.json | 5 +++-- values.yaml | 15 +++++++++++++++ 5 files changed, 62 insertions(+), 5 deletions(-) create mode 100644 test/unit/deployment.yaml diff --git a/templates/deployment.yaml b/templates/deployment.yaml index 170552e..b837498 100644 --- a/templates/deployment.yaml +++ b/templates/deployment.yaml @@ -77,10 +77,13 @@ spec: {{- range .Values.ui.extraArgs }} - {{ . | quote }} {{- end }} - {{ if .Values.ui.consumerProperties }} env: - - name: CONSUMER_PROPERTIES_FILE - value: /conf/consumer.properties + {{- if .Values.ui.consumerProperties }} + - name: CONSUMER_PROPERTIES_FILE + value: /conf/consumer.properties + {{- end }} + {{- with .Values.ui.extraEnv -}} + {{ toYaml . | nindent 10 }} {{- end }} readinessProbe: httpGet: diff --git a/test/linter/test.sh b/test/linter/test.sh index 5c97458..bf132e3 100755 --- a/test/linter/test.sh +++ b/test/linter/test.sh @@ -55,3 +55,19 @@ if [ $? -eq 0 ]; then exit 1 fi +helm lint . --strict --set 'ui.extraEnv=false' +if [ $? -eq 0 ]; then + exit 1 +fi + +helm lint . --strict --set 'ui.extraEnv={1,2,3}' +if [ $? -eq 0 ]; then + exit 1 +fi + +helm lint . --strict --set 'ui.extraEnv[0].name=qwe' --set 'ui.extraEnv[0].value=asd' +if [ $? -ne 0 ]; then + exit -1 +fi + + diff --git a/test/unit/deployment.yaml b/test/unit/deployment.yaml new file mode 100644 index 0000000..cb34c03 --- /dev/null +++ b/test/unit/deployment.yaml @@ -0,0 +1,22 @@ +suite: deployment +templates: + - deployment.yaml +tests: + - it: should emit empty env by default + asserts: + - isEmpty: + path: spec.template.spec.containers[1].env + - it: should populate env when passed + set: + ui: + extraEnv: + - name: myvar + value: myvalue + asserts: + - contains: + path: spec.template.spec.containers[1].env + content: + name: myvar + value: myvalue + count: 1 + any: false diff --git a/values.schema.json b/values.schema.json index 7370c69..3e55aa3 100644 --- a/values.schema.json +++ b/values.schema.json @@ -153,10 +153,11 @@ "type": "object", "title": "ui container k8s settings", "additionalProperties": false, "properties": { "port": {"type": "integer", "default": 9000}, - "extraArgs": { "type": "array", "title": "extra cmd line arguments", "items": { "type": "string" }, "default": [] }, + "extraArgs": { "type": "array", "title": "extra cmd line arguments", "items": {"type": "string"}, "default": [] }, "resources": { "$ref": "#/definitions/resources" }, "consumerProperties": { "type": "object", "title": "provide key value base pairs for consumer properties according to java docs", "default": {} }, - "consumerPropertiesSsl": { "$ref": "#/definitions/consumerSsl" } + "consumerPropertiesSsl": { "$ref": "#/definitions/consumerSsl" }, + "extraEnv": { "type": "array", "title": "optional environment variables", "items": {"type": "object"}, "default": [] } } }, "zk": { diff --git a/values.yaml b/values.yaml index 22c30e5..94b0235 100644 --- a/values.yaml +++ b/values.yaml @@ -93,6 +93,21 @@ ui: # password: test123 # value: + # Additional environment variables (declared as k8s style) + # ref: https://kubernetes.io/docs/tasks/inject-data-application/define-environment-variable-container/ + extraEnv: [] + # - name: GREETING + # value: "Warm greetings to" + # - name: SECRET_USERNAME + # valueFrom: + # secretKeyRef: + # name: mysecret + # key: username + # - name: SPECIAL_LEVEL_KEY + # valueFrom: + # configMapKeyRef: + # name: special-config + # key: SPECIAL_LEVEL # various settings for Zookeeper container zk: