前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >k8s源码分析-----kubelet(6)statusManager

k8s源码分析-----kubelet(6)statusManager

作者头像
月牙寂道长
修改2018-04-03 11:48:00
1.1K0
修改2018-04-03 11:48:00
举报
文章被收录于专栏:月牙寂月牙寂

说明:此文章为腾讯云机器自动从本人csdn博客搬迁过来。是本人授权操作。

申明:无本人授权,不可转载本文。如有转载,本人保留追究其法律责任的权利。

龚浩华,QQ 29185807,月牙寂 道长

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

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设计模式。

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2016年04月12日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 2.5、statusManager
    • 1、构建与启动
      • 2、具体工作流程
        • 2.1 Start
        • 2.2 GetPodStatus
        • 2.3 SetPodStatus
        • 2.4 TerminatePods
        • 2.5 DeletePodStatus
        • 2.6 RemoveOrphanedStatuses
        • 2.7 小结
    领券
    问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档