Skip to content

Commit

Permalink
ci: update helm chart for testing netpol enforcement
Browse files Browse the repository at this point in the history
  • Loading branch information
consideRatio committed Jun 12, 2022
1 parent 5b647d5 commit 6f93278
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 92 deletions.
7 changes: 0 additions & 7 deletions test-calico/Chart.yaml

This file was deleted.

24 changes: 0 additions & 24 deletions test-calico/templates/networkpolicy.yaml

This file was deleted.

7 changes: 0 additions & 7 deletions test-calico/templates/serviceaccount.yaml

This file was deleted.

41 changes: 0 additions & 41 deletions test-calico/templates/tests/test-connection.yaml

This file was deleted.

4 changes: 4 additions & 0 deletions test-netpol-enforcement/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: v2
name: test-netpol-enforcement
version: 0.1.0
appVersion: 1.16.0
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,24 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: test-calico
labels:
app.kubernetes.io/name: test-calico
name: protected-webserver
spec:
replicas: 1
selector:
matchLabels:
app.kubernetes.io/name: test-calico
app.kubernetes.io/name: protected-webserver
template:
metadata:
labels:
app.kubernetes.io/name: test-calico
test-calico-access: protected
app.kubernetes.io/name: protected-webserver
spec:
serviceAccountName: test-calico
containers:
- name: test-calico
- name: nginx
image: "nginx:{{ .Chart.AppVersion }}"
imagePullPolicy: IfNotPresent
ports:
- name: http
containerPort: 80
protocol: TCP
livenessProbe:
httpGet:
path: /
port: http
readinessProbe:
httpGet:
path: /
Expand Down
22 changes: 22 additions & 0 deletions test-netpol-enforcement/templates/networkpolicy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# This network policy targets the protected-webserver pod with regards to
# ingress, thereby disallowing all inbound network connections unless allowed by
# a rule. We provide one such rule, allowing access to the protected-webserer
# from pods with a certain label.
#
# Two different pods will attempt to connect to the protected-webserver, one
# with the label and one without, and we expect different results based on this
# network policy.
#
kind: NetworkPolicy
apiVersion: networking.k8s.io/v1
metadata:
name: allow-ingress-from-labelled-pods
spec:
podSelector:
matchLabels:
app.kubernetes.io/name: protected-webserver
ingress:
- from:
- podSelector:
matchLabels:
access-to-protected-webserver: "true"
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
apiVersion: v1
kind: Pod
metadata:
name: "test-allowed-access"
labels:
access-to-protected-webserver: "true"
annotations:
helm.sh/hook: test-success
spec:
restartPolicy: Never
containers:
- name: busybox
image: busybox
command:
- sh
- -c
- |
if ! wget -T5 test-calico:80; then
echo "FAIL: was not allowed, but should be allowed"
exit 1
fi
---
apiVersion: v1
kind: Pod
metadata:
name: "test-not-allowed-access"
annotations:
helm.sh/hook: test-success
spec:
restartPolicy: Never
containers:
- name: busybox
image: busybox
command:
- sh
- -c
- |
if wget -T5 test-calico:80; then
echo "FAIL: was allowed, and shouldn't be allowed"
exit 1
fi

0 comments on commit 6f93278

Please sign in to comment.