mirror of
https://github.com/fluxcd/flux2.git
synced 2026-02-21 23:21:48 +00:00
FLUX_SYSTEM_NAMESPACE takes priority
Signed-off-by: JB Pinalie <2850825+jybp@users.noreply.github.com>
This commit is contained in:
parent
1d61cdf4e1
commit
7ff2e1c186
1 changed files with 14 additions and 14 deletions
|
|
@ -206,19 +206,7 @@ func main() {
|
||||||
func configureDefaultNamespace() {
|
func configureDefaultNamespace() {
|
||||||
*kubeconfigArgs.Namespace = rootArgs.defaults.Namespace
|
*kubeconfigArgs.Namespace = rootArgs.defaults.Namespace
|
||||||
|
|
||||||
// First check if we should use the namespace from the current context
|
// First the FLUX_SYSTEM_NAMESPACE environment variable
|
||||||
if os.Getenv("FLUX_SYSTEM_NAMESPACE_FROM_CONTEXT") == "true" {
|
|
||||||
// Get the current context's namespace from kubeconfig
|
|
||||||
config, err := kubeconfigArgs.ToRawKubeConfigLoader().RawConfig()
|
|
||||||
if err == nil {
|
|
||||||
if ctx, exists := config.Contexts[config.CurrentContext]; exists && ctx.Namespace != "" {
|
|
||||||
kubeconfigArgs.Namespace = &ctx.Namespace
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fall back to environment variable if set
|
|
||||||
fromEnv := os.Getenv("FLUX_SYSTEM_NAMESPACE")
|
fromEnv := os.Getenv("FLUX_SYSTEM_NAMESPACE")
|
||||||
if fromEnv != "" {
|
if fromEnv != "" {
|
||||||
// namespace must be a valid DNS label. Assess against validation
|
// namespace must be a valid DNS label. Assess against validation
|
||||||
|
|
@ -228,8 +216,20 @@ func configureDefaultNamespace() {
|
||||||
logger.Warningf(" ignoring invalid FLUX_SYSTEM_NAMESPACE: %q", fromEnv)
|
logger.Warningf(" ignoring invalid FLUX_SYSTEM_NAMESPACE: %q", fromEnv)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
kubeconfigArgs.Namespace = &fromEnv
|
kubeconfigArgs.Namespace = &fromEnv
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// If no environment variable, check if we should use the namespace from the current context
|
||||||
|
if os.Getenv("FLUX_SYSTEM_NAMESPACE_FROM_CONTEXT") == "true" {
|
||||||
|
// Get the current context's namespace from kubeconfig
|
||||||
|
config, err := kubeconfigArgs.ToRawKubeConfigLoader().RawConfig()
|
||||||
|
if err == nil {
|
||||||
|
if ctx, exists := config.Contexts[config.CurrentContext]; exists && ctx.Namespace != "" {
|
||||||
|
kubeconfigArgs.Namespace = &ctx.Namespace
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue