Skip to content

✨ Add Network Policy to e2e test bundles #2078

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions hack/test/pre-upgrade-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,16 @@ rules:
- "watch"
- "bind"
- "escalate"
- apiGroups:
- networking.k8s.io
resources:
- networkpolicies
verbs:
- get
- list
- create
- update
- delete
Copy link
Contributor

@camilamacedo86 camilamacedo86 Jul 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, now I see that we have the NP in both sample versions
Can we have it in one version only, so we ensure that it works with both cases? (with and without NP)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you not mean to approve it? It already merged from your review. Also, not having the NP in one version isn't going to be any different, we always want to be able to support installing NPs so we always want the e2e to try to install one so the CI fails if it can't. There's no value-add from running the same test without an NP.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was a nit idea, I think we may could cover both scenarios
But it is all fine. I think it is OK as it is no worry.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw, thank you a lot for taking care of that !!!

- apiGroups:
- "olm.operatorframework.io"
resources:
Expand Down
24 changes: 24 additions & 0 deletions test/e2e/cluster_extension_install_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
corev1 "k8s.io/api/core/v1"
networkingv1 "k8s.io/api/networking/v1"
rbacv1 "k8s.io/api/rbac/v1"
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
"k8s.io/apimachinery/pkg/api/errors"
Expand Down Expand Up @@ -154,6 +155,23 @@ func createClusterRoleAndBindingForSA(ctx context.Context, name string, sa *core
"escalate",
},
},
{
APIGroups: []string{
"networking.k8s.io",
},
Resources: []string{
"networkpolicies",
},
Verbs: []string{
"get",
"list",
"watch",
"create",
"update",
"patch",
"delete",
},
},
},
}
err := c.Create(ctx, cr)
Expand Down Expand Up @@ -377,6 +395,12 @@ func TestClusterExtensionInstallRegistry(t *testing.T) {
assert.NotEmpty(ct, clusterExtension.Status.Install.Bundle)
}
}, pollDuration, pollInterval)

t.Log("By eventually creating the NetworkPolicy named 'test-operator-network-policy'")
require.EventuallyWithT(t, func(ct *assert.CollectT) {
var np networkingv1.NetworkPolicy
assert.NoError(ct, c.Get(context.Background(), types.NamespacedName{Name: "test-operator-network-policy", Namespace: ns.Name}, &np))
}, pollDuration, pollInterval)
})
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,16 @@ spec:
- update
- patch
- delete
- apiGroups:
- networking.k8s.io
resources:
- networkpolicies
verbs:
- get
- list
- create
- update
- delete
- apiGroups:
- coordination.k8s.io
resources:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: test-operator-network-policy
spec:
podSelector: {}
policyTypes:
- Ingress
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,16 @@ spec:
- update
- patch
- delete
- apiGroups:
- networking.k8s.io
resources:
- networkpolicies
verbs:
- get
- list
- create
- update
- delete
- apiGroups:
- coordination.k8s.io
resources:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: test-operator-network-policy
spec:
podSelector: {}
policyTypes:
- Ingress