reduce code duple

This commit is contained in:
Stavros kois
2023-02-11 16:31:56 +02:00
parent 732e409ad8
commit 6baaed12ac
19 changed files with 39 additions and 110 deletions

View File

@@ -18,12 +18,4 @@ objectData:
{{- fail (printf "ConfigMap - Expected <data> to be a dictionary, but got [%v]" (kindOf $objectData.data)) -}}
{{- end -}}
{{- if and $objectData.labels (not (kindIs "map" $objectData.labels)) -}}
{{- fail (printf "ConfigMap - Expected <labels> to be a dictionary, but got [%v]" (kindOf $objectData.labels)) -}}
{{- end -}}
{{- if and $objectData.annotations (not (kindIs "map" $objectData.annotations)) -}}
{{- fail (printf "ConfigMap - Expected <annotations> to be a dictionary, but got [%v]" (kindOf $objectData.annotations)) -}}
{{- end -}}
{{- end -}}

View File

@@ -18,14 +18,6 @@ objectData:
{{- fail (printf "Image Pull Secret - Expected <data> to be a dictionary, but got [%v]" (kindOf $objectData.data)) -}}
{{- end -}}
{{- if and $objectData.labels (not (kindIs "map" $objectData.labels)) -}}
{{- fail (printf "Image Pull Secret - Expected <labels> to be a dictionary, but got [%v]" (kindOf $objectData.labels)) -}}
{{- end -}}
{{- if and $objectData.annotations (not (kindIs "map" $objectData.annotations)) -}}
{{- fail (printf "Image Pull Secret - Expected <annotations> to be a dictionary, but got [%v]" (kindOf $objectData.annotations)) -}}
{{- end -}}
{{- range $key := (list "username" "password" "registry" "email") -}}
{{- if not (get $objectData.data $key) -}}
{{- fail (printf "Image Pull Secret - Expected non-empty <%s>" $key) -}}

View File

@@ -0,0 +1,22 @@
{{/* Metadata Validation */}}
{{/* Call this template:
{{ include "ix.v1.common.lib.metadata.validation" (dict "objectData" $objectData "caller" $caller) -}}
objectData:
labels: The labels of the configmap.
annotations: The annotations of the configmap.
data: The data of the configmap.
*/}}
{{- define "ix.v1.common.lib.metadata.validation" -}}
{{- $objectData := .objectData -}}
{{- $caller := .caller -}}
{{- if and $objectData.labels (not (kindIs "map" $objectData.labels)) -}}
{{- fail (printf "%s - Expected <labels> to be a dictionary, but got [%v]" $caller (kindOf $objectData.labels)) -}}
{{- end -}}
{{- if and $objectData.annotations (not (kindIs "map" $objectData.annotations)) -}}
{{- fail (printf "%s - Expected <annotations> to be a dictionary, but got [%v]" $caller (kindOf $objectData.annotations)) -}}
{{- end -}}
{{- end -}}

View File

