Skip to content

Commit

Permalink
feat: Adding network policy for webapp-db
Browse files Browse the repository at this point in the history
  • Loading branch information
rishabNeu committed Nov 29, 2023
1 parent de3f58b commit 46ffae1
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
7 changes: 7 additions & 0 deletions templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ app: {{ .Values.podLabel.app }}
service: {{ .Values.podLabel.service }}
{{- end }}

{{/*
DB labels
*/}}
{{- define "webapp-helm-chart.db.labels" }}
app: {{ .Values.postgresql.primary.podLabels.app }}
{{- end }}

{{/*
Selector labels
*/}}
Expand Down
20 changes: 20 additions & 0 deletions templates/network_policy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: {{ .Release.Name }}-network-policy
namespace: {{ .Values.namespace }}
spec:
podSelector:
matchLabels: {{ include "webapp-helm-chart.db.labels" . | indent 6 }}
policyTypes:
- Ingress
ingress:
- from:
- namespaceSelector:
matchLabels:
name: {{ .Values.namespace }}
- podSelector:
matchLabels: {{ include "webapp-helm-chart.labels" . | indent 14 }}
ports:
- protocol: TCP
port: 5432
4 changes: 4 additions & 0 deletions values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,7 @@ postgresql:
primary:
persistence:
size: 1Gi
labels:
app: webapp-db
podLabels:
app: webapp-db

0 comments on commit 46ffae1

Please sign in to comment.