File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -20,11 +20,6 @@ import (
2020 "errors"
2121 "fmt"
2222 "strings"
23-
24- "github.com/container-orchestrated-devices/container-device-interface/internal/multierror"
25- "k8s.io/apimachinery/pkg/api/validation"
26- "k8s.io/apimachinery/pkg/api/validation/field"
27- "k8s.io/apimachinery/pkg/util/validation/field"
2823)
2924
3025const (
@@ -142,16 +137,3 @@ func AnnotationValue(devices []string) (string, error) {
142137
143138 return value , nil
144139}
145-
146- // ValidateSpecAnnotations checks whether spec annotations are valid.
147- func ValidateSpecAnnotations (name string , annotations map [string ]string ) error {
148- fldErrorList := validation .ValidateAnnotations (annotations , field .NewPath (name , "annotations" ))
149- if len (fldErrorList ) > 0 {
150- err := multierror .New ()
151- for _ , e := range fldErrorList {
152- err = multierror .Append (err , e )
153- }
154- return err
155- }
156- return nil
157- }
Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ package cdi
1919import (
2020 "fmt"
2121
22+ "github.com/container-orchestrated-devices/container-device-interface/internal/validation"
2223 cdi "github.com/container-orchestrated-devices/container-device-interface/specs-go"
2324 oci "github.com/opencontainers/runtime-spec/specs-go"
2425)
@@ -68,6 +69,13 @@ func (d *Device) validate() error {
6869 if err := ValidateDeviceName (d .Name ); err != nil {
6970 return err
7071 }
72+ name := d .Name
73+ if d .spec != nil {
74+ name = d .GetQualifiedName ()
75+ }
76+ if err := validation .ValidateSpecAnnotations (name , d .Annotations ); err != nil {
77+ return err
78+ }
7179 edits := d .edits ()
7280 if edits .isEmpty () {
7381 return fmt .Errorf ("invalid device, empty device edits" )
Original file line number Diff line number Diff line change @@ -28,6 +28,7 @@ import (
2828 oci "github.com/opencontainers/runtime-spec/specs-go"
2929 "sigs.k8s.io/yaml"
3030
31+ "github.com/container-orchestrated-devices/container-device-interface/internal/validation"
3132 cdi "github.com/container-orchestrated-devices/container-device-interface/specs-go"
3233)
3334
@@ -219,6 +220,9 @@ func (s *Spec) validate() (map[string]*Device, error) {
219220 if err := ValidateClassName (s .class ); err != nil {
220221 return nil , err
221222 }
223+ if err := validation .ValidateSpecAnnotations (s .Kind , s .Annotations ); err != nil {
224+ return nil , err
225+ }
222226 if err := s .edits ().Validate (); err != nil {
223227 return nil , err
224228 }
You can’t perform that action at this time.
0 commit comments