From 75fd2298b8493c04ac4e5d1be754fc4d2856b9de Mon Sep 17 00:00:00 2001 From: Stavros kois Date: Sun, 10 Mar 2024 17:22:33 +0200 Subject: [PATCH] fix SFS volumeMounts --- .../tests/volumeClaimTemplate/names_test.yaml | 23 ++++++++++++++++++- .../templates/lib/container/_volumeMounts.tpl | 9 +++++++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/library/common-test/tests/volumeClaimTemplate/names_test.yaml b/library/common-test/tests/volumeClaimTemplate/names_test.yaml index 4029aad3..fc3b4353 100644 --- a/library/common-test/tests/volumeClaimTemplate/names_test.yaml +++ b/library/common-test/tests/volumeClaimTemplate/names_test.yaml @@ -11,15 +11,28 @@ tests: my-volume1: enabled: true type: vct + mountPath: /some/path1 my-volume2: enabled: true type: vct + mountPath: /some/path2 workload: main: enabled: true primary: true type: StatefulSet - podSpec: {} + podSpec: + containers: + main: + enabled: true + primary: true + probes: + liveness: + enabled: false + readiness: + enabled: false + startup: + enabled: false asserts: - documentIndex: &statefulSetDoc 0 isKind: @@ -31,7 +44,15 @@ tests: equal: path: spec.volumeClaimTemplates[0].metadata.name value: test-release-name-common-test-my-volume1 + - documentIndex: *statefulSetDoc + equal: + path: spec.template.spec.containers[0].volumeMounts[1].name + value: test-release-name-common-test-my-volume1 - documentIndex: *statefulSetDoc equal: path: spec.volumeClaimTemplates[1].metadata.name value: test-release-name-common-test-my-volume2 + - documentIndex: *statefulSetDoc + equal: + path: spec.template.spec.containers[0].volumeMounts[2].name + value: test-release-name-common-test-my-volume2 diff --git a/library/common/templates/lib/container/_volumeMounts.tpl b/library/common/templates/lib/container/_volumeMounts.tpl index dfe5190d..f44e5761 100644 --- a/library/common/templates/lib/container/_volumeMounts.tpl +++ b/library/common/templates/lib/container/_volumeMounts.tpl @@ -22,7 +22,9 @@ objectData: The object data to be used to render the container. {{- if and (eq $enabled "true") (not (and (eq $persistenceValues.type "vct") (ne $objectData.podType "StatefulSet"))) -}} {{/* Dont try to mount configmap/sercet/vct to codeserver */}} {{- if not (and (eq $objectData.shortName "codeserver") (mustHas $persistenceValues.type $codeServerIgnoredTypes)) -}} - {{- $volMount := (fromJson (include "tc.v1.common.lib.container.volumeMount.isSelected" (dict "persistenceName" $persistenceName "persistenceValues" $persistenceValues "objectData" $objectData))) -}} + {{- $volMount := (include "tc.v1.common.lib.container.volumeMount.isSelected" (dict + "rootCtx" $rootCtx "persistenceName" $persistenceName "persistenceValues" $persistenceValues "objectData" $objectData + )) | fromJson -}} {{- if $volMount -}} {{- $volMounts = mustAppend $volMounts $volMount -}} {{- end -}} @@ -69,9 +71,14 @@ objectData: The object data to be used to render the container. {{- $persistenceName := .persistenceName -}} {{- $persistenceValues := .persistenceValues -}} {{- $objectData := .objectData -}} + {{- $rootCtx := .rootCtx -}} {{/* Initialize from the default values */}} {{- $volMount := dict -}} + {{- if eq $objectData.podType "StatefulSet" -}} + {{- $fullname := include "tc.v1.common.lib.chart.names.fullname" $rootCtx -}} + {{- $persistenceName = printf "%s-%s" $fullname $persistenceName -}} + {{- end -}} {{- $_ := set $volMount "name" $persistenceName -}} {{- if eq $persistenceValues.type "device" -}} {{/* On devices use the hostPath as default if mountpath is not defined */}} {{- $_ := set $volMount "mountPath" ($persistenceValues.mountPath | default $persistenceValues.hostPath | default "") -}}