mirror of
https://github.com/fluxcd/flux2.git
synced 2026-02-07 16:27:27 +00:00
Merge 7ff2e1c186 into a4903a95be
This commit is contained in:
commit
e8bf4d365f
1 changed files with 15 additions and 1 deletions
|
|
@ -205,6 +205,8 @@ func main() {
|
|||
|
||||
func configureDefaultNamespace() {
|
||||
*kubeconfigArgs.Namespace = rootArgs.defaults.Namespace
|
||||
|
||||
// First the FLUX_SYSTEM_NAMESPACE environment variable
|
||||
fromEnv := os.Getenv("FLUX_SYSTEM_NAMESPACE")
|
||||
if fromEnv != "" {
|
||||
// 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)
|
||||
return
|
||||
}
|
||||
|
||||
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