Skip to content

Commit faa9f92

Browse files
committed
feat(chart): Add default annotations for ingress nginx controller
Signed-off-by: Viet Nguyen Duc <nguyenducviet4496@gmail.com>
1 parent c4e4024 commit faa9f92

File tree

6 files changed

+130
-2
lines changed

6 files changed

+130
-2
lines changed

charts/selenium-grid/README.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,54 @@ To uninstall:
7979
helm uninstall selenium-grid
8080
```
8181

82+
## Ingress Configuration
83+
84+
By default, ingress is enabled without annotations set. If NGINX ingress controller is used, you need to set few annotations to override the default timeout values to avoid 504 errors (see #1808). Since in Selenium Grid the default of `SE_NODE_SESSION_TIMEOUT` and `SE_SESSION_REQUEST_TIMEOUT` is `300` seconds.
85+
86+
In order to make user experience better, there are few annotations will be set by default if NGINX ingress controller is used. Mostly relates to timeouts and buffer sizes.
87+
88+
If you are not using NGINX ingress controller, you can disable these default annotations by setting `ingress.nginx` to `nil` (aka null) via Helm CLI `--set ingress.nginx=null`) or via an override-values.yaml as below:
89+
90+
```yaml
91+
ingress:
92+
nginx:
93+
# nginx: null (alternative way)
94+
```
95+
96+
Similarly, if you want to disable a sub-config of `ingress.nginx`. For example: `--set ingress.nginx.proxyBuffer=null`)
97+
98+
You are also able to combine using both default annotations and your own annotations in `ingress.annotations`. Duplicated keys will be merged strategy overwrite with your own annotations in `ingress.annotations` take precedence.
99+
100+
```yaml
101+
ingress:
102+
nginx:
103+
proxyTimeout: 360
104+
annotations:
105+
nginx.ingress.kubernetes.io/proxy-connect-timeout: "3600" # This key will take 3600 instead of 360
106+
```
107+
108+
List mapping of chart values and default annotation(s)
109+
110+
```markdown
111+
# `ingress.nginx.proxyTimeout` pass value to annotation(s)
112+
nginx.ingress.kubernetes.io/proxy-connect-timeout
113+
nginx.ingress.kubernetes.io/proxy-send-timeout
114+
nginx.ingress.kubernetes.io/proxy-read-timeout
115+
nginx.ingress.kubernetes.io/proxy-next-upstream-timeout
116+
nginx.ingress.kubernetes.io/auth-keepalive-timeout
117+
118+
# `ingress.nginx.proxyBuffer` pass value to to annotation(s)
119+
nginx.ingress.kubernetes.io/proxy-request-buffering: "on"
120+
nginx.ingress.kubernetes.io/proxy-buffering: "on"
121+
122+
# `ingress.nginx.proxyBuffer.size` pass value to to annotation(s)
123+
nginx.ingress.kubernetes.io/proxy-buffer-size
124+
nginx.ingress.kubernetes.io/client-body-buffer-size
125+
126+
# `ingress.nginx.proxyBuffer.number` pass value to annotation(s)
127+
nginx.ingress.kubernetes.io/proxy-buffers-number
128+
```
129+
82130
## Configuration
83131

84132
For now, global configuration supported is:

charts/selenium-grid/templates/_helpers.tpl

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,29 @@ Ingress fullname
8080
{{- default "selenium-ingress" .Values.ingress.nameOverride | trunc 63 | trimSuffix "-" -}}
8181
{{- end -}}
8282

83+
{{- define "seleniumGrid.ingress.nginx.annotations.default" -}}
84+
{{- with .Values.ingress.nginx }}
85+
{{- with .proxyTimeout }}
86+
nginx.ingress.kubernetes.io/proxy-connect-timeout: {{ . | quote }}
87+
nginx.ingress.kubernetes.io/proxy-send-timeout: {{ . | quote }}
88+
nginx.ingress.kubernetes.io/proxy-read-timeout: {{ . | quote }}
89+
nginx.ingress.kubernetes.io/proxy-next-upstream-timeout: {{ . | quote }}
90+
nginx.ingress.kubernetes.io/auth-keepalive-timeout: {{ . | quote }}
91+
{{- end }}
92+
{{- with .proxyBuffer }}
93+
nginx.ingress.kubernetes.io/proxy-request-buffering: "on"
94+
nginx.ingress.kubernetes.io/proxy-buffering: "on"
95+
{{- with .size }}
96+
nginx.ingress.kubernetes.io/proxy-buffer-size: {{ . | quote }}
97+
nginx.ingress.kubernetes.io/client-body-buffer-size: {{ . | quote }}
98+
{{- end }}
99+
{{- with .number }}
100+
nginx.ingress.kubernetes.io/proxy-buffers-number: {{ . | quote }}
101+
{{- end }}
102+
{{- end }}
103+
{{- end }}
104+
{{- end -}}
105+
83106
{{/*
84107
Service Account fullname
85108
*/}}

charts/selenium-grid/templates/ingress.yaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,13 @@ metadata:
2020
{{- with .Values.customLabels }}
2121
{{- toYaml . | nindent 4 }}
2222
{{- end }}
23-
{{- with .Values.ingress.annotations }}
23+
{{- $ingressAnnotations := (include "seleniumGrid.ingress.nginx.annotations.default" . | toString | fromYaml ) }}
24+
{{- with .Values.ingress.annotations -}}
25+
{{- $ingressAnnotations = mergeOverwrite $ingressAnnotations . }}
26+
{{- end }}
27+
{{- if not (empty $ingressAnnotations) }}
2428
annotations:
25-
{{- toYaml . | nindent 4 }}
29+
{{- $ingressAnnotations | toYaml | nindent 4 }}
2630
{{- end }}
2731
spec:
2832
{{- if and .Values.ingress.className (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion) }}

charts/selenium-grid/values.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ ingress:
3636
enabled: true
3737
# Name of ingress class to select which controller will implement ingress resource
3838
className: ""
39+
# Refer to list nginx annotations: https://github.com/kubernetes/ingress-nginx/blob/main/docs/user-guide/nginx-configuration/annotations.md#annotations
40+
nginx:
41+
proxyTimeout: 300
42+
proxyBuffer:
43+
size: 512m
44+
number: 4
3945
# Custom annotations for ingress resource
4046
annotations: {}
4147
# Default host for the ingress resource

tests/charts/templates/render/dummy.yaml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,34 @@ global:
1111
values:
1212
- selenium
1313
topologyKey: "kubernetes.io/hostname"
14+
ingress:
15+
nginx:
16+
proxyTimeout: 360 # Set different proxy timout
17+
proxyBuffer:
18+
size: # Disable default
19+
# number: 4 # Keep using sub-config default
20+
annotations: # Add you own annotations
21+
nginx.ingress.kubernetes.io/use-regex: "true" # Add new key
22+
nginx.ingress.kubernetes.io/rewrite-target: /$2
23+
nginx.ingress.kubernetes.io/app-root: &gridAppRoot "/selenium"
24+
nginx.ingress.kubernetes.io/proxy-connect-timeout: "3600" # Override default key
25+
nginx.ingress.kubernetes.io/proxy-send-timeout: "3600" # Override default key
26+
hostname: ""
27+
paths:
28+
- path: /selenium(/|$)(.*)
29+
pathType: ImplementationSpecific
30+
backend:
31+
service:
32+
name: '{{ template "seleniumGrid.router.fullname" $ }}'
33+
port:
34+
number: 4444
35+
- path: /(/?)(session/.*/se/vnc)
36+
pathType: ImplementationSpecific
37+
backend:
38+
service:
39+
name: '{{ template "seleniumGrid.router.fullname" $ }}'
40+
port:
41+
number: 4444
1442

1543
isolateComponents: true
1644

tests/charts/templates/test.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,31 @@ def test_set_affinity(self):
2020
resources_name = ['selenium-chrome-node', 'selenium-distributor', 'selenium-edge-node', 'selenium-firefox-node',
2121
'selenium-event-bus', 'selenium-router', 'selenium-session-map', 'selenium-session-queue']
2222
count = 0
23+
logger.info(f"Assert affinity is set in global and nodes")
2324
for doc in LIST_OF_DOCUMENTS:
2425
if doc['metadata']['name'] in resources_name and doc['kind'] == 'Deployment':
26+
logger.info(f"Assert affinity is set in resource {doc['metadata']['name']}")
2527
self.assertTrue(doc['spec']['template']['spec']['affinity']['podAffinity']['requiredDuringSchedulingIgnoredDuringExecution'][0]['labelSelector']['matchExpressions'] is not None)
2628
count += 1
2729
self.assertEqual(count, len(resources_name), "Not all resources have affinity set")
2830

31+
def test_ingress_nginx_annotations(self):
32+
resources_name = ['selenium-ingress']
33+
count = 0
34+
for doc in LIST_OF_DOCUMENTS:
35+
if doc['metadata']['name'] in resources_name and doc['kind'] == 'Ingress':
36+
logger.info(f"Assert ingress ingress annotations")
37+
logger.info(f"Config `ingress.nginx.proxyTimeout` is able to be set a different value")
38+
self.assertTrue(doc['metadata']['annotations']['nginx.ingress.kubernetes.io/proxy-read-timeout'] == '360')
39+
logger.info(f"Duplicated in `ingress.annotations` take precedence to overwrite the default value")
40+
self.assertTrue(doc['metadata']['annotations']['nginx.ingress.kubernetes.io/proxy-connect-timeout'] == '3600')
41+
logger.info(f"Default annotation is able to be disabled by setting it to null")
42+
self.assertTrue(doc['metadata']['annotations'].get('nginx.ingress.kubernetes.io/proxy-buffer-size') is None)
43+
logger.info(f"Default annotation is added if no override value")
44+
self.assertTrue(doc['metadata']['annotations']['nginx.ingress.kubernetes.io/proxy-buffers-number'] == '4')
45+
count += 1
46+
self.assertEqual(count, len(resources_name), "No ingress resources found")
47+
2948
if __name__ == '__main__':
3049
failed = False
3150
try:

0 commit comments

Comments
 (0)