Skip to content

Commit 07e13f6

Browse files
authored
fix(chart): RBAC settings for job patch finalizers (#2239)
1 parent 0762e87 commit 07e13f6

File tree

9 files changed

+110
-81
lines changed

9 files changed

+110
-81
lines changed

Diff for: charts/selenium-grid/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,7 @@ This table contains the configuration parameters of the chart and their default
704704
| `ingress.tls` | `[]` | TLS backend configuration for ingress resource |
705705
| `autoscaling.enableWithExistingKEDA` | `false` | Enable autoscaling of browser nodes. |
706706
| `autoscaling.enabled` | `false` | Same as above plus installation of KEDA |
707+
| `autoscaling.patchObjectFinalizers.enabled` | `true` | Enabled job to execute `kubectl` to patch scaled object finalizers when chart hooks failed with object existed |
707708
| `autoscaling.scalingType` | `job` | Which typ of KEDA scaling to use: `job` or `deployment` |
708709
| `autoscaling.scaledOptions` | See `values.yaml` | Common options for KEDA scaled resources (both ScaledJobs and ScaledObjects) |
709710
| `autoscaling.scaledOptions.minReplicaCount` | `0` | Min number of replicas that each browser nodes has when autoscaling |

Diff for: charts/selenium-grid/templates/_nameHelpers.tpl

+8-8
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ helm.sh/chart: {{ include "seleniumGrid.chart" . }}
4343
Autoscaling labels
4444
*/}}
4545
{{- define "seleniumGrid.autoscalingLabels" -}}
46-
component.autoscaling: "true"
46+
component.autoscaling: "{{ .Release.Name }}"
4747
{{- end -}}
4848

4949
{{- define "seleniumGrid.component.name" -}}
@@ -193,19 +193,19 @@ Server ConfigMap fullname
193193
Patch scaledObjects finalizers job fullname
194194
*/}}
195195
{{- define "seleniumGrid.keda.patchObjectsJob.fullname" -}}
196-
{{- printf "%s-%s" .Release.Name "patch-scaledobjects-finalizers" | trunc 63 | trimSuffix "-" -}}
196+
{{- tpl (include "seleniumGrid.component.name" (list "selenium-patch-scaledobjects-finalizers" $)) $ | trunc 63 | trimSuffix "-" -}}
197197
{{- end -}}
198198

199199
{{/*
200-
Patch scaled objects RoleBinding fullname
200+
RBAC RoleBinding fullname
201201
*/}}
202-
{{- define "seleniumGrid.keda.roleBinding.fullname" -}}
203-
{{- printf "%s-%s" .Release.Name "patch-keda-rb" | trunc 63 | trimSuffix "-" -}}
202+
{{- define "seleniumGrid.rbac.roleBinding.fullname" -}}
203+
{{- tpl (default (include "seleniumGrid.component.name" (list "selenium-rolebinding" $)) .Values.rbacRoleBinding.nameOverride) $ | trunc 63 | trimSuffix "-" -}}
204204
{{- end -}}
205205

