From 6216a4d941b5134248bd5353ebcbe87e53f53377 Mon Sep 17 00:00:00 2001 From: Viet Nguyen Duc Date: Thu, 29 Aug 2024 10:12:20 +0000 Subject: [PATCH] chart(feat): updateStrategy default RollingUpdate for browsers and Recreate for components Signed-off-by: Viet Nguyen Duc --- charts/selenium-grid/templates/_helpers.tpl | 20 ++++++++++++++++ .../templates/chrome-node-deployment.yaml | 2 ++ .../templates/distributor-deployment.yaml | 2 ++ .../templates/edge-node-deployment.yaml | 2 ++ .../templates/event-bus-deployment.yaml | 2 ++ .../templates/firefox-node-deployment.yaml | 2 ++ .../templates/hub-deployment.yaml | 2 ++ .../templates/router-deployment.yaml | 2 ++ .../templates/session-map-deployment.yaml | 2 ++ .../templates/session-queue-deployment.yaml | 2 ++ charts/selenium-grid/values.yaml | 19 ++++++++++++--- tests/charts/templates/test.py | 23 +++++++++++++++++++ 12 files changed, 77 insertions(+), 3 deletions(-) diff --git a/charts/selenium-grid/templates/_helpers.tpl b/charts/selenium-grid/templates/_helpers.tpl index a5530b9c1..c27743905 100644 --- a/charts/selenium-grid/templates/_helpers.tpl +++ b/charts/selenium-grid/templates/_helpers.tpl @@ -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 */}} diff --git a/charts/selenium-grid/templates/chrome-node-deployment.yaml b/charts/selenium-grid/templates/chrome-node-deployment.yaml index 0028eb359..66f256b11 100644 --- a/charts/selenium-grid/templates/chrome-node-deployment.yaml +++ b/charts/selenium-grid/templates/chrome-node-deployment.yaml @@ -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}} diff --git a/charts/selenium-grid/templates/distributor-deployment.yaml b/charts/selenium-grid/templates/distributor-deployment.yaml index f9c458677..94392a540 100644 --- a/charts/selenium-grid/templates/distributor-deployment.yaml +++ b/charts/selenium-grid/templates/distributor-deployment.yaml @@ -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: diff --git a/charts/selenium-grid/templates/edge-node-deployment.yaml b/charts/selenium-grid/templates/edge-node-deployment.yaml index 00e590ca6..fa5c4c913 100644 --- a/charts/selenium-grid/templates/edge-node-deployment.yaml +++ b/charts/selenium-grid/templates/edge-node-deployment.yaml @@ -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}} diff --git a/charts/selenium-grid/templates/event-bus-deployment.yaml b/charts/selenium-grid/templates/event-bus-deployment.yaml index 67912c62c..280ea7a4f 100644 --- a/charts/selenium-grid/templates/event-bus-deployment.yaml +++ b/charts/selenium-grid/templates/event-bus-deployment.yaml @@ -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: diff --git a/charts/selenium-grid/templates/firefox-node-deployment.yaml b/charts/selenium-grid/templates/firefox-node-deployment.yaml index b9d51132c..38adabd21 100644 --- a/charts/selenium-grid/templates/firefox-node-deployment.yaml +++ b/charts/selenium-grid/templates/firefox-node-deployment.yaml @@ -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}} diff --git a/charts/selenium-grid/templates/hub-deployment.yaml b/charts/selenium-grid/templates/hub-deployment.yaml index 31eb94e13..8e7464aaf 100644 --- a/charts/selenium-grid/templates/hub-deployment.yaml +++ b/charts/selenium-grid/templates/hub-deployment.yaml @@ -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: diff --git a/charts/selenium-grid/templates/router-deployment.yaml b/charts/selenium-grid/templates/router-deployment.yaml index 5762fbafc..e7ad92897 100644 --- a/charts/selenium-grid/templates/router-deployment.yaml +++ b/charts/selenium-grid/templates/router-deployment.yaml @@ -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: diff --git a/charts/selenium-grid/templates/session-map-deployment.yaml b/charts/selenium-grid/templates/session-map-deployment.yaml index 4a0d85dd9..f0570bf9e 100644 --- a/charts/selenium-grid/templates/session-map-deployment.yaml +++ b/charts/selenium-grid/templates/session-map-deployment.yaml @@ -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: diff --git a/charts/selenium-grid/templates/session-queue-deployment.yaml b/charts/selenium-grid/templates/session-queue-deployment.yaml index 3b406c366..32af9d35f 100644 --- a/charts/selenium-grid/templates/session-queue-deployment.yaml +++ b/charts/selenium-grid/templates/session-queue-deployment.yaml @@ -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: diff --git a/charts/selenium-grid/values.yaml b/charts/selenium-grid/values.yaml index f08bd73e7..75b6b678d 100644 --- a/charts/selenium-grid/values.yaml +++ b/charts/selenium-grid/values.yaml @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/tests/charts/templates/test.py b/tests/charts/templates/test.py index 1d6748765..26b3e1dde 100644 --- a/tests/charts/templates/test.py +++ b/tests/charts/templates/test.py @@ -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: