Skip to content

Commit d14879b

Browse files
committed
feat(autoscaling): Unified parameters to set scaled options for browser nodes
Signed-off-by: Viet Nguyen Duc <nguyenducviet4496@gmail.com>
1 parent cef5534 commit d14879b

10 files changed

+124
-98
lines changed

charts/selenium-grid/README.md

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,13 @@ This table contains the configuration parameters of the chart and their default
109109
| `ingress.tls` | `[]` | TLS backend configuration for ingress resource |
110110
| `autoscaling.enableWithExistingKEDA` | `false` | Enable autoscaling of browser nodes. |
111111
| `autoscaling.enabled` | `false` | Same as above plus installation of KEDA |
112-
| `autoscaling.scalingType` | `job` | Which typ of KEDA scaling to use: job or deployment |
113-
| `autoscaling.scaledJobOptions` | See `values.yaml` | Options for KEDA ScaledJobs |
112+
| `autoscaling.scalingType` | `job` | Which typ of KEDA scaling to use: `job` or `deployment` |
113+
| `autoscaling.scaledOptions` | See `values.yaml` | Common options for KEDA scaled resources (both ScaledJobs and ScaledObjects) |
114+
| `autoscaling.scaledOptions.minReplicaCount` | `0` | Min number of replicas that each browser nodes has when autoscaling |
115+
| `autoscaling.scaledOptions.maxReplicaCount` | `8` | Max number of replicas that each browser nodes can auto scale up to |
116+
| `autoscaling.scaledOptions.pollingInterval` | `10` | The interval to check each trigger on |
117+
| `autoscaling.scaledJobOptions` | See `values.yaml` | Options for KEDA ScaledJobs (when `scalingType` is set to `job`) |
118+
| `autoscaling.scaledObjectOptions` | See `values.yaml` | Options for KEDA ScaledObjects (when `scalingType` is set to `deployment`) |
114119
| `autoscaling.deregisterLifecycle` | See `values.yaml` | Lifecycle applied to pods of deployments controlled by KEDA. Makes the node deregister from selenium hub |
115120
| `chromeNode.enabled` | `true` | Enable chrome nodes |
116121
| `chromeNode.deploymentEnabled` | `true` | Enable creation of Deployment for chrome nodes |
@@ -146,8 +151,9 @@ This table contains the configuration parameters of the chart and their default
146151
| `chromeNode.hpa.url` | `{{ include "seleniumGrid.graphqlURL" . }}` | Graphql Url of the hub or the router |
147152
| `chromeNode.hpa.browserName` | `chrome` | BrowserName from the capability |
148153
| `chromeNode.hpa.browserVersion` | `` | BrowserVersion from the capability |
149-
| `chromeNode.maxReplicaCount` | `8` | Max number of replicas that this browsernode can auto scale up to |
150-
| `chromeNode.minReplicaCount` | `1` | Min number of replicas that this browsernode has when jobs are running |
154+
| `chromeNode.scaledOptions` | See `values.yaml` | Override the global `autoscaling.scaledOptions` with specific scaled options for chrome nodes |
155+
| `chromeNode.scaledJobOptions` | See `values.yaml` | Override the global `autoscaling.scaledJobOptions` with specific scaled options for chrome nodes |
156+
| `chromeNode.scaledObjectOptions` | See `values.yaml` | Override the global `autoscaling.scaledObjectOptions` with specific scaled options for chrome nodes |
151157
| `firefoxNode.enabled` | `true` | Enable firefox nodes |
152158
| `firefoxNode.deploymentEnabled` | `true` | Enable creation of Deployment for firefox nodes |
153159
| `firefoxNode.replicas` | `1` | Number of firefox nodes. Disabled if autoscaling is enabled. |
@@ -182,8 +188,9 @@ This table contains the configuration parameters of the chart and their default
182188
| `firefoxNode.hpa.url` | `{{ include "seleniumGrid.graphqlURL" . }}` | Graphql Url of the hub or the router |
183189
| `firefoxNode.hpa.browserName` | `firefox` | BrowserName from the capability |
184190
| `firefoxNode.hpa.browserVersion` | `` | BrowserVersion from the capability |
185-
| `firefoxNode.maxReplicaCount` | `8` | Max number of replicas that this browsernode can auto scale up to |
186-
| `firefoxNode.minReplicaCount` | `1` | Min number of replicas that this browsernode has when jobs are running |
191+
| `firefoxNode.scaledOptions` | See `values.yaml` | Override the global `autoscaling.scaledOptions` with specific scaled options for firefox nodes |
192+
| `firefoxNode.scaledJobOptions` | See `values.yaml` | Override the global `autoscaling.scaledJobOptions` with specific scaled options for firefox nodes |
193+
| `firefoxNode.scaledObjectOptions` | See `values.yaml` | Override the global `autoscaling.scaledObjectOptions` with specific scaled options for firefox nodes |
187194
| `edgeNode.enabled` | `true` | Enable edge nodes |
188195
| `edgeNode.deploymentEnabled` | `true` | Enable creation of Deployment for edge nodes |
189196
| `edgeNode.replicas` | `1` | Number of edge nodes. Disabled if autoscaling is enabled. |
@@ -218,8 +225,9 @@ This table contains the configuration parameters of the chart and their default
218225
| `edgeNode.hpa.url` | `{{ include "seleniumGrid.graphqlURL" . }}` | Graphql Url of the hub or the router |
219226
| `edgeNode.hpa.browserName` | `edge` | BrowserName from the capability |
220227
| `edgeNode.hpa.browserVersion` | `` | BrowserVersion from the capability |
221-
| `edgeNode.maxReplicaCount` | `8` | Max number of replicas that this browsernode can auto scale up to |
222-
| `edgeNode.minReplicaCount` | `1` | Min number of replicas that this browsernode has when jobs are running |
228+
| `edgeNode.scaledOptions` | See `values.yaml` | Override the global `autoscaling.scaledOptions` with specific scaled options for edge nodes |
229+
| `edgeNode.scaledJobOptions` | See `values.yaml` | Override the global `autoscaling.scaledJobOptions` with specific scaled options for edge nodes |
230+
| `edgeNode.scaledObjectOptions` | See `values.yaml` | Override the global `autoscaling.scaledObjectOptions` with specific scaled options for edge nodes |
223231
| `videoRecorder.enabled` | `false` | Enable video recorder for node |
224232
| `videoRecorder.imageName` | `selenium/video` | Selenium video recoder image name |
225233
| `videoRecorder.imageTag` | `ffmpeg-6.0-20231102` | Image tag of video recorder |

