Skip to content

Commit ac35b4f

Browse files
committed
feat: support webhook server for ingress
Signed-off-by: Ashing Zheng <axingfly@gmail.com>
1 parent a702cf0 commit ac35b4f

File tree

7 files changed

+330
-15
lines changed

7 files changed

+330
-15
lines changed

charts/apisix-ingress-controller/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,3 +158,8 @@ The same for container level, you need to set:
158158
| serviceMonitor.labels | object | `{}` | @param serviceMonitor.labels ServiceMonitor extra labels |
159159
| 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 |
160160
| serviceMonitor.namespace | string | `"monitoring"` | @param serviceMonitor.namespace Namespace in which to create the ServiceMonitor |
161+
| webhook.certificate.provided | bool | `false` | Set to true if you want to provide your own certificate |
162+
| webhook.enabled | bool | `true` | Enable or disable admission webhook |
163+
| webhook.failurePolicy | string | `"Fail"` | Failure policy for the webhook (Fail or Ignore) |
164+
| webhook.port | int | `9443` | The port for the webhook server to listen on |
165+
| 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: 10 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,6 +104,7 @@ rules:
105104
resources:
106105
- gatewayclasses/status
107106
- gateways/status
107+
- grpcroutes/status
108108
- httproutes/status
109109
- referencegrants/status
110110
verbs:
@@ -113,43 +113,38 @@ rules:
113113
- apiGroups:
114114
- gateway.networking.k8s.io
115115
resources:
116+
- gateways
117+
- grpcroutes
116118
- httproutes
117-
verbs:
118-
- get
119-
- list
120-
- watch
121-
- apiGroups:
122-
- gateway.networking.k8s.io
123-
resources:
124119
- referencegrants
125120
verbs:
121+
- get
126122
- list
127-
- update
128123
- watch
129124
- apiGroups:
130125
- networking.k8s.io
131126
resources:
132127
- ingressclasses
128+
- ingresses
133129
verbs:
134130
- get
135131
- list
136132
- watch
137133
- apiGroups:
138134
- networking.k8s.io
139135
resources:
140-
- ingresses
136+
- ingresses/status
141137
verbs:
142138
- get
143-
- list
144139
- update
145-
- watch
146140
- apiGroups:
147-
- networking.k8s.io
141+
- ""
148142
resources:
149-
- ingresses/status
143+
- endpoints
150144
verbs:
151145
- get
152-
- update
146+
- list
147+
- watch
153148

154149
---
155150
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)