diff --git a/packages/core/platform/templates/bundles/system.yaml b/packages/core/platform/templates/bundles/system.yaml index 2d545bcf5..be7b3c8f8 100644 --- a/packages/core/platform/templates/bundles/system.yaml +++ b/packages/core/platform/templates/bundles/system.yaml @@ -79,18 +79,23 @@ pointing their one DNS opening at an address with no DNS behind it. clusterDNS follows the kubeadm convention (the service CIDR's .10) unless networking.clusterDNS says otherwise. */ -}} -{{- $cozyplaneComponents := dict -}} -{{- if .Values.networking -}} -{{- $egress := dict "clusterCIDR" .Values.networking.podCIDR "serviceCIDR" .Values.networking.serviceCIDR -}} -{{- $clusterDNS := dig "clusterDNS" "" .Values.networking -}} +{{- $net := .Values.networking | default dict -}} +{{- /* Validated loudly: an empty podCIDR would silently drop the agent's + masquerade and the controller's internal denies, and the clusterDNS + derivation below reads IPv4 octets. */ -}} +{{- if not (and (dig "podCIDR" "" $net) (dig "serviceCIDR" "" $net)) -}} +{{- fail "networkingVariant cozyplane requires networking.podCIDR and networking.serviceCIDR" -}} +{{- end -}} +{{- $clusterDNS := dig "clusterDNS" "" $net -}} {{- if not $clusterDNS -}} -{{- $svcBase := splitList "/" .Values.networking.serviceCIDR | first -}} -{{- $octets := splitList "." $svcBase -}} +{{- if not (regexMatch "^([0-9]{1,3}\\.){3}[0-9]{1,3}/[0-9]{1,2}$" $net.serviceCIDR) -}} +{{- fail (printf "cannot derive networking.clusterDNS from serviceCIDR %q (not an IPv4 CIDR); set networking.clusterDNS explicitly" $net.serviceCIDR) -}} +{{- end -}} +{{- $octets := splitList "." (splitList "/" $net.serviceCIDR | first) -}} {{- $clusterDNS = printf "%s.%s.%s.10" (index $octets 0) (index $octets 1) (index $octets 2) -}} {{- end -}} -{{- $_ := set $egress "clusterDNS" $clusterDNS -}} -{{- $_ := set $cozyplaneComponents "cozyplane" (dict "values" (dict "egress" $egress)) -}} -{{- end -}} +{{- $egress := dict "clusterCIDR" $net.podCIDR "serviceCIDR" $net.serviceCIDR "clusterDNS" $clusterDNS -}} +{{- $cozyplaneComponents := dict "cozyplane" (dict "values" (dict "egress" $egress)) -}} {{- /* The cozyplane leg does not go through package.networking, so it must invoke the live-variant guard itself: a kubeovn-cilium cluster switched here loses Cilium AND kube-ovn in one reconcile. */ -}} diff --git a/packages/core/platform/tests/bundles_networking_variant_test.yaml b/packages/core/platform/tests/bundles_networking_variant_test.yaml index 36850c0f4..ff44a568d 100644 --- a/packages/core/platform/tests/bundles_networking_variant_test.yaml +++ b/packages/core/platform/tests/bundles_networking_variant_test.yaml @@ -210,6 +210,50 @@ tests: path: spec.components.cozyplane.values.egress.clusterDNS value: "10.43.0.53" + - it: refuses cozyplane without the networking CIDRs + set: + bundles: + system: + enabled: true + variant: isp-full + networkingVariant: cozyplane + networking: + podCIDR: "" + asserts: + - failedTemplate: + errorPattern: 'requires networking.podCIDR and networking.serviceCIDR' + + - it: refuses to derive clusterDNS from a non-IPv4 service CIDR + set: + bundles: + system: + enabled: true + variant: isp-full + networkingVariant: cozyplane + networking: + serviceCIDR: "fd00:10:96::/112" + asserts: + - failedTemplate: + errorPattern: 'set networking.clusterDNS explicitly' + + - it: accepts a non-IPv4 service CIDR with an explicit clusterDNS + set: + bundles: + system: + enabled: true + variant: isp-full + networkingVariant: cozyplane + networking: + serviceCIDR: "fd00:10:96::/112" + clusterDNS: "fd00:10:96::a" + asserts: + - documentSelector: + path: metadata.name + value: cozystack.networking + equal: + path: spec.components.cozyplane.values.egress.clusterDNS + value: "fd00:10:96::a" + # The ciliumPool derivation requires a /20-or-shorter podCIDR — a kube-ovn # constraint: the last /21 is carved out for Cilium. cozyplane runs no # kube-ovn, so a small pod CIDR must render there.