热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

【原创】k8s源码分析-----kubelet(6)statusManager

本文csdn博客链接:http:blog.csdn.netscrescentarticledetails51135307本文qq空间链接:http:user.qzone.qq.com


本文csdn博客链接:http://blog.csdn.net/screscent/article/details/51135307 本文qq空间链接:http://user.qzone.qq.com/29185807/blog/1460452530


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日

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


推荐阅读
author-avatar
榜榜爱打球
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有