mirror of
https://github.com/fluxcd/flux2.git
synced 2026-02-21 23:21:48 +00:00
Add environment variable flag to CLI in order to respect kubeconfig namespace
Signed-off-by: Adrian Berger <adrian.berger@bedag.ch>
This commit is contained in:
parent
5350425cdc
commit
b8b2912b77
1 changed files with 17 additions and 0 deletions
|
|
@ -205,6 +205,23 @@ func main() {
|
|||
|
||||
func configureDefaultNamespace() {
|
||||
*kubeconfigArgs.Namespace = rootArgs.defaults.Namespace
|
||||
|
||||
if _, has := os.LookupEnv("FLUX_NS_FOLLOW_KUBECONTEXT"); has {
|
||||
rawCfg, err := kubeconfigArgs.ToRawKubeConfigLoader().RawConfig()
|
||||
if err != nil {
|
||||
logger.Warningf(" failed parsing kubeconfig: %s", err)
|
||||
} else {
|
||||
ctx := *kubeconfigArgs.Context
|
||||
if ctx == "" {
|
||||
ctx = rawCfg.CurrentContext
|
||||
}
|
||||
ns := rawCfg.Contexts[ctx].Namespace
|
||||
if ns != "" {
|
||||
kubeconfigArgs.Namespace = &ns
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fromEnv := os.Getenv("FLUX_SYSTEM_NAMESPACE")
|
||||
if fromEnv != "" {
|
||||
// namespace must be a valid DNS label. Assess against validation
|
||||
|
|
|
|||
Loading…
Reference in a new issue