From 6a361e1f36404e053eadc09e2e23c3ac3e62c8fa Mon Sep 17 00:00:00 2001 From: Patrick Ohly Date: Thu, 7 Mar 2024 18:44:17 +0100 Subject: [PATCH] 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. --- .../namedresources/validation/validation.go | 14 ++++---------- .../structured/namedresources/cel/compile.go | 7 ++++++- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/pkg/apis/resource/structured/namedresources/validation/validation.go b/pkg/apis/resource/structured/namedresources/validation/validation.go index 92748c4edc82..755507c8e86c 100644 --- a/pkg/apis/resource/structured/namedresources/validation/validation.go +++ b/pkg/apis/resource/structured/namedresources/validation/validation.go @@ -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)) diff --git a/staging/src/k8s.io/dynamic-resource-allocation/structured/namedresources/cel/compile.go b/staging/src/k8s.io/dynamic-resource-allocation/structured/namedresources/cel/compile.go index b61f1eacd4ce..755dcbff10b7 100644 --- a/staging/src/k8s.io/dynamic-resource-allocation/structured/namedresources/cel/compile.go +++ b/staging/src/k8s.io/dynamic-resource-allocation/structured/namedresources/cel/compile.go @@ -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(), ),