《k8s 源码解析1 ---- 插件机制》
插件定义:用于执行目标明确的独立功能可执行文件,或任务触发。例如:一个用于压缩日志的shell脚本,其它语言(python、c++、java、golang)可执行文件。插件的实现方式:exec函数组:k8s中插件的实现方式:// 显然,k8s中插件的实现方式有2个接口:查找可执行文件(的绝对路径)、与参数 环境变量一起调用exec函数组// PluginHandler is capable of
   ·  
 插件定义:
用于执行目标明确的独立功能可执行文件,或任务触发。 例如:一个用于压缩日志的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 接口的定义,实现目标功能。
更多推荐
 
 



所有评论(0)