Skip to content

Commit

Permalink
chart(feat): updateStrategy default RollingUpdate for browsers and Re…
Browse files Browse the repository at this point in the history
…create for components

Signed-off-by: Viet Nguyen Duc <[email protected]>
  • Loading branch information
VietND96 committed Aug 29, 2024
1 parent 59397b1 commit 6216a4d
Show file tree
Hide file tree
Showing 12 changed files with 77 additions and 3 deletions.
20 changes: 20 additions & 0 deletions charts/selenium-grid/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,26 @@ triggers:
{{- end }}
{{- end -}}

{{/*
Component update strategy template
*/}}
{{- define "seleniumGrid.updateStrategy" -}}
{{- $value := index . 0 -}}
{{- $global := index . 1 -}}
{{- $spec := toYaml (dict) -}}
{{- if not (empty $global.updateStrategy) -}}
{{- $spec = merge $global.updateStrategy ($spec | fromYaml) | toYaml -}}
{{- end -}}
{{- if not (empty $value.updateStrategy) -}}
{{- $spec = merge $value.updateStrategy ($spec | fromYaml) | toYaml -}}
{{- end -}}
{{/* If final result is Recreate, update a clean object */}}
{{- if eq ($spec | fromYaml).type "Recreate" }}
{{- $spec = toYaml (dict "type" "Recreate") -}}
{{- end -}}
{{ $spec | nindent 4 }}
{{- end -}}

{{/*
Common pod template
*/}}
Expand Down
2 changes: 2 additions & 0 deletions charts/selenium-grid/templates/chrome-node-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ metadata:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
strategy:
{{- template "seleniumGrid.updateStrategy" (list $.Values.chromeNode $.Values.global.seleniumGrid) }}
{{- if and (not .Values.autoscaling.enabled) (not .Values.autoscaling.enableWithExistingKEDA) }}
replicas: {{ .Values.chromeNode.replicas }}
{{end}}
Expand Down
2 changes: 2 additions & 0 deletions charts/selenium-grid/templates/distributor-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ metadata:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
strategy:
{{- template "seleniumGrid.updateStrategy" (list $.Values.components.distributor $.Values.global.seleniumGrid) }}
replicas: 1
revisionHistoryLimit: {{ .Values.global.seleniumGrid.revisionHistoryLimit }}
selector:
Expand Down
2 changes: 2 additions & 0 deletions charts/selenium-grid/templates/edge-node-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ metadata:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
strategy:
{{- template "seleniumGrid.updateStrategy" (list $.Values.edgeNode $.Values.global.seleniumGrid) }}
{{- if and (not .Values.autoscaling.enabled) (not .Values.autoscaling.enableWithExistingKEDA) }}
replicas: {{ .Values.edgeNode.replicas }}
{{end}}
Expand Down
2 changes: 2 additions & 0 deletions charts/selenium-grid/templates/event-bus-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ metadata:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
strategy:
{{- template "seleniumGrid.updateStrategy" (list $.Values.components.eventBus $.Values.global.seleniumGrid) }}
replicas: 1
revisionHistoryLimit: {{ .Values.global.seleniumGrid.revisionHistoryLimit }}
selector:
Expand Down
2 changes: 2 additions & 0 deletions charts/selenium-grid/templates/firefox-node-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ metadata:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
strategy:
{{- template "seleniumGrid.updateStrategy" (list $.Values.firefoxNode $.Values.global.seleniumGrid) }}
{{- if and (not .Values.autoscaling.enabled) (not .Values.autoscaling.enableWithExistingKEDA) }}
replicas: {{ .Values.firefoxNode.replicas }}
{{end}}
Expand Down
2 changes: 2 additions & 0 deletions charts/selenium-grid/templates/hub-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ metadata:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
strategy:
{{- template "seleniumGrid.updateStrategy" (list $.Values.hub $.Values.global.seleniumGrid) }}
replicas: 1
revisionHistoryLimit: {{ .Values.global.seleniumGrid.revisionHistoryLimit }}
selector:
Expand Down
2 changes: 2 additions & 0 deletions charts/selenium-grid/templates/router-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ metadata:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
strategy:
{{- template "seleniumGrid.updateStrategy" (list $.Values.components.router $.Values.global.seleniumGrid) }}
replicas: 1
revisionHistoryLimit: {{ .Values.global.seleniumGrid.revisionHistoryLimit }}
selector:
Expand Down
2 changes: 2 additions & 0 deletions charts/selenium-grid/templates/session-map-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ metadata:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
strategy:
{{- template "seleniumGrid.updateStrategy" (list $.Values.components.sessionMap $.Values.global.seleniumGrid) }}
replicas: 1
revisionHistoryLimit: {{ .Values.global.seleniumGrid.revisionHistoryLimit }}
selector:
Expand Down
2 changes: 2 additions & 0 deletions charts/selenium-grid/templates/session-queue-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ metadata:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
strategy:
{{- template "seleniumGrid.updateStrategy" (list $.Values.components.sessionQueue $.Values.global.seleniumGrid) }}
replicas: 1
revisionHistoryLimit: {{ .Values.global.seleniumGrid.revisionHistoryLimit }}
selector:
Expand Down
19 changes: 16 additions & 3 deletions charts/selenium-grid/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ global:
structuredLogs: false
# Enable http logging. Tracing should be enabled to log http logs.
httpLogs: false
# Define update strategy for all components
updateStrategy:
type: Recreate
# type: RollingUpdate
rollingUpdate:
maxSurge: 1
maxUnavailable: 0

