Skip to content

Commit 0a349fb

Browse files
pohlyk8s-publishing-bot
authored andcommitted
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 kubernetes/kubernetes#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
1 parent 7c2e521 commit 0a349fb

File tree

7 files changed

+201
-154
lines changed

7 files changed

+201
-154
lines changed

resource/v1alpha2/generated.pb.go

Lines changed: 188 additions & 141 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

resource/v1alpha2/generated.proto

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

resource/v1alpha2/namedresources.go

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ type NamedResourcesAttributeValue struct {
7070
StringValue *string `json:"string,omitempty" protobuf:"bytes,5,opt,name=string"`
7171
// StringSliceValue is an array of strings.
7272
StringSliceValue *NamedResourcesStringSlice `json:"stringSlice,omitempty" protobuf:"bytes,9,rep,name=stringSlice"`
73-
// TODO: VersionValue *SemVersion `json:"version,omitempty" protobuf:"bytes,7,opt,name=version"`
73+
// VersionValue is a semantic version according to semver.org spec 2.0.0.
74+
VersionValue *string `json:"version,omitempty" protobuf:"bytes,10,opt,name=version"`
7475
}
7576

7677
// NamedResourcesIntSlice contains a slice of 64-bit integers.
@@ -89,17 +90,6 @@ type NamedResourcesStringSlice struct {
8990
Strings []string `json:"strings" protobuf:"bytes,1,opt,name=strings"`
9091
}
9192

92-
// TODO
93-
//
94-
// A wrapper around https://pkg.go.dev/github.com/blang/semver/v4#Version which
95-
// is encoded as a string. During decoding, it validates that the string
96-
// can be parsed using tolerant parsing (currently trims spaces, removes a "v" prefix,
97-
// adds a 0 patch number to versions with only major and minor components specified,
98-
// and removes leading 0s).
99-
// type NamedResourcesSemVersion struct {
100-
// semver.Version
101-
//}
102-
10393
// NamedResourcesRequest is used in ResourceRequestModel.
10494
type NamedResourcesRequest struct {
10595
// Selector is a CEL expression which must evaluate to true if a

resource/v1alpha2/zz_generated.deepcopy.go

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

testdata/HEAD/resource.k8s.io.v1alpha2.NodeResourceSlice.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@
6565
"strings": [
6666
"stringsValue"
6767
]
68-
}
68+
},
69+
"version": "versionValue"
6970
}
7071
]
7172
}
14 Bytes
Binary file not shown.

testdata/HEAD/resource.k8s.io.v1alpha2.NodeResourceSlice.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,6 @@ namedResources:
4747
stringSlice:
4848
strings:
4949
- stringsValue
50+
version: versionValue
5051
name: nameValue
5152
nodeName: nodeNameValue

0 commit comments

Comments
 (0)