Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possibility to set KUBECTX_DIR and KUBENS_DIR as an environemnt variable. #417

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cmd/kubectx/state.go
Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@
package main

import (
"cmp"
"io/ioutil"
"os"
"path/filepath"
@@ -25,7 +26,7 @@ import (
)

func kubectxPrevCtxFile() (string, error) {
home := cmdutil.HomeDir()
home := cmp.Or(os.Getenv("KUBECTX_DIR"), cmdutil.HomeDir())
if home == "" {
return "", errors.New("HOME or USERPROFILE environment variable not set")
}
3 changes: 2 additions & 1 deletion cmd/kubens/statefile.go
Original file line number Diff line number Diff line change
@@ -16,6 +16,7 @@ package main

import (
"bytes"
"cmp"
"io/ioutil"
"os"
"path/filepath"
@@ -25,7 +26,7 @@ import (
"github.com/ahmetb/kubectx/internal/cmdutil"
)

var defaultDir = filepath.Join(cmdutil.HomeDir(), ".kube", "kubens")
var defaultDir = filepath.Join(cmp.Or(os.Getenv("KUBECTX_DIR"), cmdutil.HomeDir()), ".kube", "kubens")

type NSFile struct {
dir string
3 changes: 2 additions & 1 deletion internal/kubeconfig/kubeconfigloader.go
Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@
package kubeconfig

import (
"cmp"
"github.com/ahmetb/kubectx/internal/cmdutil"
"os"
"path/filepath"
@@ -68,7 +69,7 @@ func kubeconfigPath() (string, error) {
}

// default path
home := cmdutil.HomeDir()
home := cmp.Or(os.Getenv("KUBECTX_DIR"), cmdutil.HomeDir())
if home == "" {
return "", errors.New("HOME or USERPROFILE environment variable not set")
}
3 changes: 2 additions & 1 deletion kubectx
Original file line number Diff line number Diff line change
@@ -23,7 +23,8 @@ IFS=$'\n\t'

SELF_CMD="$0"

KUBECTX="${XDG_CACHE_HOME:-$HOME/.kube}/kubectx"
[ -v KUBECTX_DIR ] && KUBECTX_DIR=${KUBECTX_DIR}/.kube/kubectx
KUBECTX="${KUBECTX_DIR:-${XDG_CACHE_HOME:-$HOME/.kube}/kubectx}"

usage() {
local SELF
3 changes: 2 additions & 1 deletion kubens
Original file line number Diff line number Diff line change
@@ -23,7 +23,8 @@ IFS=$'\n\t'

SELF_CMD="$0"

KUBENS_DIR="${XDG_CACHE_HOME:-$HOME/.kube}/kubens"
[ -v KUBENS_DIR ] && KUBENS_DIR=${KUBENS_DIR}/.kube/kubectx
KUBENS_DIR="${KUBENS_DIR:-${XDG_CACHE_HOME:-$HOME/.kube}/kubectx}"

usage() {
local SELF