Skip to content

Commit

Permalink
fix: prioritize KUBECONFIG env over inCluster
Browse files Browse the repository at this point in the history
This is the behaviour even for kubectl CLI.
  • Loading branch information
Jainam M committed Jun 26, 2023
1 parent df9a017 commit f96cfd5
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pkg/collector/kube.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package collector

import (
"fmt"
"os"

"k8s.io/client-go/discovery"
"k8s.io/client-go/rest"
Expand Down Expand Up @@ -35,6 +36,11 @@ func newKubeCollector(kubeconfig string, kubecontext string, discoveryClient dis
}

func newClientRestConfig(kubeconfig string, kubecontext string, inClusterFn func() (*rest.Config, error), userAgent string) (*rest.Config, error) {

if kubeconfig == "" {
kubeconfig = os.Getenv(clientcmd.RecommendedConfigPathEnvVar)
}

if kubeconfig == "" {
if restConfig, err := inClusterFn(); err == nil {
restConfig.UserAgent = userAgent
Expand Down

0 comments on commit f96cfd5

Please sign in to comment.