From f2de7e04b8e6f3a8f98dcfad02ff57c1cdf6acb9 Mon Sep 17 00:00:00 2001 From: Stefan Prodan Date: Mon, 1 Nov 2021 13:14:21 +0200 Subject: [PATCH] Set default ns with FLUX_SYSTEM_NAMESPACE env var Signed-off-by: Stefan Prodan --- cmd/flux/main.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/cmd/flux/main.go b/cmd/flux/main.go index 945b49ed..916c4940 100644 --- a/cmd/flux/main.go +++ b/cmd/flux/main.go @@ -107,7 +107,8 @@ type rootFlags struct { var rootArgs = NewRootFlags() func init() { - rootCmd.PersistentFlags().StringVarP(&rootArgs.namespace, "namespace", "n", rootArgs.defaults.Namespace, "the namespace scope for this operation") + rootCmd.PersistentFlags().StringVarP(&rootArgs.namespace, "namespace", "n", rootArgs.defaults.Namespace, + "the namespace scope for this operation, can be set with FLUX_SYSTEM_NAMESPACE env var") rootCmd.RegisterFlagCompletionFunc("namespace", resourceNamesCompletionFunc(corev1.SchemeGroupVersion.WithKind("Namespace"))) rootCmd.PersistentFlags().DurationVar(&rootArgs.timeout, "timeout", 5*time.Minute, "timeout for this operation") @@ -134,6 +135,7 @@ func NewRootFlags() rootFlags { func main() { log.SetFlags(0) configureKubeconfig() + configureDefaultNamespace() if err := rootCmd.Execute(); err != nil { logger.Failuref("%v", err) os.Exit(1) @@ -152,6 +154,13 @@ func configureKubeconfig() { } } +func configureDefaultNamespace() { + fromEnv := os.Getenv("FLUX_SYSTEM_NAMESPACE") + if fromEnv != "" && rootArgs.namespace == rootArgs.defaults.Namespace { + rootArgs.namespace = fromEnv + } +} + func homeDir() string { if h := os.Getenv("HOME"); h != "" { return h