merge validation

This commit is contained in:
Stavros kois
2022-12-05 21:07:34 +02:00
parent 3e3142a835
commit 98edbc5c4b
2 changed files with 28 additions and 31 deletions

View File

@@ -1,29 +0,0 @@
{{- define "ix.v1.common.externalInterface.validate" -}}
{{- $iface := .iface -}}
{{- if not $iface.hostInterface -}}
{{- fail "<hostInterface> is required when configuring External Interfaces." -}}
{{- end -}}
{{- if not $iface.ipam.type -}}
{{- fail (printf "<ipam.type> is required. Interface (%s)" $iface.hostInterface) -}}
{{- else if not (mustHas $iface.ipam.type (list "static" "dhcp")) -}}
{{- fail (printf "Invalid option for <ipam.type> (%s). Valid options are static and dhcp. Interface (%s)" $iface.ipam.type $iface.hostInterface) -}}
{{- end -}}
{{- if and (or $iface.staticIPConfigurations $iface.staticRoutes) (ne $iface.ipam.type "static") -}}
{{- fail (printf "<staticIPConfigurations> and <staticRoutes> cannot be used with <ipam.type> of (%s). Interface (%s)" $iface.ipam.type $iface.hostInterface) -}}
{{- end -}}
{{- if eq $iface.ipam.type "static" -}}
{{- if not $iface.staticIPConfigurations -}}
{{- fail (printf "Static IP is required when <ipam.type> is static. Interface (%s)" $iface.hostInterface) -}}
{{- end -}}
{{- with $iface.staticRoutes -}}
{{- range . -}}
{{- if or (not .destination) (not .gateway) -}}
{{- fail (printf "<destination> and <gateway> are required when <staticRoutes> are defined. Interface (%s)" $iface.hostInterface) -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}

View File

@@ -1,8 +1,34 @@
{{- define "ix.v1.common.spawner.externalInterface" -}}
{{/* Validate that data from externalInterfaces are correct before start creating objects */}}
{{- range .Values.externalInterfaces -}}
{{- include "ix.v1.common.externalInterface.validate" (dict "iface" .) -}}
{{- range $iface := .Values.externalInterfaces -}}
{{- if not $iface.hostInterface -}}
{{- fail "<hostInterface> is required when configuring External Interfaces." -}}
{{- end -}}
{{- if not $iface.ipam.type -}}
{{- fail (printf "<ipam.type> is required. Interface (%s)" $iface.hostInterface) -}}
{{- else if not (mustHas $iface.ipam.type (list "static" "dhcp")) -}}
{{- fail (printf "Invalid option for <ipam.type> (%s). Valid options are static and dhcp. Interface (%s)" $iface.ipam.type $iface.hostInterface) -}}
{{- end -}}
{{- if and (or $iface.staticIPConfigurations $iface.staticRoutes) (ne $iface.ipam.type "static") -}}
{{- fail (printf "<staticIPConfigurations> and <staticRoutes> cannot be used with <ipam.type> of (%s). Interface (%s)" $iface.ipam.type $iface.hostInterface) -}}
{{- end -}}
{{- if eq $iface.ipam.type "static" -}}
{{- if not $iface.staticIPConfigurations -}}
{{- fail (printf "Static IP is required when <ipam.type> is static. Interface (%s)" $iface.hostInterface) -}}
{{- end -}}
{{- with $iface.staticRoutes -}}
{{- range . -}}
{{- if or (not .destination) (not .gateway) -}}
{{- fail (printf "<destination> and <gateway> are required when <staticRoutes> are defined. Interface (%s)" $iface.hostInterface) -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{/* Now we are sure data is validated, spawn the objects */}}
{{- range $index, $iface := .Values.ixExternalInterfacesConfiguration -}}
{{- include "ix.v1.common.class.externalInterface" (dict "iface" $iface "index" $index "root" $) -}}
{{- end -}}