From 4c3285554053b8b9f6f9d64a61fbe15530c9b8d3 Mon Sep 17 00:00:00 2001 From: Patrick Ohly Date: Mon, 4 Mar 2024 09:13:19 +0100 Subject: [PATCH] dra api: implement semver attribute value type This adds support for semantic version comparison to the CEL support in the "named resources" structured parameter model. For example, it can be used to check that an instance supports a certain API level. To minimize the risk, the new "semver" type is only defined in the CEL environment for DRA expressions, not in the base library. See https://github.com/kubernetes/kubernetes/pull/123664 for a PR which adds it to the base library. Validation of semver strings is done with the regular expression from semver.org. The actual evaluation at runtime then uses semver/v4. Kubernetes-commit: 42ee56f093133402ed860d4c5f54b049041386c9 --- applyconfigurations/internal/internal.go | 3 +++ .../resource/v1alpha2/namedresourcesattribute.go | 8 ++++++++ .../resource/v1alpha2/namedresourcesattributevalue.go | 9 +++++++++ 3 files changed, 20 insertions(+) diff --git a/applyconfigurations/internal/internal.go b/applyconfigurations/internal/internal.go index ca1f4952..2a3325a3 100644 --- a/applyconfigurations/internal/internal.go +++ b/applyconfigurations/internal/internal.go @@ -12022,6 +12022,9 @@ var schemaYAML = typed.YAMLObject(`types: - name: stringSlice type: namedType: io.k8s.api.resource.v1alpha2.NamedResourcesStringSlice + - name: version + type: + scalar: string - name: io.k8s.api.resource.v1alpha2.NamedResourcesFilter map: fields: diff --git a/applyconfigurations/resource/v1alpha2/namedresourcesattribute.go b/applyconfigurations/resource/v1alpha2/namedresourcesattribute.go index 43cd9044..d9545d05 100644 --- a/applyconfigurations/resource/v1alpha2/namedresourcesattribute.go +++ b/applyconfigurations/resource/v1alpha2/namedresourcesattribute.go @@ -90,3 +90,11 @@ func (b *NamedResourcesAttributeApplyConfiguration) WithStringSliceValue(value * b.StringSliceValue = value return b } + +// WithVersionValue sets the VersionValue field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the VersionValue field is set to the value of the last call. +func (b *NamedResourcesAttributeApplyConfiguration) WithVersionValue(value string) *NamedResourcesAttributeApplyConfiguration { + b.VersionValue = &value + return b +} diff --git a/applyconfigurations/resource/v1alpha2/namedresourcesattributevalue.go b/applyconfigurations/resource/v1alpha2/namedresourcesattributevalue.go index ad2c7e18..e0b19650 100644 --- a/applyconfigurations/resource/v1alpha2/namedresourcesattributevalue.go +++ b/applyconfigurations/resource/v1alpha2/namedresourcesattributevalue.go @@ -31,6 +31,7 @@ type NamedResourcesAttributeValueApplyConfiguration struct { IntSliceValue *NamedResourcesIntSliceApplyConfiguration `json:"intSlice,omitempty"` StringValue *string `json:"string,omitempty"` StringSliceValue *NamedResourcesStringSliceApplyConfiguration `json:"stringSlice,omitempty"` + VersionValue *string `json:"version,omitempty"` } // NamedResourcesAttributeValueApplyConfiguration constructs an declarative configuration of the NamedResourcesAttributeValue type for use with @@ -86,3 +87,11 @@ func (b *NamedResourcesAttributeValueApplyConfiguration) WithStringSliceValue(va b.StringSliceValue = value return b } + +// WithVersionValue sets the VersionValue field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the VersionValue field is set to the value of the last call. +func (b *NamedResourcesAttributeValueApplyConfiguration) WithVersionValue(value string) *NamedResourcesAttributeValueApplyConfiguration { + b.VersionValue = &value + return b +}