Skip to content

Commit

Permalink
fixed kubeconfig handling
Browse files Browse the repository at this point in the history
  • Loading branch information
gerald1248 committed Jan 11, 2019
1 parent f031d2d commit 8dea0ad
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,23 @@ func main() {
os.Exit(0)
}

// flags
// determine config path first
var kubeconfig *string
if home := homeDir(); home != "" {
kubeconfig = flag.String("kubeconfig", filepath.Join(home, ".kube", "config"), "absolute path to the kubeconfig file")
} else {
kubeconfig = flag.String("kubeconfig", "", "absolute path to the kubeconfig file")
// if presented as flag, use that
kubeconfig = flag.String("kubeconfig", "", "absolute path to the kubeconfig file")
// failing that, use ${KUBECONFIG}
if len(*kubeconfig) == 0 {
*kubeconfig = os.Getenv("KUBECONFIG")
}
// as a last resort, use standard location
if len(*kubeconfig) == 0 {
*kubeconfig = filepath.Join(homeDir(), ".kube", "config")
}

// other flags
all := flag.Bool("a", false, "return all matching pods")
namespace := flag.String("n", "", "namespace")

flag.Parse()

// params
Expand Down

0 comments on commit 8dea0ad

Please sign in to comment.