dra api: enable new CEL features by faking their version

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.
This commit is contained in:
Patrick Ohly 2024-03-07 18:44:17 +01:00
parent 7f5566ac6f
commit 6a361e1f36
2 changed files with 10 additions and 11 deletions

View File

@ -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))

View File

@ -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(),
),