Skip to content

Commit 09adf93

Browse files
committed
Support KUBECONFIG env var
1 parent 3855e8c commit 09adf93

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

main.go

+9
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ func (p ByPodName) Less(i, j int) bool { return p[i].podName < p[j].podName }
5454
func (p ByPodName) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
5555

5656
func main() {
57+
kubeconfigEnv := os.Getenv("KUBECONFIG")
5758
kubeconfig := flag.String("kubeconfig", "", "Path to the kubeconfig file")
5859
container := flag.String("c", "", "Container to execute the command against")
5960
labelSelector := flag.String("l", "", "Label selector to filter pods")
@@ -81,6 +82,11 @@ func main() {
8182
fmt.Println("Error: command to execute is required")
8283
os.Exit(1)
8384
}
85+
fmt.Printf("before kubeconfig: %v", *kubeconfig)
86+
if kubeconfig == nil || len(*kubeconfig) == 0 && len(kubeconfigEnv) > 0 {
87+
kubeconfig = &kubeconfigEnv
88+
}
89+
fmt.Printf("after kubeconfig: %v", *kubeconfig)
8490

8591
config, err := clientcmd.BuildConfigFromFlags("", *kubeconfig)
8692
if err != nil {
@@ -90,6 +96,7 @@ func main() {
9096
}
9197
}
9298

99+
fmt.Println("hi")
93100
clientset, err := kubernetes.NewForConfig(config)
94101
if err != nil {
95102
panic(err)
@@ -102,6 +109,7 @@ func main() {
102109
panic(err)
103110
}
104111

112+
fmt.Println("hi")
105113
var wg sync.WaitGroup
106114
resultsChan := make(chan PodResult, len(pods.Items))
107115

@@ -121,6 +129,7 @@ func main() {
121129
results = append(results, result)
122130
}
123131

132+
fmt.Println("hi")
124133
sort.Sort(ByPodName(results))
125134

126135
for _, result := range results {

0 commit comments

Comments
 (0)