@@ -155,7 +155,7 @@ type criService struct {
155155 // sandboxService is the sandbox related service for CRI
156156 sandboxService sandboxService
157157 // runtimeHandlers contains runtime handler info
158- runtimeHandlers [ ]* runtime.RuntimeHandler
158+ runtimeHandlers map [ string ]* runtime.RuntimeHandler
159159 // runtimeFeatures container runtime features info
160160 runtimeFeatures * runtime.RuntimeFeatures
161161}
@@ -198,6 +198,7 @@ func NewCRIService(options *CRIServiceOptions) (CRIService, runtime.RuntimeServi
198198 containerNameIndex : registrar .NewRegistrar (),
199199 netPlugin : make (map [string ]cni.CNI ),
200200 sandboxService : newCriSandboxService (& config , options .SandboxControllers ),
201+ runtimeHandlers : make (map [string ]* runtime.RuntimeHandler ),
201202 }
202203
203204 // TODO: Make discard time configurable
@@ -241,9 +242,11 @@ func NewCRIService(options *CRIServiceOptions) (CRIService, runtime.RuntimeServi
241242
242243 c .nri = nri .NewAPI (options .NRI , & criImplementation {c })
243244
244- c .runtimeHandlers , err = c .introspectRuntimeHandlers (ctx )
245- if err != nil {
246- return nil , nil , fmt .Errorf ("failed to introspect runtime handlers: %w" , err )
245+ intro := c .client .IntrospectionService ()
246+ for name , r := range c .config .Runtimes {
247+ if err := c .introspectRuntimeHandler (ctx , intro , name , r ); err != nil {
248+ return nil , nil , fmt .Errorf ("failed to introspect runtime %s: %w" , name , err )
249+ }
247250 }
248251
249252 c .runtimeFeatures = & runtime.RuntimeFeatures {
@@ -365,38 +368,36 @@ func (c *criService) IsInitialized() bool {
365368 return c .initialized .Load ()
366369}
367370
368- func (c * criService ) introspectRuntimeHandlers (ctx context.Context ) ([]* runtime.RuntimeHandler , error ) {
369- var res []* runtime.RuntimeHandler
370- intro := c .client .IntrospectionService ()
371- for name , r := range c .config .Runtimes {
372- h := runtime.RuntimeHandler {
373- Name : name ,
374- }
375- rawFeatures , err := introspectRuntimeFeatures (ctx , intro , r )
376- if err != nil {
377- log .G (ctx ).WithError (err ).Debugf ("failed to introspect features of runtime %q" , name )
378- } else {
379- h .Features = & runtime.RuntimeHandlerFeatures {}
380- if slices .Contains (rawFeatures .MountOptions , "rro" ) {
381- if kernelSupportsRRO {
382- log .G (ctx ).Debugf ("runtime %q supports recursive read-only mounts" , name )
383- h .Features .RecursiveReadOnlyMounts = true
384- } else {
385- log .G (ctx ).Debugf ("runtime %q supports recursive read-only mounts, but the kernel does not" , name )
386- }
371+ func (c * criService ) introspectRuntimeHandler (ctx context.Context , intro introspection.Service , name string , r config.Runtime ) error {
372+ h := & runtime.RuntimeHandler {
373+ Name : name ,
374+ }
375+ rawFeatures , err := introspectRuntimeFeatures (ctx , intro , r )
376+ if err != nil {
377+ log .G (ctx ).WithError (err ).Debugf ("failed to introspect features of runtime %q" , name )
378+ } else {
379+ h .Features = & runtime.RuntimeHandlerFeatures {}
380+ if slices .Contains (rawFeatures .MountOptions , "rro" ) {
381+ if kernelSupportsRRO {
382+ log .G (ctx ).Debugf ("runtime %q supports recursive read-only mounts" , name )
383+ h .Features .RecursiveReadOnlyMounts = true
384+ } else {
385+ log .G (ctx ).Debugf ("runtime %q supports recursive read-only mounts, but the kernel does not" , name )
387386 }
388- userns := supportsCRIUserns (rawFeatures )
389- h .Features .UserNamespaces = userns
390- log .G (ctx ).Debugf ("runtime %q supports CRI userns: %v" , name , userns )
391- }
392- res = append (res , & h )
393- if name == c .config .DefaultRuntimeName {
394- defH := h
395- defH .Name = "" // denotes default
396- res = append (res , & defH )
397387 }
388+ userns := supportsCRIUserns (rawFeatures )
389+ h .Features .UserNamespaces = userns
390+ log .G (ctx ).Debugf ("runtime %q supports CRI userns: %v" , name , userns )
398391 }
399- return res , nil
392+
393+ c .runtimeHandlers [name ] = h
394+ if name == c .config .DefaultRuntimeName {
395+ defH := * h
396+ defH .Name = "" // denotes default
397+ c .runtimeHandlers ["" ] = & defH
398+ }
399+
400+ return nil
400401}
401402
402403func introspectRuntimeFeatures (ctx context.Context , intro introspection.Service , r config.Runtime ) (* features.Features , error ) {
0 commit comments