charts/selenium-grid/templates/_helpers.tpl

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,47 @@ Is autoscaling using KEDA enabled
101101
{{- or .Values.autoscaling.enabled .Values.autoscaling.enableWithExistingKEDA | ternary "true" "" -}}
102102
{{- end -}}
103103

104+
{{/*
105+
Common autoscaling spec template
106+
*/}}
107+
{{- define "seleniumGrid.autoscalingTemplate" -}}
108+
{{- $spec := toYaml (dict) -}}
109+
{{/* Merge with precedence from right to left */}}
110+
{{- with .Values.autoscaling.scaledOptions -}}
111+
{{- $spec = mergeOverwrite ($spec | fromYaml) . | toYaml -}}
112+
{{- end -}}
113+
{{- with .node.scaledOptions -}}
114+
{{- $spec = mergeOverwrite ($spec | fromYaml) . | toYaml -}}
115+
{{- end -}}
116+
{{- if eq .Values.autoscaling.scalingType "deployment" -}}
117+
{{- with .Values.autoscaling.scaledObjectOptions -}}
118+
{{- $spec = mergeOverwrite ($spec | fromYaml) . | toYaml -}}
119+
{{- end -}}
120+
{{- with .node.scaledObjectOptions -}}
121+
{{- $spec = mergeOverwrite ($spec | fromYaml) . | toYaml -}}
122+
{{- end -}}
123+
{{- $spec = mergeOverwrite ($spec | fromYaml) (dict "scaleTargetRef" (dict "name" .name)) | toYaml -}}
124+
{{- else if eq .Values.autoscaling.scalingType "job" -}}
125+
{{- with .Values.autoscaling.scaledJobOptions -}}
126+
{{- $spec = mergeOverwrite ($spec | fromYaml) . | toYaml -}}
127+
{{- end -}}
128+
{{- with .node.scaledJobOptions -}}
129+
{{- $spec = mergeOverwrite ($spec | fromYaml) . | toYaml -}}
130+
{{- end -}}
131+
{{- $spec = mergeOverwrite ($spec | fromYaml) (dict "jobTargetRef" .podTemplate) | toYaml -}}
132+
{{- end -}}
133+
{{- if and $spec (ne $spec "{}") -}}
134+
{{ tpl $spec $ }}
135+
{{- end -}}
136+
{{- if not .Values.autoscaling.scaledOptions.triggers }}
137+
triggers:
138+
- type: selenium-grid
139+
{{- with .node.hpa }}
140+
metadata: {{- tpl (toYaml .) $ | nindent 6 }}
141+
{{- end }}
142+
{{- end }}
143+
{{- end -}}
144+
104145
{{/*
105146
Common pod template
106147
*/}}

charts/selenium-grid/templates/chrome-node-hpa.yaml

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,8 @@ metadata:
1111
labels:
1212
deploymentName: {{ template "seleniumGrid.chromeNode.fullname" . }}
1313
spec:
14-
maxReplicaCount: {{ .Values.chromeNode.maxReplicaCount }}
15-
minReplicaCount: {{ .Values.chromeNode.minReplicaCount }}
16-
scaleTargetRef:
17-
name: {{ template "seleniumGrid.chromeNode.fullname" . }}
18-
triggers:
19-
- type: selenium-grid
20-
{{- with .Values.chromeNode.hpa }}
21-
metadata: {{- tpl (toYaml .) $ | nindent 8 }}
22-
{{- end }}
14+
{{- $podScope := deepCopy . -}}
15+
{{- $_ := set $podScope "name" (include "seleniumGrid.chromeNode.fullname" .) -}}
16+
{{- $_ = set $podScope "node" .Values.chromeNode -}}
17+
{{- include "seleniumGrid.autoscalingTemplate" $podScope | nindent 2 }}
2318
{{- end }}

charts/selenium-grid/templates/chrome-node-scaledjobs.yaml

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,10 @@ metadata:
1919
{{- toYaml . | nindent 4 }}
2020
{{- end }}
2121
spec:
22-
maxReplicaCount: {{ .Values.chromeNode.maxReplicaCount }}
23-
{{- with .Values.autoscaling.scaledJobOptions -}}
24-
{{ toYaml . | nindent 2 }}
25-
{{- end }}
26-
triggers:
27-
- type: selenium-grid
28-
{{- with .Values.chromeNode.hpa }}
29-
metadata: {{- tpl (toYaml .) $ | nindent 8 }}
30-
{{- end }}
31-
jobTargetRef:
32-
parallelism: 1
33-
completions: 1
34-
backoffLimit: 0
35-
{{- $podScope := deepCopy . -}}
36-
{{- $_ := set $podScope "name" "selenium-chrome-node" -}}
37-
{{- $_ = set $podScope "node" .Values.chromeNode -}}
38-
{{- $_ = set $podScope "uploader" (get .Values.videoRecorder (.Values.videoRecorder.uploader | toString)) -}}
39-
{{- include "seleniumGrid.podTemplate" $podScope | nindent 4 }}
22+
{{- $podScope := deepCopy . -}}
23+
{{- $_ := set $podScope "name" "selenium-chrome-node" -}}
24+
{{- $_ = set $podScope "node" .Values.chromeNode -}}
25+
{{- $_ = set $podScope "uploader" (get .Values.videoRecorder (.Values.videoRecorder.uploader | toString)) -}}
26+
{{- $_ = set $podScope "podTemplate" (include "seleniumGrid.podTemplate" $podScope | fromYaml) }}
27+
{{- include "seleniumGrid.autoscalingTemplate" $podScope | nindent 2 }}
4028
{{- end }}

charts/selenium-grid/templates/edge-node-hpa.yaml

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,8 @@ metadata:
1111
labels:
1212
deploymentName: {{ template "seleniumGrid.edgeNode.fullname" . }}
1313
spec:
14-
maxReplicaCount: {{ .Values.edgeNode.maxReplicaCount }}
15-
minReplicaCount: {{ .Values.edgeNode.minReplicaCount }}
16-
scaleTargetRef:
17-
name: {{ template "seleniumGrid.edgeNode.fullname" . }}
18-
triggers:
19-
- type: selenium-grid
20-
{{- with .Values.edgeNode.hpa }}
21-
metadata: {{- tpl (toYaml .) $ | nindent 8 }}
22-
{{- end }}
14+
{{- $podScope := deepCopy . -}}
15+
{{- $_ := set $podScope "name" (include "seleniumGrid.edgeNode.fullname" .) -}}
16+
{{- $_ = set $podScope "node" .Values.edgeNode -}}
17+
{{- include "seleniumGrid.autoscalingTemplate" $podScope | nindent 2 }}
2318
{{- end }}

