@@ -242,7 +242,10 @@ func NewContainerHandler(name string, watchType watcher.ContainerWatchSource, me
242
242
defer factoriesLock .RUnlock ()
243
243
244
244
// Create the ContainerHandler with the first factory that supports it.
245
- for _ , factory := range factories [watchType ] {
245
+ // Note that since RawContainerHandler can support a wide range of paths,
246
+ // it's evaluated last just to make sure if any other ContainerHandler
247
+ // can support it.
248
+ for _ , factory := range GetReorderedFactoryList (watchType ) {
246
249
canHandle , canAccept , err := factory .CanHandleAndAccept (name )
247
250
if err != nil {
248
251
klog .V (4 ).Infof ("Error trying to work out if we can handle %s: %v" , name , err )
@@ -285,3 +288,26 @@ func DebugInfo() map[string][]string {
285
288
}
286
289
return out
287
290
}
291
+
292
+ // GetReorderedFactoryList returns the list of ContainerHandlerFactory where the
293
+ // RawContainerHandler is always the last element.
294
+ func GetReorderedFactoryList (watchType watcher.ContainerWatchSource ) []ContainerHandlerFactory {
295
+ ContainerHandlerFactoryList := make ([]ContainerHandlerFactory , 0 , len (factories ))
296
+
297
+ var rawFactory ContainerHandlerFactory
298
+ for _ , v := range factories [watchType ] {
299
+ if v != nil {
300
+ if v .String () == "raw" {
301
+ rawFactory = v
302
+ continue
303
+ }
304
+ ContainerHandlerFactoryList = append (ContainerHandlerFactoryList , v )
305
+ }
306
+ }
307
+
308
+ if rawFactory != nil {
309
+ ContainerHandlerFactoryList = append (ContainerHandlerFactoryList , rawFactory )
310
+ }
311
+
312
+ return ContainerHandlerFactoryList
313
+ }
0 commit comments