@@ -266,6 +266,10 @@ type Dependencies struct {
266
266
KubeletConfigController * kubeletconfig.Controller
267
267
RemoteRuntimeService internalapi.RuntimeService
268
268
RemoteImageService internalapi.ImageManagerService
269
+ criHandler http.Handler
270
+ dockerLegacyService dockershim.DockerLegacyService
271
+ // remove it after cadvisor.UsingLegacyCadvisorStats dropped.
272
+ useLegacyCadvisorStats bool
269
273
}
270
274
271
275
// makePodSourceConfig creates a config.PodConfig from the given
@@ -319,13 +323,90 @@ func makePodSourceConfig(kubeCfg *kubeletconfiginternal.KubeletConfiguration, ku
319
323
return cfg , nil
320
324
}
321
325
326
+ // PreInitRuntimeService will init runtime service before RunKubelet.
327
+ func PreInitRuntimeService (kubeCfg * kubeletconfiginternal.KubeletConfiguration ,
328
+ kubeDeps * Dependencies ,
329
+ crOptions * config.ContainerRuntimeOptions ,
330
+ containerRuntime string ,
331
+ runtimeCgroups string ,
332
+ remoteRuntimeEndpoint string ,
333
+ remoteImageEndpoint string ,
334
+ nonMasqueradeCIDR string ) error {
335
+ if remoteRuntimeEndpoint != "" {
336
+ // remoteImageEndpoint is same as remoteRuntimeEndpoint if not explicitly specified
337
+ if remoteImageEndpoint == "" {
338
+ remoteImageEndpoint = remoteRuntimeEndpoint
339
+ }
340
+ }
341
+
342
+ switch containerRuntime {
343
+ case kubetypes .DockerContainerRuntime :
344
+ // TODO: These need to become arguments to a standalone docker shim.
345
+ pluginSettings := dockershim.NetworkPluginSettings {
346
+ HairpinMode : kubeletconfiginternal .HairpinMode (kubeCfg .HairpinMode ),
347
+ NonMasqueradeCIDR : nonMasqueradeCIDR ,
348
+ PluginName : crOptions .NetworkPluginName ,
349
+ PluginConfDir : crOptions .CNIConfDir ,
350
+ PluginBinDirString : crOptions .CNIBinDir ,
351
+ PluginCacheDir : crOptions .CNICacheDir ,
352
+ MTU : int (crOptions .NetworkPluginMTU ),
353
+ }
354
+
355
+ // Create and start the CRI shim running as a grpc server.
356
+ streamingConfig := getStreamingConfig (kubeCfg , kubeDeps , crOptions )
357
+ ds , err := dockershim .NewDockerService (kubeDeps .DockerClientConfig , crOptions .PodSandboxImage , streamingConfig ,
358
+ & pluginSettings , runtimeCgroups , kubeCfg .CgroupDriver , crOptions .DockershimRootDirectory , ! crOptions .RedirectContainerStreaming )
359
+ if err != nil {
360
+ return err
361
+ }
362
+ if crOptions .RedirectContainerStreaming {
363
+ kubeDeps .criHandler = ds
364
+ }
365
+
366
+ // The unix socket for kubelet <-> dockershim communication, dockershim start before runtime service init.
367
+ klog .V (5 ).Infof ("RemoteRuntimeEndpoint: %q, RemoteImageEndpoint: %q" ,
368
+ remoteRuntimeEndpoint ,
369
+ remoteImageEndpoint )
370
+ klog .V (2 ).Infof ("Starting the GRPC server for the docker CRI shim." )
371
+ dockerServer := dockerremote .NewDockerServer (remoteRuntimeEndpoint , ds )
372
+ if err := dockerServer .Start (); err != nil {
373
+ return err
374
+ }
375
+
376
+ // Create dockerLegacyService when the logging driver is not supported.
377
+ supported , err := ds .IsCRISupportedLogDriver ()
378
+ if err != nil {
379
+ return err
380
+ }
381
+ if ! supported {
382
+ kubeDeps .dockerLegacyService = ds
383
+ }
384
+ case kubetypes .RemoteContainerRuntime :
385
+ // No-op.
386
+ break
387
+ default :
388
+ return fmt .Errorf ("unsupported CRI runtime: %q" , containerRuntime )
389
+ }
390
+
391
+ var err error
392
+ if kubeDeps .RemoteRuntimeService , err = remote .NewRemoteRuntimeService (remoteRuntimeEndpoint , kubeCfg .RuntimeRequestTimeout .Duration ); err != nil {
393
+ return err
394
+ }
395
+ if kubeDeps .RemoteImageService , err = remote .NewRemoteImageService (remoteImageEndpoint , kubeCfg .RuntimeRequestTimeout .Duration ); err != nil {
396
+ return err
397
+ }
398
+
399
+ kubeDeps .useLegacyCadvisorStats = cadvisor .UsingLegacyCadvisorStats (containerRuntime , remoteRuntimeEndpoint )
400
+
401
+ return nil
402
+ }
403
+
322
404
// NewMainKubelet instantiates a new Kubelet object along with all the required internal modules.
323
405
// No initialization of Kubelet and its modules should happen here.
324
406
func NewMainKubelet (kubeCfg * kubeletconfiginternal.KubeletConfiguration ,
325
407
kubeDeps * Dependencies ,
326
408
crOptions * config.ContainerRuntimeOptions ,
327
409
containerRuntime string ,
328
- runtimeCgroups string ,
329
410
hostnameOverride string ,
330
411
nodeIP string ,
331
412
providerID string ,
@@ -335,8 +416,6 @@ func NewMainKubelet(kubeCfg *kubeletconfiginternal.KubeletConfiguration,
335
416
registerNode bool ,
336
417
registerWithTaints []api.Taint ,
337
418
allowedUnsafeSysctls []string ,
338
- remoteRuntimeEndpoint string ,
339
- remoteImageEndpoint string ,
340
419
experimentalMounterPath string ,
341
420
experimentalKernelMemcgNotification bool ,
342
421
experimentalCheckNodeCapabilitiesBeforeMount bool ,
@@ -346,7 +425,6 @@ func NewMainKubelet(kubeCfg *kubeletconfiginternal.KubeletConfiguration,
346
425
maxContainerCount int32 ,
347
426
masterServiceNamespace string ,
348
427
registerSchedulable bool ,
349
- nonMasqueradeCIDR string ,
350
428
keepTerminatedPodVolumes bool ,
351
429
nodeLabels map [string ]string ,
352
430
seccompProfileRoot string ,
@@ -589,82 +667,11 @@ func NewMainKubelet(kubeCfg *kubeletconfiginternal.KubeletConfiguration,
589
667
590
668
klet .statusManager = status .NewManager (klet .kubeClient , klet .podManager , klet )
591
669
592
- if remoteRuntimeEndpoint != "" {
593
- // remoteImageEndpoint is same as remoteRuntimeEndpoint if not explicitly specified
594
- if remoteImageEndpoint == "" {
595
- remoteImageEndpoint = remoteRuntimeEndpoint
596
- }
597
- }
598
-
599
- // TODO: These need to become arguments to a standalone docker shim.
600
- pluginSettings := dockershim.NetworkPluginSettings {
601
- HairpinMode : kubeletconfiginternal .HairpinMode (kubeCfg .HairpinMode ),
602
- NonMasqueradeCIDR : nonMasqueradeCIDR ,
603
- PluginName : crOptions .NetworkPluginName ,
604
- PluginConfDir : crOptions .CNIConfDir ,
605
- PluginBinDirString : crOptions .CNIBinDir ,
606
- PluginCacheDir : crOptions .CNICacheDir ,
607
- MTU : int (crOptions .NetworkPluginMTU ),
608
- }
609
-
610
670
klet .resourceAnalyzer = serverstats .NewResourceAnalyzer (klet , kubeCfg .VolumeStatsAggPeriod .Duration )
611
671
612
- // if left at nil, that means it is unneeded
613
- var legacyLogProvider kuberuntime.LegacyLogProvider
614
-
615
- switch containerRuntime {
616
- case kubetypes .DockerContainerRuntime :
617
- // Create and start the CRI shim running as a grpc server.
618
- streamingConfig := getStreamingConfig (kubeCfg , kubeDeps , crOptions )
619
- ds , err := dockershim .NewDockerService (kubeDeps .DockerClientConfig , crOptions .PodSandboxImage , streamingConfig ,
620
- & pluginSettings , runtimeCgroups , kubeCfg .CgroupDriver , crOptions .DockershimRootDirectory , ! crOptions .RedirectContainerStreaming )
621
- if err != nil {
622
- return nil , err
623
- }
624
- if crOptions .RedirectContainerStreaming {
625
- klet .criHandler = ds
626
- }
627
-
628
- // The unix socket for kubelet <-> dockershim communication.
629
- klog .V (5 ).Infof ("RemoteRuntimeEndpoint: %q, RemoteImageEndpoint: %q" ,
630
- remoteRuntimeEndpoint ,
631
- remoteImageEndpoint )
632
- klog .V (2 ).Infof ("Starting the GRPC server for the docker CRI shim." )
633
- server := dockerremote .NewDockerServer (remoteRuntimeEndpoint , ds )
634
- if err := server .Start (); err != nil {
635
- return nil , err
636
- }
637
-
638
- // Create dockerLegacyService when the logging driver is not supported.
639
- supported , err := ds .IsCRISupportedLogDriver ()
640
- if err != nil {
641
- return nil , err
642
- }
643
- if ! supported {
644
- klet .dockerLegacyService = ds
645
- legacyLogProvider = ds
646
- }
647
- case kubetypes .RemoteContainerRuntime :
648
- // No-op.
649
- break
650
- default :
651
- return nil , fmt .Errorf ("unsupported CRI runtime: %q" , containerRuntime )
652
- }
653
-
654
- runtimeService , imageService := kubeDeps .RemoteRuntimeService , kubeDeps .RemoteImageService
655
- if runtimeService == nil {
656
- runtimeService , err = remote .NewRemoteRuntimeService (remoteRuntimeEndpoint , kubeCfg .RuntimeRequestTimeout .Duration )
657
- if err != nil {
658
- return nil , err
659
- }
660
- }
661
- if imageService == nil {
662
- imageService , err = remote .NewRemoteImageService (remoteImageEndpoint , kubeCfg .RuntimeRequestTimeout .Duration )
663
- if err != nil {
664
- return nil , err
665
- }
666
- }
667
- klet .runtimeService = runtimeService
672
+ klet .dockerLegacyService = kubeDeps .dockerLegacyService
673
+ klet .criHandler = kubeDeps .criHandler
674
+ klet .runtimeService = kubeDeps .RemoteRuntimeService
668
675
669
676
if utilfeature .DefaultFeatureGate .Enabled (features .RuntimeClass ) && kubeDeps .KubeClient != nil {
670
677
klet .runtimeClassManager = runtimeclass .NewManager (kubeDeps .KubeClient )
@@ -687,10 +694,10 @@ func NewMainKubelet(kubeCfg *kubeletconfiginternal.KubeletConfiguration,
687
694
int (kubeCfg .RegistryBurst ),
688
695
kubeCfg .CPUCFSQuota ,
689
696
kubeCfg .CPUCFSQuotaPeriod ,
690
- runtimeService ,
691
- imageService ,
697
+ kubeDeps . RemoteRuntimeService ,
698
+ kubeDeps . RemoteImageService ,
692
699
kubeDeps .ContainerManager .InternalContainerLifecycle (),
693
- legacyLogProvider ,
700
+ kubeDeps . dockerLegacyService ,
694
701
klet .runtimeClassManager ,
695
702
)
696
703
if err != nil {
@@ -706,7 +713,7 @@ func NewMainKubelet(kubeCfg *kubeletconfiginternal.KubeletConfiguration,
706
713
}
707
714
klet .runtimeCache = runtimeCache
708
715
709
- if cadvisor . UsingLegacyCadvisorStats ( containerRuntime , remoteRuntimeEndpoint ) {
716
+ if kubeDeps . useLegacyCadvisorStats {
710
717
klet .StatsProvider = stats .NewCadvisorStatsProvider (
711
718
klet .cadvisor ,
712
719
klet .resourceAnalyzer ,
@@ -720,8 +727,8 @@ func NewMainKubelet(kubeCfg *kubeletconfiginternal.KubeletConfiguration,
720
727
klet .resourceAnalyzer ,
721
728
klet .podManager ,
722
729
klet .runtimeCache ,
723
- runtimeService ,
724
- imageService ,
730
+ kubeDeps . RemoteRuntimeService ,
731
+ kubeDeps . RemoteImageService ,
725
732
stats .NewLogMetricsService (),
726
733
kubecontainer.RealOS {})
727
734
}
0 commit comments