fix(platform): validate the cozyplane variant's networking inputs

An empty networking.podCIDR rendered an empty egress.clusterCIDR, which
silently drops the agent's masquerade and the controller's internal
denies; a non-IPv4 serviceCIDR made the clusterDNS octet derivation die
with an index error that names no field. Refuse both legibly: the
variant requires podCIDR and serviceCIDR, and a service CIDR the
derivation cannot read requires an explicit networking.clusterDNS.

Assisted-by: LLM
Signed-off-by: Timofei Larkin <lllamnyp@gmail.com>
This commit is contained in:
Timofei Larkin committed 2026-11-19 12:04:16 +01:00
1 parent f0d1a802f0
commit 296ce0bf7f
2 files changed
+58 -9

No files matched your search

@@ -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. */ -}}
@@ -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.