feat(validation): add oldSelf support to x-deckhouse-validations CEL rules#764
Merged
Conversation
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.
Summary
Adds
oldSelftransition-rule support tox-deckhouse-validationsCEL expressions, mirroring the semantics ofx-kubernetes-validationsin Kubernetes CRD validation.Previously, CEL rules in module schemas could only inspect the current value (
self). This change threads the previous value through the entire validation stack so that rules can also referenceoldSelfto implement update-time invariants — most notably immutability constraints onModuleConfigfields.Changes
pkg/values/validation/cel/cel.goValidateto a thin wrapper; introducedValidateTransition(schema, values, oldValues)as the main entry point.oldSelfis bound as a CEL variable at each schema level and resolved recursively by matching property names in the old value map.oldSelfare detected via AST traversal (expressionUsesOldSelf) and skipped when no previous value exists at that schema level (create path or newly added subtrees). This preventsoldSelf-referencing rules from failing on initial creation.pkg/values/validation/schemas.goValidateTransition,ValidateConfigValuesTransition,ValidateValuesTransition, andValidateModuleHelmValuesTransitiononSchemaStorage.Validatenow delegates toValidateTransition(…, nil), keeping all existing callers working without changes.validateObjectaccepts an optionaloldDataObjand passes it tocel.ValidateTransition.pkg/module_manager/models/modules/values_storage.govalidateConfigValuesnow callsValidateConfigValuesTransition, passing the currently storedconfigValuesas the old state.validateValuesnow callsValidateValuesTransition, passing the currently mergedresultValuesas the old state.pkg/values/validation/cel/cel_test.go(new)Full test suite covering:
oldSelf-only rules skipped on createoldSelfrules fire correctly on updateoldSelfinside CEL macros/comprehensions (e.g.all(x, x in oldSelf.items))ValidatewrapperUsage example