博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【原创】k8s源码分析-----kubelet(6)statusManager
阅读量:4032 次
发布时间:2019-05-24

本文共 1844 字,大约阅读时间需要 6 分钟。

 

本文csdn博客链接:

本文qq空间链接:

 

2.5、statusManager

1、构建与启动

 

代码在k8s.io\kubernetes\pkg\kubelet\kubelet.go中

func NewMainKubelet(

很简单,参数就是kubeclient,与apiserver连接的接口,就不再详细分析了。

 

我们再看下启动

// Run starts the kubelet reacting to config updates

func (kl *Kubelet) Run(updates <-chan PodUpdate) {

在Run中启动的

2、具体工作流程

代码在k8s.io\kubernetes\pkg\kubelet\status下

先NewManager

我们看看结构体

podStatuses:用于保存podstatus

podStatusChannel:用于模块间通信用

 

再看看对外暴露的接口

下面我们一个一个来进行解析

2.1 Start

// Start the API server status sync loop.

开启与api server的同步任务

开启了一个定时任务syncBatch

继续跟踪

从podStatusChannel中获取到请求请求任务

然后通过kubeclient获取最新的状态

获取到最新状态之后,进行更新,并判断是否terminated,再判断是否正在运行,没有这删除

最后,如果操作失败,则删除,等待下次操作。

2.2 GetPodStatus

// GetPodStatus returns the cached status for the provided pod UID,

    //as well as whether it was a cache hit.

这个很简单,直接从map中查找,返回结果

 

2.3 SetPodStatus

    // SetPodStatus caches updates the cached status for the given pod,

    //and triggers a status update.

更新caches,并触发状态更新

从caches(map)中查找,查找不到,则赋值启动时间

然后放入到caches(map)中,并通过podStatusChannel发布一个任务请求。这个将在start启动的同步任中获取到

 

2.4 TerminatePods

    // TerminatePods resets the container status for the provided pods

    //to terminated and triggers

    // a status update. This function may not enqueue all the provided pods,

    //in which case it will

    // return false

终止一个pod,并触发一个终止任务

设置pod的Terminated状态。然后通过podStatusChannel触发任务。如果发送失败则返回false,可以通过下次再一次尝试

 

2.5 DeletePodStatus

// DeletePodStatus simply removes the given pod from the status cache.

删除一个podstatus,主要是从caches(map)中删除

2.6 RemoveOrphanedStatuses

    // RemoveOrphanedStatuses scans the status cache and removes any entries

    //for pods not included in

    // the provided podUIDs.

也是一个删除操作,从caches(map)中删除

 

2.7 小结

statusManager功能单一,逻辑清晰,通过暴露接口向外提供操作。是典型的golang设计模式。

 

龚浩华

QQ 月牙寂 道长 29185807

2016年4月12日

(版权声明:本文为作者原创,如需转载请通知本人,并标明出处和作者。擅自转载的,保留追究其侵权的权利。)

 

如果你觉得本文对你有帮助,可以转到你的朋友圈,让更多人一起学习。

第一时间获取文章,可以关注本人公众号:月牙寂道长,也可以扫码关注

 

你可能感兴趣的文章
vsftp 配置具有匿名登录也有系统用户登录,系统用户有管理权限,匿名只有下载权限。
查看>>
linux安装usb wifi接收器
查看>>
关于共享单车定位不准问题
查看>>
终于搞定CString和string之间转换的问题了
查看>>
用防火墙自动拦截攻击IP
查看>>
补充自动屏蔽攻击ip
查看>>
谷歌走了
查看>>
多线程使用随机函数需要注意的一点
查看>>
getpeername,getsockname
查看>>
让我做你的下一行Code
查看>>
浅析:setsockopt()改善程序的健壮性
查看>>
关于对象赋值及返回临时对象过程中的构造与析构
查看>>
VS 2005 CRT函数的安全性增强版本
查看>>
SQL 多表联合查询
查看>>
Visual Studio 2010:C++0x新特性
查看>>
drwtsn32.exe和adplus.vbs进行dump文件抓取
查看>>
cppcheck c++静态代码检查
查看>>
CLOSE_WAIT和TIME_WAIT
查看>>
在C++中使用Lua
查看>>
在Dll中调用自身的位图资源
查看>>