From b00fb0663f5e3cc8fc6c8dd19e633a44052242bd Mon Sep 17 00:00:00 2001 From: Stavros kois Date: Thu, 22 Dec 2022 20:12:33 +0200 Subject: [PATCH] small fixes --- .../container_in_deployment/env_test.yaml | 24 ++-- library/common-test/values.yaml | 103 +++++++++++------- .../templates/lib/container/_env_from.tpl | 4 +- .../lib/container/env/_checkDuplicates.tpl | 5 +- .../templates/spawner/_configmapAndSecret.tpl | 2 +- 5 files changed, 79 insertions(+), 59 deletions(-) diff --git a/library/common-test/tests/container_in_deployment/env_test.yaml b/library/common-test/tests/container_in_deployment/env_test.yaml index db4e98054e..ed6f5bfdd3 100644 --- a/library/common-test/tests/container_in_deployment/env_test.yaml +++ b/library/common-test/tests/container_in_deployment/env_test.yaml @@ -130,7 +130,7 @@ tests: name: RELEASE-NAME-common-test-somename asserts: - failedTemplate: - errorMessage: Environment Variable (ENVVAR) on container (RELEASE-NAME-common-test) is set more than once. [to (something) on (env)] and [to (ABC) on (Configmap-RELEASE-NAME-common-test-somename)] + errorMessage: Environment Variable (ENVVAR) on container (RELEASE-NAME-common-test) is set more than once. [to (something) on (env)] and [to (ABC) on (configmap-RELEASE-NAME-common-test-somename)] - it: should fail with env trying to override secret set: @@ -147,7 +147,7 @@ tests: name: RELEASE-NAME-common-test-somename asserts: - failedTemplate: - errorMessage: Environment Variable (ENVVAR) on container (RELEASE-NAME-common-test) is set more than once. [to (something) on (env)] and [to (ABC) on (Secret-RELEASE-NAME-common-test-somename)] + errorMessage: Environment Variable (ENVVAR) on container (RELEASE-NAME-common-test) is set more than once. [to (something) on (env)] and [to (ABC) on (secret-RELEASE-NAME-common-test-somename)] - it: should fail with env trying to override envList set: @@ -196,7 +196,7 @@ tests: name: RELEASE-NAME-common-test-somename asserts: - failedTemplate: - errorMessage: Environment Variable (POSTGRES_HOST) on container (RELEASE-NAME-common-test) is set more than once. [to (something) on (envList)] and [to (something) on (Configmap-RELEASE-NAME-common-test-somename)] + errorMessage: Environment Variable (POSTGRES_HOST) on container (RELEASE-NAME-common-test) is set more than once. [to (something) on (envList)] and [to (something) on (configmap-RELEASE-NAME-common-test-somename)] - it: should fail with envList trying to override secret set: @@ -214,7 +214,7 @@ tests: name: RELEASE-NAME-common-test-somename asserts: - failedTemplate: - errorMessage: Environment Variable (POSTGRES_HOST) on container (RELEASE-NAME-common-test) is set more than once. [to (something) on (envList)] and [to (something) on (Secret-RELEASE-NAME-common-test-somename)] + errorMessage: Environment Variable (POSTGRES_HOST) on container (RELEASE-NAME-common-test) is set more than once. [to (something) on (envList)] and [to (something) on (secret-RELEASE-NAME-common-test-somename)] - it: should fail with configmap trying to override fixedEnv set: @@ -229,7 +229,7 @@ tests: name: RELEASE-NAME-common-test-somename asserts: - failedTemplate: - errorMessage: Environment Variable (TZ) on container (RELEASE-NAME-common-test) is set more than once. [to (UTC) on (fixedEnv)] and [to (something) on (Configmap-RELEASE-NAME-common-test-somename)] + errorMessage: Environment Variable (TZ) on container (RELEASE-NAME-common-test) is set more than once. [to (UTC) on (fixedEnv)] and [to (something) on (configmap-RELEASE-NAME-common-test-somename)] - it: should fail with configmap trying to override env set: @@ -246,7 +246,7 @@ tests: name: RELEASE-NAME-common-test-somename asserts: - failedTemplate: - errorMessage: Environment Variable (POSTGRES_HOST) on container (RELEASE-NAME-common-test) is set more than once. [to (postgres.svc.cluster.local) on (env)] and [to (something) on (Configmap-RELEASE-NAME-common-test-somename)] + errorMessage: Environment Variable (POSTGRES_HOST) on container (RELEASE-NAME-common-test) is set more than once. [to (postgres.svc.cluster.local) on (env)] and [to (something) on (configmap-RELEASE-NAME-common-test-somename)] - it: should fail with configmap trying to override envList set: @@ -264,7 +264,7 @@ tests: name: RELEASE-NAME-common-test-somename asserts: - failedTemplate: - errorMessage: Environment Variable (POSTGRES_HOST) on container (RELEASE-NAME-common-test) is set more than once. [to (postgres.svc.cluster.local) on (envList)] and [to (something) on (Configmap-RELEASE-NAME-common-test-somename)] + errorMessage: Environment Variable (POSTGRES_HOST) on container (RELEASE-NAME-common-test) is set more than once. [to (postgres.svc.cluster.local) on (envList)] and [to (something) on (configmap-RELEASE-NAME-common-test-somename)] - it: should fail with configmap trying to override secret set: @@ -287,7 +287,7 @@ tests: name: RELEASE-NAME-common-test-somename asserts: - failedTemplate: - errorMessage: Environment Variable (POSTGRES_HOST) on container (RELEASE-NAME-common-test) is set more than once. [to (something) on (Configmap-RELEASE-NAME-common-test-somename)] and [to (something123) on (Secret-RELEASE-NAME-common-test-somename)] + errorMessage: Environment Variable (POSTGRES_HOST) on container (RELEASE-NAME-common-test) is set more than once. [to (something) on (configmap-RELEASE-NAME-common-test-somename)] and [to (something123) on (secret-RELEASE-NAME-common-test-somename)] - it: should fail with secret trying to override fixedEnv set: @@ -302,7 +302,7 @@ tests: name: RELEASE-NAME-common-test-somename asserts: - failedTemplate: - errorMessage: Environment Variable (TZ) on container (RELEASE-NAME-common-test) is set more than once. [to (UTC) on (fixedEnv)] and [to (something) on (Secret-RELEASE-NAME-common-test-somename)] + errorMessage: Environment Variable (TZ) on container (RELEASE-NAME-common-test) is set more than once. [to (UTC) on (fixedEnv)] and [to (something) on (secret-RELEASE-NAME-common-test-somename)] - it: should fail with secret trying to override env set: @@ -319,7 +319,7 @@ tests: name: RELEASE-NAME-common-test-somename asserts: - failedTemplate: - errorMessage: Environment Variable (POSTGRES_HOST) on container (RELEASE-NAME-common-test) is set more than once. [to (postgres.svc.cluster.local) on (env)] and [to (something) on (Secret-RELEASE-NAME-common-test-somename)] + errorMessage: Environment Variable (POSTGRES_HOST) on container (RELEASE-NAME-common-test) is set more than once. [to (postgres.svc.cluster.local) on (env)] and [to (something) on (secret-RELEASE-NAME-common-test-somename)] - it: should fail with secret trying to override envList set: @@ -337,7 +337,7 @@ tests: name: RELEASE-NAME-common-test-somename asserts: - failedTemplate: - errorMessage: Environment Variable (POSTGRES_HOST) on container (RELEASE-NAME-common-test) is set more than once. [to (postgres.svc.cluster.local) on (envList)] and [to (something) on (Secret-RELEASE-NAME-common-test-somename)] + errorMessage: Environment Variable (POSTGRES_HOST) on container (RELEASE-NAME-common-test) is set more than once. [to (postgres.svc.cluster.local) on (envList)] and [to (something) on (secret-RELEASE-NAME-common-test-somename)] - it: should fail with secret trying to override configmap set: @@ -360,7 +360,7 @@ tests: name: RELEASE-NAME-common-test-somename asserts: - failedTemplate: - errorMessage: Environment Variable (POSTGRES_HOST) on container (RELEASE-NAME-common-test) is set more than once. [to (something123) on (Configmap-RELEASE-NAME-common-test-somename)] and [to (something) on (Secret-RELEASE-NAME-common-test-somename)] + errorMessage: Environment Variable (POSTGRES_HOST) on container (RELEASE-NAME-common-test) is set more than once. [to (something123) on (configmap-RELEASE-NAME-common-test-somename)] and [to (something) on (secret-RELEASE-NAME-common-test-somename)] - it: should pass with envs defined with int value documentIndex: *deploymentDoc diff --git a/library/common-test/values.yaml b/library/common-test/values.yaml index 147b88b3e7..463832b5ee 100644 --- a/library/common-test/values.yaml +++ b/library/common-test/values.yaml @@ -7,45 +7,66 @@ service: initImage: repository: something tag: somethingeles + + +# env: +# TZ: tsd + +# TODO: check why it mixes up envs from main container with init container for dupe check + # TODO: Unittests -initContainers: - init-db: - name: ss - imageSelector: initImage - pullPolicy: Always - tty: true - stdin: true - command: - - this - - is - - | - a test - args: - - this args - - is - - | - a test - extraArgs: - - this extraargs - - is - - | - a test - lifecycle: - preStop: - command: - - /bin/sh - - -c - - | - echo "Doing things..." - termination: - messagePath: something - messagePolicy: FallbackToLogsOnError - scaleGPU: - gpu.intel.com/i915: "1" - resources: - limits: - cpu: 1000m - memory: 2Gi - requests: - cpu: 10m - memory: 10Mi +# initContainers: +# init-db: +# name: ss +# imageSelector: initImage +# pullPolicy: Always +# tty: true +# stdin: true +# command: +# - this +# - is +# - | +# a test +# args: +# - this args +# - is +# - | +# a test +# extraArgs: +# - this extraargs +# - is +# - | +# a test +# lifecycle: +# preStop: +# command: +# - /bin/sh +# - -c +# - | +# echo "Doing things..." +# termination: +# messagePath: something +# messagePolicy: FallbackToLogsOnError +# scaleGPU: +# gpu.intel.com/i915: "1" +# resources: +# limits: +# cpu: 1000m +# memory: 2Gi +# requests: +# cpu: 10m +# memory: 10Mi +# env: +# key: value +# test: tasdt +# blbla: tasd +# envFrom: +# - configMapRef: +# name: omething +# - secretRef: +# name: omething +# envList: +# # - name: blbla +# # value: tasd +# - name: blbla23 +# value: tasd234 diff --git a/library/common/1.0.0/templates/lib/container/_env_from.tpl b/library/common/1.0.0/templates/lib/container/_env_from.tpl index 5559db7516..7e8d7504d0 100644 --- a/library/common/1.0.0/templates/lib/container/_env_from.tpl +++ b/library/common/1.0.0/templates/lib/container/_env_from.tpl @@ -20,12 +20,12 @@ That's why the custom dict is expected. {{- $secretName := (tpl (required "Name is required for secretRef in envFrom." .secretRef.name) $root) }} - secretRef: name: {{ $secretName | quote }} - {{- include "ix.v1.common.util.storeEnvFromVarsForCheck" (dict "root" $root "containers" (list $containerName) "name" $secretName "type" "secret") -}} + {{- include "ix.v1.common.util.storeEnvFromVarsForCheck" (dict "root" $root "containerName" $containerName "source" (printf "%s-%s" "secret" $secretName)) -}} {{- else if .configMapRef }} {{- $configName := (tpl (required "Name is required for configMapRef in envFrom." .configMapRef.name) $root) }} - configMapRef: name: {{ $configName | quote }} - {{- include "ix.v1.common.util.storeEnvFromVarsForCheck" (dict "root" $root "containers" (list $containerName) "name" $configName "type" "configmap") -}} + {{- include "ix.v1.common.util.storeEnvFromVarsForCheck" (dict "root" $root "containerName" $containerName "source" (printf "%s-%s" "configmap" $configName)) -}} {{- else -}} {{- fail "Not valid Ref or key is missing in envFrom." -}} {{- end -}} diff --git a/library/common/1.0.0/templates/lib/container/env/_checkDuplicates.tpl b/library/common/1.0.0/templates/lib/container/env/_checkDuplicates.tpl index 139794dbaf..b68f202bd8 100644 --- a/library/common/1.0.0/templates/lib/container/env/_checkDuplicates.tpl +++ b/library/common/1.0.0/templates/lib/container/env/_checkDuplicates.tpl @@ -52,13 +52,12 @@ {{- define "ix.v1.common.util.storeEnvFromVarsForCheck" -}} {{- $root := .root -}} - {{- $name := .name -}} + {{- $source := .source -}} {{- $containerName := .containerName -}} - {{- $type := .type -}} {{- $dupes := $root.Values.envsForDupeCheck -}} {{- range $item := $dupes -}} - {{- if eq $item.source (printf "%s-%s" (camelcase $type) $name) -}} + {{- if eq $item.source $source -}} {{- if not (mustHas $containerName $item.containers) -}} {{- $dupes = without $dupes $item -}} {{- $_ := set $item "containers" (mustAppend $item.containers $containerName) -}} diff --git a/library/common/1.0.0/templates/spawner/_configmapAndSecret.tpl b/library/common/1.0.0/templates/spawner/_configmapAndSecret.tpl index fe458ca769..b66a97a978 100644 --- a/library/common/1.0.0/templates/spawner/_configmapAndSecret.tpl +++ b/library/common/1.0.0/templates/spawner/_configmapAndSecret.tpl @@ -58,7 +58,7 @@ {{- end -}} {{/* Add the to the list for dupeCheck */}} - {{- include "ix.v1.common.util.storeEnvsForDupeCheck" (dict "root" $root "source" (printf "%s-%s" (camelcase $objectType) $objectName) "containers" list "data" $dupeCheck) -}} + {{- include "ix.v1.common.util.storeEnvsForDupeCheck" (dict "root" $root "source" (printf "%s-%s" $objectType $objectName) "containers" list "data" $dupeCheck) -}} {{/* Convert to Yaml before sending to classes */}} {{- $classData = toYaml $classData -}}