Tinoj Joseph | dd1fd9d | 2022-08-01 23:59:26 +0530 | [diff] [blame^] | 1 | # Copyright 2022-present Open Networking Foundation |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | # you may not use this file except in compliance with the License. |
| 5 | # You may obtain a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | # See the License for the specific language governing permissions and |
| 13 | # limitations under the License. |
| 14 | |
| 15 | {{- if .Values.networkPolicy.enabled }} |
| 16 | kind: NetworkPolicy |
| 17 | apiVersion: {{ template "networkPolicy.apiVersion" . }} |
| 18 | metadata: |
| 19 | name: {{ template "redis.fullname" . }} |
| 20 | namespace: {{ .Release.Namespace | quote }} |
| 21 | labels: |
| 22 | app: {{ template "redis.name" . }} |
| 23 | chart: {{ template "redis.chart" . }} |
| 24 | release: {{ .Release.Name }} |
| 25 | heritage: {{ .Release.Service }} |
| 26 | spec: |
| 27 | podSelector: |
| 28 | matchLabels: |
| 29 | app: {{ template "redis.name" . }} |
| 30 | release: {{ .Release.Name }} |
| 31 | {{- if .Values.global.redis.cluster.enabled }} |
| 32 | policyTypes: |
| 33 | - Ingress |
| 34 | - Egress |
| 35 | egress: |
| 36 | # Allow dns resolution |
| 37 | - ports: |
| 38 | - port: 53 |
| 39 | protocol: UDP |
| 40 | # Allow outbound connections to other cluster pods |
| 41 | - ports: |
| 42 | - port: {{ .Values.redisPort }} |
| 43 | {{- if .Values.global.redis.sentinel.enabled }} |
| 44 | - port: {{ .Values.sentinel.port }} |
| 45 | {{- end }} |
| 46 | to: |
| 47 | - podSelector: |
| 48 | matchLabels: |
| 49 | app: {{ template "redis.name" . }} |
| 50 | release: {{ .Release.Name }} |
| 51 | {{- end }} |
| 52 | ingress: |
| 53 | # Allow inbound connections |
| 54 | - ports: |
| 55 | - port: {{ .Values.redisPort }} |
| 56 | {{- if .Values.global.redis.sentinel.enabled }} |
| 57 | - port: {{ .Values.sentinel.port }} |
| 58 | {{- end }} |
| 59 | {{- if not .Values.networkPolicy.allowExternal }} |
| 60 | from: |
| 61 | - podSelector: |
| 62 | matchLabels: |
| 63 | {{ template "redis.fullname" . }}-client: "true" |
| 64 | - podSelector: |
| 65 | matchLabels: |
| 66 | app: {{ template "redis.name" . }} |
| 67 | release: {{ .Release.Name }} |
| 68 | {{- if .Values.networkPolicy.ingressNSMatchLabels }} |
| 69 | - namespaceSelector: |
| 70 | matchLabels: |
| 71 | {{- range $key, $value := .Values.networkPolicy.ingressNSMatchLabels }} |
| 72 | {{ $key | quote }}: {{ $value | quote }} |
| 73 | {{- end }} |
| 74 | {{- if .Values.networkPolicy.ingressNSPodMatchLabels }} |
| 75 | podSelector: |
| 76 | matchLabels: |
| 77 | {{- range $key, $value := .Values.networkPolicy.ingressNSPodMatchLabels }} |
| 78 | {{ $key | quote }}: {{ $value | quote }} |
| 79 | {{- end }} |
| 80 | {{- end }} |
| 81 | {{- end }} |
| 82 | {{- end }} |
| 83 | {{- if .Values.metrics.enabled }} |
| 84 | # Allow prometheus scrapes for metrics |
| 85 | - ports: |
| 86 | - port: 9121 |
| 87 | {{- end }} |
| 88 | {{- end }} |