From 82876b446f4bc72ad672beeef735909cf1d1d3ed Mon Sep 17 00:00:00 2001 From: Tobias Wolter Date: Mon, 28 Aug 2023 14:03:38 +0200 Subject: [PATCH] Respect `KUBECACHEDIR` environment variable This adds a check for the existence of a (non-empty) `KUBECACHEDIR` environment variable that will be used to construct the cache directory path if present. --- pkg/cmd/cmd.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/pkg/cmd/cmd.go b/pkg/cmd/cmd.go index e4953c08..613b5923 100644 --- a/pkg/cmd/cmd.go +++ b/pkg/cmd/cmd.go @@ -4,6 +4,7 @@ import ( "context" "path/filepath" "runtime" + "os" "github.com/google/wire" "github.com/int128/kubelogin/pkg/infrastructure/logger" @@ -23,8 +24,17 @@ type Interface interface { Run(ctx context.Context, args []string, version string) int } +func getDefaultTokenCacheDir(key, fallback string) string { + if value, ok := os.LookupEnv(key); ok { + return value + } + return fallback +} + var defaultListenAddress = []string{"127.0.0.1:8000", "127.0.0.1:18000"} -var defaultTokenCacheDir = filepath.Join("~", ".kube", "cache", "oidc-login") +var defaultTokenCacheDir = filepath.Join( + getDefaultTokenCacheDir("KUBECACHEDIR", filepath.Join("~", ".kube", "cache")), + "oidc-login") const defaultAuthenticationTimeoutSec = 180