feat: add @immutable annotation emitting CEL XValidation rule#24
feat: add @immutable annotation emitting CEL XValidation rule#24lexfrei wants to merge 1 commit into
Conversation
|
Warning Rate limit exceeded
You’ve run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Code Review
This pull request introduces support for an @immutable annotation in OpenAPI definitions. It updates the parsing logic to recognize the tag, propagates the immutable state through the internal representation, and generates a Kubernetes XValidation marker (self == oldSelf) to enforce immutability during updates. Unit tests were added to verify both the parsing and the marker generation. I have no feedback to provide.
79a3bd9 to
1f2d405
Compare
A new `## @immutable` flag annotation in values.yaml marks a field as immutable-after-creation. cozyvalues-gen now: - parses the annotation alongside the existing @minimum/@maxLength/etc. constraint family; - carries it on Raw and Node via the new Immutable bool; - emits a kubebuilder validation marker `+kubebuilder:validation:XValidation:rule="self == oldSelf", message="<field> is immutable after creation"` on the generated Go field, which controller-gen translates into the standard x-kubernetes-validations entry on the CRD and, by passthrough, into the chart's values.schema.json. Three new tests pin the behaviour: - TestParseImmutable / TestParseImmutable_AbsentByDefault for the parser path; - TestGenerateImmutableMarker / TestGenerateImmutableMarker_NotEmittedByDefault for the Go-code emitter. Assisted-By: Claude <noreply@anthropic.com> Signed-off-by: Aleksei Sviridkin <f@lex.la>
1f2d405 to
0ce4f39
Compare
Summary
A new
## @immutableflag annotation in values.yaml marks a field as immutable-after-creation.cozyvalues-gen now:
@minimum/@maxLength/etc. constraint family.RawandNodevia a newImmutable boolfield.controller-gen translates that marker into the standard
x-kubernetes-validationsentry on the CRD; by passthrough it lands in the chart'svalues.schema.jsonas well.Why
I want the Cozystack UI to be able to mark immutable resource fields as read-only on edit forms. The decision was to use the schema as the source of truth — specifically the standard K8s
x-kubernetes-validationsCEL ruleself == oldSelf— rather than maintaining a hand-rolled mapping on the UI side. cozyvalues-gen is the canonical pipeline that produces that schema, so the annotation belongs here.Tests
Four new tests pin the behaviour:
TestParseImmutable/TestParseImmutable_AbsentByDefaultfor the parser path.TestGenerateImmutableMarker/TestGenerateImmutableMarker_NotEmittedByDefaultfor the Go-code emitter.Full suite is green:
Downstream
Two follow-up PRs depend on this:
storageClassand regenerate.