37 Star 411 Fork 76

GVPrancher/rancher

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
config.go 978 Bytes
一键复制 编辑 原始数据 按行查看 历史
Darren Shepherd 提交于 2018-02-27 16:39 . Fix local clusters
package k8s
import (
"context"
"fmt"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
)
func GetConfig(ctx context.Context, k8sMode string, kubeConfig string) (bool, context.Context, *rest.Config, error) {
var (
cfg *rest.Config
err error
)
switch k8sMode {
case "auto":
return getAuto(ctx, kubeConfig)
case "embedded":
return getEmbedded(ctx)
case "external":
cfg, err = getExternal(kubeConfig)
default:
return false, nil, nil, fmt.Errorf("invalid k8s-mode %s", k8sMode)
}
return false, ctx, cfg, err
}
func getAuto(ctx context.Context, kubeConfig string) (bool, context.Context, *rest.Config, error) {
if kubeConfig != "" {
cfg, err := getExternal(kubeConfig)
return false, ctx, cfg, err
}
if config, err := rest.InClusterConfig(); err == nil {
return false, ctx, config, nil
}
return getEmbedded(ctx)
}
func getExternal(kubeConfig string) (*rest.Config, error) {
return clientcmd.BuildConfigFromFlags("", kubeConfig)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/rancher/rancher.git
git@gitee.com:rancher/rancher.git
rancher
rancher
rancher
v2.0.3-rc1

搜索帮助

0d507c66 1850385 C8b1a773 1850385