mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +00:00
Allow to define kubeconfig file for OpenStack cloud provider
Now, to build a kubernetes client, provider uses only in-cluster config, but if kubelet is not running as a pod, then it doesn't work. This commit adds an ability to specify a path to the kubeconfig file if necessary. If no value was provided, then the provider falls back to in-cluster config.
This commit is contained in:
parent
7a8e11c16d
commit
bac2291141
@ -161,6 +161,7 @@ type Config struct {
|
||||
CAFile string `gcfg:"ca-file"`
|
||||
SecretName string `gcfg:"secret-name"`
|
||||
SecretNamespace string `gcfg:"secret-namespace"`
|
||||
KubeconfigPath string `gcfg:"kubeconfig-path"`
|
||||
}
|
||||
LoadBalancer LoadBalancerOpts
|
||||
BlockStorage BlockStorageOpts
|
||||
@ -238,6 +239,7 @@ func configFromEnv() (cfg Config, ok bool) {
|
||||
|
||||
cfg.Global.SecretName = os.Getenv("SECRET_NAME")
|
||||
cfg.Global.SecretNamespace = os.Getenv("SECRET_NAMESPACE")
|
||||
cfg.Global.KubeconfigPath = os.Getenv("KUBECONFIG_PATH")
|
||||
|
||||
ok = cfg.Global.AuthURL != "" &&
|
||||
cfg.Global.Username != "" &&
|
||||
@ -253,11 +255,10 @@ func configFromEnv() (cfg Config, ok bool) {
|
||||
return
|
||||
}
|
||||
|
||||
func createKubernetesClient() (*kubernetes.Clientset, error) {
|
||||
func createKubernetesClient(kubeconfigPath string) (*kubernetes.Clientset, error) {
|
||||
klog.Info("Creating kubernetes API client.")
|
||||
|
||||
// create in-cluster config
|
||||
cfg, err := clientcmd.BuildConfigFromFlags("", "")
|
||||
cfg, err := clientcmd.BuildConfigFromFlags("", kubeconfigPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -280,8 +281,9 @@ func createKubernetesClient() (*kubernetes.Clientset, error) {
|
||||
func setConfigFromSecret(cfg *Config) error {
|
||||
secretName := cfg.Global.SecretName
|
||||
secretNamespace := cfg.Global.SecretNamespace
|
||||
kubeconfigPath := cfg.Global.KubeconfigPath
|
||||
|
||||
k8sClient, err := createKubernetesClient()
|
||||
k8sClient, err := createKubernetesClient(kubeconfigPath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get kubernetes client: %v", err)
|
||||
}
|
||||
|
@ -317,6 +317,7 @@ func getOpenstackConfig() openstack.Config {
|
||||
CAFile string `gcfg:"ca-file"`
|
||||
SecretName string `gcfg:"secret-name"`
|
||||
SecretNamespace string `gcfg:"secret-namespace"`
|
||||
KubeconfigPath string `gcfg:"kubeconfig-path"`
|
||||
}{
|
||||
Username: "user",
|
||||
Password: "pass",
|
||||
|
Loading…
Reference in New Issue
Block a user