@@ -1,25 +1,3 @@
{{/* RBAC Validation */}}
{{/* Call this template:
{{ include "ix.v1.common.lib.rbac.validation" (dict "objectData" $objectData) -}}
objectData:
labels: The labels of the rbac.
annotations: The annotations of the rbac.
data: The data of the rbac.
*/}}
{{- define "ix.v1.common.lib.rbac.validation" -}}
{{- $objectData := .objectData -}}
{{- if and $objectData.labels (not (kindIs "map" $objectData.labels)) -}}
{{- fail (printf "RBAC - Expected <labels> to be a dictionary, but got [%v]" (kindOf $objectData.labels)) -}}
{{- end -}}
{{- if and $objectData.annotations (not (kindIs "map" $objectData.annotations)) -}}
{{- fail (printf "RBAC - Expected <annotations> to be a dictionary, but got [%v]" (kindOf $objectData.annotations)) -}}
{{- end -}}
{{- end -}}
{{/* RBAC Primary Validation */}}
{{/* Call this template:
{{ include "ix.v1.common.lib.rbac.primaryValidation" $ -}}

View File

@@ -22,12 +22,4 @@ objectData:
{{- fail (printf "Secret - Found <type> key, but it's empty") -}}
{{- end -}}
{{- if and $objectData.labels (not (kindIs "map" $objectData.labels)) -}}
{{- fail (printf "Secret - Expected <labels> to be a dictionary, but got [%v]" (kindOf $objectData.labels)) -}}
{{- end -}}
{{- if and $objectData.annotations (not (kindIs "map" $objectData.annotations)) -}}
{{- fail (printf "Secret - Expected <annotations> to be a dictionary, but got [%v]" (kindOf $objectData.annotations)) -}}
{{- end -}}
{{- end -}}

View File

@@ -10,14 +10,6 @@ objectData:
{{- $rootCtx := .rootCtx -}}
{{- $objectData := .objectData -}}
{{- if and $objectData.labels (not (kindIs "map" $objectData.labels)) -}}
{{- fail (printf "Service - Expected <labels> to be a dictionary, but got [%v]" (kindOf $objectData.labels)) -}}
{{- end -}}
{{- if and $objectData.annotations (not (kindIs "map" $objectData.annotations)) -}}
{{- fail (printf "Service - Expected <annotations> to be a dictionary, but got [%v]" (kindOf $objectData.annotations)) -}}
{{- end -}}
{{- if and $objectData.targetSelector (not (kindIs "string" $objectData.targetSelector)) -}}
{{- fail (printf "Service - Expected <targetSelector> to be [string], but got [%s]" (kindOf $objectData.targetSelector)) -}}
{{- end -}}

View File

@@ -1,24 +1,3 @@
{{/* Service Account Validation */}}
{{/* Call this template:
{{ include "ix.v1.common.lib.serviceAccount.validation" (dict "objectData" $objectData) -}}
objectData:
labels: The labels of the serviceAccount.
annotations: The annotations of the serviceAccount.
*/}}
{{- define "ix.v1.common.lib.serviceAccount.validation" -}}
{{- $objectData := .objectData -}}
{{- if and $objectData.labels (not (kindIs "map" $objectData.labels)) -}}
{{- fail (printf "Service Account - Expected <labels> to be a dictionary, but got [%v]" (kindOf $objectData.labels)) -}}
{{- end -}}
{{- if and $objectData.annotations (not (kindIs "map" $objectData.annotations)) -}}
{{- fail (printf "Service Account - Expected <annotations> to be a dictionary, but got [%v]" (kindOf $objectData.annotations)) -}}
{{- end -}}
{{- end -}}
{{/* Service Account Primary Validation */}}
{{/* Call this template:
{{ include "ix.v1.common.lib.serviceAccount.primaryValidation" $ -}}

View File

@@ -10,14 +10,6 @@ objectData:
{{- $rootCtx := .rootCtx -}}
{{- $objectData := .objectData -}}
{{- if and $objectData.labels (not (kindIs "map" $objectData.labels)) -}}
{{- fail (printf "Persistence - Expected <labels> to be a dictionary, but got [%v]" (kindOf $objectData.labels)) -}}
{{- end -}}
{{- if and $objectData.annotations (not (kindIs "map" $objectData.annotations)) -}}
{{- fail (printf "Persistence - Expected <annotations> to be a dictionary, but got [%v]" (kindOf $objectData.annotations)) -}}
{{- end -}}
{{- $types := (list "pvc" "emptyDir" "nfs" "hostPath" "ixVolume" "secret" "configmap") -}}
{{- if not (mustHas $objectData.type $types) -}}
{{- fail (printf "Persistence - Expected <type> to be one of [%s], but got [%s]" (join ", " $types) $objectData.type) -}}

View File

@@ -41,24 +41,3 @@
{{- end -}}
{{- end -}}
{{/* Workload Basic Validation */}}
{{/* Call this template:
{{ include "ix.v1.common.lib.workload.basicValidation" (dict "objectData" $objectData) -}}
rootCtx: The root context of the template. It is used to access the global context.
objectData:
labels: The labels of the object.
annotations: The annotations of the object.
*/}}
{{- define "ix.v1.common.lib.workload.basicValidation" -}}
{{- $objectData := .objectData -}}
{{- if and $objectData.labels (not (kindIs "map" $objectData.labels)) -}}
{{- fail (printf "Workload - Expected <labels> to be a dictionary, but got [%v]" (kindOf $objectData.labels)) -}}
{{- end -}}
{{- if and $objectData.annotations (not (kindIs "map" $objectData.annotations)) -}}
{{- fail (printf "Workload - Expected <annotations> to be a dictionary, but got [%v]" (kindOf $objectData.annotations)) -}}
{{- end -}}
{{- end -}}

View File

@@ -4,6 +4,9 @@
{{/* Render ConfigMap(s) */}}
{{- include "ix.v1.common.spawner.configmap" . | nindent 0 -}}
{{/* Render Certificate(s) */}}
{{- include "ix.v1.common.spawner.certificate" . | nindent 0 -}}
{{/* Render Secret(s) */}}
{{- include "ix.v1.common.spawner.secret" . | nindent 0 -}}

View File

@@ -16,6 +16,7 @@
{{/* Perform validations */}}
{{- include "ix.v1.common.lib.chart.names.validation" (dict "name" $objectName) -}}
{{- include "ix.v1.common.lib.configmap.validation" (dict "objectData" $objectData) -}}
{{- include "ix.v1.common.lib.metadata.validation" (dict "objectData" $objectData "caller" "ConfigMap") -}}
{{/* Set the name of the configmap */}}
{{- $_ := set $objectData "name" $objectName -}}

