Skip to content

Commit a9167e6

Browse files
committed
apis/nfd/validate: loosen validation of feature annotations
Don't require that the annotation value must conform to the (strict) requirements of label values. In the Kubernetes API annotation values do not have other restrictions than that the total size (keys and values) of _all_ annotations combined of an object must not exceed 256kB. This patch sets a maximum size limit of 1kB for the value of a single feature annotation created by NFD. This limit is rather arbitrary but should be enough for the NFD usage scenarios (until proven wrong).
1 parent 6b80f65 commit a9167e6

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

api/nfd/v1alpha1/annotations_labels.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,7 @@ const (
7474

7575
// FeatureAnnotationSubNsSuffix is the suffix for allowed feature annotation sub-namespaces.
7676
FeatureAnnotationSubNsSuffix = "." + FeatureAnnotationNs
77+
78+
// FeatureAnnotationValueSizeLimit is the maximum allowed length for the value of a feature annotation.
79+
FeatureAnnotationValueSizeLimit = 1 << 10
7780
)

pkg/apis/nfd/validate/validate.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,8 @@ func Annotation(key, value string) error {
155155
}
156156

157157
// Validate annotation value
158-
if errs := k8svalidation.IsValidLabelValue(value); len(errs) > 0 {
159-
return fmt.Errorf("invalid value %q: %s", value, strings.Join(errs, "; "))
158+
if len(value) > nfdv1alpha1.FeatureAnnotationValueSizeLimit {
159+
return fmt.Errorf("invalid value: too long: feature annotations must not be longer than %d characters", nfdv1alpha1.FeatureAnnotationValueSizeLimit)
160160
}
161161

162162
return nil

pkg/apis/nfd/validate/validate_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ func TestAnnotation(t *testing.T) {
2929
{
3030
name: "Invalid annotation value",
3131
key: "feature.node.kubernetes.io/feature",
32-
value: "invalid value",
33-
want: "invalid value \"invalid value\": ",
32+
value: string(make([]byte, 1100)),
33+
want: "invalid value: too long:",
3434
},
3535
{
3636
name: "Denied annotation key",

0 commit comments

Comments
 (0)