栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

《k8s 源码解析1 ---- 插件机制》

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

《k8s 源码解析1 ---- 插件机制》

插件定义:

用于执行目标明确的独立功能可执行文件,或任务触发。 例如:一个用于压缩日志的shell脚本,其它语言(python、c++、java、golang)可执行文件。

插件的实现方式:

exec函数组:

k8s中插件的实现方式:
// 显然,k8s中插件的实现方式有2个接口:查找可执行文件(的绝对路径)、与参数 环境变量一起调用exec函数组
// PluginHandler is capable of parsing command line arguments                                                                                                                                        
// and performing executable filename lookups to search                                                                                                                                              
// for valid plugin files, and execute found plugins.                                                                                                                                                
type PluginHandler interface {                                                                                                                                                                       
        // exists at the given filename, or a boolean false.                                                                                                                                         
        // Lookup will iterate over a list of given prefixes                                                                                                                                         
        // in order to recognize valid plugin filenames.                                                                                                                                             
        // The first filepath to match a prefix is returned.                                                                                                                                         
        Lookup(filename string) (string, bool)                                                                                                                                                       
        // Execute receives an executable's filepath, a slice                                                                                                                                        
        // of arguments, and a slice of environment variables                                                                                                                                        
        // to relay to the executable.                                                                                                                                                               
        Execute(executablePath string, cmdArgs, environment []string) error                                                                                                                          
}                                                                                                                                                                                                    
                                                                                                                                                                                                     
// DefaultPluginHandler implements PluginHandler                                                                                                                                                     
type DefaultPluginHandler struct {                                                                                                                                                                   
        ValidPrefixes []string        // (应用)插件的home目录,例如nginx的 /var/lib/nginx、/var/lib/jenkins                                                                                                                                                               
} 

k8s的在master分支中只有一个默认插件,做了简单的exec调用。 二次开发时,插件可以实现cmd.PluginHandler 接口的定义,实现目标功能。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/915976.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号