Skip to content

Commit

Permalink
dra api: enable new CEL features by faking their version
Browse files Browse the repository at this point in the history
There are two approaches for making new versioned CEL features available in the
release where they get introduced:
- Always use the environment for "StoredExpressions".
- Use an older version (typically 1.0) and only bump it up later.

The second approach was used before, so this is now also done here.
  • Loading branch information
pohly committed Mar 7, 2024
1 parent 7f5566a commit 6a361e1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
Expand Up @@ -149,16 +149,10 @@ func validateSelector(opts Options, selector string, fldPath *field.Path) field.
if selector == "" {
allErrs = append(allErrs, field.Required(fldPath, ""))
} else {
// TODO (https://github.com/kubernetes/kubernetes/issues/123687):
// when this API gets promoted to beta, we have to
// validate new and stored expressions differently.
// While it is alpha, new expressions are allowed to
// use everything that is currently available.
// envType := environment.NewExpressions
// if opts.StoredExpressions {
// envType = environment.StoredExpressions
// }
envType := environment.StoredExpressions
envType := environment.NewExpressions
if opts.StoredExpressions {
envType = environment.StoredExpressions
}
result := namedresourcescel.Compiler.CompileCELExpression(selector, envType)
if result.Error != nil {
allErrs = append(allErrs, convertCELErrorToValidationError(fldPath, selector, result.Error))
Expand Down
Expand Up @@ -187,7 +187,12 @@ func mustBuildEnv() *environment.EnvSet {
envset := environment.MustBaseEnvSet(environment.DefaultCompatibilityVersion())
versioned := []environment.VersionedOptions{
{
IntroducedVersion: version.MajorMinor(1, 30),
// Feature epoch was actually 1.30, but we artificially set it to 1.0 because these
// options should always be present.
//
// TODO (https://github.com/kubernetes/kubernetes/issues/123687): set this
// version properly before going to beta.
IntroducedVersion: version.MajorMinor(1, 0),
EnvOptions: append(buildVersionedAttributes(),
SemverLib(),
),
Expand Down

0 comments on commit 6a361e1

Please sign in to comment.