Skip to content

Commit c8d7c1e

Browse files
authored
(e2e) fix namespaces network-policy test searches in (#2034)
The test was previously listing networkpolicies to validate only in the namespace operator-controller is deployed in. Upstream, that is valid since the namespace that operator-controller is deployed in, is the namespace that all other components are deployed in (and therefore all the network polices we expect to find). A different distribution of olmv1 (downstream) could decide to deploy the policies in different namespaces, in which case the test will not look into all the namespaces it should look into. This PR fixes the issue by searching in the namespaces both operator-controller and catalogd is deployed in.
1 parent d18883d commit c8d7c1e

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

test/e2e/network_policy_test.go

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,14 +140,26 @@ func TestNetworkPolicyJustifications(t *testing.T) {
140140
}
141141

142142
clientForComponent := utils.FindK8sClient(t)
143-
componentNamespace := getComponentNamespace(t, clientForComponent, operatorManagerSelector)
144-
clusterPolicies := &networkingv1.NetworkPolicyList{}
145-
err := c.List(ctx, clusterPolicies, client.InNamespace(componentNamespace))
146-
require.NoError(t, err, "Failed to list NetworkPolicies in namespace %q", componentNamespace)
143+
144+
operatorControllerNamespace := getComponentNamespace(t, clientForComponent, operatorManagerSelector)
145+
catalogDNamespace := getComponentNamespace(t, clientForComponent, catalogdManagerSelector)
146+
147+
policies := &networkingv1.NetworkPolicyList{}
148+
err := c.List(ctx, policies, client.InNamespace(operatorControllerNamespace))
149+
require.NoError(t, err, "Failed to list NetworkPolicies in namespace %q", operatorControllerNamespace)
150+
151+
clusterPolicies := policies.Items
152+
153+
if operatorControllerNamespace != catalogDNamespace {
154+
policies := &networkingv1.NetworkPolicyList{}
155+
err := c.List(ctx, policies, client.InNamespace(catalogDNamespace))
156+
require.NoError(t, err, "Failed to list NetworkPolicies in namespace %q", catalogDNamespace)
157+
clusterPolicies = append(clusterPolicies, policies.Items...)
158+
}
147159

148160
validatedRegistryPolicies := make(map[string]bool)
149161

150-
for _, policy := range clusterPolicies.Items {
162+
for _, policy := range clusterPolicies {
151163
t.Run(fmt.Sprintf("Policy_%s", strings.ReplaceAll(policy.Name, "-", "_")), func(t *testing.T) {
152164
expectedPolicy, found := allowedNetworkPolicies[policy.Name]
153165
require.Truef(t, found, "NetworkPolicy %q found in cluster but not in allowed registry. Namespace: %s", policy.Name, policy.Namespace)

0 commit comments

Comments
 (0)