Skip to content

Commit 1d61cdf

Browse files
committed
Add FLUX_SYSTEM_NAMESPACE_FROM_CONTEXT to inherit kubens context
Signed-off-by: JB Pinalie <[email protected]>
1 parent 7b551b0 commit 1d61cdf

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

cmd/flux/main.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,20 @@ func main() {
205205

206206
func configureDefaultNamespace() {
207207
*kubeconfigArgs.Namespace = rootArgs.defaults.Namespace
208+
209+
// First check if we should use the namespace from the current context
210+
if os.Getenv("FLUX_SYSTEM_NAMESPACE_FROM_CONTEXT") == "true" {
211+
// Get the current context's namespace from kubeconfig
212+
config, err := kubeconfigArgs.ToRawKubeConfigLoader().RawConfig()
213+
if err == nil {
214+
if ctx, exists := config.Contexts[config.CurrentContext]; exists && ctx.Namespace != "" {
215+
kubeconfigArgs.Namespace = &ctx.Namespace
216+
return
217+
}
218+
}
219+
}
220+
221+
// Fall back to environment variable if set
208222
fromEnv := os.Getenv("FLUX_SYSTEM_NAMESPACE")
209223
if fromEnv != "" {
210224
// namespace must be a valid DNS label. Assess against validation

0 commit comments

Comments
 (0)