Skip to content

Commit 7fd5bd2

Browse files
authored
feat: support webhook server for ingress (#888)
Signed-off-by: Ashing Zheng <[email protected]>
1 parent 4883379 commit 7fd5bd2

File tree

7 files changed

+424
-15
lines changed

7 files changed

+424
-15
lines changed

charts/apisix-ingress-controller/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,3 +166,8 @@ The same for container level, you need to set:
166166
| serviceMonitor.labels | object | `{}` | @param serviceMonitor.labels ServiceMonitor extra labels |
167167
| serviceMonitor.metricRelabelings | object | `{}` | @param serviceMonitor.metricRelabelings MetricRelabelConfigs to apply to samples before ingestion. ref: https://prometheus.io/docs/prometheus/latest/configuration/configuration/#metric_relabel_configs |
168168
| serviceMonitor.namespace | string | `"monitoring"` | @param serviceMonitor.namespace Namespace in which to create the ServiceMonitor |
169+
| webhook.certificate.provided | bool | `false` | Set to true if you want to provide your own certificate |
170+
| webhook.enabled | bool | `true` | Enable or disable admission webhook |
171+
| webhook.failurePolicy | string | `"Fail"` | Failure policy for the webhook (Fail or Ignore) |
172+
| webhook.port | int | `9443` | The port for the webhook server to listen on |
173+
| webhook.timeoutSeconds | int | `10` | Timeout in seconds for the webhook |

charts/apisix-ingress-controller/templates/_helpers.tpl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,23 @@ app.kubernetes.io/name: {{ include "apisix-ingress-controller-manager.name" . }}
6767
app.kubernetes.io/instance: {{ .Release.Name }}
6868
{{- end }}
6969
{{- end }}
70+
71+
{{/*
72+
Webhook service name - ensure it stays within 63 character limit
73+
*/}}
74+
{{- define "apisix-ingress-controller-manager.webhook.serviceName" -}}
75+
{{- $suffix := "-webhook-svc" -}}
76+
{{- $maxLen := sub 63 (len $suffix) | int -}}
77+
{{- $baseName := include "apisix-ingress-controller-manager.name.fullname" . | trunc $maxLen | trimSuffix "-" -}}
78+
{{- printf "%s%s" $baseName $suffix -}}
79+
{{- end }}
80+
81+
{{/*
82+
Webhook secret name - ensure it stays within 63 character limit
83+
*/}}
84+
{{- define "apisix-ingress-controller-manager.webhook.secretName" -}}
85+
{{- $suffix := "-webhook-cert" -}}
86+
{{- $maxLen := sub 63 (len $suffix) | int -}}
87+
{{- $baseName := include "apisix-ingress-controller-manager.name.fullname" . | trunc $maxLen | trimSuffix "-" -}}
88+
{{- printf "%s%s" $baseName $suffix -}}
89+
{{- end }}

charts/apisix-ingress-controller/templates/cluster_role.yaml

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ rules:
9494
- gateway.networking.k8s.io
9595
resources:
9696
- gatewayclasses
97-
- gateways
9897
verbs:
9998
- get
10099
- list
@@ -105,51 +104,53 @@ rules:
105104
resources:
106105
- gatewayclasses/status
107106
- gateways/status
107+
- grpcroutes/status
108108
- httproutes/status
109+
- tcproutes/status
110+
- udproutes/status
111+
- tlsroutes/status
109112
- referencegrants/status
110113
verbs:
111114
- get
112115
- update
113116
- apiGroups:
114117
- gateway.networking.k8s.io
115118
resources:
119+
- gateways
120+
- grpcroutes
116121
- httproutes
117-
verbs:
118-
- get
119-
- list
120-
- watch
121-
- apiGroups:
122-
- gateway.networking.k8s.io
123-
resources:
122+
- tcproutes
123+
- udproutes
124+
- tlsroutes
124125
- referencegrants
125126
verbs:
127+
- get
126128
- list
127-
- update
128129
- watch
129130
- apiGroups:
130131
- networking.k8s.io
131132
resources:
132133
- ingressclasses
134+
- ingresses
133135
verbs:
134136
- get
135137
- list
136138
- watch
137139
- apiGroups:
138140
- networking.k8s.io
139141
resources:
140-
- ingresses
142+
- ingresses/status
141143
verbs:
142144
- get
143-
- list
144145
- update
145-
- watch
146146
- apiGroups:
147-
- networking.k8s.io
147+
- ""
148148
resources:
149-
- ingresses/status
149+
- endpoints
150150
verbs:
151151
- get
152-
- update
152+
- list
153+
- watch
153154

154155
---
155156
apiVersion: rbac.authorization.k8s.io/v1

charts/apisix-ingress-controller/templates/configmap.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,11 @@ data:
3838
type: {{ .Values.config.provider.type | default "apisix" }}
3939
sync_period: {{ .Values.config.provider.syncPeriod | default "1s" }}
4040
init_sync_delay: {{ .Values.config.provider.initSyncDelay | default "20m" }}
41+
{{- if .Values.webhook.enabled }}
42+
webhook:
43+
enable: true
44+
port: {{ .Values.webhook.port }}
45+
tls_cert_file: "tls.crt"
46+
tls_key_file: "tls.key"
47+
tls_cert_dir: "/certs"
48+
{{- end }}

charts/apisix-ingress-controller/templates/deployment.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,20 @@ spec:
5858
- containerPort: {{ splitList ":" .Values.config.metricsAddr | last | int }}
5959
name: metrics
6060
protocol: TCP
61+
{{- if .Values.webhook.enabled }}
62+
- containerPort: {{ .Values.webhook.port }}
63+
name: webhook
64+
protocol: TCP
65+
{{- end }}
6166
volumeMounts:
6267
- name: {{ .Release.Name }}-ingress-config
6368
mountPath: /app/conf/config.yaml
6469
subPath: config.yaml
70+
{{- if .Values.webhook.enabled }}
71+
- name: webhook-certs
72+
mountPath: /certs
73+
readOnly: true
74+
{{- end }}
6575
livenessProbe:
6676
httpGet:
6777
path: /healthz
@@ -136,6 +146,11 @@ spec:
136146
- name: {{ .Release.Name }}-ingress-config
137147
configMap:
138148
name: {{ .Release.Name }}-ingress-config
149+
{{- if .Values.webhook.enabled }}
150+
- name: webhook-certs
151+
secret:
152+
secretName: {{ include "apisix-ingress-controller-manager.webhook.secretName" . }}
153+
{{- end }}
139154
securityContext:
140155
runAsNonRoot: false
141156
serviceAccountName: {{ .Release.Name }}

0 commit comments

Comments
 (0)