「连载」边缘计算(十八)02-21:边缘部分源码(源码分析篇)

(接上篇)

|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| k8s.io/Kubernetes/pkg/Kubelet/dockershim/docker_service.go |
| // NewdockerService creates a new `dockerService` struct. // NOTE: Anything passed to dockerService should be eventually handled in another way when we switch to running the shim as a different process. func NewdockerService(config *ClientConfig, podSandboxImage string, streamingConfig *streaming.Config, pluginSettings *NetworkPluginSettings, cgroupsName string, kubeCgroupDriver string, dockershimRootDir string, startLocalStreamingServer bool) (dockerService, error) { ... ds := &dockerService{ client: c, os: kubecontainer.RealOS{}, podSandboxImage: podSandboxImage, streamingRuntime: &streamingRuntime{ client: client, execHandler: &NativeExecHandler{}, }, containerManager: cm.NewContainerManager(cgroupsName, client), checkpointManager: checkpointManager, startLocalStreamingServer: startLocalStreamingServer, networkReady: make(map[string]bool), containerCleanupInfos: make(map[string]*containerCleanupInfo), } ... } |

从 NewdockerService()函数可以看出,dockershim的真身是dockerService struct。dockerService struct定义具体如下所示。

|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| k8s.io/Kubernetes/pkg/Kubelet/dockershim/docker_service.go |
| type dockerService struct { client libdocker.Interface os kubecontainer.OSInterface podSandboxImage string streamingRuntime *streamingRuntime streamingServer streaming.Server network *network.PluginManager // Map of podSandboxID :: network-is-ready networkReady map[string]bool networkReadyLock sync.Mutex containerManager cm.ContainerManager // cgroup driver used by docker runtime. cgroupDriver string checkpointManager checkpointmanager.CheckpointManager // caches the version of the runtime. // To be compatible with multiple docker versions, we need to perform // version checking for some operations. Use this cache to avoid querying // the docker daemon every time we need to do such checks. versionCache *cache.ObjectCache // startLocalStreamingServer indicates whether dockershim should start a // streaming server on localhost. startLocalStreamingServer bool // containerCleanupInfos maps container IDs to the `containerCleanupInfo` structs // needed to clean up after containers have been started or removed. // (see `applyPlatformSpecificdockerConfig` and `performPlatformSpecificContainerCleanup` // methods for more info). containerCleanupInfos map[string]*containerCleanupInfo } |

从dockerService的定义可以看出,大部分属性都是与container、pod、image相关的。我们从这些属性可以推测dockerService是与container runtime交互的一个组件。为了进一步验证猜想,可以在同一个文件中(k8s.io/Kubernetes/pkg/Kubelet/dockershim/docker_service.go)查看dockerService实现的方法。

以上只是剖析了edged的初始化过程。下面剖析edged的启动过程,具体如下所示。

|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| KubeEdge/edge/pkg/edged/edged.go |
| func (e *edged) Start(c *context.Context) { e.context = c e.metaClient = client.New(c) // use self defined client to replace fake kube client e.kubeClient = fakekube.NewSimpleClientset(e.metaClient) e.statusManager = status.NewManager(e.kubeClient, e.podManager, utilpod.NewpodDeleteSafety(), e.metaClient) if err := e.initializeModules(); err != nil { klog.Errorf("initialize module error: %v", err) os.Exit(1) } e.volumeManager = volumemanager.NewVolumeManager( ... ) go e.volumeManager.Run(edgedutil.NewSourcesReady(), utilwait.NeverStop) go utilwait.Until(e.syncNodeStatus, e.nodeStatusUpdateFrequency, utilwait.NeverStop) e.probeManager = prober.NewManager(e.statusManager, e.livenessManager, containers.NewContainerRunner(), kubecontainer.NewRefManager(), record.NewEventRecorder()) e.pleg = edgepleg.NewGenericLifecycleRemote(e.containerRuntime, e.probeManager, plegChannelCapacity, plegRelistPeriod, e.podManager, e.statusManager, e.podCache, clock.RealClock{}, e.interfaceName) e.statusManager.Start() e.pleg.Start() e.podAddWorkerRun(concurrentConsumers) e.podRemoveWorkerRun(concurrentConsumers) housekeepingTicker := time.NewTicker(housekeepingPeriod) syncWorkQueueCh := time.NewTicker(syncWorkQueuePeriod) e.probeManager.Start() go e.syncLoopIteration(e.pleg.Watch(), housekeepingTicker.C, syncWorkQueueCh.C) go e.server.ListenAndServe() e.imageGCManager.Start() e.StartGarbageCollection() e.pluginManager = pluginmanager.NewPluginManager( ... ) // Adding Registration Callback function for CSI Driver e.pluginManager.AddHandler(pluginwatcherapi.CSIPlugin, plugincache.PluginHandler(csiplugin.PluginHandler)) // Start the plugin manager go e.pluginManager.Run(edgedutil.NewSourcesReady(), utilwait.NeverStop) e.syncpod() } |

未完待续......

相关推荐
uncle_ll3 分钟前
PyTorch图像预处理:计算均值和方差以实现标准化
图像处理·人工智能·pytorch·均值算法·标准化
宋138102797203 分钟前
Manus Xsens Metagloves虚拟现实手套
人工智能·机器人·vr·动作捕捉
SEVEN-YEARS7 分钟前
深入理解TensorFlow中的形状处理函数
人工智能·python·tensorflow
世优科技虚拟人10 分钟前
AI、VR与空间计算:教育和文旅领域的数字转型力量
人工智能·vr·空间计算
cloud studio AI应用17 分钟前
腾讯云 AI 代码助手:产品研发过程的思考和方法论
人工智能·云计算·腾讯云
禁默28 分钟前
第六届机器人、智能控制与人工智能国际学术会议(RICAI 2024)
人工智能·机器人·智能控制
Robot25136 分钟前
浅谈,华为切入具身智能赛道
人工智能
只怕自己不够好40 分钟前
OpenCV 图像运算全解析:加法、位运算(与、异或)在图像处理中的奇妙应用
图像处理·人工智能·opencv
果冻人工智能2 小时前
2025 年将颠覆商业的 8 大 AI 应用场景
人工智能·ai员工
代码不行的搬运工2 小时前
神经网络12-Time-Series Transformer (TST)模型
人工智能·神经网络·transformer