1
0
Fork 0
mirror of https://github.com/kubernetes-sigs/node-feature-discovery.git synced 2024-12-14 11:57:51 +00:00

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).
This commit is contained in:
Markus Lehtonen 2024-02-16 09:54:12 +02:00
parent 6b80f654d4
commit a9167e6875
3 changed files with 7 additions and 4 deletions

View file

@ -74,4 +74,7 @@ const (
// FeatureAnnotationSubNsSuffix is the suffix for allowed feature annotation sub-namespaces. // FeatureAnnotationSubNsSuffix is the suffix for allowed feature annotation sub-namespaces.
FeatureAnnotationSubNsSuffix = "." + FeatureAnnotationNs FeatureAnnotationSubNsSuffix = "." + FeatureAnnotationNs
// FeatureAnnotationValueSizeLimit is the maximum allowed length for the value of a feature annotation.
FeatureAnnotationValueSizeLimit = 1 << 10
) )

View file

@ -155,8 +155,8 @@ func Annotation(key, value string) error {
} }
// Validate annotation value // Validate annotation value
if errs := k8svalidation.IsValidLabelValue(value); len(errs) > 0 { if len(value) > nfdv1alpha1.FeatureAnnotationValueSizeLimit {
return fmt.Errorf("invalid value %q: %s", value, strings.Join(errs, "; ")) return fmt.Errorf("invalid value: too long: feature annotations must not be longer than %d characters", nfdv1alpha1.FeatureAnnotationValueSizeLimit)
} }
return nil return nil

View file

@ -29,8 +29,8 @@ func TestAnnotation(t *testing.T) {
{ {
name: "Invalid annotation value", name: "Invalid annotation value",
key: "feature.node.kubernetes.io/feature", key: "feature.node.kubernetes.io/feature",
value: "invalid value", value: string(make([]byte, 1100)),
want: "invalid value \"invalid value\": ", want: "invalid value: too long:",
}, },
{ {
name: "Denied annotation key", name: "Denied annotation key",