Skip to content
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

feat(testkube): add networkpolicy support #784

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
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
160 changes: 160 additions & 0 deletions charts/testkube/templates/networkpolicy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
{{- if .Values.networkPolicy.enabled -}}
# this policy will be assigned to any pod in the namespace
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: testkube-all
namespace: testkube
spec:
podSelector: {}
policyTypes:
- Egress
egress:
- to:
- podSelector:
matchLabels:
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this be done similar to how services use a helper method? Example https://github.com/kubeshop/helm-charts/blob/develop/charts/testkube-api/templates/service.yaml#L27

Copy link
Author

Choose a reason for hiding this comment

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

feel free to refactor to your hearts content

Copy link
Contributor

Choose a reason for hiding this comment

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

could you assist? :)

app.kubernetes.io/name: api-server
app.kubernetes.io/instance: testkube
ports:
- protocol: TCP
port: {{ index .Values "testkube-api" "service" "port" }}
- to:
- podSelector:
matchLabels:
app: testkube-minio-testkube
ports:
- protocol: TCP
port: {{ index .Values "testkube-api" "storage" "endpoint_port" }}
---
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: testkube-operator
namespace: testkube
spec:
podSelector:
matchLabels:
Copy link
Contributor

Choose a reason for hiding this comment

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

same as above comment for selector

control-plane: controller-manager
policyTypes:
- Ingress
ingress:
- ports:
- protocol: TCP
port: 9443
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this also be referenced through a param?

---
# API must accept connections from everything
# (e.g. kube-proxy, pods in this namespace, external ingress controller)
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: testkube-api-server
namespace: testkube
spec:
podSelector:
matchLabels:
app.kubernetes.io/name: api-server
app.kubernetes.io/instance: testkube
policyTypes:
- Egress
- Ingress
egress:
- to:
- podSelector:
matchLabels:
Copy link
Contributor

Choose a reason for hiding this comment

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

same comment for selectors

app.kubernetes.io/name: nats
app.kubernetes.io/instance: testkube
ports:
- protocol: TCP
port: 4222
- to:
Copy link
Contributor

Choose a reason for hiding this comment

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

this might need to be dynamic if mongodb is disabled (customer is bringing own mongo)

- podSelector:
matchLabels:
Copy link
Contributor

Choose a reason for hiding this comment

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

same comment for selectors, they should be used through a helper funcion (from the mongodb chart?)

app.kubernetes.io/name: mongodb
app.kubernetes.io/instance: testkube
ports:
- protocol: TCP
port: {{ .Values.mongodb.service.port }}
ingress:
- ports:
- protocol: TCP
port: {{ index .Values "testkube-api" "service" "port" }}
---
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: testkube-minio
namespace: testkube
spec:
podSelector:
matchLabels:
app: testkube-minio-testkube
policyTypes:
- Ingress
ingress:
- ports:
- protocol: TCP
port: {{ index .Values "testkube-api" "storage" "endpoint_port" }}
---
{{- if .Values.mongodb.enabled -}}
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: testkube-mongodb
namespace: testkube
spec:
podSelector:
matchLabels:
app.kubernetes.io/name: mongodb
app.kubernetes.io/instance: testkube
policyTypes:
- Ingress
ingress:
- from:
- podSelector:
matchLabels:
app.kubernetes.io/instance: testkube
ports:
- protocol: TCP
port: {{ .Values.mongodb.service.port }}
---
{{- end -}}
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: testkube-nats
namespace: testkube
spec:
podSelector:
matchLabels:
app.kubernetes.io/name: nats
app.kubernetes.io/instance: testkube
policyTypes:
- Ingress
ingress:
- from:
- podSelector:
matchLabels:
app.kubernetes.io/instance: testkube
ports:
- protocol: TCP
port: 4222
---
{{- if index .Values "testkube-dashboard" "enabled" -}}
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: testkube-dashboard
namespace: testkube
spec:
podSelector:
matchLabels:
app.kubernetes.io/name: dashboard
app.kubernetes.io/instance: testkube
policyTypes:
- Ingress
ingress:
- ports:
- protocol: TCP
port: {{ index .Values "testkube-dashboard" "service" "port" }}
{{- end -}}
{{- end -}}
3 changes: 3 additions & 0 deletions charts/testkube/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1084,3 +1084,6 @@ testkube-operator:
operator: Equal
value: arm64
effect: NoSchedule

networkPolicy:
enabled: false
Loading