File tree Expand file tree Collapse file tree 3 files changed +12
-18
lines changed Expand file tree Collapse file tree 3 files changed +12
-18
lines changed Original file line number Diff line number Diff line change @@ -20,11 +20,6 @@ import (
20
20
"errors"
21
21
"fmt"
22
22
"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"
28
23
)
29
24
30
25
const (
@@ -142,16 +137,3 @@ func AnnotationValue(devices []string) (string, error) {
142
137
143
138
return value , nil
144
139
}
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
19
19
import (
20
20
"fmt"
21
21
22
+ "github.com/container-orchestrated-devices/container-device-interface/internal/validation"
22
23
cdi "github.com/container-orchestrated-devices/container-device-interface/specs-go"
23
24
oci "github.com/opencontainers/runtime-spec/specs-go"
24
25
)
@@ -68,6 +69,13 @@ func (d *Device) validate() error {
68
69
if err := ValidateDeviceName (d .Name ); err != nil {
69
70
return err
70
71
}
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
+ }
71
79
edits := d .edits ()
72
80
if edits .isEmpty () {
73
81
return fmt .Errorf ("invalid device, empty device edits" )
Original file line number Diff line number Diff line change @@ -28,6 +28,7 @@ import (
28
28
oci "github.com/opencontainers/runtime-spec/specs-go"
29
29
"sigs.k8s.io/yaml"
30
30
31
+ "github.com/container-orchestrated-devices/container-device-interface/internal/validation"
31
32
cdi "github.com/container-orchestrated-devices/container-device-interface/specs-go"
32
33
)
33
34
@@ -219,6 +220,9 @@ func (s *Spec) validate() (map[string]*Device, error) {
219
220
if err := ValidateClassName (s .class ); err != nil {
220
221
return nil , err
221
222
}
223
+ if err := validation .ValidateSpecAnnotations (s .Kind , s .Annotations ); err != nil {
224
+ return nil , err
225
+ }
222
226
if err := s .edits ().Validate (); err != nil {
223
227
return nil , err
224
228
}
You can’t perform that action at this time.
0 commit comments