Repository navigation
ci: enforce NetworkPolicies in Kind test clusters #4172
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
rm3l
merged 3 commits into
redhat-developer:main
from
rm3l:RHDHBUGS-4068--tech-debt-set-up-test-kind-clusters-with-networkpolicy-enforcement-in-upstream-chart-and-operator-repos
Nov 30, 2026
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| #!/usr/bin/env bash | ||
| # | ||
| # Install Calico on a KinD (or any Kubernetes) cluster so that NetworkPolicies are | ||
| # actually enforced. | ||
| # | ||
| # KinD's default CNI (kindnet) does not implement NetworkPolicy enforcement, which | ||
| # means the NetworkPolicies shipped by the RHDH Operator are silently ignored and | ||
| # tests can pass even when the policies are wrong or incomplete. | ||
| # | ||
| # The KinD cluster must be created with: | ||
| # | ||
| # networking: | ||
| # disableDefaultCNI: true | ||
| # podSubnet: "192.168.0.0/16" # matches Calico's default IPv4 pool | ||
| # | ||
| # See hack/kind-config.yaml for a ready-to-use configuration. | ||
| # | ||
| # Usage: | ||
| # ./hack/install-calico.sh | ||
| # CALICO_VERSION=v3.31.7 ./hack/install-calico.sh | ||
| # | ||
| set -euo pipefail | ||
|
|
||
| # The workflows in this repo create KinD clusters with kind v0.26 (Kubernetes 1.32), | ||
| # so pin Calico to a release tested against that Kubernetes version. | ||
| CALICO_VERSION="${CALICO_VERSION:-v3.31.7}" | ||
| WAIT_TIMEOUT="${WAIT_TIMEOUT:-300s}" | ||
| MANIFEST_URL="https://raw.githubusercontent.com/projectcalico/calico/${CALICO_VERSION}/manifests/calico.yaml" | ||
|
|
||
| log() { | ||
| echo "[install-calico] $*" | ||
| } | ||
|
|
||
| if kubectl get daemonset -n kube-system kindnet >/dev/null 2>&1; then | ||
| echo "[install-calico] ERROR: kindnet is still installed in this cluster." >&2 | ||
| echo "[install-calico] Recreate the cluster with networking.disableDefaultCNI=true (see hack/kind-config.yaml)." >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| log "Installing Calico ${CALICO_VERSION} (NetworkPolicy enforcement)..." | ||
|
|
||
| manifest="$(mktemp)" | ||
| trap 'rm -f "${manifest}"' EXIT | ||
|
|
||
| curl -fsSL --retry 5 --retry-all-errors --retry-delay 2 "${MANIFEST_URL}" -o "${manifest}" | ||
|
Check warning on line 45 in hack/install-calico.sh
|
||
|
|
||
| # Calico's manifest is large; server-side apply avoids the client-side | ||
| # "metadata.annotations: Too long" limitation. | ||
| kubectl apply --server-side --force-conflicts -f "${manifest}" | ||
|
|
||
| log "Waiting for calico-node DaemonSet to roll out..." | ||
| kubectl -n kube-system rollout status daemonset/calico-node --timeout="${WAIT_TIMEOUT}" | ||
|
|
||
| log "Waiting for calico-kube-controllers Deployment to roll out..." | ||
| kubectl -n kube-system rollout status deployment/calico-kube-controllers --timeout="${WAIT_TIMEOUT}" | ||
|
|
||
| log "Waiting for all nodes to become Ready..." | ||
| kubectl wait --for=condition=Ready nodes --all --timeout="${WAIT_TIMEOUT}" | ||
|
|
||
| log "Calico is ready; NetworkPolicies are now enforced." | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| # KinD cluster configuration with NetworkPolicy enforcement. | ||
| # | ||
| # kindnet (KinD's default CNI) does not enforce NetworkPolicies, so we disable it | ||
| # and install Calico after the cluster is created (see hack/install-calico.sh). | ||
| # | ||
| # The podSubnet must match Calico's default IPv4 pool (192.168.0.0/16). | ||
| apiVersion: kind.x-k8s.io/v1alpha4 | ||
| kind: Cluster | ||
| networking: | ||
| disableDefaultCNI: true | ||
| podSubnet: "192.168.0.0/16" | ||
| nodes: | ||
| - role: control-plane |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.