Skip to content

Commit 6bad977

Browse files
authored
K8s: Update overProvisionRatio to use scalingModifiers instead scaler trigger param (#2930)
Signed-off-by: Viet Nguyen Duc <[email protected]>
1 parent 57e4626 commit 6bad977

File tree

8 files changed

+139
-67
lines changed

8 files changed

+139
-67
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ KEDA_CORE_VERSION := $(or $(KEDA_CORE_VERSION),$(KEDA_CORE_VERSION),2.17.2)
3535
KEDA_TAG_VERSION := $(or $(KEDA_TAG_VERSION),$(KEDA_TAG_VERSION),2.17.2-selenium-grid)
3636
KEDA_BASED_NAME := $(or $(KEDA_BASED_NAME),$(KEDA_BASED_NAME),ndviet)
3737
KEDA_BASED_TAG := $(or $(KEDA_BASED_TAG),$(KEDA_BASED_TAG),2.17.2-selenium-grid-20250721)
38-
TEST_PATCHED_KEDA := $(or $(TEST_PATCHED_KEDA),$(TEST_PATCHED_KEDA),true)
38+
TEST_PATCHED_KEDA := $(or $(TEST_PATCHED_KEDA),$(TEST_PATCHED_KEDA),false)
3939

4040
all: hub \
4141
distributor \

charts/selenium-grid/CONFIGURATION.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -412,15 +412,20 @@ A Helm chart for creating a Selenium Grid Server in Kubernetes
412412
| autoscaling.patchObjectFinalizers.resources | object | `{"limits":{"cpu":"200m","memory":"500Mi"},"requests":{"cpu":"100m","memory":"200Mi"}}` | Define resources for container in patch job |
413413
| autoscaling.patchObjectFinalizers.nodeSelector | object | `{}` | Node selector for the patch job |
414414
| autoscaling.patchObjectFinalizers.tolerations | list | `[]` | Tolerations for the patch job |
415-
| autoscaling.scaledOptions | object | `{"maxReplicaCount":24,"minReplicaCount":0,"pollingInterval":20}` | Options for KEDA scaled resources (keep only common options used for both ScaledJob and ScaledObject) |
415+
| autoscaling.defaultTriggerType | string | `"selenium-grid"` | Default type of trigger to use (`selenium-grid` is build-in scaler in KEDA) |
416+
| autoscaling.defaultTriggerName | string | `"seleniumGrid"` | Default alias name of trigger type (which is used in formula if you want to add scalingModifiers to advanced spec) |
417+
| autoscaling.scaledOptions | object | `{"maxReplicaCount":24,"minReplicaCount":0,"pollingInterval":20,"triggers":[]}` | Options for KEDA scaled resources (keep only common options used for both ScaledJob and ScaledObject) |
416418
| autoscaling.scaledOptions.minReplicaCount | int | `0` | Minimum number of replicas |
417419
| autoscaling.scaledOptions.maxReplicaCount | int | `24` | Maximum number of replicas |
418420
| autoscaling.scaledOptions.pollingInterval | int | `20` | Polling interval in seconds |
421+
| autoscaling.scaledOptions.triggers | list | `[]` | List of triggers. Be careful, the default trigger of `selenium-grid` will be overwritten if you specify this |
419422
| autoscaling.scaledJobOptions.scalingStrategy.strategy | string | `"default"` | Scaling strategy for KEDA ScaledJob - https://keda.sh/docs/latest/reference/scaledjob-spec/#scalingstrategy |
420423
| autoscaling.scaledJobOptions.successfulJobsHistoryLimit | int | `0` | Number of Completed jobs should be kept |
421424
| autoscaling.scaledJobOptions.failedJobsHistoryLimit | int | `0` | Number of Failed jobs should be kept (for troubleshooting purposes) |
422425
| autoscaling.scaledJobOptions.jobTargetRef | object | `{"backoffLimit":0,"completions":1,"parallelism":1}` | Specify job target ref for KEDA ScaledJob |
426+
| autoscaling.scaledObjectOptions.advanced.restoreToOriginalReplicaCount | bool | `true` | |
423427
| autoscaling.scaledObjectOptions.scaleTargetRef.kind | string | `"Deployment"` | Target reference for KEDA ScaledObject |
428+
| autoscaling.scaledOverProvisionRatio | string | `""` | |
424429
| autoscaling.terminationGracePeriodSeconds | int | `3600` | Define terminationGracePeriodSeconds for scalingType "deployment". Period for `deregisterLifecycle` to gracefully shut down the node before force terminating it |
425430
| autoscaling.deregisterLifecycle | string | `nil` | Define preStop command to shut down the node gracefully when scalingType is set to "deployment" |
426431
| crossBrowsers.chromeNode | list | `[{"nameOverride":null}]` | Additional chrome nodes, array of objects with the same structure as `chromeNode` |
@@ -478,12 +483,12 @@ A Helm chart for creating a Selenium Grid Server in Kubernetes
478483
| chromeNode.scaledOptions | string | `nil` | Override the scaled options for chrome nodes |
479484
| chromeNode.scaledJobOptions | string | `nil` | Override the scaledJobOptions for chrome nodes |
480485
| chromeNode.scaledObjectOptions | string | `nil` | Override the scaledObjectOptions for chrome nodes |
486+
| chromeNode.scaledOverProvisionRatio | string | `""` | |
481487
| chromeNode.hpa.browserName | string | `"chrome"` | browserName should match with Node stereotype and request capability is scaled by this scaler |
482488
| chromeNode.hpa.sessionBrowserName | string | `"chrome"` | sessionBrowserName if the browserName is different from the sessionBrowserName |
483489
| chromeNode.hpa.browserVersion | string | `""` | browserVersion should match with Node stereotype and request capability is scaled by this scaler |
484490
| chromeNode.hpa.platformName | string | `""` | platformName should match with Node stereotype and request capability is scaled by this scaler |
485491
| chromeNode.hpa.unsafeSsl | string | `"{{ template \"seleniumGrid.graphqlURL.unsafeSsl\" . }}"` | Skip check SSL when connecting to the Graphql endpoint |
486-
| chromeNode.hpa.overProvisionRatio | string | `""` | The number of overprovisioning ratio to scale more than the actual number of requests. For example, over over-provisioning ratio `0.2` means 20% more than the actual requests |
487492
| chromeNode.initContainers | list | `[]` | It is used to add initContainers in the same pod of the browser node. It should be set using the --set-json option |
488493
| chromeNode.sidecars | list | `[]` | It is used to add sidecars proxy in the same pod of the browser node. It means it will add a new container to the deployment itself. It should be set using the --set-json option |
489494
| chromeNode.videoRecorder | object | `{}` | Override specific video recording settings for chrome node |
@@ -538,12 +543,12 @@ A Helm chart for creating a Selenium Grid Server in Kubernetes
538543
| firefoxNode.scaledOptions | string | `nil` | Override the scaled options for firefox nodes |
539544
| firefoxNode.scaledJobOptions | string | `nil` | Override the scaledJobOptions for firefox nodes |
540545
| firefoxNode.scaledObjectOptions | string | `nil` | Override the scaledObjectOptions for firefox nodes |
546+
| firefoxNode.scaledOverProvisionRatio | string | `""` | |
541547
| firefoxNode.hpa.browserName | string | `"firefox"` | browserName should match with Node stereotype and request capability is scaled by this scaler |
542548
| firefoxNode.hpa.sessionBrowserName | string | `"firefox"` | sessionBrowserName if the browserName is different from the sessionBrowserName |
543549
| firefoxNode.hpa.browserVersion | string | `""` | browserVersion should match with Node stereotype and request capability is scaled by this scaler |
544550
| firefoxNode.hpa.platformName | string | `""` | platformName should match with Node stereotype and request capability is scaled by this scaler |
545551
| firefoxNode.hpa.unsafeSsl | string | `"{{ template \"seleniumGrid.graphqlURL.unsafeSsl\" . }}"` | Skip check SSL when connecting to the Graphql endpoint |
546-
| firefoxNode.hpa.overProvisionRatio | string | `""` | The number of overprovisioning ratio to scale more than the actual number of requests. For example, over over-provisioning ratio `0.2` means 20% more than the actual requests |
547552
| firefoxNode.initContainers | list | `[]` | It is used to add initContainers in the same pod of the browser node. It should be set using the --set-json option |
548553
| firefoxNode.sidecars | list | `[]` | It is used to add sidecars proxy in the same pod of the browser node. It means it will add a new container to the deployment itself. It should be set using the --set-json option |
549554
| firefoxNode.videoRecorder | object | `{}` | Override specific video recording settings for firefox node |
@@ -598,12 +603,12 @@ A Helm chart for creating a Selenium Grid Server in Kubernetes
598603
| edgeNode.scaledOptions | string | `nil` | Override the scaled options for edge nodes |
599604
| edgeNode.scaledJobOptions | string | `nil` | Override the scaledJobOptions for edge nodes |
600605
| edgeNode.scaledObjectOptions | string | `nil` | Override the scaledObjectOptions for edge nodes |
606+
| edgeNode.scaledOverProvisionRatio | string | `""` | |
601607
| edgeNode.hpa.browserName | string | `"MicrosoftEdge"` | browserName should match with Node stereotype and request capability is scaled by this scaler |
602608
| edgeNode.hpa.sessionBrowserName | string | `"msedge"` | sessionBrowserName if the browserName is different from the sessionBrowserName |
603609
| edgeNode.hpa.browserVersion | string | `""` | browserVersion should match with Node stereotype and request capability is scaled by this scaler |
604610
| edgeNode.hpa.platformName | string | `""` | platformName should match with Node stereotype and request capability is scaled by this scaler |
605611
| edgeNode.hpa.unsafeSsl | string | `"{{ template \"seleniumGrid.graphqlURL.unsafeSsl\" . }}"` | Skip check SSL when connecting to the Graphql endpoint |
606-
| edgeNode.hpa.overProvisionRatio | string | `""` | The number of overprovisioning ratio to scale more than the actual number of requests. For example, over over-provisioning ratio `0.2` means 20% more than the actual requests |
607612
| edgeNode.initContainers | list | `[]` | It is used to add initContainers in the same pod of the browser node. It should be set using the --set-json option |
608613
| edgeNode.sidecars | list | `[]` | It is used to add sidecars proxy in the same pod of the browser node. It means it will add a new container to the deployment itself. It should be set using the --set-json option |
609614
| edgeNode.videoRecorder | object | `{}` | Override specific video recording settings for edge node |
@@ -659,12 +664,12 @@ A Helm chart for creating a Selenium Grid Server in Kubernetes
659664
| relayNode.scaledOptions | string | `nil` | Override the scaled options for relay nodes |
660665
| relayNode.scaledJobOptions | string | `nil` | Override the scaledJobOptions for relay nodes |
661666
| relayNode.scaledObjectOptions | string | `nil` | Override the scaledObjectOptions for relay nodes |
667+
| relayNode.scaledOverProvisionRatio | string | `""` | |
662668
| relayNode.hpa.browserName | string | `""` | browserName should match with Node stereotype and request capability is scaled by this scaler |
663669
| relayNode.hpa.sessionBrowserName | string | `""` | sessionBrowserName if the browserName is different from the sessionBrowserName |
664670
| relayNode.hpa.browserVersion | string | `""` | browserVersion should match with Node stereotype and request capability is scaled by this scaler |
665671
| relayNode.hpa.platformName | string | `""` | platformName should match with Node stereotype and request capability is scaled by this scaler |
666672
| relayNode.hpa.unsafeSsl | string | `"{{ template \"seleniumGrid.graphqlURL.unsafeSsl\" . }}"` | Skip check SSL when connecting to the Graphql endpoint |
667-
| relayNode.hpa.overProvisionRatio | string | `""` | The number of overprovisioning ratio to scale more than the actual number of requests. For example, over over-provisioning ratio `0.2` means 20% more than the actual requests |
668673
| relayNode.initContainers | list | `[]` | It is used to add initContainers in the same pod of the browser node. It should be set using the --set-json option |
669674
| relayNode.sidecars | list | `[]` | It is used to add sidecars proxy in the same pod of the browser node. It means it will add a new container to the deployment itself. It should be set using the --set-json option |
670675
| relayNode.videoRecorder | object | `{}` | Override specific video recording settings for edge node |
@@ -737,7 +742,6 @@ A Helm chart for creating a Selenium Grid Server in Kubernetes
737742
| videoManager.priorityClassName | string | `""` | Priority class name for router pods |
738743
| videoManager.extraVolumeMounts | list | `[]` | |
739744
| videoManager.extraVolumes | list | `[]` | Extra volumes for video recorder pod |
740-
| keda.image | object | `{"keda":{"registry":"selenium","repository":"keda","tag":"2.17.2-selenium-grid-20250721"},"metricsApiServer":{"registry":"selenium","repository":"keda-metrics-apiserver","tag":"2.17.2-selenium-grid-20250721"},"webhooks":{"registry":"selenium","repository":"keda-admission-webhooks","tag":"2.17.2-selenium-grid-20250721"}}` | Specify image for KEDA components |
741745
| keda.additionalAnnotations | string | `nil` | Annotations for KEDA resources |
742746
| keda.http.timeout | int | `60000` | |
743747
| keda.webhooks | object | `{"enabled":false}` | Enable KEDA admission webhooks component |

charts/selenium-grid/templates/_helpers.tpl

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -213,45 +213,68 @@ based on sum of maxReplicaCount of all enabled Nodes in autoscaling
213213
{{- $slotSelector -}}
214214
{{- end -}}
215215

216+
{{/*
217+
Apply scaledOverProvisionRatio to scalingModifiers. Link with autoscaling template
218+
*/}}
219+
{{- define "seleniumGrid.autoscaling.scaledOverProvisionRatio" -}}
220+
{{- $scalingModifier := (dict) -}}
221+
{{- $value := default $.Values.autoscaling.scaledOverProvisionRatio .node.scaledOverProvisionRatio | float64 -}}
222+
{{- $triggerName := $.Values.autoscaling.defaultTriggerName -}}
223+
{{- if gt $value (1.0 | float64) -}}
224+
{{- $scalingModifier = mergeOverwrite ($scalingModifier) (dict "advanced" (dict "scalingModifiers" (dict "formula" (printf "float(%s * %.2f)" $triggerName $value) "target" "1"))) -}}
225+
{{- end -}}
226+
{{- toYaml $scalingModifier -}}
227+
{{- end -}}
228+
216229
{{/*
217230
Common autoscaling spec template
218231
*/}}
219232
{{- define "seleniumGrid.autoscalingTemplate" -}}
220-
{{- $spec := toYaml (dict) -}}
233+
{{- $spec := (dict) -}}
221234
{{- $nodeMaxSessions := default $.Values.global.seleniumGrid.nodeMaxSessions .node.nodeMaxSessions | int64 -}}
222235
{{- $nodeEnableManagedDownloads := default $.Values.global.seleniumGrid.nodeEnableManagedDownloads .node.nodeEnableManagedDownloads -}}
223236
{{- $nodeCustomCapabilities := default $.Values.global.seleniumGrid.nodeCustomCapabilities .node.nodeCustomCapabilities -}}
224237
{{/* Merge with precedence from right to left */}}
225238
{{- with $.Values.autoscaling.scaledOptions -}}
226-
{{- $spec = mergeOverwrite ($spec | fromYaml) . | toYaml -}}
239+
{{- $spec = mergeOverwrite ($spec) . -}}
227240
{{- end -}}
228241
{{- with .node.scaledOptions -}}
229-
{{- $spec = mergeOverwrite ($spec | fromYaml) . | toYaml -}}
242+
{{- $spec = mergeOverwrite ($spec) . -}}
230243
{{- end -}}
231244
{{- if eq $.Values.autoscaling.scalingType "deployment" -}}
245+
{{- $advanced := (dict "scaleTargetRef" (dict "name" .name) "advanced" (dict "horizontalPodAutoscalerConfig" (dict "name" .name))) -}}
246+
{{- $advanced = mergeOverwrite $advanced (include "seleniumGrid.autoscaling.scaledOverProvisionRatio" . | fromYaml) }}
247+
{{- $spec = mergeOverwrite ($spec) $advanced -}}
232248
{{- with $.Values.autoscaling.scaledObjectOptions -}}
233-
{{- $spec = mergeOverwrite ($spec | fromYaml) . | toYaml -}}
249+
{{- $spec = mergeOverwrite ($spec) . -}}
234250
{{- end -}}
235251
{{- with .node.scaledObjectOptions -}}
236-
{{- $spec = mergeOverwrite ($spec | fromYaml) . | toYaml -}}
252+
{{- $spec = mergeOverwrite ($spec) . -}}
237253
{{- end -}}
238-
{{- $advanced := (dict "scaleTargetRef" (dict "name" .name) "advanced" (dict "horizontalPodAutoscalerConfig" (dict "name" .name) "restoreToOriginalReplicaCount" true)) -}}
239-
{{- $spec = mergeOverwrite ($spec | fromYaml) $advanced | toYaml -}}
240254
{{- else if eq $.Values.autoscaling.scalingType "job" -}}
255+
{{- $spec = mergeOverwrite ($spec) (dict "jobTargetRef" .podTemplate) -}}
241256
{{- with $.Values.autoscaling.scaledJobOptions -}}
242-
{{- $spec = mergeOverwrite ($spec | fromYaml) . | toYaml -}}
257+
{{- $spec = mergeOverwrite ($spec) . -}}
243258
{{- end -}}
244259
{{- with .node.scaledJobOptions -}}
245-
{{- $spec = mergeOverwrite ($spec | fromYaml) . | toYaml -}}
260+
{{- $spec = mergeOverwrite ($spec) . -}}
246261
{{- end -}}
247-
{{- $spec = mergeOverwrite ($spec | fromYaml) (dict "jobTargetRef" .podTemplate) | toYaml -}}
248262
{{- end -}}
249-
{{- if and $spec (ne $spec "{}") -}}
250-
{{ tpl $spec $ }}
263+
{{- if and $spec (not (empty $spec)) -}}
264+
{{- $cleanSpec := dict -}}
265+
{{- range $key, $value := $spec -}}
266+
{{- if not (empty $value) -}}
267+
{{- $cleanSpec = set $cleanSpec $key $value -}}
268+
{{- end -}}
269+
{{- end -}}
270+
{{- if not (empty $cleanSpec) -}}
271+
{{ tpl (toYaml $cleanSpec) $ | nindent 0 }}
272+
{{- end -}}
251273
{{- end -}}
252274
{{- if not $.Values.autoscaling.scaledOptions.triggers }}
253275
triggers:
254-
- type: selenium-grid
276+
- type: {{ $.Values.autoscaling.defaultTriggerType }}
277+
name: {{ $.Values.autoscaling.defaultTriggerName }}
255278
metadata:
256279
{{- with .node.hpa }}
257280
{{- range $key, $value := . }}

0 commit comments

Comments
 (0)