@@ -206,19 +206,7 @@ func main() {
206206func configureDefaultNamespace () {
207207 * kubeconfigArgs .Namespace = rootArgs .defaults .Namespace
208208
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
209+ // First the FLUX_SYSTEM_NAMESPACE environment variable
222210 fromEnv := os .Getenv ("FLUX_SYSTEM_NAMESPACE" )
223211 if fromEnv != "" {
224212 // namespace must be a valid DNS label. Assess against validation
@@ -228,8 +216,20 @@ func configureDefaultNamespace() {
228216 logger .Warningf (" ignoring invalid FLUX_SYSTEM_NAMESPACE: %q" , fromEnv )
229217 return
230218 }
231-
232219 kubeconfigArgs .Namespace = & fromEnv
220+ return
221+ }
222+
223+ // If no environment variable, check if we should use the namespace from the current context
224+ if os .Getenv ("FLUX_SYSTEM_NAMESPACE_FROM_CONTEXT" ) == "true" {
225+ // Get the current context's namespace from kubeconfig
226+ config , err := kubeconfigArgs .ToRawKubeConfigLoader ().RawConfig ()
227+ if err == nil {
228+ if ctx , exists := config .Contexts [config .CurrentContext ]; exists && ctx .Namespace != "" {
229+ kubeconfigArgs .Namespace = & ctx .Namespace
230+ return
231+ }
232+ }
233233 }
234234}
235235
0 commit comments