J release changes
[ric-plt/ric-dep.git] / helm / infrastructure / subcharts / kong / templates / admission-webhook.yaml
1 {{- if (and .Values.ingressController.admissionWebhook.enabled .Values.ingressController.enabled) }}
2 {{- $certCert := "" -}}
3 {{- $certKey := "" -}}
4 {{- $caCert := "" -}}
5 {{- $caKey := "" -}}
6 {{- if not .Values.ingressController.admissionWebhook.certificate.provided }}
7 {{- $cn := printf "%s.%s.svc" ( include "kong.service.validationWebhook" . ) ( include "kong.namespace" . ) -}}
8 {{- $ca := genCA "kong-admission-ca" 3650 -}}
9 {{- $cert := genSignedCert $cn nil (list $cn) 3650 $ca -}}
10 {{- $certCert = $cert.Cert -}}
11 {{- $certKey = $cert.Key -}}
12 {{- $caCert = $ca.Cert -}}
13 {{- $caKey = $ca.Key -}}
14
15 {{- $caSecret := (lookup "v1" "Secret" (include "kong.namespace" .) (printf "%s-validation-webhook-ca-keypair" (include "kong.fullname" .))) -}}
16 {{- $certSecret := (lookup "v1" "Secret" (include "kong.namespace" .) (printf "%s-validation-webhook-keypair" (include "kong.fullname" .))) -}}
17 {{- if $certSecret }}
18 {{- $certCert = (b64dec (get $certSecret.data "tls.crt")) -}}
19 {{- $certKey = (b64dec (get $certSecret.data "tls.key")) -}}
20 {{- end }}
21 {{- if $caSecret }}
22 {{- $caCert = (b64dec (get $caSecret.data "tls.crt")) -}}
23 {{- $caKey = (b64dec (get $caSecret.data "tls.key")) -}}
24 {{- end }}
25 {{- end }}
26 kind: ValidatingWebhookConfiguration
27 {{- if .Capabilities.APIVersions.Has "admissionregistration.k8s.io/v1" }}
28 apiVersion: admissionregistration.k8s.io/v1
29 {{- else }}
30 apiVersion: admissionregistration.k8s.io/v1beta1
31 {{- end }}
32 metadata:
33   name: {{ template "kong.fullname" . }}-validations
34   namespace: {{ template "kong.namespace" . }}
35   labels:
36     {{- include "kong.metaLabels" . | nindent 4 }}
37   {{- if .Values.ingressController.admissionWebhook.annotations }}
38   annotations:
39   {{- range $key, $value := .Values.ingressController.admissionWebhook.annotations }}
40     {{ $key }}: {{ $value | quote }}
41   {{- end }}
42   {{- end }}
43 webhooks:
44 - name: validations.kong.konghq.com
45   {{- with .Values.ingressController.admissionWebhook.namespaceSelector }}
46   namespaceSelector:
47     {{- toYaml . | nindent 4 }}
48   {{- end }}
49   {{- with .Values.ingressController.admissionWebhook.timeoutSeconds }}
50   timeoutSeconds: {{ . }}
51   {{- end }}
52   objectSelector:
53     matchExpressions:
54     - key: owner
55       operator: NotIn
56       values:
57       - helm
58   failurePolicy: {{ .Values.ingressController.admissionWebhook.failurePolicy }}
59   sideEffects: None
60   admissionReviewVersions: ["v1beta1"]
61   rules:
62   - apiGroups:
63     - configuration.konghq.com
64     apiVersions:
65     - '*'
66     operations:
67     - CREATE
68     - UPDATE
69     resources:
70     - kongconsumers
71     - kongplugins
72 {{- if (semverCompare ">= 2.0.4" (include "kong.effectiveVersion" .Values.ingressController.image)) }}
73     - kongclusterplugins
74 {{- end }}
75 {{- if (semverCompare ">= 2.8.0" (include "kong.effectiveVersion" .Values.ingressController.image)) }}
76     - kongingresses
77 {{- end }}
78   - apiGroups:
79     - ''
80     apiVersions:
81     - 'v1'
82     operations:
83 {{- if (semverCompare ">= 2.12.1" (include "kong.effectiveVersion" .Values.ingressController.image)) }}
84     - CREATE
85 {{- end }}
86     - UPDATE
87     resources:
88     - secrets
89 {{- if (semverCompare ">= 3.0.0" (include "kong.effectiveVersion" .Values.ingressController.image)) }}
90     - services
91 {{- end }}
92 {{- if (semverCompare ">= 2.12.0" (include "kong.effectiveVersion" .Values.ingressController.image)) }}
93   - apiGroups:
94     - networking.k8s.io
95     apiVersions:
96       - 'v1'
97     operations:
98     - CREATE
99     - UPDATE
100     resources:
101     - ingresses
102   - apiGroups:
103     - gateway.networking.k8s.io
104     apiVersions:
105     - 'v1alpha2'
106     - 'v1beta1'
107 {{- if (semverCompare ">= 3.0.0" (include "kong.effectiveVersion" .Values.ingressController.image)) }}
108     - 'v1'
109 {{- end }}
110     operations:
111     - CREATE
112     - UPDATE
113     resources:
114     - gateways
115     - httproutes
116 {{- end }}
117   clientConfig:
118     {{- if not .Values.ingressController.admissionWebhook.certificate.provided }}
119     caBundle: {{ b64enc $caCert }}
120     {{- else }}
121     {{- if .Values.ingressController.admissionWebhook.certificate.caBundle }}
122     caBundle: {{ b64enc .Values.ingressController.admissionWebhook.certificate.caBundle }}
123     {{- end }}
124     {{- end }}
125     service:
126       name: {{ template "kong.service.validationWebhook" . }}
127       namespace: {{ template "kong.namespace" . }}
128 ---
129 apiVersion: v1
130 kind: Service
131 metadata:
132   name: {{ template "kong.service.validationWebhook" . }}
133   namespace: {{ template "kong.namespace" . }}
134   labels:
135     {{- include "kong.metaLabels" . | nindent 4 }}
136     {{- if .Values.ingressController.admissionWebhook.service.labels }}
137       {{- toYaml .Values.ingressController.admissionWebhook.service.labels | nindent 4 }}
138     {{- end }}
139 spec:
140   ports:
141   - name: webhook
142     port: 443
143     protocol: TCP
144     targetPort: webhook
145   selector:
146     {{- include "kong.metaLabels" . | nindent 4 }}
147     app.kubernetes.io/component: app
148 {{- if not .Values.ingressController.admissionWebhook.certificate.provided }}
149 ---
150 apiVersion: v1
151 kind: Secret
152 metadata:
153   name: {{ template "kong.fullname" . }}-validation-webhook-ca-keypair
154   namespace:  {{ template "kong.namespace" . }}
155   labels:
156     {{- include "kong.metaLabels" . | nindent 4 }}
157 type: kubernetes.io/tls
158 data:
159     tls.crt: {{ b64enc $caCert  }}
160     tls.key: {{ b64enc $caKey  }}
161 ---
162 apiVersion: v1
163 kind: Secret
164 metadata:
165   name: {{ template "kong.fullname" . }}-validation-webhook-keypair
166   namespace:  {{ template "kong.namespace" . }}
167   labels:
168     {{- include "kong.metaLabels" . | nindent 4 }}
169 type: kubernetes.io/tls
170 data:
171   tls.crt: {{ b64enc $certCert }}
172   tls.key: {{ b64enc $certKey }}
173 {{- end }}
174 {{- end }}