@@ -45,12 +45,14 @@ func (c *Config) AddRuntime(name string, path string, setAsDefault bool) error {
4545 config .SetPath ([]string {"plugins" , "io.containerd.grpc.v1.cri" , "containerd" , "runtimes" , name , "privileged_without_host_devices" }, false )
4646 }
4747
48- cdiAnnotations := []interface {}{"cdi.k8s.io/*" }
49- containerAnnotations , ok := config .GetPath ([]string {"plugins" , "io.containerd.grpc.v1.cri" , "containerd" , "runtimes" , name , "container_annotations" }).([]interface {})
50- if ok && containerAnnotations != nil {
51- cdiAnnotations = append (containerAnnotations , cdiAnnotations ... )
48+ if len (c .ContainerAnnotations ) > 0 {
49+ annotations , err := c .getRuntimeAnnotations ([]string {"plugins" , "io.containerd.grpc.v1.cri" , "containerd" , "runtimes" , name , "container_annotations" })
50+ if err != nil {
51+ return err
52+ }
53+ annotations = append (c .ContainerAnnotations , annotations ... )
54+ config .SetPath ([]string {"plugins" , "io.containerd.grpc.v1.cri" , "containerd" , "runtimes" , name , "container_annotations" }, annotations )
5255 }
53- config .SetPath ([]string {"plugins" , "io.containerd.grpc.v1.cri" , "containerd" , "runtimes" , name , "container_annotations" }, cdiAnnotations )
5456
5557 config .SetPath ([]string {"plugins" , "io.containerd.grpc.v1.cri" , "containerd" , "runtimes" , name , "options" , "BinaryName" }, path )
5658
@@ -62,6 +64,32 @@ func (c *Config) AddRuntime(name string, path string, setAsDefault bool) error {
6264 return nil
6365}
6466
67+ func (c * Config ) getRuntimeAnnotations (path []string ) ([]string , error ) {
68+ if c == nil || c .Tree == nil {
69+ return nil , nil
70+ }
71+
72+ config := * c .Tree
73+ if ! config .HasPath (path ) {
74+ return nil , nil
75+ }
76+ annotationsI , ok := config .GetPath (path ).([]interface {})
77+ if ! ok {
78+ return nil , fmt .Errorf ("invalid annotations: %v" , annotationsI )
79+ }
80+
81+ var annotations []string
82+ for _ , annotation := range annotationsI {
83+ a , ok := annotation .(string )
84+ if ! ok {
85+ return nil , fmt .Errorf ("invalid annotation: %v" , annotation )
86+ }
87+ annotations = append (annotations , a )
88+ }
89+
90+ return annotations , nil
91+ }
92+
6593// DefaultRuntime returns the default runtime for the cri-o config
6694func (c Config ) DefaultRuntime () string {
6795 if runtime , ok := c .GetPath ([]string {"plugins" , "io.containerd.grpc.v1.cri" , "containerd" , "default_runtime_name" }).(string ); ok {
0 commit comments