Skip to content

Commit

Permalink
[kube-prometheus-stack] add network policies (#2580)
Browse files Browse the repository at this point in the history
Signed-off-by: QuentinBisson <quentin@giantswarm.io>

Signed-off-by: QuentinBisson <quentin@giantswarm.io>
  • Loading branch information
QuentinBisson authored Oct 17, 2022
1 parent ecb874e commit 2857c46
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 1 deletion.
2 changes: 1 addition & 1 deletion charts/kube-prometheus-stack/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ name: kube-prometheus-stack
sources:
- https://github.com/prometheus-community/helm-charts
- https://github.com/prometheus-operator/kube-prometheus
version: 41.4.1
version: 41.5.0
appVersion: 0.60.1
kubeVersion: ">=1.16.0-0"
home: https://github.com/prometheus-operator/kube-prometheus
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{{- if .Values.prometheusOperator.networkPolicy.enabled }}
{{- if and .Values.prometheusOperator.enabled .Values.prometheusOperator.admissionWebhooks.enabled .Values.prometheusOperator.admissionWebhooks.patch.enabled (not .Values.prometheusOperator.admissionWebhooks.certManager.enabled) }}
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: {{ template "kube-prometheus-stack.fullname" . }}-admission-create
namespace: {{ template "kube-prometheus-stack.namespace" . }}
annotations:
"helm.sh/hook": pre-install,pre-upgrade
"helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded
## Ensure this is run before the job
"helm.sh/hook-weight": "-5"
{{- with .Values.prometheusOperator.admissionWebhooks.annotations }}
{{ toYaml . | indent 4 }}
{{- end }}
labels:
app: {{ template "kube-prometheus-stack.name" $ }}-admission-create
{{- include "kube-prometheus-stack.labels" $ | indent 4 }}
spec:
podSelector:
matchLabels:
app: {{ template "kube-prometheus-stack.name" $ }}-admission-create
{{- include "kube-prometheus-stack.labels" $ | indent 6 }}
egress:
- {}
policyTypes:
- Egress
{{- end }}
{{- end }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{{- if .Values.prometheusOperator.networkPolicy.enabled }}
{{- if and .Values.prometheusOperator.enabled .Values.prometheusOperator.admissionWebhooks.enabled .Values.prometheusOperator.admissionWebhooks.patch.enabled (not .Values.prometheusOperator.admissionWebhooks.certManager.enabled) }}
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: {{ template "kube-prometheus-stack.fullname" . }}-admission-patch
namespace: {{ template "kube-prometheus-stack.namespace" . }}
annotations:
"helm.sh/hook": post-install,post-upgrade
"helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded
## Ensure this is run before the job
"helm.sh/hook-weight": "-5"
{{- with .Values.prometheusOperator.admissionWebhooks.patch.annotations }}
{{ toYaml . | indent 4 }}
{{- end }}
labels:
app: {{ template "kube-prometheus-stack.name" $ }}-admission-patch
{{- include "kube-prometheus-stack.labels" $ | indent 4 }}
spec:
podSelector:
matchLabels:
app: {{ template "kube-prometheus-stack.name" $ }}-admission-patch
{{- include "kube-prometheus-stack.labels" $ | indent 6 }}
egress:
- {}
policyTypes:
- Egress
{{- end }}
{{- end }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{{- if .Values.prometheusOperator.networkPolicy.enabled }}
apiVersion: {{ template "prometheus.networkPolicy.apiVersion" . }}
kind: NetworkPolicy
metadata:
name: {{ template "kube-prometheus-stack.fullname" . }}-operator
namespace: {{ template "kube-prometheus-stack.namespace" . }}
labels:
app: {{ template "kube-prometheus-stack.name" . }}-operator
spec:
podSelector:
matchLabels:
app: {{ template "kube-prometheus-stack.name" . }}-operator
release: {{ $.Release.Name | quote }}
ingress:
- ports:
{{- if .Values.prometheusOperator.tls.enabled }}
- port: {{ .Values.prometheusOperator.tls.internalPort }}
{{- else }}
- port: 8080
{{- end }}
{{- end }}
5 changes: 5 additions & 0 deletions charts/kube-prometheus-stack/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1692,6 +1692,11 @@ prometheusOperator:
##
# clusterDomain: "cluster.local"

networkPolicy:
## Enable creation of NetworkPolicy resources.
##
enabled: false

## Service account for Alertmanager to use.
## ref: https://kubernetes.io/docs/tasks/configure-pod-container/configure-service-account/
##
Expand Down

0 comments on commit 2857c46

Please sign in to comment.