206206
{{/*
207-
Patch scaled objects Role fullname
207+
RBAC Role fullname
208208
*/}}
209-
{{- define "seleniumGrid.keda.role.fullname" -}}
210-
{{- printf "%s-%s" .Release.Name "patch-keda-role" | trunc 63 | trimSuffix "-" -}}
209+
{{- define "seleniumGrid.rbac.role.fullname" -}}
210+
{{- tpl (default (include "seleniumGrid.component.name" (list "selenium-role" $)) .Values.rbacRole.nameOverride) $ | trunc 63 | trimSuffix "-" -}}
211211
{{- end -}}
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
{{- if eq (include "seleniumGrid.useKEDA" $) "true" }}
1+
{{- if and (eq (include "seleniumGrid.useKEDA" $) "true") $.Values.autoscaling.patchObjectFinalizers.enabled }}
22
apiVersion: batch/v1
33
kind: Job
44
metadata:
55
name: {{ template "seleniumGrid.keda.patchObjectsJob.fullname" $ }}
66
namespace: {{ .Release.Namespace }}
77
annotations:
8-
"helm.sh/hook-delete-policy": hook-succeeded
9-
"helm.sh/resource-policy": delete
10-
{{- with $.Values.autoscaling.annotations }}
8+
{{- with $.Values.autoscaling.patchObjectFinalizers.annotations }}
119
{{- toYaml . | nindent 4 }}
1210
{{- end }}
1311
labels:
@@ -21,15 +19,17 @@ spec:
2119
metadata:
2220
name: {{ template "seleniumGrid.keda.patchObjectsJob.fullname" $ }}
2321
spec:
24-
activeDeadlineSeconds: 120
22+
activeDeadlineSeconds: {{ $.Values.autoscaling.patchObjectFinalizers.activeDeadlineSeconds }}
2523
serviceAccountName: {{ template "seleniumGrid.serviceAccount.fullname" $ }}
2624
serviceAccount: {{ template "seleniumGrid.serviceAccount.fullname" $ }}
2725
containers:
2826
- name: {{ template "seleniumGrid.keda.patchObjectsJob.fullname" $ }}
2927
image: {{ $.Values.global.seleniumGrid.kubectlImage }}
30-
command:
31-
- "bin/bash"
32-
- "-c"
33-
- "kubectl get ScaledObjects,ScaledJobs -n {{ .Release.Namespace }} -l component.autoscaling=true -o=json | jq '.metadata.finalizers = null' | kubectl apply -f -"
28+
command: ["/bin/bash", "-c"]
29+
args:
30+
- |
31+
kubectl get ScaledObjects,ScaledJobs -n {{ .Release.Namespace }} -l component.autoscaling={{ .Release.Name }} -o=json | jq '.metadata.finalizers = null' | kubectl apply -f - || true ;
32+
kubectl delete ScaledObjects,ScaledJobs -n {{ .Release.Namespace }} -l component.autoscaling={{ .Release.Name }} --wait || true ;
33+
kubectl delete hpa -n {{ .Release.Namespace }} -l component.autoscaling={{ .Release.Name }} --wait || true ;
3434
restartPolicy: Never
3535
{{- end }}

Diff for: charts/selenium-grid/templates/patch-keda/patch-keda-rb.yaml

-20
This file was deleted.

Diff for: charts/selenium-grid/templates/patch-keda/patch-keda-role.yaml

-37
This file was deleted.

Diff for: charts/selenium-grid/templates/rbac-role.yaml

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{{- if $.Values.rbacRole.create }}
2+
apiVersion: rbac.authorization.k8s.io/v1
3+
kind: Role
4+
metadata:
5+
name: {{ template "seleniumGrid.rbac.role.fullname" $ }}
6+
namespace: {{ .Release.Namespace }}
7+
annotations:
8+
{{- with $.Values.rbacRole.annotations }}
9+
{{- toYaml . | nindent 4 }}
10+
{{- end }}
11+
labels:
12+
deploymentName: {{ template "seleniumGrid.rbac.role.fullname" $ }}
13+
{{- include "seleniumGrid.commonLabels" $ | nindent 4 }}
14+
{{- with $.Values.customLabels }}
15+
{{- toYaml . | nindent 4 }}
16+
{{- end }}
17+
{{- with $.Values.rbacRole.rules }}
18+
rules:
19+
{{- toYaml . | nindent 2 }}
20+
{{- end }}
21+
{{- end }}

Diff for: charts/selenium-grid/templates/rbac-rolebinding.yaml

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{{- if $.Values.rbacRoleBinding.create }}
2+
apiVersion: rbac.authorization.k8s.io/v1
3+
kind: RoleBinding
4+
metadata:
5+
name: {{ template "seleniumGrid.rbac.roleBinding.fullname" $ }}
6+
namespace: {{ .Release.Namespace }}
7+
annotations:
8+
{{- with $.Values.rbacRoleBinding.annotations }}
9+
{{- toYaml . | nindent 4 }}
10+
{{- end }}
11+
labels:
12+
deploymentName: {{ template "seleniumGrid.rbac.roleBinding.fullname" $ }}
13+
{{- include "seleniumGrid.commonLabels" $ | nindent 4 }}
14+
{{- with $.Values.customLabels }}
15+
{{- toYaml . | nindent 4 }}
16+
{{- end }}
17+
subjects:
18+
- kind: ServiceAccount
19+
name: {{ template "seleniumGrid.serviceAccount.fullname" $ }}
20+
{{ with $.Values.rbacRoleBinding.roleRef }}
21+
{{- $roleRef := merge (dict "name" (include "seleniumGrid.rbac.role.fullname" $)) . -}}
22+
roleRef:
23+
{{ $roleRef | toYaml | nindent 2 }}
24+
{{- end }}
25+
{{- end }}

Diff for: charts/selenium-grid/values.yaml

