From 746ce96985cdcdcfd47a44efce10e304b400e1b2 Mon Sep 17 00:00:00 2001 From: Stavros kois Date: Mon, 13 Feb 2023 17:37:06 +0200 Subject: [PATCH] move check --- .../tests/container/lifecycle_test.yaml | 17 ++++++++++++----- .../templates/lib/container/_lifecycle.tpl | 9 +++------ .../container/probe-lifecyle-actions/_exec.tpl | 9 +++++++-- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/library/common-test/tests/container/lifecycle_test.yaml b/library/common-test/tests/container/lifecycle_test.yaml index 2d99b8ddc0..d08c38a5e7 100644 --- a/library/common-test/tests/container/lifecycle_test.yaml +++ b/library/common-test/tests/container/lifecycle_test.yaml @@ -19,6 +19,13 @@ tests: enabled: true primary: true imageSelector: image + probes: &probes + liveness: + enabled: false + readiness: + enabled: false + startup: + enabled: false lifecycle: postStart: type: exec @@ -57,7 +64,6 @@ tests: some_command: ./some_command some_port: 80 some_host: some_host - some_scheme: HTTPS some_path: /api/v1 some_value: 123 workload: @@ -71,12 +77,12 @@ tests: enabled: true primary: true imageSelector: image + probes: *probes lifecycle: postStart: - type: http + type: https port: "{{ .Values.some_port }}" host: "{{ .Values.some_host }}" - scheme: "{{ .Values.some_scheme }}" path: "{{ .Values.some_path }}" httpHeaders: key: "{{ .Values.some_value }}" @@ -123,6 +129,7 @@ tests: container-name1: enabled: true primary: true + probes: *probes imageSelector: image lifecycle: invalid: {} @@ -171,7 +178,7 @@ tests: command: [] asserts: - failedTemplate: - errorMessage: Container - Expected to be one of [exec, http], but got [invalid] + errorMessage: Container - Expected to be one of [exec, http, https], but got [invalid] - it: should fail with empty command on exec lifecycle type set: @@ -238,7 +245,7 @@ tests: path: "api/v1" asserts: - failedTemplate: - errorMessage: Container - Expected to start with a forward slash [/] on type + errorMessage: Container - Expected to start with a forward slash [/] on type - it: should fail with empty value on httpHeaders on http lifecycle type set: diff --git a/library/common/1.0.0/templates/lib/container/_lifecycle.tpl b/library/common/1.0.0/templates/lib/container/_lifecycle.tpl index 95022b94fd..5863fce175 100644 --- a/library/common/1.0.0/templates/lib/container/_lifecycle.tpl +++ b/library/common/1.0.0/templates/lib/container/_lifecycle.tpl @@ -9,7 +9,7 @@ objectData: The object data to be used to render the container. {{- $objectData := .objectData -}} {{- $hooks := (list "preStop" "postStart") -}} - {{- $types := (list "exec" "http") -}} + {{- $types := (list "exec" "http" "https") -}} {{- with $objectData.lifecycle -}} {{- range $hook, $hookValues := . -}} {{- if not (mustHas $hook $hooks) -}} @@ -29,11 +29,8 @@ objectData: The object data to be used to render the container. {{- fail "Container - Expected non-empty on [exec] type" -}} {{- end }} {{- include "ix.v1.common.lib.container.actions.exec" (dict "rootCtx" $rootCtx "objectData" $hookValues) | trim | nindent 2 }} - {{- else if eq $hookValues.type "http" }} - {{- if not $hookValues.port -}} - {{- fail "Container - Expected non-empty on [http] type" -}} - {{- end }} - {{- include "ix.v1.common.lib.container.actions.httpGet" (dict "rootCtx" $rootCtx "objectData" $hookValues) | trim | nindent 2 }} + {{- else if mustHas $hookValues.type (list "http" "https") }} + {{- include "ix.v1.common.lib.container.actions.httpGet" (dict "rootCtx" $rootCtx "objectData" $hookValues "caller" "lifecycle") | trim | nindent 2 }} {{- end -}} {{- end -}} diff --git a/library/common/1.0.0/templates/lib/container/probe-lifecyle-actions/_exec.tpl b/library/common/1.0.0/templates/lib/container/probe-lifecyle-actions/_exec.tpl index d3241f70a1..89b0ba2520 100644 --- a/library/common/1.0.0/templates/lib/container/probe-lifecyle-actions/_exec.tpl +++ b/library/common/1.0.0/templates/lib/container/probe-lifecyle-actions/_exec.tpl @@ -1,12 +1,17 @@ {{/* Returns exec action */}} {{/* Call this template: -{{ include "ix.v1.common.lib.container.actions.exec" (dict "rootCtx" $ "objectData" $objectData) }} +{{ include "ix.v1.common.lib.container.actions.exec" (dict "rootCtx" $ "objectData" $objectData "caller" $caller) }} rootCtx: The root context of the chart. objectData: The object data to be used to render the container. */}} {{- define "ix.v1.common.lib.container.actions.exec" -}} {{- $rootCtx := .rootCtx -}} - {{- $objectData := .objectData }} + {{- $objectData := .objectData -}} + {{- $caller := .caller -}} + + {{- if not $objectData.command -}} + {{- fail (printf "Container - Expected non-empty <%s> on [exec] type" $caller) -}} + {{- end }} exec: command: {{- include "ix.v1.common.lib.container.command" (dict "rootCtx" $rootCtx "objectData" $objectData) | trim | nindent 4}}