Skip to content

Commit 17f513d

Browse files
committed
K8s: Add configs for sessions external datastore
Signed-off-by: Viet Nguyen Duc <[email protected]>
1 parent 9800a03 commit 17f513d

File tree

13 files changed

+219
-7
lines changed

13 files changed

+219
-7
lines changed

Base/Dockerfile

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ ARG OPENTELEMETRY_VERSION=1.44.1
1111
ARG GRPC_VERSION=1.68.1
1212
ARG NETTY_VERSION=4.1.115.Final
1313
ARG CS_VERSION=2.1.18
14+
ARG POSTGRESQL_VERSION=42.7.4
15+
ARG MVN_SELENIUM_VERSION=4.27.0
1416

1517
#Arguments to define the user running Selenium
1618
ARG SEL_USER=seluser
@@ -118,8 +120,16 @@ RUN --mount=type=secret,id=SEL_PASSWD \
118120
&& if [ -f "/tmp/cs" ]; then \
119121
java -jar /tmp/cs fetch --classpath --cache /external_jars \
120122
io.opentelemetry:opentelemetry-exporter-otlp:${OPENTELEMETRY_VERSION} \
121-
io.grpc:grpc-netty:${GRPC_VERSION} io.netty:netty-codec-http:${NETTY_VERSION} > /external_jars/.classpath.txt \
122-
&& chmod 664 /external_jars/.classpath.txt ; \
123+
io.grpc:grpc-netty:${GRPC_VERSION} \
124+
io.netty:netty-codec-http:${NETTY_VERSION} \
125+
> /external_jars/.classpath.txt \
126+
&& chmod 664 /external_jars/.classpath.txt \
127+
&& java -jar /tmp/cs fetch --classpath --cache /external_jars \
128+
org.seleniumhq.selenium:selenium-session-map-jdbc:${MVN_SELENIUM_VERSION} \
129+
org.postgresql:postgresql:${POSTGRESQL_VERSION} \
130+
org.seleniumhq.selenium:selenium-session-map-redis:${MVN_SELENIUM_VERSION} \
131+
> /external_jars/.classpath_session_map.txt \
132+
&& chmod 664 /external_jars/.classpath_session_map.txt ; \
123133
fi \
124134
&& rm -fr /root/.cache/* \
125135
# (Note that .bashrc is only executed in interactive bash shells.)

Sessions/Dockerfile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,13 @@ USER ${SEL_UID}
1212

1313
EXPOSE 5556
1414

15-
COPY --chown="${SEL_UID}:${SEL_GID}" start-selenium-grid-sessions.sh \
15+
COPY --chown="${SEL_UID}:${SEL_GID}" start-selenium-grid-sessions.sh generate_config \
1616
/opt/bin/
1717

1818
COPY selenium-grid-sessions.conf /etc/supervisor/conf.d/
1919

20-
ENV SE_OTEL_SERVICE_NAME="selenium-session-map"
20+
ENV SE_OTEL_SERVICE_NAME="selenium-session-map" \
21+
# Path to the Configfile
22+
CONFIG_FILE=/opt/selenium/config.toml \
23+
GENERATE_CONFIG=true \
24+
SE_SESSIONS_MAP_EXTERNAL_DATASTORE=false

Sessions/generate_config

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/bin/bash
2+
3+
if [[ -z "$CONFIG_FILE" ]]; then
4+
FILENAME="/opt/selenium/config.toml"
5+
else
6+
FILENAME="$CONFIG_FILE"
7+
fi
8+
9+
echo "[sessions]" >"$FILENAME"
10+
11+
if [ "${SE_SESSIONS_MAP_EXTERNAL_DATASTORE}" = "true" ]; then
12+
if [[ -n "${SE_SESSIONS_MAP_EXTERNAL_SCHEME}" ]]; then
13+
echo "scheme = \"${SE_SESSIONS_MAP_EXTERNAL_SCHEME}\"" >>"$FILENAME"
14+
fi
15+
16+
if [[ -n "${SE_SESSIONS_MAP_EXTERNAL_IMPLEMENTATION}" ]]; then
17+
echo "implementation = \"${SE_SESSIONS_MAP_EXTERNAL_IMPLEMENTATION}\"" >>"$FILENAME"
18+
fi
19+
20+
if [[ -n "${SE_SESSIONS_MAP_EXTERNAL_HOSTNAME}" ]]; then
21+
echo "hostname = \"${SE_SESSIONS_MAP_EXTERNAL_HOSTNAME}\"" >>"$FILENAME"
22+
fi
23+
24+
if [[ -n "${SE_SESSIONS_MAP_EXTERNAL_PORT}" ]]; then
25+
echo "port = \"${SE_SESSIONS_MAP_EXTERNAL_PORT}\"" >>"$FILENAME"
26+
fi
27+
28+
if [[ -n "${SE_SESSIONS_MAP_EXTERNAL_JDBC_URL}" ]]; then
29+
echo "jdbc-url = \"${SE_SESSIONS_MAP_EXTERNAL_JDBC_URL}\"" >>"$FILENAME"
30+
fi
31+
32+
if [[ -n "${SE_SESSIONS_MAP_EXTERNAL_JDBC_USER}" ]]; then
33+
echo "jdbc-user = \"${SE_SESSIONS_MAP_EXTERNAL_JDBC_USER}\"" >>"$FILENAME"
34+
fi
35+
36+
if [[ -n "${SE_SESSIONS_MAP_EXTERNAL_JDBC_PASSWORD}" ]]; then
37+
echo "jdbc-password = \"${SE_SESSIONS_MAP_EXTERNAL_JDBC_PASSWORD}\"" >>"$FILENAME"
38+
fi
39+
fi

Sessions/start-selenium-grid-sessions.sh

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
# set -e: exit asap if a command exits with a non-zero status
44
set -e
55

6-
echo "Starting Selenium Grid Sessions..."
7-
86
function append_se_opts() {
97
local option="${1}"
108
local value="${2:-""}"
@@ -98,12 +96,21 @@ if [ ! -z "$SE_REGISTRATION_SECRET" ]; then
9896
append_se_opts "--registration-secret" "${SE_REGISTRATION_SECRET}" "false"
9997
fi
10098

99+
if [ "$GENERATE_CONFIG" = true ]; then
100+
echo "Generating Selenium Config for Sessions"
101+
/opt/bin/generate_config
102+
fi
103+
104+
if [ ! -z "${CONFIG_FILE}" ]; then
105+
append_se_opts "--config" "${CONFIG_FILE}"
106+
fi
107+
101108
EXTRA_LIBS=""
102109

103110
if [ "$SE_ENABLE_TRACING" = "true" ]; then
104111
EXTERNAL_JARS=$(</external_jars/.classpath.txt)
105112
[ -n "$EXTRA_LIBS" ] && [ -n "${EXTERNAL_JARS}" ] && EXTRA_LIBS=${EXTRA_LIBS}:
106-
EXTRA_LIBS="--ext "${EXTRA_LIBS}${EXTERNAL_JARS}
113+
EXTRA_LIBS="${EXTRA_LIBS}${EXTERNAL_JARS}"
107114
echo "Tracing is enabled"
108115
echo "Classpath will be enriched with these external jars : " ${EXTRA_LIBS}
109116
if [ -n "$SE_OTEL_SERVICE_NAME" ]; then
@@ -128,6 +135,19 @@ else
128135
echo "Tracing is disabled"
129136
fi
130137

138+
if [ "${SE_SESSIONS_MAP_EXTERNAL_DATASTORE}" = "true" ]; then
139+
EXTERNAL_JARS=$(</external_jars/.classpath_session_map.txt)
140+
[ -n "$EXTRA_LIBS" ] && [ -n "${EXTERNAL_JARS}" ] && EXTRA_LIBS=${EXTRA_LIBS}:
141+
EXTRA_LIBS="${EXTRA_LIBS}${EXTERNAL_JARS}"
142+
fi
143+
144+
if [ -n "${EXTRA_LIBS}" ]; then
145+
EXTRA_LIBS="--ext ${EXTRA_LIBS}"
146+
fi
147+
148+
cat "$CONFIG_FILE"
149+
echo "Starting Selenium Grid Sessions..."
150+
131151
java ${JAVA_OPTS:-$SE_JAVA_OPTS} \
132152
-jar /opt/selenium/selenium-server.jar \
133153
${EXTRA_LIBS} sessions \

charts/selenium-grid/CONFIGURATION.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ A Helm chart for creating a Selenium Grid Server in Kubernetes
1818

1919
| Repository | Name | Version |
2020
|------------|------|---------|
21+
| https://charts.bitnami.com/bitnami | postgresql | 16.2.3 |
22+
| https://charts.bitnami.com/bitnami | redis | 20.4.0 |
2123
| https://jaegertracing.github.io/helm-charts | jaeger | 3.3.3 |
2224
| https://kedacore.github.io/charts | keda | 2.16.0 |
2325
| https://kubernetes.github.io/ingress-nginx | ingress-nginx | 4.11.3 |
@@ -109,6 +111,8 @@ A Helm chart for creating a Selenium Grid Server in Kubernetes
109111
| ingress.tls | list | `[]` | TLS backend configuration for ingress resource |
110112
| busConfigMap.nameOverride | string | `nil` | Override the name of the bus configMap |
111113
| busConfigMap.annotations | object | `{}` | Custom annotations for configmap |
114+
| sessionMapConfigMap.nameOverride | string | `nil` | Override the name of the session map configMap |
115+
| sessionMapConfigMap.annotations | object | `{}` | Custom annotations for configmap |
112116
| distributorConfigMap.nameOverride | string | `nil` | Override the name of the distributor configMap |
113117
| distributorConfigMap.defaultMode | int | `493` | Default mode for ConfigMap is mounted as file |
114118
| distributorConfigMap.extraScriptsImportFrom | string | `"configs/distributor/**"` | Directory where the extra scripts are imported to ConfigMap by default (if given a relative path, it should be in chart's directory) |
@@ -244,6 +248,10 @@ A Helm chart for creating a Selenium Grid Server in Kubernetes
244248
| components.sessionMap.tolerations | list | `[]` | Tolerations for Session Map pods |
245249
| components.sessionMap.nodeSelector | object | `{}` | Node selector for Session Map pods |
246250
| components.sessionMap.priorityClassName | string | `""` | Priority class name for Session Map pods |
251+
| components.sessionMap.externalDatastore.enabled | bool | `false` | Enable external datastore for Session Map |
252+
| components.sessionMap.externalDatastore.backend | string | `"postgresql"` | Backend for external datastore (supported: postgresql, redis). Details for each backend are described below config key |
253+
| components.sessionMap.externalDatastore.postgresql | object | `{"implementation":"org.openqa.selenium.grid.sessionmap.jdbc.JdbcBackedSessionMap","jdbcPassword":"seluser","jdbcUrl":"jdbc:postgresql://{{ $.Release.Name }}-postgresql-hl:5432/selenium_sessions","jdbcUser":"seluser"}` | Configure database backed Session Map (https://www.selenium.dev/documentation/grid/advanced_features/external_datastore/#database-backed-session-map) |
254+
| components.sessionMap.externalDatastore.redis | object | `{"hostname":"{{ $.Release.Name }}-redis-headless","implementation":"org.openqa.selenium.grid.sessionmap.redis.RedisBackedSessionMap","port":"6379","scheme":"redis"}` | Configure Redis backed Session Map (https://www.selenium.dev/documentation/grid/advanced_features/external_datastore/#redis-backed-session-map) |
247255
| components.sessionQueue.imageRegistry | string | `nil` | Registry to pull the image (this overwrites global.seleniumGrid.imageRegistry parameter) |
248256
| components.sessionQueue.imageName | string | `"session-queue"` | Session Queue image name |
249257
| components.sessionQueue.imageTag | string | `nil` | Session Queue image tag (this overwrites global.seleniumGrid.imageTag parameter) |
@@ -590,4 +598,10 @@ A Helm chart for creating a Selenium Grid Server in Kubernetes
590598
| ingress-nginx | object | `{"controller":{"admissionWebhooks":{"enabled":false}}}` | Configuration for dependency chart ingress-nginx |
591599
| kube-prometheus-stack | object | `{"cleanPrometheusOperatorObjectNames":true,"prometheus":{"prometheusSpec":{"additionalConfig":{"additionalScrapeConfigs":{"key":"{{ template \"seleniumGrid.monitoring.scrape.key\" $ }}","name":"{{ template \"seleniumGrid.monitoring.exporter.fullname\" $ }}"}}}}}` | Configuration for dependency chart kube-prometheus-stack |
592600
| jaeger | object | `{"agent":{"enabled":false},"allInOne":{"enabled":true,"extraEnv":[{"name":"QUERY_BASE_PATH","value":"/jaeger"}]},"collector":{"enabled":false},"provisionDataStore":{"cassandra":false},"query":{"enabled":false},"storage":{"type":"badger"}}` | Configuration for dependency chart jaeger |
601+
| postgresql.enabled | bool | `false` | Enable to install PostgreSQL along with Grid |
602+
| postgresql.auth | object | `{"database":"selenium_sessions","password":"seluser","username":"seluser"}` | Authentication should be aligned with config in session map |
603+
| postgresql.primary.initdb.scripts | object | `{"init.sql":"CREATE TABLE IF NOT EXISTS sessions_map(\n session_ids varchar(256),\n session_caps text,\n session_uri varchar(256),\n session_stereotype text,\n session_start varchar(256)\n);\n"}` | Initdb scripts for PostgreSQL to create sessions_map table |
604+
| redis.enabled | bool | `false` | Enable to install Redis along with Grid |
605+
| redis.architecture | string | `"standalone"` | Setup architecture |
606+
| redis.auth.enabled | bool | `false` | Disable authentication due to implementation still not supporting it |
593607

charts/selenium-grid/Chart.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ dependencies:
2222
version: 66.3.0
2323
name: kube-prometheus-stack
2424
condition: monitoring.enabled, prometheus-stack.enabled
25+
- repository: https://charts.bitnami.com/bitnami
26+
version: 16.2.3
27+
name: postgresql
28+
condition: postgresql.enabled
29+
- repository: https://charts.bitnami.com/bitnami
30+
version: 20.4.0
31+
name: redis
32+
condition: redis.enabled
2533
maintainers:
2634
- name: SeleniumHQ
2735

charts/selenium-grid/templates/_nameHelpers.tpl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,13 @@ Event bus ConfigMap fullname
9191
{{- tpl (default (include "seleniumGrid.component.name" (list "selenium-event-bus-config" $)) .Values.busConfigMap.nameOverride) $ | trunc 63 | trimSuffix "-" -}}
9292
{{- end -}}
9393

94+
{{/*
95+
Session Map ConfigMap fullname
96+
*/}}
97+
{{- define "seleniumGrid.sessionMap.configmap.fullname" -}}
98+
{{- tpl (default (include "seleniumGrid.component.name" (list "selenium-session-map-config" $)) .Values.sessionMapConfigMap.nameOverride) $ | trunc 63 | trimSuffix "-" -}}
99+
{{- end -}}
100+
94101
{{/*
95102
Router fullname
96103
*/}}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{{- if .Values.isolateComponents }}
2+
apiVersion: v1
3+
kind: ConfigMap
4+
metadata:
5+
name: {{ template "seleniumGrid.sessionMap.configmap.fullname" . }}
6+
namespace: {{ .Release.Namespace }}
7+
{{- with .Values.sessionMapConfigMap.annotations }}
8+
annotations: {{- toYaml . | nindent 4 }}
9+
{{- end }}
10+
labels:
11+
{{- include "seleniumGrid.commonLabels" . | nindent 4 }}
12+
{{- with .Values.customLabels }}
13+
{{- toYaml . | nindent 4 }}
14+
{{- end }}
15+
data:
16+
{{- if .Values.components.sessionMap.externalDatastore.enabled }}
17+
SE_SESSIONS_MAP_EXTERNAL_DATASTORE: "true"
18+
{{- $backend := .Values.components.sessionMap.externalDatastore.backend -}}
19+
{{- with (get .Values.components.sessionMap.externalDatastore $backend) }}
20+
{{- with .scheme }}
21+
SE_SESSIONS_MAP_EXTERNAL_SCHEME: {{ tpl . $ | quote }}
22+
{{- end }}
23+
{{- with .implementation }}
24+
SE_SESSIONS_MAP_EXTERNAL_IMPLEMENTATION: {{ tpl . $ | quote }}
25+
{{- end }}
26+
{{- with .hostname }}
27+
SE_SESSIONS_MAP_EXTERNAL_HOSTNAME: {{ tpl . $ | quote }}
28+
{{- end }}
29+
{{- with .port }}
30+
SE_SESSIONS_MAP_EXTERNAL_PORT: {{ tpl . $ | quote }}
31+
{{- end }}
32+
{{- with .jdbcUrl }}
33+
SE_SESSIONS_MAP_EXTERNAL_JDBC_URL: {{ tpl . $ | quote }}
34+
{{- end }}
35+
{{- with .jdbcUser }}
36+
SE_SESSIONS_MAP_EXTERNAL_JDBC_USER: {{ tpl . $ | quote }}
37+
{{- end }}
38+
{{- with .jdbcPassword }}
39+
SE_SESSIONS_MAP_EXTERNAL_JDBC_PASSWORD: {{ tpl . $ | quote }}
40+
{{- end }}
41+
{{- end }}
42+
{{- else }}
43+
SE_SESSIONS_MAP_EXTERNAL_DATASTORE: "false"
44+
{{- end }}
45+
{{- end }}

