add tests for volMounts

This commit is contained in:
Stavros kois
2023-02-11 22:43:06 +02:00
parent 65519a101f
commit 66349cd7fd
7 changed files with 142 additions and 11 deletions

View File

@@ -448,6 +448,107 @@ tests:
mountPath: /some/path
readOnly: true
- it: should pass with cert mounted as volume with subPath
set:
image: *image
ixCertificates:
"1":
certificate: some_cert
key: some_key
scaleCertificate:
cert-name:
enabled: false
id: 1
workload:
workload-name:
enabled: true
primary: true
type: Deployment
podSpec:
containers:
container-name1:
enabled: true
primary: true
imageSelector: image
persistence:
cert-vol:
enabled: true
type: secret
objectName: cert-name
readOnly: true
targetSelector:
workload-name:
container-name1:
mountPath: /some/path/cert.crt
readOnly: true
subPath: cert.crt
asserts:
- documentIndex: &deploymentDoc 0
isKind:
of: Deployment
- documentIndex: *deploymentDoc
isAPIVersion:
of: apps/v1
- documentIndex: *deploymentDoc
contains:
path: spec.template.spec.containers[0].volumeMounts
content:
name: cert-vol
mountPath: /some/path/cert.crt
readOnly: true
subPath: cert.crt
- it: should pass with cert mounted as volume with subPath
set:
image: *image
ixCertificates:
"1":
certificate: some_cert
key: some_key
scaleCertificate:
cert-name:
enabled: false
id: 1
workload:
workload-name:
enabled: true
primary: true
type: Deployment
podSpec:
containers:
container-name1:
enabled: true
primary: true
imageSelector: image
persistence:
cert-vol:
enabled: true
type: secret
objectName: cert-name
readOnly: true
items:
- key: crt
path: cert.crt
targetSelector:
workload-name:
container-name1:
mountPath: /some/path
readOnly: true
asserts:
- documentIndex: &deploymentDoc 0
isKind:
of: Deployment
- documentIndex: *deploymentDoc
isAPIVersion:
of: apps/v1
- documentIndex: *deploymentDoc
contains:
path: spec.template.spec.containers[0].volumeMounts
content:
name: cert-vol
mountPath: /some/path
readOnly: true
# Failures
- it: should fail with invalid mountPropagation
set:

View File

@@ -101,6 +101,22 @@ tests:
# Failures
- it: should fail without objectName in configmap
set:
workload:
some-workload:
enabled: true
primary: true
type: Deployment
podSpec: {}
persistence:
volume1:
enabled: true
type: configmap
asserts:
- failedTemplate:
errorMessage: Persistence - Expected non-empty <objectName> on <configmap> type
- it: should fail with empty objectName in configmap
set:
workload:
some-workload:

View File

@@ -117,6 +117,23 @@ tests:
- failedTemplate:
errorMessage: Persistence - Expected non-empty <objectName> on <secret> type
- it: should fail with empty objectName in secret
set:
workload:
some-workload:
enabled: true
primary: true
type: Deployment
podSpec: {}
persistence:
volume1:
enabled: true
type: secret
objectName: ""
asserts:
- failedTemplate:
errorMessage: Persistence - Expected non-empty <objectName> on <secret> type
- it: should fail with defaultMode not a string in secret
set:
workload:

View File

@@ -41,8 +41,6 @@ You can mount certificate as a secret using the following snippet:
scaleCertificate:
cert-name:
enabled: false
labels: {}
annotations: {}
id: 1
persistence:

View File

@@ -44,7 +44,6 @@ objectData: The object data to be used to render the Pod.
{{- end -}}
{{/* TODO:
volumeMounts
probes
env

View File

@@ -8,6 +8,10 @@ objectData: The object data to be used to render the volume.
{{- $rootCtx := .rootCtx -}}
{{- $objectData := .objectData -}}
{{- if not $objectData.objectName -}}
{{- fail "Persistence - Expected non-empty <objectName> on <configmap> type" -}}
{{- end -}}
{{- $objectName := tpl $objectData.objectName $rootCtx -}}
{{- $expandName := true -}}
{{- if kindIs "bool" $objectData.expandObjectName -}}
@@ -20,10 +24,6 @@ objectData: The object data to be used to render the volume.
{{- $defMode := "" -}}
{{- if not $objectData.objectName -}}
{{- fail "Persistence - Expected non-empty <objectName> on <configmap> type" -}}
{{- end -}}
{{- if (and $objectData.defaultMode (not (kindIs "string" $objectData.defaultMode))) -}}
{{- fail (printf "Persistence - Expected <defaultMode> to be [string], but got [%s]" (kindOf $objectData.defaultMode)) -}}
{{- end -}}

View File

@@ -8,6 +8,10 @@ objectData: The object data to be used to render the volume.
{{- $rootCtx := .rootCtx -}}
{{- $objectData := .objectData -}}
{{- if not $objectData.objectName -}}
{{- fail "Persistence - Expected non-empty <objectName> on <secret> type" -}}
{{- end -}}
{{- $objectName := tpl $objectData.objectName $rootCtx -}}
{{- $expandName := true -}}
{{- if kindIs "bool" $objectData.expandObjectName -}}
@@ -20,10 +24,6 @@ objectData: The object data to be used to render the volume.
{{- $defMode := "" -}}
{{- if not $objectData.objectName -}}
{{- fail "Persistence - Expected non-empty <objectName> on <secret> type" -}}
{{- end -}}
{{- if (and $objectData.defaultMode (not (kindIs "string" $objectData.defaultMode))) -}}
{{- fail (printf "Persistence - Expected <defaultMode> to be [string], but got [%s]" (kindOf $objectData.defaultMode)) -}}
{{- end -}}