View File

@@ -17,6 +17,7 @@
{{/* Perform validations */}}
{{- include "ix.v1.common.lib.chart.names.validation" (dict "name" $objectName) -}}
{{- include "ix.v1.common.lib.imagePullSecret.validation" (dict "objectData" $objectData) -}}
{{- include "ix.v1.common.lib.metadata.validation" (dict "objectData" $objectData "caller" "Image Pull Secret") -}}
{{- $data := include "ix.v1.common.lib.imagePullSecret.createData" (dict "rootCtx" $ "objectData" $objectData) -}}
{{/* Update the data */}}

View File

@@ -16,6 +16,7 @@
{{/* Perform general validations */}}
{{- include "ix.v1.common.lib.persistence.validation" (dict "rootCtx" $ "objectData" $objectData) -}}
{{- include "ix.v1.common.lib.metadata.validation" (dict "objectData" $objectData "caller" "Persistence") -}}
{{/* Only spawn PVC if it's enabled and type of "pvc" */}}
{{- if and (eq "pvc" $objectData.type) (not $objectData.existingClaim) -}}

View File

@@ -22,7 +22,7 @@
{{/* Perform validations */}}
{{- include "ix.v1.common.lib.chart.names.validation" (dict "name" $objectName) -}}
{{- include "ix.v1.common.lib.rbac.validation" (dict "objectData" $objectData) -}}
{{- include "ix.v1.common.lib.metadata.validation" (dict "objectData" $objectData "caller" "RBAC") -}}
{{/* Set the name of the rbac */}}
{{- $_ := set $objectData "name" $objectName -}}

View File

@@ -16,6 +16,7 @@
{{/* Perform validations */}}
{{- include "ix.v1.common.lib.chart.names.validation" (dict "name" $objectName) -}}
{{- include "ix.v1.common.lib.secret.validation" (dict "objectData" $objectData) -}}
{{- include "ix.v1.common.lib.metadata.validation" (dict "objectData" $objectData "caller" "Secret") -}}
{{/* Set the name of the secret */}}
{{- $_ := set $objectData "name" $objectName -}}

View File

@@ -23,6 +23,7 @@
{{/* Perform validations */}}
{{- include "ix.v1.common.lib.chart.names.validation" (dict "name" $objectName) -}}
{{- include "ix.v1.common.lib.service.validation" (dict "rootCtx" $ "objectData" $objectData) -}}
{{- include "ix.v1.common.lib.metadata.validation" (dict "objectData" $objectData "caller" "Service") -}}
{{/* Set the name of the service account */}}
{{- $_ := set $objectData "name" $objectName -}}

View File

@@ -22,7 +22,7 @@
{{/* Perform validations */}}
{{- include "ix.v1.common.lib.chart.names.validation" (dict "name" $objectName) -}}
{{- include "ix.v1.common.lib.serviceAccount.validation" (dict "objectData" $objectData) -}}
{{- include "ix.v1.common.lib.metadata.validation" (dict "objectData" $objectData "caller" "Service Account") -}}
{{/* Set the name of the service account */}}
{{- $_ := set $objectData "name" $objectName -}}

View File

@@ -23,7 +23,7 @@
{{/* Perform validations */}}
{{- include "ix.v1.common.lib.chart.names.validation" (dict "name" $objectName) -}}
{{- include "ix.v1.common.lib.workload.basicValidation" (dict "objectData" $objectData) -}}
{{- include "ix.v1.common.lib.metadata.validation" (dict "objectData" $objectData "caller" "Workload") -}}
{{/* Set the name of the workload */}}
{{- $_ := set $objectData "name" $objectName -}}

View File

@@ -31,6 +31,9 @@ fallbackDefaults:
pvcAccessModes:
- ReadWriteOnce
# -- Timezone used everywhere applicable
TIMEZONE: UTC
# -- Injected from SCALE middleware
# Only for reference here
ixExternalInterfacesConfiguration: []
@@ -54,8 +57,6 @@ image:
# -- Image pull policy
pullPolicy: IfNotPresent
# TODO: Docs
TIMEZONE: UTC
# TODO: Docs
# -- Security Context
@@ -300,11 +301,13 @@ scaleGPU:
# -- SCALE Certificate
scaleCert:
scaleCertificate:
# -- Certificate name
cert-name:
# -- Enables the certificate
enabled: false
labels: {}
annotations: {}
# -- Certificate ID (Comes from SCALE)
id: 1
# -- Default Paths that will be used on all defined containers