@@ -161,6 +161,7 @@ type Config struct {
161
161
CAFile string `gcfg:"ca-file"`
162
162
SecretName string `gcfg:"secret-name"`
163
163
SecretNamespace string `gcfg:"secret-namespace"`
164
+ KubeconfigPath string `gcfg:"kubeconfig-path"`
164
165
}
165
166
LoadBalancer LoadBalancerOpts
166
167
BlockStorage BlockStorageOpts
@@ -238,6 +239,7 @@ func configFromEnv() (cfg Config, ok bool) {
238
239
239
240
cfg .Global .SecretName = os .Getenv ("SECRET_NAME" )
240
241
cfg .Global .SecretNamespace = os .Getenv ("SECRET_NAMESPACE" )
242
+ cfg .Global .KubeconfigPath = os .Getenv ("KUBECONFIG_PATH" )
241
243
242
244
ok = cfg .Global .AuthURL != "" &&
243
245
cfg .Global .Username != "" &&
@@ -253,11 +255,10 @@ func configFromEnv() (cfg Config, ok bool) {
253
255
return
254
256
}
255
257
256
- func createKubernetesClient () (* kubernetes.Clientset , error ) {
258
+ func createKubernetesClient (kubeconfigPath string ) (* kubernetes.Clientset , error ) {
257
259
klog .Info ("Creating kubernetes API client." )
258
260
259
- // create in-cluster config
260
- cfg , err := clientcmd .BuildConfigFromFlags ("" , "" )
261
+ cfg , err := clientcmd .BuildConfigFromFlags ("" , kubeconfigPath )
261
262
if err != nil {
262
263
return nil , err
263
264
}
@@ -280,8 +281,9 @@ func createKubernetesClient() (*kubernetes.Clientset, error) {
280
281
func setConfigFromSecret (cfg * Config ) error {
281
282
secretName := cfg .Global .SecretName
282
283
secretNamespace := cfg .Global .SecretNamespace
284
+ kubeconfigPath := cfg .Global .KubeconfigPath
283
285
284
- k8sClient , err := createKubernetesClient ()
286
+ k8sClient , err := createKubernetesClient (kubeconfigPath )
285
287
if err != nil {
286
288
return fmt .Errorf ("failed to get kubernetes client: %v" , err )
287
289
}
0 commit comments