From 98edbc5c4bf46d27412950c7cec1ed69a8f283fb Mon Sep 17 00:00:00 2001 From: Stavros kois Date: Mon, 5 Dec 2022 21:07:34 +0200 Subject: [PATCH] merge validation --- .../_externalInterfaceValidation.tpl | 29 ------------------ .../templates/spawner/_externalInterfaces.tpl | 30 +++++++++++++++++-- 2 files changed, 28 insertions(+), 31 deletions(-) delete mode 100644 library/common/1.0.0/templates/lib/externalInterface/_externalInterfaceValidation.tpl diff --git a/library/common/1.0.0/templates/lib/externalInterface/_externalInterfaceValidation.tpl b/library/common/1.0.0/templates/lib/externalInterface/_externalInterfaceValidation.tpl deleted file mode 100644 index 17558c20..00000000 --- a/library/common/1.0.0/templates/lib/externalInterface/_externalInterfaceValidation.tpl +++ /dev/null @@ -1,29 +0,0 @@ -{{- define "ix.v1.common.externalInterface.validate" -}} - {{- $iface := .iface -}} - - {{- if not $iface.hostInterface -}} - {{- fail " is required when configuring External Interfaces." -}} - {{- end -}} - {{- if not $iface.ipam.type -}} - {{- fail (printf " is required. Interface (%s)" $iface.hostInterface) -}} - {{- else if not (mustHas $iface.ipam.type (list "static" "dhcp")) -}} - {{- fail (printf "Invalid option for (%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 " and cannot be used with 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 is static. Interface (%s)" $iface.hostInterface) -}} - {{- end -}} - {{- with $iface.staticRoutes -}} - {{- range . -}} - {{- if or (not .destination) (not .gateway) -}} - {{- fail (printf " and are required when are defined. Interface (%s)" $iface.hostInterface) -}} - {{- end -}} - {{- end -}} - {{- end -}} - {{- end -}} -{{- end -}} diff --git a/library/common/1.0.0/templates/spawner/_externalInterfaces.tpl b/library/common/1.0.0/templates/spawner/_externalInterfaces.tpl index 18bb92e3..af4af20e 100644 --- a/library/common/1.0.0/templates/spawner/_externalInterfaces.tpl +++ b/library/common/1.0.0/templates/spawner/_externalInterfaces.tpl @@ -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 " is required when configuring External Interfaces." -}} + {{- end -}} + {{- if not $iface.ipam.type -}} + {{- fail (printf " is required. Interface (%s)" $iface.hostInterface) -}} + {{- else if not (mustHas $iface.ipam.type (list "static" "dhcp")) -}} + {{- fail (printf "Invalid option for (%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 " and cannot be used with 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 is static. Interface (%s)" $iface.hostInterface) -}} + {{- end -}} + {{- with $iface.staticRoutes -}} + {{- range . -}} + {{- if or (not .destination) (not .gateway) -}} + {{- fail (printf " and are required when 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 -}}