mirror of
https://github.com/fluxcd/flux2.git
synced 2026-02-08 00:37:27 +00:00
Add FLUX_SYSTEM_NAMESPACE_FROM_CONTEXT to inherit kubens context
Signed-off-by: JB Pinalie <2850825+jybp@users.noreply.github.com>
This commit is contained in:
parent
7b551b0d35
commit
1d61cdf4e1
1 changed files with 14 additions and 0 deletions
|
|
@ -205,6 +205,20 @@ func main() {
|
|||
|
||||
func configureDefaultNamespace() {
|
||||
*kubeconfigArgs.Namespace = rootArgs.defaults.Namespace
|
||||
|
||||
// First 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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Fall back to environment variable if set
|
||||
fromEnv := os.Getenv("FLUX_SYSTEM_NAMESPACE")
|
||||
if fromEnv != "" {
|
||||
// namespace must be a valid DNS label. Assess against validation
|
||||
|
|
|
|||
Loading…
Reference in a new issue