Hed*_*dge 5 go kubernetes kubernetes-go-client
我想使用 Kubernetes Go 客户端在集群中执行各种操作。我正在加载kubeconfig包含多个集群和上下文的本地。默认上下文是prod,我要覆盖的配置值之一是CurrentContext
clientConfig := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(
&clientcmd.ClientConfigLoadingRules{ExplicitPath: "/Users/me/.kube/config"},
&clientcmd.ConfigOverrides{
CurrentContext: "stage",
})
rawConfig, _ := clientConfig.RawConfig()
log.Printf(rawConfig.CurrentContext) // outputs "prod" instead of "stage"
Run Code Online (Sandbox Code Playgroud)
当我检查 RawConfig()当前上下文时,仍然是“prod”而不是“stage”。为什么配置覆盖不起作用?
AuthInfo 等的覆盖如何工作?覆盖只接受一个,AuthInfo而配置包含一个映射AuthInfo。
GitHub 相关问题https://github.com/kubernetes/client-go/issues/735
为什么配置覆盖不起作用?
根据
// 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)
Run Code Online (Sandbox Code Playgroud)
RawConfig应该返回带有覆盖的配置,但实际上没有
func (config *DirectClientConfig) RawConfig() (clientcmdapi.Config, error) {
return config.config, nil
}
Run Code Online (Sandbox Code Playgroud)
只需返回配置而不覆盖。您可以在我的补丁中看到可能的解决方案
https://github.com/vvelikodny/kubernetes-client-go/pull/1/files
另外 AuthInfo 等的覆盖如何工作?覆盖仅接受单个 AuthInfo,而配置包含 AuthInfo 等的映射。
仅使用 context.AuthInfo(字符串)中显示的用户名密钥覆盖 AuthInfo。
// 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
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
619 次 |
| 最近记录: |