fix: default TPP paranoiaLevels so CRD applies#258
Merged
Conversation
The ParanoiaLevels struct gained an XValidation rule (self.detection >= self.blocking) in #251, but the field kept an empty default. The apiserver validates a schema node's structural default against its own CEL rules, and the default {} has no detection/blocking keys — so CRD registration fails with "no such key: detection" and kubectl apply of the CRD is rejected, breaking every branch's e2e "Prepare e2e" step. Set the field default to {blocking:1,detection:1} so it satisfies the rule (1 >= 1). Per-field defaults are unchanged and #251's rule still rejects inverted user-supplied values. CRD manifest regenerated. Closes #257
Add an envtest suite that installs the generated CRDs against a real apiserver and creates a defaulted TrafficProtectionPolicy. The apiserver validates a schema node's structural default against that node's own CEL rules at CRD registration, so an invalid default is rejected during envtest start — the fake client the rest of the suite uses never sees schema, defaults, or CEL, which is why the #257 regression went undetected. The suite skips when KUBEBUILDER_ASSETS is unset (plain go test) and runs under `make test`, which provisions the assets. Key checks: - TPP CRD installs and a policy created with only its required targetRef defaults paranoiaLevels to a pair satisfying detection>=blocking. - An inverted user-supplied pair is still rejected, so the default fix did not loosen the #251 rule it depends on. Part of #257.
yahyafakhroji
approved these changes
Jul 13, 2026
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.
Fixes #257.
Problem
The
trafficprotectionpoliciesCRD is rejected at apply time, sokubectl applyof the CRD fails and every branch's e2e "Prepare e2e" step goes red regardless of its own changes (e.g. #255):Root cause
Regression from #251 (fix for #250). It added a struct CEL rule on
ParanoiaLevels(self.detection >= self.blocking) but the field kept+kubebuilder:default={}. The apiserver validates a schema node's structural default against that node'sx-kubernetes-validations; the default{}has nodetection/blockingkeys (per-field defaults are not injected before the parent default is CEL-checked), soself.detectionis no such key and CRD registration fails.Fix
Set the field default to
{blocking:1,detection:1}so it satisfies1 >= 1. Per-field defaults are unchanged and #251's rule still rejects inverted user-supplied values. CRD manifest regenerated viamake manifests.Regression guard
Adds an envtest suite (
test/crd/) that installs the generated CRDs against a real apiserver and creates a defaulted TPP. The whole suite uses the fake client, which never sees schema/defaults/CEL — that is exactly why #251 slipped through. envtest reproduces the apiserver's default-vs-CEL validation, so an invalid default fails at CRD install. Verified: reverting the default to{}fails the suite with the exact error above.paranoiaLevelsto{blocking:1,detection:1}.blocking:3,detection:1) is still rejected, so the default fix did not loosen fix: reject inverted TrafficProtectionPolicy paranoia levels at admission #251's rule.KUBEBUILDER_ASSETSis unset; runs undermake test.