From 3dddb7d0027adbf56b9e287888ec05f309d04c07 Mon Sep 17 00:00:00 2001 From: Viet Nguyen Duc Date: Thu, 14 Nov 2024 20:40:08 +0700 Subject: [PATCH] K8s: Update ScaledJob scaling strategy to `eager` as default (#2466) --- charts/selenium-grid/CONFIGURATION.md | 8 ++++---- charts/selenium-grid/templates/_helpers.tpl | 2 ++ .../patch-keda/patch-keda-objects-job.yaml | 4 ++-- charts/selenium-grid/values.yaml | 15 +++++++++------ 4 files changed, 17 insertions(+), 12 deletions(-) diff --git a/charts/selenium-grid/CONFIGURATION.md b/charts/selenium-grid/CONFIGURATION.md index c429fb6ef..ff986b3f9 100644 --- a/charts/selenium-grid/CONFIGURATION.md +++ b/charts/selenium-grid/CONFIGURATION.md @@ -79,7 +79,7 @@ A Helm chart for creating a Selenium Grid Server in Kubernetes | serviceAccount.create | bool | `true` | Create a service account for all components. If using an external service account, set to false and provide its name in `nameOverride` below | | serviceAccount.nameOverride | string | `nil` | Override to use an external service account | | serviceAccount.annotations | object | `{}` | Annotations for the service account | -| rbacRole | object | `{"annotations":{},"create":true,"nameOverride":null,"rules":[{"apiGroups":["keda.sh"],"resources":["scaledjobs"],"verbs":["get","list","patch","update","delete"]},{"apiGroups":["keda.sh"],"resources":["scaledobjects"],"verbs":["get","list","patch","update","delete"]},{"apiGroups":["keda.sh"],"resources":["triggerauthentication"],"verbs":["get","list","patch","update","delete"]},{"apiGroups":["autoscaling"],"resources":["horizontalpodautoscalers"],"verbs":["get","list","patch","update","delete"]}]}` | RBAC settings for patching finalizers KEDA scaled resources | +| rbacRole | object | `{"annotations":{},"create":true,"nameOverride":null,"rules":[{"apiGroups":["keda.sh"],"resources":["scaledjobs"],"verbs":["get","list","patch","update","delete"]},{"apiGroups":["keda.sh"],"resources":["scaledobjects"],"verbs":["get","list","patch","update","delete"]},{"apiGroups":["keda.sh"],"resources":["triggerauthentications"],"verbs":["get","list","patch","update","delete"]},{"apiGroups":["autoscaling"],"resources":["horizontalpodautoscalers"],"verbs":["get","list","patch","update","delete"]}]}` | RBAC settings for patching finalizers KEDA scaled resources | | rbacRole.create | bool | `true` | Enable to create RBAC role to access few KEDA resources. If using an external role, set to false and provide its name in `nameOverride` below | | rbacRole.nameOverride | string | `nil` | Override resource name or provide an external role name | | rbacRoleBinding | object | `{"annotations":{},"create":true,"nameOverride":null,"roleRef":{"apiGroup":"rbac.authorization.k8s.io","kind":"Role"},"subjects":[{"kind":"ServiceAccount"}]}` | RBAC role binding settings for patching finalizers KEDA scaled resources | @@ -326,8 +326,8 @@ A Helm chart for creating a Selenium Grid Server in Kubernetes | autoscaling.enabled | bool | `false` | Enable autoscaling. Implies installing KEDA | | autoscaling.enableWithExistingKEDA | bool | `false` | Enable autoscaling without automatically installing KEDA | | autoscaling.scalingType | string | `"job"` | Which type of KEDA scaling to use: job or deployment | -| autoscaling.authenticationRef | object | `{"annotations":{"helm.sh/hook":"post-install,post-upgrade,post-rollback","helm.sh/hook-weight":"-2"},"name":""}` | Specify an external KEDA TriggerAuthentication resource is used for scaler triggers config. Apply for all browser nodes | -| autoscaling.useCachedMetrics | bool | `true` | Enables caching of metric values during polling interval (as specified in .spec.pollingInterval). | +| autoscaling.authenticationRef | object | `{"annotations":{"helm.sh/hook":"post-install,post-upgrade,post-rollback","helm.sh/hook-weight":"0"},"name":""}` | Specify an external KEDA TriggerAuthentication resource is used for scaler triggers config. Apply for all browser nodes | +| autoscaling.useCachedMetrics | bool | `false` | Enables caching of metric values during polling interval (as specified in .spec.pollingInterval). | | autoscaling.metricType | string | `"Value"` | The type of metric that should be used (Override the default: AverageValue in KEDA) | | autoscaling.annotations | object | `{"helm.sh/hook":"post-install,post-upgrade,post-rollback","helm.sh/hook-weight":"1"}` | Annotations for KEDA resources: ScaledObject and ScaledJob | | autoscaling.patchObjectFinalizers.nameOverride | string | `nil` | Override the name of the patch job | @@ -341,7 +341,7 @@ A Helm chart for creating a Selenium Grid Server in Kubernetes | autoscaling.scaledOptions.minReplicaCount | int | `0` | Minimum number of replicas | | autoscaling.scaledOptions.maxReplicaCount | int | `8` | Maximum number of replicas | | autoscaling.scaledOptions.pollingInterval | int | `10` | Polling interval in seconds | -| autoscaling.scaledJobOptions.scalingStrategy.strategy | string | `"accurate"` | Scaling strategy for KEDA ScaledJob | +| autoscaling.scaledJobOptions.scalingStrategy.strategy | string | `"eager"` | Scaling strategy for KEDA ScaledJob - https://keda.sh/docs/latest/reference/scaledjob-spec/#scalingstrategy | | autoscaling.scaledJobOptions.successfulJobsHistoryLimit | int | `0` | Number of Completed jobs should be kept | | autoscaling.scaledJobOptions.failedJobsHistoryLimit | int | `0` | Number of Failed jobs should be kept (for troubleshooting purposes) | | autoscaling.scaledJobOptions.jobTargetRef | object | `{"backoffLimit":0,"completions":1,"parallelism":1}` | Specify job target ref for KEDA ScaledJob | diff --git a/charts/selenium-grid/templates/_helpers.tpl b/charts/selenium-grid/templates/_helpers.tpl index 1ea6ab74a..9bb8c2b5b 100644 --- a/charts/selenium-grid/templates/_helpers.tpl +++ b/charts/selenium-grid/templates/_helpers.tpl @@ -249,7 +249,9 @@ triggers: authenticationRef: name: {{ template "seleniumGrid.autoscaling.authenticationRef.fullname" $ }} useCachedMetrics: {{ $.Values.autoscaling.useCachedMetrics }} + {{- if eq $.Values.autoscaling.scalingType "deployment" }} metricType: {{ $.Values.autoscaling.metricType }} + {{- end }} {{- end }} {{- end -}} diff --git a/charts/selenium-grid/templates/patch-keda/patch-keda-objects-job.yaml b/charts/selenium-grid/templates/patch-keda/patch-keda-objects-job.yaml index 1337e1953..7b7509692 100644 --- a/charts/selenium-grid/templates/patch-keda/patch-keda-objects-job.yaml +++ b/charts/selenium-grid/templates/patch-keda/patch-keda-objects-job.yaml @@ -35,8 +35,8 @@ spec: - | echo "Cleaning up ScaledObjects, ScaledJobs and HPAs for {{ .Release.Name }} when upgrading or disabling autoscaling." kubectl get ScaledObjects,ScaledJobs,TriggerAuthentication -n {{ .Release.Namespace }} -l component.autoscaling={{ .Release.Name }} -o=json | jq '.metadata.finalizers = null' | kubectl apply -f - || true ; - kubectl delete ScaledObjects,ScaledJobs,TriggerAuthentication -n {{ .Release.Namespace }} -l component.autoscaling={{ .Release.Name }} --wait || true ; - kubectl delete hpa -n {{ .Release.Namespace }} -l component.autoscaling={{ .Release.Name }} --wait || true ; + kubectl delete ScaledObjects,ScaledJobs,TriggerAuthentication -n {{ .Release.Namespace }} -l component.autoscaling={{ .Release.Name }} --wait false || true ; + kubectl delete hpa -n {{ .Release.Namespace }} -l component.autoscaling={{ .Release.Name }} --wait false || true ; {{- with $.Values.autoscaling.patchObjectFinalizers.resources }} resources: {{ toYaml . | nindent 12 }} {{- end }} diff --git a/charts/selenium-grid/values.yaml b/charts/selenium-grid/values.yaml index fb36edd3c..42d89cf06 100644 --- a/charts/selenium-grid/values.yaml +++ b/charts/selenium-grid/values.yaml @@ -156,7 +156,7 @@ rbacRole: - apiGroups: - keda.sh resources: - - triggerauthentication + - triggerauthentications verbs: [get, list, patch, update, delete] - apiGroups: - autoscaling @@ -835,15 +835,17 @@ autoscaling: name: "" annotations: "helm.sh/hook": post-install,post-upgrade,post-rollback - "helm.sh/hook-weight": "-2" + # TriggerAuthentication is used by ScaledObject/ScaledJob, hence weight should be less than those hooks + "helm.sh/hook-weight": "0" # Configuration for ScaledObject triggers https://keda.sh/docs/latest/reference/scaledobject-spec/#triggers # -- Enables caching of metric values during polling interval (as specified in .spec.pollingInterval). - useCachedMetrics: true + useCachedMetrics: false # -- The type of metric that should be used (Override the default: AverageValue in KEDA) metricType: Value # -- Annotations for KEDA resources: ScaledObject and ScaledJob annotations: "helm.sh/hook": post-install,post-upgrade,post-rollback + # Ensure the weight should be higher than TriggerAuthentication hook "helm.sh/hook-weight": "1" patchObjectFinalizers: # -- Override the name of the patch job @@ -856,6 +858,7 @@ autoscaling: annotations: "helm.sh/hook": post-install,post-upgrade,post-rollback,pre-delete "helm.sh/hook-delete-policy": hook-succeeded,before-hook-creation + # This should be run before all other hooks (since delete action is called), so use a negative weight "helm.sh/hook-weight": "-1" # -- Define an external service account name contains permissions to patch KEDA scaled resources serviceAccount: "" @@ -882,9 +885,9 @@ autoscaling: # Options for KEDA ScaledJobs (only used when scalingType is set to "job"). See https://keda.sh/docs/latest/concepts/scaling-jobs/#scaledjob-spec scaledJobOptions: scalingStrategy: - # Offer the strategy default with scaler calculation updated in https://github.com/SeleniumHQ/docker-selenium/tree/trunk/.keda/README.md - # -- Scaling strategy for KEDA ScaledJob - strategy: accurate + # Use `eager` strategy for utilizing all available slots up to the maxReplicaCount, ensuring that waiting request are processed as quickly as possible. + # -- Scaling strategy for KEDA ScaledJob - https://keda.sh/docs/latest/reference/scaledjob-spec/#scalingstrategy + strategy: eager # -- Number of Completed jobs should be kept successfulJobsHistoryLimit: 0 # -- Number of Failed jobs should be kept (for troubleshooting purposes)