Skip to content

Commit

Permalink
Merge pull request #15 from ajgon/fix/kubeconfig
Browse files Browse the repository at this point in the history
support for KUBECONFIG env
  • Loading branch information
jkulzer authored Nov 30, 2024
2 parents 1a232c6 + 7bf40f5 commit 094a3bc
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion kubefetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"math"
"os"
"os/user"
"path/filepath"
"strings"
"time"
Expand Down Expand Up @@ -48,9 +49,23 @@ func main() {
}
}

func getKubeconfigPath() string {
if path := os.Getenv("KUBECONFIG"); path != "" {
usr, _ := user.Current()
homeDir := usr.HomeDir
if strings.HasPrefix(path, "~/") {
path = filepath.Join(homeDir, path[2:])
}

return path
}

return filepath.Join(os.Getenv("HOME"), ".kube", "config")
}

func getKubeconfig() (*rest.Config, error) {
// Get the path to the kubeconfig file
kubeconfig := filepath.Join(os.Getenv("HOME"), ".kube", "config")
kubeconfig := getKubeconfigPath()

// Build the client config from the kubeconfig file
config, err := clientcmd.BuildConfigFromFlags("", kubeconfig)
Expand Down

0 comments on commit 094a3bc

Please sign in to comment.