mirror of
https://github.com/grafana/grafana.git
synced 2025-07-29 10:22:12 +08:00
36 lines
911 B
Go
36 lines
911 B
Go
package utils
|
|
|
|
import (
|
|
clientrest "k8s.io/client-go/rest"
|
|
clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
|
|
)
|
|
|
|
func FormatKubeConfig(restConfig *clientrest.Config) clientcmdapi.Config {
|
|
clusters := make(map[string]*clientcmdapi.Cluster)
|
|
clusters["default-cluster"] = &clientcmdapi.Cluster{
|
|
Server: restConfig.Host,
|
|
InsecureSkipTLSVerify: true,
|
|
}
|
|
|
|
contexts := make(map[string]*clientcmdapi.Context)
|
|
contexts["default-context"] = &clientcmdapi.Context{
|
|
Cluster: "default-cluster",
|
|
Namespace: "default",
|
|
AuthInfo: "default",
|
|
}
|
|
|
|
authinfos := make(map[string]*clientcmdapi.AuthInfo)
|
|
authinfos["default"] = &clientcmdapi.AuthInfo{
|
|
Token: restConfig.BearerToken,
|
|
}
|
|
|
|
return clientcmdapi.Config{
|
|
Kind: "Config",
|
|
APIVersion: "v1",
|
|
Clusters: clusters,
|
|
Contexts: contexts,
|
|
CurrentContext: "default-context",
|
|
AuthInfos: authinfos,
|
|
}
|
|
}
|