From 5d7898f3573ffac9dd72f9d0f20ad3bcb847a3ca Mon Sep 17 00:00:00 2001 From: Anatolii Bazko Date: Thu, 8 Oct 2026 16:37:21 +0200 Subject: [PATCH] chore: pass operator namespace to GetDefaultNetworkPolicy Move the infrastructure initialization check and operator namespace lookup out of GetDefaultNetworkPolicy and into setDefaultNetworkPolicy, passing the namespace in as an argument instead. This lets external consumers (such as che-operator) reuse the default network policy rules with an explicit namespace, without depending on the infrastructure package being initialized in their process. Assisted-by: Claude Opus 5 Co-Authored-By: Claude Opus 5 Signed-off-by: Anatolii Bazko --- pkg/config/defaults.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/pkg/config/defaults.go b/pkg/config/defaults.go index 1b772e0ed..7b34e554b 100644 --- a/pkg/config/defaults.go +++ b/pkg/config/defaults.go @@ -219,7 +219,15 @@ func setDefaultOverrideConfig() error { } func setDefaultNetworkPolicy() error { - ingress, egress, err := GetDefaultNetworkPolicy() + if !infrastructure.IsInitialized() { + return fmt.Errorf("can not set default network policy, infrastructure not detected") + } + operatorNamespace, err := infrastructure.GetNamespace() + if err != nil { + return err + } + + ingress, egress, err := GetDefaultNetworkPolicy(operatorNamespace) if err != nil { return err } @@ -235,19 +243,11 @@ func setDefaultNetworkPolicy() error { // GetDefaultNetworkPolicy returns the default NetworkPolicy applied to DevWorkspace pods. // It is exposed publicly for other operators (such as che-operator) that need to read // and extend the default rules rather than hardcoding or duplicating them. -func GetDefaultNetworkPolicy() ( +func GetDefaultNetworkPolicy(operatorNamespace string) ( []networkingv1.NetworkPolicyIngressRule, []networkingv1.NetworkPolicyEgressRule, error, ) { - if !infrastructure.IsInitialized() { - return nil, nil, fmt.Errorf("can not set default network policy, infrastructure not detected") - } - operatorNamespace, err := infrastructure.GetNamespace() - if err != nil { - return nil, nil, err - } - var ingressPolicyRules []networkingv1.NetworkPolicyIngressRule if infrastructure.IsOpenShift() { allowFromDevWorkspaceIngressPolicyRule := networkingv1.NetworkPolicyIngressRule{