Skip to content

Commit

Permalink
feat(chart): Simplify to change log level in Kubernetes (#2072)
Browse files Browse the repository at this point in the history
feat(chart): Simplify to change log level in Kubernetes

Signed-off-by: Viet Nguyen Duc <[email protected]>
  • Loading branch information
VietND96 authored Dec 18, 2023
1 parent 3e22a51 commit 02e6af2
Show file tree
Hide file tree
Showing 23 changed files with 121 additions and 9 deletions.
5 changes: 5 additions & 0 deletions Distributor/start-selenium-grid-distributor.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ if [ ! -z "$SE_DISTRIBUTOR_PORT" ]; then
PORT_CONFIG="--port ${SE_DISTRIBUTOR_PORT}"
fi

if [ ! -z "$SE_LOG_LEVEL" ]; then
echo "Appending Selenium options: --log-level ${SE_LOG_LEVEL}"
SE_OPTS="$SE_OPTS --log-level ${SE_LOG_LEVEL}"
fi

EXTRA_LIBS=""

if [ ! -z "$SE_ENABLE_TRACING" ]; then
Expand Down
5 changes: 5 additions & 0 deletions EventBus/start-selenium-grid-eventbus.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ if [ ! -z "$SE_OPTS" ]; then
echo "Appending Selenium options: ${SE_OPTS}"
fi

if [ ! -z "$SE_LOG_LEVEL" ]; then
echo "Appending Selenium options: --log-level ${SE_LOG_LEVEL}"
SE_OPTS="$SE_OPTS --log-level ${SE_LOG_LEVEL}"
fi

EXTRA_LIBS=""

if [ ! -z "$SE_ENABLE_TRACING" ]; then
Expand Down
5 changes: 5 additions & 0 deletions Hub/start-selenium-grid-hub.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ if [ ! -z "$SE_SUB_PATH" ]; then
SUB_PATH_CONFIG="--sub-path ${SE_SUB_PATH}"
fi

if [ ! -z "$SE_LOG_LEVEL" ]; then
echo "Appending Selenium options: --log-level ${SE_LOG_LEVEL}"
SE_OPTS="$SE_OPTS --log-level ${SE_LOG_LEVEL}"
fi

EXTRA_LIBS=""

if [ ! -z "$SE_ENABLE_TRACING" ]; then
Expand Down
5 changes: 5 additions & 0 deletions NodeBase/start-selenium-node.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ if [ ! -z "$SE_NODE_SESSION_TIMEOUT" ]; then
echo "Appending Selenium node session timeout via SE_OPTS: ${SE_OPTS}"
fi

if [ ! -z "$SE_LOG_LEVEL" ]; then
echo "Appending Selenium options: --log-level ${SE_LOG_LEVEL}"
SE_OPTS="$SE_OPTS --log-level ${SE_LOG_LEVEL}"
fi

if [ "$GENERATE_CONFIG" = true ]; then
echo "Generating Selenium Config"
/opt/bin/generate_config
Expand Down
5 changes: 5 additions & 0 deletions NodeDocker/start-selenium-grid-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ if [ ! -z "$SE_NODE_GRID_URL" ]; then
SE_GRID_URL="--grid-url ${SE_NODE_GRID_URL}"
fi

if [ ! -z "$SE_LOG_LEVEL" ]; then
echo "Appending Selenium options: --log-level ${SE_LOG_LEVEL}"
SE_OPTS="$SE_OPTS --log-level ${SE_LOG_LEVEL}"
fi

EXTRA_LIBS=""

if [ ! -z "$SE_ENABLE_TRACING" ]; then
Expand Down
5 changes: 5 additions & 0 deletions Router/start-selenium-grid-router.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ if [ ! -z "$SE_ROUTER_PORT" ]; then
PORT_CONFIG="--port ${SE_ROUTER_PORT}"
fi

if [ ! -z "$SE_LOG_LEVEL" ]; then
echo "Appending Selenium options: --log-level ${SE_LOG_LEVEL}"
SE_OPTS="$SE_OPTS --log-level ${SE_LOG_LEVEL}"
fi

EXTRA_LIBS=""

if [ ! -z "$SE_ENABLE_TRACING" ]; then
Expand Down
5 changes: 5 additions & 0 deletions SessionQueue/start-selenium-grid-session-queue.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ if [ ! -z "$SE_SESSION_QUEUE_PORT" ]; then
PORT_CONFIG="--port ${SE_SESSION_QUEUE_PORT}"
fi

if [ ! -z "$SE_LOG_LEVEL" ]; then
echo "Appending Selenium options: --log-level ${SE_LOG_LEVEL}"
SE_OPTS="$SE_OPTS --log-level ${SE_LOG_LEVEL}"
fi

EXTRA_LIBS=""

if [ ! -z "$SE_ENABLE_TRACING" ]; then
Expand Down
5 changes: 5 additions & 0 deletions Sessions/start-selenium-grid-sessions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ if [ ! -z "$SE_SESSIONS_PORT" ]; then
PORT_CONFIG="--port ${SE_SESSIONS_PORT}"
fi

if [ ! -z "$SE_LOG_LEVEL" ]; then
echo "Appending Selenium options: --log-level ${SE_LOG_LEVEL}"
SE_OPTS="$SE_OPTS --log-level ${SE_LOG_LEVEL}"
fi

EXTRA_LIBS=""

if [ ! -z "$SE_ENABLE_TRACING" ]; then
Expand Down
5 changes: 5 additions & 0 deletions Standalone/start-selenium-standalone.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ if [ ! -z "$SE_OPTS" ]; then
echo "Appending Selenium options: ${SE_OPTS}"
fi

if [ ! -z "$SE_LOG_LEVEL" ]; then
echo "Appending Selenium options: --log-level ${SE_LOG_LEVEL}"
SE_OPTS="$SE_OPTS --log-level ${SE_LOG_LEVEL}"
fi

/opt/bin/generate_config

echo "Selenium Grid Standalone configuration: "
Expand Down
5 changes: 5 additions & 0 deletions StandaloneDocker/start-selenium-grid-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ if [ ! -z "$SE_NODE_GRID_URL" ]; then
SE_GRID_URL="--grid-url ${SE_NODE_GRID_URL}"
fi

if [ ! -z "$SE_LOG_LEVEL" ]; then
echo "Appending Selenium options: --log-level ${SE_LOG_LEVEL}"
SE_OPTS="$SE_OPTS --log-level ${SE_LOG_LEVEL}"
fi

EXTRA_LIBS=""

if [ ! -z "$SE_ENABLE_TRACING" ]; then
Expand Down
2 changes: 1 addition & 1 deletion charts/selenium-grid/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ appVersion: 4.16.1-20231212
icon: https://github.com/SeleniumHQ/docker-selenium/raw/trunk/logo.png
dependencies:
- repository: https://kedacore.github.io/charts
version: 2.12.0
version: 2.12.1
name: keda
condition: autoscaling.enabled
maintainers:
Expand Down
1 change: 1 addition & 0 deletions charts/selenium-grid/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ For now, global configuration supported is:
| `global.seleniumGrid.imagePullSecret` | `""` | Pull secret to be used for all images |
| `global.seleniumGrid.imagePullSecret` | `""` | Pull secret to be used for all images |
| `global.seleniumGrid.affinity` | `{}` | Affinity assigned globally |
| `global.seleniumGrid.logLevel` | `INFO` | Set log level for all components |

This table contains the configuration parameters of the chart and their default values:

Expand Down
2 changes: 2 additions & 0 deletions charts/selenium-grid/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ template:
name: {{ .Values.busConfigMap.name }}
- configMapRef:
name: {{ .Values.nodeConfigMap.name }}
- configMapRef:
name: {{ .Values.loggingConfigMap.name }}
{{- with .node.extraEnvFrom }}
{{- tpl (toYaml .) $ | nindent 10 }}
{{- 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 @@ -47,6 +47,8 @@ spec:
envFrom:
- configMapRef:
name: {{ .Values.busConfigMap.name }}
- configMapRef:
name: {{ .Values.loggingConfigMap.name }}
{{- with .Values.components.extraEnvFrom }}
{{- toYaml . | nindent 12 }}
{{- end }}
Expand Down
6 changes: 4 additions & 2 deletions charts/selenium-grid/templates/event-bus-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@ spec:
{{- with .Values.components.extraEnvironmentVariables }}
env: {{- tpl (toYaml .) $ | nindent 12 }}
{{- end }}
{{- with .Values.components.extraEnvFrom }}
envFrom:
- configMapRef:
name: {{ .Values.loggingConfigMap.name }}
{{- with .Values.components.extraEnvFrom }}
{{- toYaml . | nindent 12 }}
{{- end }}
{{- end }}
{{- with .Values.components.eventBus.resources }}
resources: {{- toYaml . | nindent 12 }}
{{- end }}
Expand Down
6 changes: 4 additions & 2 deletions charts/selenium-grid/templates/hub-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,12 @@ spec:
{{- with .Values.hub.extraEnvironmentVariables }}
{{- tpl (toYaml .) $ | nindent 12 }}
{{- end }}
{{- with .Values.hub.extraEnvFrom }}
envFrom:
- configMapRef:
name: {{ .Values.loggingConfigMap.name }}
{{- with .Values.hub.extraEnvFrom }}
{{- toYaml . | nindent 12 }}
{{- end }}
{{- end }}
{{- with .Values.hub.extraVolumeMounts }}
volumeMounts:
{{- tpl (toYaml .) $ | nindent 12 }}
Expand Down
15 changes: 15 additions & 0 deletions charts/selenium-grid/templates/logging-configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ .Values.loggingConfigMap.name }}
namespace: {{ .Release.Namespace }}
{{- with .Values.loggingConfigMap.annotations }}
annotations: {{- toYaml . | nindent 4 }}
{{- end }}
labels:
{{- include "seleniumGrid.commonLabels" . | nindent 4 }}
{{- with .Values.customLabels }}
{{- toYaml . | nindent 4 }}
{{- end }}
data:
SE_LOG_LEVEL: "{{ default "INFO" .Values.global.seleniumGrid.logLevel }}"
6 changes: 4 additions & 2 deletions charts/selenium-grid/templates/router-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,12 @@ spec:
{{- with .Values.components.extraEnvironmentVariables }}
{{- tpl (toYaml .) $ | nindent 12 }}
{{- end }}
{{- with .Values.components.extraEnvFrom }}
envFrom:
- configMapRef:
name: {{ .Values.loggingConfigMap.name }}
{{- with .Values.components.extraEnvFrom }}
{{- toYaml . | nindent 12 }}
{{- end }}
{{- end }}
ports:
- containerPort: {{ .Values.components.router.port }}
protocol: TCP
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 @@ -36,6 +36,8 @@ spec:
env: {{- tpl (toYaml .) $ | nindent 12 }}
{{- end }}
envFrom:
- configMapRef:
name: {{ .Values.loggingConfigMap.name }}
- configMapRef:
name: {{ .Values.busConfigMap.name }}
{{- with .Values.components.extraEnvFrom }}
Expand Down
6 changes: 4 additions & 2 deletions charts/selenium-grid/templates/session-queuer-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@ spec:
{{- with .Values.components.extraEnvironmentVariables }}
env: {{- tpl (toYaml .) $ | nindent 12 }}
{{- end }}
{{- with .Values.components.extraEnvFrom }}
envFrom:
- configMapRef:
name: {{ .Values.loggingConfigMap.name }}
{{- with .Values.components.extraEnvFrom }}
{{- toYaml . | nindent 12 }}
{{- end }}
{{- end }}
ports:
- containerPort: {{ .Values.components.sessionQueue.port }}
protocol: TCP
Expand Down
8 changes: 8 additions & 0 deletions charts/selenium-grid/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ global:
videoImageTag: ffmpeg-6.1-20231212
# Pull secret for all components, can be overridden individually
imagePullSecret: ""
# Log level for all components. Possible values describe here: https://www.selenium.dev/documentation/grid/configuration/cli_options/#logging
logLevel: INFO

# Basic auth settings for Selenium Grid
basicAuth:
Expand Down Expand Up @@ -68,6 +70,12 @@ nodeConfigMap:
# Custom annotations for configmap
annotations: {}

# ConfigMap that contains common environment variables for Logging (https://www.selenium.dev/documentation/grid/configuration/cli_options/#logging)
loggingConfigMap:
name: selenium-logging-config
# Custom annotations for configmap
annotations: {}

# Configuration for isolated components (applied only if `isolateComponents: true`)
components:

Expand Down
1 change: 1 addition & 0 deletions tests/charts/templates/render/dummy.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# This is dummy values file for chart template testing
global:
seleniumGrid:
logLevel: FINE
affinity: &affinity
podAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
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 @@ -67,6 +67,29 @@ def test_sub_path_set_to_grid_env_var(self):
is_present = True
self.assertTrue(is_present, "ENV variable SE_SUB_PATH is not populated")

def test_log_level_set_to_logging_config_map(self):
resources_name = ['selenium-chrome-node', 'selenium-distributor', 'selenium-edge-node', 'selenium-firefox-node',
'selenium-event-bus', 'selenium-router', 'selenium-session-map', 'selenium-session-queue']
logger.info(f"Assert log level value is set to logging ConfigMap")
count_config = 0
for doc in LIST_OF_DOCUMENTS:
if doc['metadata']['name'] == 'selenium-logging-config' and doc['kind'] == 'ConfigMap':
self.assertTrue(doc['data']['SE_LOG_LEVEL'] == 'FINE')
count_config += 1
self.assertEqual(count_config, 1, "No logging ConfigMap found")
count = 0
for doc in LIST_OF_DOCUMENTS:
if doc['metadata']['name'] in resources_name and doc['kind'] == 'Deployment':
is_present = False
logger.info(f"Assert logging ConfigMap is set to envFrom in resource {doc['metadata']['name']}")
list_env_from = doc['spec']['template']['spec']['containers'][0]['envFrom']
for env in list_env_from:
if env['configMapRef']['name'] == 'selenium-logging-config':
is_present = True
self.assertTrue(is_present, "envFrom doesn't contain logging ConfigMap")
count += 1
self.assertEqual(count, len(resources_name), "Logging ConfigMap is not present in expected resources")

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

0 comments on commit 02e6af2

Please sign in to comment.