mirror of
https://github.com/fluxcd/flux2.git
synced 2026-02-22 23:51:48 +00:00
Merge 7ff2e1c186 into 99f182be06
This commit is contained in:
commit
92dd9be030
1 changed files with 15 additions and 1 deletions
|
|
@ -205,6 +205,8 @@ func main() {
|
||||||
|
|
||||||
func configureDefaultNamespace() {
|
func configureDefaultNamespace() {
|
||||||
*kubeconfigArgs.Namespace = rootArgs.defaults.Namespace
|
*kubeconfigArgs.Namespace = rootArgs.defaults.Namespace
|
||||||
|
|
||||||
|
// First the FLUX_SYSTEM_NAMESPACE environment variable
|
||||||
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
|
||||||
|
|
@ -214,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