tls:
# Name of external secret containing the TLS certificate and key
Expand Down Expand Up @@ -721,7 +728,9 @@ chromeNode:
# true (default) - if you want long-living pods
# false - for provisioning your own custom type such as Jobs
deploymentEnabled: true

# Global update strategy will be overwritten by individual component
updateStrategy:
type: RollingUpdate
# Number of chrome nodes
replicas: 1
# imageRegistry: selenium
Expand Down Expand Up @@ -882,7 +891,9 @@ firefoxNode:
# true (default) - if you want long living pods
# false - for provisioning your own custom type such as Jobs
deploymentEnabled: true

# Global update strategy will be overwritten by individual component
updateStrategy:
type: RollingUpdate
# Number of firefox nodes
replicas: 1
# imageRegistry: selenium
Expand Down Expand Up @@ -1042,7 +1053,9 @@ edgeNode:
# true (default) - if you want long living pods
# false - for provisioning your own custom type such as Jobs
deploymentEnabled: true

# Global update strategy will be overwritten by individual component
updateStrategy:
type: RollingUpdate
# Number of edge nodes
replicas: 1
# imageRegistry: selenium
Expand Down
23 changes: 23 additions & 0 deletions tests/charts/templates/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,29 @@ def test_enable_tracing(self):
count += 1
self.assertEqual(count, len(resources_name), "No node config resources found")

def test_update_strategy_in_all_components(self):
recreate = ['{0}selenium-distributor'.format(RELEASE_NAME),
'{0}selenium-event-bus'.format(RELEASE_NAME),
'{0}selenium-router'.format(RELEASE_NAME),
'{0}selenium-session-map'.format(RELEASE_NAME),
'{0}selenium-session-queue'.format(RELEASE_NAME),]
rolling = ['{0}selenium-chrome-node'.format(RELEASE_NAME),
'{0}selenium-edge-node'.format(RELEASE_NAME),
'{0}selenium-firefox-node'.format(RELEASE_NAME),]
count_recreate = 0
count_rolling = 0
for doc in LIST_OF_DOCUMENTS:
if doc['metadata']['name'] in rolling and doc['kind'] == 'Deployment':
logger.info(f"Assert updateStrategy is set in resource {doc['metadata']['name']}")
self.assertTrue(doc['spec']['strategy']['type'] == 'RollingUpdate', f"Resource {doc['metadata']['name']} doesn't have strategy RollingUpdate")
count_rolling += 1
if doc['metadata']['name'] in recreate and doc['kind'] == 'Deployment':
logger.info(f"Assert updateStrategy is set in resource {doc['metadata']['name']}")
self.assertTrue(doc['spec']['strategy']['type'] == 'Recreate', f"Resource {doc['metadata']['name']} doesn't have strategy Recreate")
count_recreate += 1
self.assertEqual(count_rolling, len(rolling), "No deployment resources found with strategy RollingUpdate")
self.assertEqual(count_recreate, len(recreate), "No deployment resources found with strategy Recreate")

if __name__ == '__main__':
failed = False
try:
Expand Down

0 comments on commit 6216a4d

Please sign in to comment.