Skip to content

Commit

Permalink
K8s: Multiple nodes browser in Helm configs (#2475)
Browse files Browse the repository at this point in the history
Signed-off-by: Viet Nguyen Duc <[email protected]>
  • Loading branch information
VietND96 authored Nov 26, 2024
1 parent 6dc901e commit bea0769
Show file tree
Hide file tree
Showing 23 changed files with 436 additions and 294 deletions.
28 changes: 14 additions & 14 deletions .keda/scalers/selenium-grid-scaler.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ metadata:
name: selenium-grid-chrome-scaledobject
namespace: keda
labels:
deploymentName: selenium-chrome-node
deploymentName: selenium-node-chrome
spec:
maxReplicaCount: 8
scaleTargetRef:
name: selenium-chrome-node
name: selenium-node-chrome
triggers:
- type: selenium-grid
metadata:
Expand All @@ -78,11 +78,11 @@ metadata:
name: selenium-grid-firefox-scaledobject
namespace: keda
labels:
deploymentName: selenium-firefox-node
deploymentName: selenium-node-firefox
spec:
maxReplicaCount: 8
scaleTargetRef:
name: selenium-firefox-node
name: selenium-node-firefox
triggers:
- type: selenium-grid
metadata:
Expand All @@ -99,11 +99,11 @@ metadata:
name: selenium-grid-edge-scaledobject
namespace: keda
labels:
deploymentName: selenium-edge-node
deploymentName: selenium-node-edge
spec:
maxReplicaCount: 8
scaleTargetRef:
name: selenium-edge-node
name: selenium-node-edge
triggers:
- type: selenium-grid
metadata:
Expand All @@ -121,11 +121,11 @@ metadata:
name: selenium-grid-chrome-scaledobject
namespace: keda
labels:
deploymentName: selenium-chrome-node
deploymentName: selenium-node-chrome
spec:
maxReplicaCount: 8
scaleTargetRef:
name: selenium-chrome-node
name: selenium-node-chrome
triggers:
- type: selenium-grid
metadata:
Expand All @@ -143,11 +143,11 @@ metadata:
name: selenium-grid-chrome-91-scaledobject
namespace: keda
labels:
deploymentName: selenium-chrome-node-91
deploymentName: selenium-node-chrome-91
spec:
maxReplicaCount: 8
scaleTargetRef:
name: selenium-chrome-node-91
name: selenium-node-chrome-91
triggers:
- type: selenium-grid
metadata:
Expand All @@ -163,11 +163,11 @@ metadata:
name: selenium-grid-chrome-90-scaledobject
namespace: keda
labels:
deploymentName: selenium-chrome-node-90
deploymentName: selenium-node-chrome-90
spec:
maxReplicaCount: 8
scaleTargetRef:
name: selenium-chrome-node-90
name: selenium-node-chrome-90
triggers:
- type: selenium-grid
metadata:
Expand Down Expand Up @@ -219,11 +219,11 @@ metadata:
name: selenium-grid-chrome-scaledobject
namespace: keda
labels:
deploymentName: selenium-chrome-node
deploymentName: selenium-node-chrome
spec:
maxReplicaCount: 8
scaleTargetRef:
name: selenium-chrome-node
name: selenium-node-chrome
triggers:
- type: selenium-grid
metadata:
Expand Down
4 changes: 4 additions & 0 deletions charts/selenium-grid/CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,10 @@ A Helm chart for creating a Selenium Grid Server in Kubernetes
| autoscaling.scaledObjectOptions.scaleTargetRef.kind | string | `"Deployment"` | Target reference for KEDA ScaledObject |
| autoscaling.terminationGracePeriodSeconds | int | `3600` | Define terminationGracePeriodSeconds for scalingType "deployment". Period for `deregisterLifecycle` to gracefully shut down the node before force terminating it |
| autoscaling.deregisterLifecycle | string | `nil` | Define preStop command to shut down the node gracefully when scalingType is set to "deployment" |
| crossBrowsers.chromeNode | list | `[{"nameOverride":null}]` | Additional chrome nodes, array of objects with the same structure as `chromeNode` |
| crossBrowsers.firefoxNode | list | `[{"nameOverride":null}]` | Additional firefox nodes, array of objects with the same structure as `firefoxNode` |
| crossBrowsers.edgeNode | list | `[{"nameOverride":null}]` | Additional edge nodes, array of objects with the same structure as `edgeNode` |
| crossBrowsers.relayNode | list | `[{"nameOverride":null}]` | Additional release nodes, array of objects with the same structure as `relayNode` |
| chromeNode.enabled | bool | `true` | Enable chrome nodes |
| chromeNode.deploymentEnabled | bool | `true` | NOTE: Only used when autoscaling.enabled is false Enable creation of Deployment true (default) - if you want long-living pods false - for provisioning your own custom type such as Jobs |
| chromeNode.updateStrategy | object | `{"type":"RollingUpdate"}` | Global update strategy will be overwritten by individual component |
Expand Down
46 changes: 46 additions & 0 deletions charts/selenium-grid/cross-browsers-values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
crossBrowsers:
chromeNode:
# Keep the first iteration with latest version of Chrome
- nameOverride:
- nameOverride: '{{ $.Release.Name }}-node-chrome-130'
imageTag: '130.0'
hpa:
browserVersion: '130.0'
- nameOverride: '{{ $.Release.Name }}-node-chrome-129'
imageTag: '129.0'
hpa:
browserVersion: '129.0'
- nameOverride: '{{ $.Release.Name }}-node-chrome-128'
imageTag: '128.0'
hpa:
browserVersion: '128.0'
firefoxNode:
# Keep the first iteration with latest version of Firefox
- nameOverride:
- nameOverride: '{{ $.Release.Name }}-node-firefox-130'
imageTag: '130.0'
hpa:
browserVersion: '130.0'
- nameOverride: '{{ $.Release.Name }}-node-firefox-129'
imageTag: '129.0'
hpa:
browserVersion: '129.0'
- nameOverride: '{{ $.Release.Name }}-node-firefox-128'
imageTag: '128.0'
hpa:
browserVersion: '128.0'
edgeNode:
# Keep the first iteration with latest version of Edge
- nameOverride:
- nameOverride: '{{ $.Release.Name }}-node-edge-130'
imageTag: '130.0'
hpa:
browserVersion: '130.0'
- nameOverride: '{{ $.Release.Name }}-node-edge-129'
imageTag: '129.0'
hpa:
browserVersion: '129.0'
- nameOverride: '{{ $.Release.Name }}-node-edge-128'
imageTag: '128.0'
hpa:
browserVersion: '128.0'
16 changes: 12 additions & 4 deletions charts/selenium-grid/templates/_nameHelpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -123,28 +123,36 @@ SessionQueue fullname
Chrome node fullname
*/}}
{{- define "seleniumGrid.chromeNode.fullname" -}}
{{- tpl (default (include "seleniumGrid.component.name" (list "selenium-chrome-node" $)) .Values.chromeNode.nameOverride) $ | trunc 63 | trimSuffix "-" -}}
{{- $component := index . 0 }}
{{- $root := index . 1 }}
{{- tpl (default (include "seleniumGrid.component.name" (list "selenium-node-chrome" $root)) $component.nameOverride) $root | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Firefox node fullname
*/}}
{{- define "seleniumGrid.firefoxNode.fullname" -}}
{{- tpl (default (include "seleniumGrid.component.name" (list "selenium-firefox-node" $)) .Values.firefoxNode.nameOverride) $ | trunc 63 | trimSuffix "-" -}}
{{- $component := index . 0 }}
{{- $root := index . 1 }}
{{- tpl (default (include "seleniumGrid.component.name" (list "selenium-node-firefox" $root)) $component.nameOverride) $root | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Edge node fullname
*/}}
{{- define "seleniumGrid.edgeNode.fullname" -}}
{{- tpl (default (include "seleniumGrid.component.name" (list "selenium-edge-node" $)) .Values.edgeNode.nameOverride) $ | trunc 63 | trimSuffix "-" -}}
{{- $component := index . 0 }}
{{- $root := index . 1 }}
{{- tpl (default (include "seleniumGrid.component.name" (list "selenium-node-edge" $root)) $component.nameOverride) $root | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Relay node fullname
*/}}
{{- define "seleniumGrid.relayNode.fullname" -}}
{{- tpl (default (include "seleniumGrid.component.name" (list "selenium-relay-node" $)) .Values.relayNode.nameOverride) $ | trunc 63 | trimSuffix "-" -}}
{{- $component := index . 0 }}
{{- $root := index . 1 }}
{{- tpl (default (include "seleniumGrid.component.name" (list "selenium-node-relay" $root)) $component.nameOverride) $root | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Expand Down
42 changes: 23 additions & 19 deletions charts/selenium-grid/templates/chrome-node-deployment.yaml
Original file line number Diff line number Diff line change
@@ -1,36 +1,40 @@
{{- if and .Values.chromeNode.enabled ((eq (include "seleniumGrid.useKEDA" .) "true") | ternary (eq .Values.autoscaling.scalingType "deployment") .Values.chromeNode.deploymentEnabled) }}
{{- range $i, $newNode := .Values.crossBrowsers.chromeNode }}
{{- $nodeConfig := merge $newNode $.Values.chromeNode -}}
{{- if and $nodeConfig.enabled ((eq (include "seleniumGrid.useKEDA" $) "true") | ternary (eq $.Values.autoscaling.scalingType "deployment") $nodeConfig.deploymentEnabled) }}
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ template "seleniumGrid.chromeNode.fullname" . }}
namespace: {{ .Release.Namespace }}
name: {{ template "seleniumGrid.chromeNode.fullname" (list $nodeConfig $) }}
namespace: {{ $.Release.Namespace }}
labels:
app: {{ template "seleniumGrid.chromeNode.fullname" . }}
app.kubernetes.io/name: {{ template "seleniumGrid.chromeNode.fullname" . }}
{{- include "seleniumGrid.commonLabels" . | nindent 4 }}
{{- with .Values.chromeNode.labels }}
app: {{ template "seleniumGrid.chromeNode.fullname" (list $nodeConfig $) }}
app.kubernetes.io/name: {{ template "seleniumGrid.chromeNode.fullname" (list $nodeConfig $) }}
{{- include "seleniumGrid.commonLabels" $ | nindent 4 }}
{{- with $nodeConfig.labels }}
{{- toYaml . | nindent 4 }}
{{- end }}
{{- with .Values.customLabels }}
{{- with $.Values.customLabels }}
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
strategy:
{{- template "seleniumGrid.updateStrategy" (list $.Values.chromeNode $.Values.global.seleniumGrid) }}
{{- template "seleniumGrid.updateStrategy" (list $nodeConfig $.Values.global.seleniumGrid) }}
{{- if not (eq (include "seleniumGrid.useKEDA" $) "true") }}
replicas: {{ .Values.chromeNode.replicas }}
replicas: {{ $nodeConfig.replicas }}
{{- else }}
replicas: {{ default $.Values.autoscaling.scaledOptions.minReplicaCount ($.Values.chromeNode.scaledOptions).minReplicaCount }}
replicas: {{ default $.Values.autoscaling.scaledOptions.minReplicaCount ($nodeConfig.scaledOptions).minReplicaCount }}
{{- end }}
revisionHistoryLimit: {{ .Values.global.seleniumGrid.revisionHistoryLimit }}
revisionHistoryLimit: {{ $.Values.global.seleniumGrid.revisionHistoryLimit }}
selector:
matchLabels:
app: {{ template "seleniumGrid.chromeNode.fullname" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- $podScope := deepCopy . -}}
{{- $_ := set $podScope "name" (include "seleniumGrid.chromeNode.fullname" .) -}}
{{- $_ = set $podScope "node" .Values.chromeNode -}}
{{- $_ = set $podScope "recorder" (mergeOverwrite .Values.videoRecorder .Values.chromeNode.videoRecorder) -}}
{{- $_ = set $podScope "uploader" (get .Values.videoRecorder ($podScope.recorder.uploader.name | toString)) -}}
app: {{ template "seleniumGrid.chromeNode.fullname" (list $nodeConfig $) }}
app.kubernetes.io/instance: {{ $.Release.Name }}
{{- $podScope := deepCopy $ -}}
{{- $_ := set $podScope "name" (include "seleniumGrid.chromeNode.fullname" (list $nodeConfig $)) -}}
{{- $_ = set $podScope "node" $nodeConfig -}}
{{- $_ = set $podScope "recorder" (mergeOverwrite $.Values.videoRecorder $nodeConfig.videoRecorder) -}}
{{- $_ = set $podScope "uploader" (get $.Values.videoRecorder ($podScope.recorder.uploader.name | toString)) -}}
{{- include "seleniumGrid.podTemplate" $podScope | nindent 2 }}
---
{{- end }}
{{- end }}
28 changes: 16 additions & 12 deletions charts/selenium-grid/templates/chrome-node-hpa.yaml
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
{{- if and .Values.chromeNode.enabled (eq (include "seleniumGrid.useKEDA" .) "true") (eq .Values.autoscaling.scalingType "deployment") }}
{{- range $i, $newNode := .Values.crossBrowsers.chromeNode }}
{{- $nodeConfig := merge $newNode $.Values.chromeNode -}}
{{- if and $nodeConfig.enabled (eq (include "seleniumGrid.useKEDA" $) "true") (eq $.Values.autoscaling.scalingType "deployment") }}
apiVersion: keda.sh/v1alpha1
kind: ScaledObject
metadata:
name: {{ template "seleniumGrid.chromeNode.fullname" . }}
namespace: {{ .Release.Namespace }}
name: {{ template "seleniumGrid.chromeNode.fullname" (list $nodeConfig $) }}
namespace: {{ $.Release.Namespace }}
annotations:
{{- with .Values.autoscaling.annotations }}
{{- with $.Values.autoscaling.annotations }}
{{- toYaml . | nindent 4 }}
{{- end }}
labels:
deploymentName: {{ template "seleniumGrid.chromeNode.fullname" . }}
{{- include "seleniumGrid.commonLabels" . | nindent 4 }}
{{- include "seleniumGrid.autoscalingLabels" . | nindent 4 }}
{{- with .Values.chromeNode.labels }}
deploymentName: {{ template "seleniumGrid.chromeNode.fullname" (list $nodeConfig $) }}
{{- include "seleniumGrid.commonLabels" $ | nindent 4 }}
{{- include "seleniumGrid.autoscalingLabels" $ | nindent 4 }}
{{- with $nodeConfig.labels }}
{{- toYaml . | nindent 4 }}
{{- end }}
{{- with .Values.customLabels }}
{{- with $.Values.customLabels }}
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
{{- $podScope := deepCopy . -}}
{{- $_ := set $podScope "name" (include "seleniumGrid.chromeNode.fullname" .) -}}
{{- $_ = set $podScope "node" .Values.chromeNode -}}
{{- $podScope := deepCopy $ -}}
{{- $_ := set $podScope "name" (include "seleniumGrid.chromeNode.fullname" (list $nodeConfig $)) -}}
{{- $_ = set $podScope "node" $nodeConfig -}}
{{- include "seleniumGrid.autoscalingTemplate" $podScope | nindent 2 }}
---
{{- end }}
{{- end }}
34 changes: 19 additions & 15 deletions charts/selenium-grid/templates/chrome-node-scaledjobs.yaml
Original file line number Diff line number Diff line change
@@ -1,30 +1,34 @@
{{- if and .Values.chromeNode.enabled (include "seleniumGrid.useKEDA" .) (eq .Values.autoscaling.scalingType "job") }}
{{- range $i, $newNode := .Values.crossBrowsers.chromeNode }}
{{- $nodeConfig := merge $newNode $.Values.chromeNode -}}
{{- if and $nodeConfig.enabled (include "seleniumGrid.useKEDA" $) (eq $.Values.autoscaling.scalingType "job") }}
apiVersion: keda.sh/v1alpha1
kind: ScaledJob
metadata:
name: {{ template "seleniumGrid.chromeNode.fullname" . }}
namespace: {{ .Release.Namespace }}
name: {{ template "seleniumGrid.chromeNode.fullname" (list $nodeConfig $) }}
namespace: {{ $.Release.Namespace }}
annotations:
{{- with .Values.autoscaling.annotations }}
{{- with $.Values.autoscaling.annotations }}
{{- toYaml . | nindent 4 }}
{{- end }}
labels:
app: {{ template "seleniumGrid.chromeNode.fullname" . }}
app.kubernetes.io/name: {{ template "seleniumGrid.chromeNode.fullname" . }}
{{- include "seleniumGrid.commonLabels" . | nindent 4 }}
{{- include "seleniumGrid.autoscalingLabels" . | nindent 4 }}
{{- with .Values.chromeNode.labels }}
app: {{ template "seleniumGrid.chromeNode.fullname" (list $nodeConfig $) }}
app.kubernetes.io/name: {{ template "seleniumGrid.chromeNode.fullname" (list $nodeConfig $) }}
{{- include "seleniumGrid.commonLabels" $ | nindent 4 }}
{{- include "seleniumGrid.autoscalingLabels" $ | nindent 4 }}
{{- with $nodeConfig.labels }}
{{- toYaml . | nindent 4 }}
{{- end }}
{{- with .Values.customLabels }}
{{- with $.Values.customLabels }}
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
{{- $podScope := deepCopy . -}}
{{- $_ := set $podScope "name" (include "seleniumGrid.chromeNode.fullname" .) -}}
{{- $_ = set $podScope "node" .Values.chromeNode -}}
{{- $_ = set $podScope "recorder" (mergeOverwrite .Values.videoRecorder .Values.chromeNode.videoRecorder) -}}
{{- $_ = set $podScope "uploader" (get .Values.videoRecorder ($podScope.recorder.uploader.name | toString)) -}}
{{- $podScope := deepCopy $ -}}
{{- $_ := set $podScope "name" (include "seleniumGrid.chromeNode.fullname" (list $nodeConfig $)) -}}
{{- $_ = set $podScope "node" $nodeConfig -}}
{{- $_ = set $podScope "recorder" (mergeOverwrite $.Values.videoRecorder $nodeConfig.videoRecorder) -}}
{{- $_ = set $podScope "uploader" (get $.Values.videoRecorder ($podScope.recorder.uploader.name | toString)) -}}
{{- $_ = set $podScope "podTemplate" (include "seleniumGrid.podTemplate" $podScope | fromYaml) }}
{{- include "seleniumGrid.autoscalingTemplate" $podScope | nindent 2 }}
---
{{- end }}
{{- end }}
Loading

0 comments on commit bea0769

Please sign in to comment.