Skip to content

Commit 624c02e

Browse files
authored
Merge pull request #1633 from marquiz/devel/validate-tests
apis/nfd/validate: loosen validation of feature annotations
2 parents 86a3817 + 7fbada8 commit 624c02e

File tree

3 files changed

+408
-10
lines changed

3 files changed

+408
-10
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: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func MatchFeatures(matchFeature nfdv1alpha1.FeatureMatcher) []error {
5757
var validationErr []error
5858

5959
for _, match := range matchFeature {
60-
nameSplit := strings.SplitN(match.Feature, ".", 2)
60+
nameSplit := strings.Split(match.Feature, ".")
6161
if len(nameSplit) != 2 {
6262
validationErr = append(validationErr, fmt.Errorf("invalid feature name %v (not <domain>.<feature>), cannot be used for templating", match.Feature))
6363
}
@@ -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

0 commit comments

Comments
 (0)