From 3f36ee5b6712d04740209fa38704fe4ac1cdd3f9 Mon Sep 17 00:00:00 2001 From: Viet Nguyen Duc Date: Tue, 31 Dec 2024 11:54:54 +0700 Subject: [PATCH] K8s: Allow extra data set to EventBus and Node configmap Signed-off-by: Viet Nguyen Duc --- charts/selenium-grid/CONFIGURATION.md | 2 ++ charts/selenium-grid/templates/_helpers.tpl | 4 ++-- .../selenium-grid/templates/event-bus-configmap.yaml | 5 ++++- charts/selenium-grid/templates/node-configmap.yaml | 12 +++++++++--- charts/selenium-grid/values.yaml | 4 ++++ tests/charts/templates/test.py | 2 +- 6 files changed, 22 insertions(+), 7 deletions(-) diff --git a/charts/selenium-grid/CONFIGURATION.md b/charts/selenium-grid/CONFIGURATION.md index cf51663ee9..ee338780e6 100644 --- a/charts/selenium-grid/CONFIGURATION.md +++ b/charts/selenium-grid/CONFIGURATION.md @@ -110,6 +110,7 @@ A Helm chart for creating a Selenium Grid Server in Kubernetes | ingress.paths | list | `[]` | List of paths for the ingress resource. This will override the default path | | ingress.tls | list | `[]` | TLS backend configuration for ingress resource | | busConfigMap.nameOverride | string | `nil` | Override the name of the bus configMap | +| busConfigMap.data | object | `{}` | Override or add extra data to the ConfigMap. The property that appears last within the ConfigMap overwrites any preceding values | | busConfigMap.annotations | object | `{}` | Custom annotations for configmap | | sessionMapConfigMap.nameOverride | string | `nil` | Override the name of the session map configMap | | sessionMapConfigMap.annotations | object | `{}` | Custom annotations for configmap | @@ -129,6 +130,7 @@ A Helm chart for creating a Selenium Grid Server in Kubernetes | routerConfigMap.scriptVolumeMountName | string | `nil` | Name of volume mount is used to mount scripts in the ConfigMap | | routerConfigMap.annotations | object | `{}` | Custom annotations for configmap | | nodeConfigMap.nameOverride | string | `nil` | Override the name of the node configMap | +| nodeConfigMap.data | object | `{}` | Override or add extra data to the ConfigMap. The property that appears last within the ConfigMap overwrites any preceding values | | nodeConfigMap.defaultMode | int | `493` | Default mode for ConfigMap is mounted as file | | nodeConfigMap.extraScriptsImportFrom | string | `"configs/node/**"` | Directory where the extra scripts are imported to ConfigMap by default (if given a relative path, it should be in chart's directory) | | nodeConfigMap.extraScriptsDirectory | string | `"/opt/bin"` | Directory where the extra scripts are mounted to | diff --git a/charts/selenium-grid/templates/_helpers.tpl b/charts/selenium-grid/templates/_helpers.tpl index febcad1bff..b7b21d7923 100644 --- a/charts/selenium-grid/templates/_helpers.tpl +++ b/charts/selenium-grid/templates/_helpers.tpl @@ -707,7 +707,7 @@ Graphql Url for internal monitoring exporter {{- end -}} {{- define "seleniumGrid.url.host" -}} -{{- $host := printf "%s.%s" (include ($.Values.isolateComponents | ternary "seleniumGrid.router.fullname" "seleniumGrid.hub.fullname") $ ) (.Release.Namespace) -}} +{{- $host := printf "%s.%s.svc.cluster.local" (include ($.Values.isolateComponents | ternary "seleniumGrid.router.fullname" "seleniumGrid.hub.fullname") $ ) (.Release.Namespace) -}} {{- if eq (include "seleniumGrid.ingress.enabled" $) "true" -}} {{- if and (not .Values.ingress.hostname) .Values.global.K8S_PUBLIC_IP -}} {{- $host = .Values.global.K8S_PUBLIC_IP -}} @@ -721,7 +721,7 @@ Graphql Url for internal monitoring exporter {{- end -}} {{- define "seleniumGrid.server.url.host" -}} -{{- $host := printf "%s.%s" (include ($.Values.isolateComponents | ternary "seleniumGrid.router.fullname" "seleniumGrid.hub.fullname") $ ) (.Release.Namespace) -}} +{{- $host := printf "%s.%s.svc.cluster.local" (include ($.Values.isolateComponents | ternary "seleniumGrid.router.fullname" "seleniumGrid.hub.fullname") $ ) (.Release.Namespace) -}} {{- $host }} {{- end -}} diff --git a/charts/selenium-grid/templates/event-bus-configmap.yaml b/charts/selenium-grid/templates/event-bus-configmap.yaml index 7bbfd952d5..b6c2ef0047 100644 --- a/charts/selenium-grid/templates/event-bus-configmap.yaml +++ b/charts/selenium-grid/templates/event-bus-configmap.yaml @@ -1,4 +1,4 @@ -{{- $eventBusHost := printf "%s.%s" (ternary (include "seleniumGrid.eventBus.fullname" .) (include "seleniumGrid.hub.fullname" .) .Values.isolateComponents) (.Release.Namespace) -}} +{{- $eventBusHost := printf "%s.%s.svc.cluster.local" (ternary (include "seleniumGrid.eventBus.fullname" .) (include "seleniumGrid.hub.fullname" .) .Values.isolateComponents) (.Release.Namespace) -}} {{- $eventBusPublishPort := ternary .Values.components.eventBus.publishPort .Values.hub.publishPort .Values.isolateComponents -}} {{- $eventBusSubscribePort := ternary .Values.components.eventBus.subscribePort .Values.hub.subscribePort .Values.isolateComponents -}} apiVersion: v1 @@ -18,3 +18,6 @@ data: SE_EVENT_BUS_HOST: {{ $eventBusHost | quote }} SE_EVENT_BUS_PUBLISH_PORT: {{ $eventBusPublishPort | quote }} SE_EVENT_BUS_SUBSCRIBE_PORT: {{ $eventBusSubscribePort | quote }} +{{- with .Values.busConfigMap.data }} + {{- tpl (toYaml .) $ | nindent 2 }} +{{- end }} diff --git a/charts/selenium-grid/templates/node-configmap.yaml b/charts/selenium-grid/templates/node-configmap.yaml index abd813d92b..3c86f1b56c 100644 --- a/charts/selenium-grid/templates/node-configmap.yaml +++ b/charts/selenium-grid/templates/node-configmap.yaml @@ -1,3 +1,6 @@ +{{- $distributorHost := printf "%s.%s.svc.cluster.local" (include "seleniumGrid.distributor.fullname" .) (.Release.Namespace) -}} +{{- $routerHost := printf "%s.%s.svc.cluster.local" (include "seleniumGrid.router.fullname" .) (.Release.Namespace) -}} +{{- $hubHost := printf "%s.%s.svc.cluster.local" (include "seleniumGrid.hub.fullname" .) (.Release.Namespace) -}} apiVersion: v1 kind: ConfigMap metadata: @@ -13,12 +16,12 @@ metadata: {{- end }} data: {{- if .Values.isolateComponents }} - SE_DISTRIBUTOR_HOST: '{{ include "seleniumGrid.distributor.fullname" . }}.{{ .Release.Namespace }}' + SE_DISTRIBUTOR_HOST: {{ $distributorHost | quote }} SE_DISTRIBUTOR_PORT: '{{ .Values.components.distributor.port }}' - SE_ROUTER_HOST: '{{ include "seleniumGrid.router.fullname" . }}.{{ .Release.Namespace }}' + SE_ROUTER_HOST: {{ $routerHost | quote }} SE_ROUTER_PORT: '{{ .Values.components.router.port }}' {{- else }} - SE_HUB_HOST: '{{ include "seleniumGrid.hub.fullname" . }}.{{ .Release.Namespace }}' + SE_HUB_HOST: {{ $hubHost | quote }} SE_HUB_PORT: '{{ .Values.hub.port }}' {{- end }} NODE_CONFIG_DIRECTORY: '{{ $.Values.nodeConfigMap.extraScriptsDirectory }}' @@ -38,6 +41,9 @@ data: SE_BROWSER_LEFTOVERS_TEMPFILES_DAYS: '{{ . }}' {{- end }} {{- end }} +{{- with .Values.nodeConfigMap.data }} + {{- tpl (toYaml .) $ | nindent 2 }} +{{- end }} {{- $fileProceeded := list -}} {{- range $path, $_ := .Files.Glob $.Values.nodeConfigMap.extraScriptsImportFrom }} {{- $fileName := base $path -}} diff --git a/charts/selenium-grid/values.yaml b/charts/selenium-grid/values.yaml index 0dfe3be98e..63e6a68c6f 100644 --- a/charts/selenium-grid/values.yaml +++ b/charts/selenium-grid/values.yaml @@ -232,6 +232,8 @@ ingress: busConfigMap: # -- Override the name of the bus configMap nameOverride: + # -- Override or add extra data to the ConfigMap. The property that appears last within the ConfigMap overwrites any preceding values + data: {} # -- Custom annotations for configmap annotations: {} @@ -282,6 +284,8 @@ routerConfigMap: nodeConfigMap: # -- Override the name of the node configMap nameOverride: + # -- Override or add extra data to the ConfigMap. The property that appears last within the ConfigMap overwrites any preceding values + data: {} # -- Default mode for ConfigMap is mounted as file defaultMode: 0755 # -- Directory where the extra scripts are imported to ConfigMap by default (if given a relative path, it should be in chart's directory) diff --git a/tests/charts/templates/test.py b/tests/charts/templates/test.py index 7365c15a8b..f8929c699a 100644 --- a/tests/charts/templates/test.py +++ b/tests/charts/templates/test.py @@ -80,7 +80,7 @@ def test_graphql_url_for_autoscaling_constructed_without_basic_auth_in_url(self) logger.info(f"Assert graphql url is constructed without basic auth in url") base64_url = doc['data']['SE_NODE_GRID_GRAPHQL_URL'] decoded_url = base64.b64decode(base64_url).decode('utf-8') - self.assertTrue(decoded_url == f'https://{RELEASE_NAME}selenium-router.default:4444/selenium/graphql', decoded_url) + self.assertTrue(decoded_url == f'https://{RELEASE_NAME}selenium-router.default.svc.cluster.local:4444/selenium/graphql', decoded_url) def test_distributor_new_session_thread_pool_size(self): resources_name = [f'{RELEASE_NAME}selenium-distributor']