charts/selenium-grid/templates/session-map-deployment.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ spec:
5353
{{- tpl (toYaml .) $ | nindent 12 }}
5454
{{- end }}
5555
envFrom:
56+
- configMapRef:
57+
name: {{ template "seleniumGrid.sessionMap.configmap.fullname" $ }}
5658
- configMapRef:
5759
name: {{ template "seleniumGrid.logging.configmap.fullname" $ }}
5860
- configMapRef:

charts/selenium-grid/values.yaml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,13 @@ busConfigMap:
235235
# -- Custom annotations for configmap
236236
annotations: {}
237237

238+
# ConfigMap that contains environment variables for session map
239+
sessionMapConfigMap:
240+
# -- Override the name of the session map configMap
241+
nameOverride:
242+
# -- Custom annotations for configmap
243+
annotations: {}
244+
238245
distributorConfigMap:
239246
# -- Override the name of the distributor configMap
240247
nameOverride:
@@ -597,6 +604,23 @@ components:
597604
nodeSelector: {}
598605
# -- Priority class name for Session Map pods
599606
priorityClassName: ""
607+
externalDatastore:
608+
# -- Enable external datastore for Session Map
609+
enabled: false
610+
# -- Backend for external datastore (supported: postgresql, redis). Details for each backend are described below config key
611+
backend: postgresql
612+
# -- Configure database backed Session Map (https://www.selenium.dev/documentation/grid/advanced_features/external_datastore/#database-backed-session-map)
613+
postgresql:
614+
implementation: "org.openqa.selenium.grid.sessionmap.jdbc.JdbcBackedSessionMap"
615+
jdbcUser: "seluser"
616+
jdbcPassword: "seluser"
617+
jdbcUrl: "jdbc:postgresql://{{ $.Release.Name }}-postgresql-hl:5432/selenium_sessions"
618+
# -- Configure Redis backed Session Map (https://www.selenium.dev/documentation/grid/advanced_features/external_datastore/#redis-backed-session-map)
619+
redis:
620+
scheme: "redis"
621+
implementation: "org.openqa.selenium.grid.sessionmap.redis.RedisBackedSessionMap"
622+
hostname: "{{ $.Release.Name }}-redis-headless"
623+
port: "6379"
600624

601625
# Configuration for Session Queue component
602626
sessionQueue:
@@ -1852,3 +1876,35 @@ jaeger:
18521876
enabled: false
18531877
query:
18541878
enabled: false
1879+
1880+
# Configuration for dependency chart PostgreSQL (README: https://artifacthub.io/packages/helm/bitnami/postgresql)
1881+
postgresql:
1882+
# -- Enable to install PostgreSQL along with Grid
1883+
enabled: false
1884+
# -- Authentication should be aligned with config in session map
1885+
auth:
1886+
username: "seluser"
1887+
password: "seluser"
1888+
database: "selenium_sessions"
1889+
primary:
1890+
initdb:
1891+
# -- Initdb scripts for PostgreSQL to create sessions_map table
1892+
scripts:
1893+
init.sql: |
1894+
CREATE TABLE IF NOT EXISTS sessions_map(
1895+
session_ids varchar(256),
1896+
session_caps text,
1897+
session_uri varchar(256),
1898+
session_stereotype text,
1899+
session_start varchar(256)
1900+
);
1901+
1902+
# Configuration for dependency chart Redis (README: https://artifacthub.io/packages/helm/bitnami/redis)
1903+
redis:
1904+
# -- Enable to install Redis along with Grid
1905+
enabled: false
1906+
# -- Setup architecture
1907+
architecture: standalone
1908+
auth:
1909+
# -- Disable authentication due to implementation still not supporting it
1910+
enabled: false

0 commit comments

Comments
 (0)