为什么配置覆盖不起作用?
根据
https://github.com/kubernetes/client-go/blob/a432bd9ba7da427ae0a38a6889d72136bce4c4ea/tools/clientcmd/client_config.go#L57-L58
// ClientConfig is used to make it easy to get an api server client
type ClientConfig interface {
// RawConfig returns the merged result of all overrides
RawConfig() (clientcmdapi.Config, error)
RawConfig
应该返回带有覆盖的配置,但实际上并没有
https://github.com/kubernetes/client-go/blob/a432bd9ba7da427ae0a38a6889d72136bce4c4ea/tools/clientcmd/client_config.go#L122-L124
func (config *DirectClientConfig) RawConfig() (clientcmdapi.Config, error) {
return config.config, nil
}
只返回没有覆盖的配置。你可以在我的补丁中看到一个可能的解决方案
https://github.com/vvelikodny/kubernetes-client-go/pull/1/files
另外 AuthInfo 等的覆盖是如何工作的?覆盖仅接受单个 AuthInfo,而配置包含 AuthInfo 等的映射。
仅使用 context.AuthInfo(字符串)中提供的用户名键覆盖 AuthInfo。
https://github.com/kubernetes/client-go/blob/a432bd9ba7da427ae0a38a6889d72136bce4c4ea/tools/clientcmd/client_config.go#L424-L437
https://github.com/kubernetes/client-go/blob/a432bd9ba7da427ae0a38a6889d72136bce4c4ea/tools/clientcmd/client_config.go#L388-L394
// getAuthInfoName returns a string containing the current authinfo name for the current context,
// and a boolean indicating whether the default authInfo name is overwritten by a user-set flag, or
// left as its default value
func (config *DirectClientConfig) getAuthInfoName() (string, bool) {
if len(config.overrides.Context.AuthInfo) != 0 {
return config.overrides.Context.AuthInfo, true
}
context, _ := config.getContext()
return context.AuthInfo, false
}