mirror of
https://github.com/fluxcd/flux2.git
synced 2026-02-21 15:11:47 +00:00
Set default ns with FLUX_SYSTEM_NAMESPACE env var
Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
This commit is contained in:
parent
8b3e3b1dd7
commit
f2de7e04b8
1 changed files with 10 additions and 1 deletions
|
|
@ -107,7 +107,8 @@ type rootFlags struct {
|
||||||
var rootArgs = NewRootFlags()
|
var rootArgs = NewRootFlags()
|
||||||
|
|
||||||
func init() {
|
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.RegisterFlagCompletionFunc("namespace", resourceNamesCompletionFunc(corev1.SchemeGroupVersion.WithKind("Namespace")))
|
||||||
|
|
||||||
rootCmd.PersistentFlags().DurationVar(&rootArgs.timeout, "timeout", 5*time.Minute, "timeout for this operation")
|
rootCmd.PersistentFlags().DurationVar(&rootArgs.timeout, "timeout", 5*time.Minute, "timeout for this operation")
|
||||||
|
|
@ -134,6 +135,7 @@ func NewRootFlags() rootFlags {
|
||||||
func main() {
|
func main() {
|
||||||
log.SetFlags(0)
|
log.SetFlags(0)
|
||||||
configureKubeconfig()
|
configureKubeconfig()
|
||||||
|
configureDefaultNamespace()
|
||||||
if err := rootCmd.Execute(); err != nil {
|
if err := rootCmd.Execute(); err != nil {
|
||||||
logger.Failuref("%v", err)
|
logger.Failuref("%v", err)
|
||||||
os.Exit(1)
|
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 {
|
func homeDir() string {
|
||||||
if h := os.Getenv("HOME"); h != "" {
|
if h := os.Getenv("HOME"); h != "" {
|
||||||
return h
|
return h
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue