From 30ba8ac78567a68716938aa1c4f94665322e6346 Mon Sep 17 00:00:00 2001 From: Pablo Hiroshi Alonso Miyazaki Date: Mon, 20 Nov 2023 09:05:57 +0000 Subject: [PATCH] feat: volumes + volumeMounts support --- templates/deployment-registry.yaml | 8 ++++ templates/deployment-sync.yaml | 8 ++++ test/linter/test.sh | 45 ++++++++++++++++++++++ test/unit/volume_registry_test.yaml | 60 +++++++++++++++++++++++++++++ test/unit/volume_sync_test.yaml | 57 +++++++++++++++++++++++++++ values.schema.json | 10 +++++ values.yaml | 20 ++++++++++ 7 files changed, 208 insertions(+) create mode 100644 test/unit/volume_registry_test.yaml create mode 100644 test/unit/volume_sync_test.yaml diff --git a/templates/deployment-registry.yaml b/templates/deployment-registry.yaml index 49a93ae..8b45e3e 100644 --- a/templates/deployment-registry.yaml +++ b/templates/deployment-registry.yaml @@ -76,4 +76,12 @@ spec: resources: {{ . | toYaml | nindent 12 }} {{- end }} + {{- with .Values.registry.extraVolumeMounts }} + volumeMounts: + {{- toYaml . | nindent 12 }} + {{- end }} + {{- with .Values.registry.extraVolumes }} + volumes: + {{- toYaml . | nindent 8 }} + {{- end }} {{- end }} diff --git a/templates/deployment-sync.yaml b/templates/deployment-sync.yaml index 37647d0..c0b819e 100644 --- a/templates/deployment-sync.yaml +++ b/templates/deployment-sync.yaml @@ -66,4 +66,12 @@ spec: resources: {{ . | toYaml | nindent 12 }} {{- end }} + {{- with .Values.sync.extraVolumeMounts }} + volumeMounts: + {{- toYaml . | nindent 12 }} + {{- end }} + {{- with .Values.sync.extraVolumes }} + volumes: + {{- toYaml . | nindent 8 }} + {{- end }} {{- end }} diff --git a/test/linter/test.sh b/test/linter/test.sh index 66e7a3b..f9dfcb7 100755 --- a/test/linter/test.sh +++ b/test/linter/test.sh @@ -100,6 +100,51 @@ if [ $? -eq 0 ]; then exit 1 fi +# extraVolumeMounts - correct +helm lint . --strict --set registry.extraVolumeMounts[0].name=foo,registry.extraVolumeMounts[0].mountPath=/bar +if [ $? -ne 0 ]; then + exit 1 +fi + +helm lint . --strict --set sync.extraVolumeMounts[0].name=foo,registry.extraVolumeMounts[0].mountPath=/bar +if [ $? -ne 0 ]; then + exit 1 +fi + +# extraVolumeMounts - wrong +helm lint . --strict --set registry.extraVolumeMounts.name=foo,registry.extraVolumeMounts.mountPath=/bar +if [ $? -eq 0 ]; then + exit 1 +fi + +helm lint . --strict --set sync.extraVolumeMounts.name=foo,registry.extraVolumeMounts.mountPath=/bar +if [ $? -eq 0 ]; then + exit 1 +fi + +# extraVolumes - correct +helm lint . --strict --set registry.extraVolumes[0].name=foo,registry.extraVolumes[0].emptyDir=true +if [ $? -ne 0 ]; then + exit 1 +fi + +helm lint . --strict --set sync.extraVolumes[0].name=foo,sync.extraVolumes[0].emptyDir=true +if [ $? -ne 0 ]; then + exit 1 +fi + +# extraVolumes - wrong +helm lint . --strict --set registry.extraVolumes.name=foo,registry.extraVolumes.emptyDir=true +if [ $? -eq 0 ]; then + exit 1 +fi + +helm lint . --strict --set sync.extraVolumes.name=foo,sync.extraVolumes.emptyDir=true +if [ $? -eq 0 ]; then + exit 1 +fi + + echo "==================================================================================" echo " LINT PASSED" echo "==================================================================================" diff --git a/test/unit/volume_registry_test.yaml b/test/unit/volume_registry_test.yaml new file mode 100644 index 0000000..efe0b30 --- /dev/null +++ b/test/unit/volume_registry_test.yaml @@ -0,0 +1,60 @@ +--- +suite: test registry volumes +templates: + - deployment-registry.yaml +tests: + - it: no volumes + asserts: + - notExists: + path: spec.template.spec.volumes + - it: volumes + set: + registry: + extraVolumes: + - name: baz + emptyDir: {} + - name: foo + secret: + secretName: bar + optional: false + asserts: + - exists: + path: spec.template.spec.volumes + - equal: + path: spec.template.spec.volumes[0].name + value: baz + - equal: + path: spec.template.spec.volumes[0].emptyDir + value: {} + - equal: + path: spec.template.spec.volumes[1].name + value: foo + - equal: + path: spec.template.spec.volumes[1].secret.secretName + value: bar + - equal: + path: spec.template.spec.volumes[1].secret.optional + value: false + - it: no volume mounts + asserts: + - notExists: + path: spec.template.spec.containers[0].volumeMounts + - it: volume mounts + set: + registry: + extraVolumeMounts: + - name: foo + mountPath: /bar + readOnly: true + asserts: + - exists: + path: spec.template.spec.containers[0].volumeMounts + - equal: + path: spec.template.spec.containers[0].volumeMounts[0].name + value: foo + - equal: + path: spec.template.spec.containers[0].volumeMounts[0].mountPath + value: /bar + - equal: + path: spec.template.spec.containers[0].volumeMounts[0].readOnly + value: true \ No newline at end of file diff --git a/test/unit/volume_sync_test.yaml b/test/unit/volume_sync_test.yaml new file mode 100644 index 0000000..9f78b66 --- /dev/null +++ b/test/unit/volume_sync_test.yaml @@ -0,0 +1,57 @@ +--- +suite: test sync volumes +templates: + - deployment-sync.yaml +tests: + - it: no volumes + asserts: + - notExists: + path: spec.template.spec.volumes + - it: volumes + set: + sync: + extraVolumes: + - name: baz + emptyDir: {} + - name: foo + secret: + secretName: bar + optional: false + asserts: + - exists: + path: spec.template.spec.volumes + - equal: + path: spec.template.spec.volumes[0].name + value: baz + - equal: + path: spec.template.spec.volumes[0].emptyDir + value: {} + - equal: + path: spec.template.spec.volumes[1].name + value: foo + - equal: + path: spec.template.spec.volumes[1].secret.secretName + value: bar + - it: no volume mounts + asserts: + - notExists: + path: spec.template.spec.containers[0].volumeMounts + - it: volume mounts + set: + sync: + extraVolumeMounts: + - name: foo + mountPath: /bar + readOnly: true + asserts: + - exists: + path: spec.template.spec.containers[0].volumeMounts + - equal: + path: spec.template.spec.containers[0].volumeMounts[0].name + value: foo + - equal: + path: spec.template.spec.containers[0].volumeMounts[0].mountPath + value: /bar + - equal: + path: spec.template.spec.containers[0].volumeMounts[0].readOnly + value: true \ No newline at end of file diff --git a/values.schema.json b/values.schema.json index d97e516..4468249 100644 --- a/values.schema.json +++ b/values.schema.json @@ -57,6 +57,12 @@ "initContainers": { "type": "array", "default": [] }, + "volumeMounts": { + "type": "array", "default": [] + }, + "volumes": { + "type": "array", "default": [] + }, "ingress": { "type": "object", "title": "ingress resource for registry", "required": ["enabled", "host", "path"], @@ -89,6 +95,8 @@ "items": {"$ref": "#/definitions/keyValue"} }, "resources": {"$ref": "#/definitions/podResources"}, + "extraVolumeMounts": {"$ref": "#/definitions/volumeMounts"}, + "extraVolumes": {"$ref": "#/definitions/volumes"}, "kafka": {"$ref": "#/definitions/persistence/kafka"}, "sql": {"$ref": "#/definitions/persistence/sql"}, "ingress": {"$ref": "#/definitions/ingress"} @@ -103,6 +111,8 @@ "nodeSelector": {"type": "object", "title": "node selector for registry content sync"}, "initContainers": {"$ref": "#/definitions/initContainers"}, "resources": {"$ref": "#/definitions/podResources"}, + "extraVolumeMounts": {"$ref": "#/definitions/volumeMounts"}, + "extraVolumes": {"$ref": "#/definitions/volumes"}, "registryUrl": {"type": ["null", "string"], "default": null} } } diff --git a/values.yaml b/values.yaml index 36a4e9c..9378c44 100644 --- a/values.yaml +++ b/values.yaml @@ -30,6 +30,16 @@ registry: # requests: # cpu: 200m # memory: 600Mi + # list of extra volume mounts + extraVolumeMounts: [] + # - name: kafkauser + # mountPath: /opt/user + # readOnly: true + # list of extra volumes + extraVolumes: [] + # - name: kafkauser + # secret: + # secretName: kafka-user ingress: enabled: false @@ -57,4 +67,14 @@ sync: # requests: # cpu: 200m # memory: 600Mi + # list of extra volume mounts + extraVolumeMounts: [] + # - name: kafkauser + # mountPath: /opt/user + # readOnly: true + # list of extra volumes + extraVolumes: [] + # - name: kafkauser + # secret: + # secretName: kafka-user