Skip to content

Commit

Permalink
Fix #72 - allow KUBECONFIG to be set for override
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
  • Loading branch information
alexellis committed Feb 16, 2024
1 parent f7c2e3d commit 8ca6ae7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"io/ioutil"
"log"
"os"
"runtime"
"strings"
"time"

Expand Down Expand Up @@ -54,11 +55,27 @@ func main() {
file string
)

kubeConfigDefault := "$HOME/.kube/config"
flag.StringVar(&outFile, "out", "", "File to write to or leave blank for STDOUT")
flag.StringVar(&kubeconfig, "kubeconfig", "$HOME/.kube/config", "Path to KUBECONFIG")
flag.StringVar(&file, "f", "", "Job to run or leave blank for job.yaml in current directory")
flag.Parse()

// If there is no override for -kubeconfig, then check the environment for an override
if kubeconfig == kubeConfigDefault {
if v, ok := os.LookupEnv("KUBECONFIG"); ok && len(v) > 0 {
kubeconfig = v
}
}

// Windows requires %HOMEPATH% instead of $HOME
if runtime.GOOS == "windows" {
kubeconfig = strings.ReplaceAll(kubeconfig, "$HOME", "$HOMEPATH")
}

// ExpandEnv is required to for Windows users
kubeconfig = os.Expand(kubeconfig, os.Getenv)

if len(file) == 0 {
if stat, err := os.Stat("./job.yaml"); err != nil {
log.Fatal("specify a job file with -f or provide a job file called job.yaml in this directory")
Expand Down
File renamed without changes.

0 comments on commit 8ca6ae7

Please sign in to comment.