charts/selenium-grid/templates/edge-node-scaledjob.yaml

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,10 @@ metadata:
1919
{{- toYaml . | nindent 4 }}
2020
{{- end }}
2121
spec:
22-
maxReplicaCount: {{ .Values.edgeNode.maxReplicaCount }}
23-
{{- with .Values.autoscaling.scaledJobOptions -}}
24-
{{ toYaml . | nindent 2 }}
25-
{{- end }}
26-
triggers:
27-
- type: selenium-grid
28-
{{- with .Values.edgeNode.hpa }}
29-
metadata: {{- tpl (toYaml .) $ | nindent 8 }}
30-
{{- end }}
31-
jobTargetRef:
32-
parallelism: 1
33-
completions: 1
34-
backoffLimit: 0
35-
{{- $podScope := deepCopy . -}}
36-
{{- $_ := set $podScope "name" "selenium-edge-node" -}}
37-
{{- $_ = set $podScope "node" .Values.edgeNode -}}
38-
{{- $_ = set $podScope "uploader" (get .Values.videoRecorder (.Values.videoRecorder.uploader | toString)) -}}
39-
{{- include "seleniumGrid.podTemplate" $podScope | nindent 4 }}
22+
{{- $podScope := deepCopy . -}}
23+
{{- $_ := set $podScope "name" "selenium-edge-node" -}}
24+
{{- $_ = set $podScope "node" .Values.edgeNode -}}
25+
{{- $_ = set $podScope "uploader" (get .Values.videoRecorder (.Values.videoRecorder.uploader | toString)) -}}
26+
{{- $_ = set $podScope "podTemplate" (include "seleniumGrid.podTemplate" $podScope | fromYaml) }}
27+
{{- include "seleniumGrid.autoscalingTemplate" $podScope | nindent 2 }}
4028
{{- end }}

charts/selenium-grid/templates/event-bus-configmap.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ metadata:
1515
{{- toYaml . | nindent 4 }}
1616
{{- end }}
1717
data:
18-
SE_EVENT_BUS_HOST: {{ $eventBusHost }}
18+
SE_EVENT_BUS_HOST: {{ $eventBusHost | quote }}
1919
SE_EVENT_BUS_PUBLISH_PORT: {{ $eventBusPublishPort | quote }}
2020
SE_EVENT_BUS_SUBSCRIBE_PORT: {{ $eventBusSubscribePort | quote }}

charts/selenium-grid/templates/firefox-node-hpa.yaml

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,8 @@ metadata:
1111
labels:
1212
deploymentName: {{ template "seleniumGrid.firefoxNode.fullname" . }}
1313
spec:
14-
maxReplicaCount: {{ .Values.firefoxNode.maxReplicaCount }}
15-
minReplicaCount: {{ .Values.firefoxNode.minReplicaCount }}
16-
scaleTargetRef:
17-
name: {{ template "seleniumGrid.firefoxNode.fullname" . }}
18-
triggers:
19-
- type: selenium-grid
20-
{{- with .Values.firefoxNode.hpa }}
21-
metadata: {{- tpl (toYaml .) $ | nindent 8 }}
22-
{{- end }}
14+
{{- $podScope := deepCopy . -}}
15+
{{- $_ := set $podScope "name" (include "seleniumGrid.firefoxNode.fullname" .) -}}
16+
{{- $_ = set $podScope "node" .Values.firefoxNode -}}
17+
{{- include "seleniumGrid.autoscalingTemplate" $podScope | nindent 2 }}
2318
{{- end }}

charts/selenium-grid/templates/firefox-node-scaledjob.yaml

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,10 @@ metadata:
1919
{{- toYaml . | nindent 4 }}
2020
{{- end }}
2121
spec:
22-
maxReplicaCount: {{ .Values.firefoxNode.maxReplicaCount }}
23-
{{- with .Values.autoscaling.scaledJobOptions -}}
24-
{{ toYaml . | nindent 2 }}
25-
{{- end }}
26-
triggers:
27-
- type: selenium-grid
28-
{{- with .Values.firefoxNode.hpa }}
29-
metadata: {{- tpl (toYaml .) $ | nindent 8 }}
30-
{{- end }}
31-
jobTargetRef:
32-
parallelism: 1
33-
completions: 1
34-
backoffLimit: 0
35-
{{- $podScope := deepCopy . -}}
36-
{{- $_ := set $podScope "name" "selenium-firefox-node" -}}
37-
{{- $_ = set $podScope "node" .Values.firefoxNode -}}
38-
{{- $_ = set $podScope "uploader" (get .Values.videoRecorder (.Values.videoRecorder.uploader | toString)) -}}
39-
{{- include "seleniumGrid.podTemplate" $podScope | nindent 4 }}
22+
{{- $podScope := deepCopy . -}}
23+
{{- $_ := set $podScope "name" "selenium-firefox-node" -}}
24+
{{- $_ = set $podScope "node" .Values.firefoxNode -}}
25+
{{- $_ = set $podScope "uploader" (get .Values.videoRecorder (.Values.videoRecorder.uploader | toString)) -}}
26+
{{- $_ = set $podScope "podTemplate" (include "seleniumGrid.podTemplate" $podScope | fromYaml) }}
27+
{{- include "seleniumGrid.autoscalingTemplate" $podScope | nindent 2 }}
4028
{{- end }}

0 commit comments

Comments
 (0)