Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

apis/nfd/validate: loosen validation of feature annotations #1633

Merged
merged 2 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions api/nfd/v1alpha1/annotations_labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,7 @@ const (

// FeatureAnnotationSubNsSuffix is the suffix for allowed feature annotation sub-namespaces.
FeatureAnnotationSubNsSuffix = "." + FeatureAnnotationNs

// FeatureAnnotationValueSizeLimit is the maximum allowed length for the value of a feature annotation.
FeatureAnnotationValueSizeLimit = 1 << 10
)
6 changes: 3 additions & 3 deletions pkg/apis/nfd/validate/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func MatchFeatures(matchFeature nfdv1alpha1.FeatureMatcher) []error {
var validationErr []error

for _, match := range matchFeature {
nameSplit := strings.SplitN(match.Feature, ".", 2)
nameSplit := strings.Split(match.Feature, ".")
if len(nameSplit) != 2 {
validationErr = append(validationErr, fmt.Errorf("invalid feature name %v (not <domain>.<feature>), cannot be used for templating", match.Feature))
}
Expand Down Expand Up @@ -155,8 +155,8 @@ func Annotation(key, value string) error {
}

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

return nil
Expand Down
Loading