+45-6
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,36 @@ serviceAccount:
7070
annotations: {}
7171
# eks.amazonaws.com/role-arn: "arn:aws:iam::12345678:role/video-bucket-permissions"
7272

73+
# RBAC settings
74+
rbacRole:
75+
create: true
76+
# nameOverride:
77+
annotations: {}
78+
rules:
79+
- apiGroups:
80+
- keda.sh
81+
resources:
82+
- scaledjobs
83+
verbs: [get, list, patch, update, delete]
84+
- apiGroups:
85+
- keda.sh
86+
resources:
87+
- scaledobjects
88+
verbs: [get, list, patch, update, delete]
89+
- apiGroups:
90+
- autoscaling
91+
resources:
92+
- horizontalpodautoscalers
93+
verbs: [get, list, patch, update, delete]
94+
95+
rbacRoleBinding:
96+
create: true
97+
# nameOverride:
98+
annotations: {}
99+
roleRef:
100+
kind: Role
101+
apiGroup: rbac.authorization.k8s.io
102+
73103
# Configure the ingress resource to access the Grid installation.
74104
ingress:
75105
# Enable or disable ingress resource
@@ -548,7 +578,16 @@ autoscaling:
548578
scalingType: job
549579
# Annotations for KEDA resources: ScaledObject and ScaledJob
550580
annotations:
551-
"helm.sh/hook": post-install,post-upgrade,post-rollback,pre-delete
581+
"helm.sh/hook": post-install,post-upgrade,post-rollback
582+
"helm.sh/hook-weight": "1"
583+
# Workaround for Hook post-upgrade selenium-grid/templates/x-node-hpa.yaml failed: object is being deleted: scaledobjects.keda.sh "x" already exists
584+
patchObjectFinalizers:
585+
enabled: true
586+
activeDeadlineSeconds: 120
587+
annotations:
588+
"helm.sh/hook": post-install,post-upgrade,post-rollback,pre-delete
589+
"helm.sh/hook-delete-policy": hook-succeeded,before-hook-creation
590+
"helm.sh/hook-weight": "-1"
552591
# Options for KEDA scaled resources (keep only common options used for both ScaledJob and ScaledObject)
553592
scaledOptions:
554593
minReplicaCount: 0
@@ -1187,7 +1226,7 @@ customLabels: {}
11871226
# Configuration for dependency chart keda
11881227
keda:
11891228
additionalAnnotations:
1190-
"helm.sh/hook": pre-install,pre-upgrade,pre-rollback,post-delete
1229+
"helm.sh/hook": pre-install,pre-upgrade,pre-rollback
11911230
http:
11921231
timeout: 60000
11931232
webhooks:
@@ -1223,19 +1262,19 @@ prometheus-stack:
12231262
defaultRules:
12241263
create: true
12251264
annotations:
1226-
"helm.sh/hook": post-install,post-upgrade,post-rollback,pre-delete
1265+
"helm.sh/hook": post-install,post-upgrade,post-rollback
12271266
alertmanager:
12281267
enabled: true
12291268
annotations:
1230-
"helm.sh/hook": post-install,post-upgrade,post-rollback,pre-delete
1269+
"helm.sh/hook": post-install,post-upgrade,post-rollback
12311270
grafana:
12321271
enabled: true
12331272
adminPassword: admin
12341273
forceDeployDatasources: true
12351274
forceDeployDashboards: true
12361275
annotations:
1237-
"helm.sh/hook": post-install,post-upgrade,post-rollback,pre-delete
1276+
"helm.sh/hook": post-install,post-upgrade,post-rollback
12381277
prometheus:
12391278
enabled: true
12401279
annotations:
1241-
"helm.sh/hook": post-install,post-upgrade,post-rollback,pre-delete
1280+
"helm.sh/hook": post-install,post-upgrade,post-rollback

Diff for: tests/charts/make/chart_setup_env.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ if [ "$(uname -m)" = "x86_64" ]; then
110110
echo "==============================="
111111

112112
echo "Installing Helm for AMD64 / x86_64"
113-
HELM_VERSION=${HELM_VERSION:-"v3.14.3"}
113+
HELM_VERSION=${HELM_VERSION:-"v3.14.4"}
114114
curl -fsSL -o helm.tar.gz https://get.helm.sh/helm-${HELM_VERSION}-linux-amd64.tar.gz
115115
mkdir -p helm
116116
tar -xf helm.tar.gz --strip-components 1 -C helm

0 commit comments

Comments
 (0)