fix(crd): make vlanInterfaces item validation actually take effect - #7108
Draft
oilbeater wants to merge 1 commit into
Draft
fix(crd): make vlanInterfaces item validation actually take effect#7108oilbeater wants to merge 1 commit into
oilbeater wants to merge 1 commit into
Conversation
The `+kubebuilder:validation:Items={Type=string,Pattern=...}` marker on
ProviderNetwork.Spec.VlanInterfaces is not a marker controller-gen knows,
so it was silently dropped: the generated CRD carried a bare
`items: {type: string}` with no constraint at all. Any string could be
stored in the field, and daemon just logs a warning and skips entries it
cannot parse, so a typo was invisible to the user.
The pattern itself was also wrong. Inside a Go raw string literal `\\.`
is a literal backslash followed by any character, not an escaped dot, so
the expression rejected every legal value such as `eth0.10` — fixing only
the marker name would have turned a no-op into a regression.
Use the `items:` marker prefix that controller-gen supports, with the dot
escaped once, and cap the length at IFNAMSIZ-1 like the other interface
name fields. The pattern matches exactly what the daemon accepts: it
splits the name on the first dot and derives the VLAN ID from the
suffix (pkg/daemon/controller.go, pkg/daemon/ovs_linux.go).
Verified against the regenerated CRD: `eth0.10`, `bond0.4094`,
`enp1s0f0.100`, `eth-0.1` and `eth_0.4094` are accepted; `eth0`,
`vlan100`, `eth0.10.20`, `eth0.99999`, `.10` and `eth0.` are rejected.
Signed-off-by: Mengxin Liu <liumengxinfly@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
ProviderNetwork.Spec.VlanInterfacescarried this marker:// +kubebuilder:validation:Items={Type=string,Pattern=`^[a-zA-Z0-9_-]+\\.[0-9]{1,4}$`}Items={...}is not a marker controller-gen recognises, so it was silentlydropped. The generated CRD ships a bare
items: {type: string}— the fieldaccepts any string today.
The pattern was wrong too: inside a Go raw string literal
\\.is a literalbackslash followed by any character, not an escaped dot, so the expression
rejects every legal value such as
eth0.10. Fixing only the marker namewould have turned a silent no-op into a hard regression — worth knowing for
anyone reviewing similar markers.
Change
Use the
items:marker prefix controller-gen supports, escape the dot once,and cap the length at
IFNAMSIZ-1to matchdefaultInterfaceandcustomInterfaces[].interface:Regenerated CRDs via
make gen-crd(charts v1/v2 +install.sh).Why this shape
The pattern encodes exactly what the daemon accepts.
createVlanSubinterfacessplits the name on the first dot and requires the parent to match the provider
network's default interface, and
ExtractVlanIDFromInterfacederives the VLANID from the suffix. A name the daemon cannot parse is only reported as a
klog.Warningfand then skipped, so today a typo in this field is invisible tothe user — the resource is accepted and the interface is silently never
programmed.
Validation
Checked against the regenerated schema:
eth0.10,bond0.4094,enp1s0f0.100,eth-0.1,eth_0.4094eth0,vlan100,eth0.10.20,eth0.99999,.10,eth0.make lint(includesverify-crd) passes with 0 issues;go build ./...andgo test ./pkg/util/...pass.Compatibility
Existing
ProviderNetworkresources that already hold a value the daemonaccepts stay valid — the pattern is strictly narrower than "any string" but
strictly wider than what the daemon has ever been able to program. A resource
holding an unparseable name (which never worked) will be rejected on its next
update.
🤖 Generated with Claude Code