Skip to content

Commit

Permalink
[🚀 Feature]: Update objects name convention with prefix is Chart RELE…
Browse files Browse the repository at this point in the history
…ASENAME #2109 (#2120)

[feature]: Update objects name convention with prefix is Chart RELEASENAME #2109
  • Loading branch information
Opvolger authored and VietND96 committed Feb 12, 2024
1 parent 85b708f commit 646e5c5
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 33 deletions.
30 changes: 15 additions & 15 deletions charts/selenium-grid/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -43,70 +43,70 @@ helm.sh/chart: {{ include "seleniumGrid.chart" . }}
Selenium Hub fullname
*/}}
{{- define "seleniumGrid.hub.fullname" -}}
{{- tpl (default "selenium-hub" .Values.hub.nameOverride) $ | trunc 63 | trimSuffix "-" -}}
{{- tpl (default (printf "%s-selenium-hub" .Release.Name) .Values.hub.nameOverride) $ | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Event bus fullname
*/}}
{{- define "seleniumGrid.eventBus.fullname" -}}
{{- tpl (default "selenium-event-bus" .Values.components.eventBus.nameOverride) $ | trunc 63 | trimSuffix "-" -}}
{{- tpl (default (printf "%s-selenium-event-bus" .Release.Name) .Values.components.eventBus.nameOverride) $ | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Router fullname
*/}}
{{- define "seleniumGrid.router.fullname" -}}
{{- tpl (default "selenium-router" .Values.components.router.nameOverride) $ | trunc 63 | trimSuffix "-" -}}
{{- tpl (default (printf "%s-selenium-router" .Release.Name) .Values.components.router.nameOverride) $ | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Distributor fullname
*/}}
{{- define "seleniumGrid.distributor.fullname" -}}
{{- tpl (default "selenium-distributor" .Values.components.distributor.nameOverride) $ | trunc 63 | trimSuffix "-" -}}
{{- tpl (default (printf "%s-selenium-distributor" .Release.Name) .Values.components.distributor.nameOverride) $ | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
SessionMap fullname
*/}}
{{- define "seleniumGrid.sessionMap.fullname" -}}
{{- tpl (default "selenium-session-map" .Values.components.sessionMap.nameOverride) $ | trunc 63 | trimSuffix "-" -}}
{{- tpl (default (printf "%s-selenium-session-map" .Release.Name) .Values.components.sessionMap.nameOverride) $ | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
SessionQueue fullname
*/}}
{{- define "seleniumGrid.sessionQueue.fullname" -}}
{{- tpl (default "selenium-session-queue" .Values.components.sessionQueue.nameOverride) $ | trunc 63 | trimSuffix "-" -}}
{{- tpl (default (printf "%s-selenium-session-queue" .Release.Name) .Values.components.sessionQueue.nameOverride) $ | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Chrome node fullname
*/}}
{{- define "seleniumGrid.chromeNode.fullname" -}}
{{- tpl (default "selenium-chrome-node" .Values.chromeNode.nameOverride) $ | trunc 63 | trimSuffix "-" -}}
{{- tpl (default (printf "%s-selenium-chrome-node" .Release.Name) .Values.chromeNode.nameOverride) $ | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Firefox node fullname
*/}}
{{- define "seleniumGrid.firefoxNode.fullname" -}}
{{- tpl (default "selenium-firefox-node" .Values.firefoxNode.nameOverride) $ | trunc 63 | trimSuffix "-" -}}
{{- tpl (default (printf "%s-selenium-firefox-node" .Release.Name) .Values.firefoxNode.nameOverride) $ | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Edge node fullname
*/}}
{{- define "seleniumGrid.edgeNode.fullname" -}}
{{- tpl (default "selenium-edge-node" .Values.edgeNode.nameOverride) $ | trunc 63 | trimSuffix "-" -}}
{{- tpl (default (printf "%s-selenium-edge-node" .Release.Name) .Values.edgeNode.nameOverride) $ | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Ingress fullname
*/}}
{{- define "seleniumGrid.ingress.fullname" -}}
{{- tpl (default "selenium-ingress" .Values.ingress.nameOverride) $ | trunc 63 | trimSuffix "-" -}}
{{- tpl (default (printf "%s-selenium-ingress" .Release.Name) .Values.ingress.nameOverride) $ | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Expand Down Expand Up @@ -170,7 +170,7 @@ Get probe settings
Secret TLS fullname
*/}}
{{- define "seleniumGrid.tls.fullname" -}}
{{- ( tpl (default "selenium-tls-secret" .Values.tls.nameOverride) $ )| trunc 63 | trimSuffix "-" -}}
{{- ( tpl (default (printf "%s-selenium-tls-secret" .Release.Name) .Values.tls.nameOverride) $ )| trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Expand All @@ -197,7 +197,7 @@ Get default certificate file name in chart
Common secrets cross components
*/}}
{{- define "seleniumGrid.common.secrets" -}}
{{- tpl (default "selenium-secrets" .Values.secrets.nameOverride) $ | trunc 63 | trimSuffix "-" -}}
{{- tpl (default (printf "%s-selenium-secrets" .Release.Name) .Values.secrets.nameOverride) $ | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{- define "seleniumGrid.ingress.nginx.annotations.default" -}}
Expand Down Expand Up @@ -231,21 +231,21 @@ nginx.ingress.kubernetes.io/backend-protocol: "HTTPS"
Service Account fullname
*/}}
{{- define "seleniumGrid.serviceAccount.fullname" -}}
{{- tpl (.Values.serviceAccount.name | default "selenium-serviceaccount") $ | trunc 63 | trimSuffix "-" -}}
{{- tpl (.Values.serviceAccount.name | default (printf "%s-selenium-serviceaccount" .Release.Name)) $ | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Recorder ConfigMap fullname
*/}}
{{- define "seleniumGrid.recorder.fullname" -}}
{{- tpl (default "selenium-recorder-config" .Values.recorderConfigMap.name) $ | trunc 63 | trimSuffix "-" -}}
{{- tpl (default (printf "%s-selenium-recorder-config" .Release.Name) .Values.recorderConfigMap.name) $ | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Uploader ConfigMap fullname
*/}}
{{- define "seleniumGrid.uploader.fullname" -}}
{{- tpl (default "selenium-uploader-config" .Values.uploaderConfigMap.name) $ | trunc 63 | trimSuffix "-" -}}
{{- tpl (default (printf "%s-selenium-uploader-config" .Release.Name) .Values.uploaderConfigMap.name) $ | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Expand Down
12 changes: 6 additions & 6 deletions charts/selenium-grid/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,13 @@ ingress:
# ConfigMap that contains SE_EVENT_BUS_HOST, SE_EVENT_BUS_PUBLISH_PORT and SE_EVENT_BUS_SUBSCRIBE_PORT variables
busConfigMap:
# Name of the configmap
name: selenium-event-bus-config
name: "{{ .Release.Name }}-selenium-event-bus-config"
# Custom annotations for configmap
annotations: {}

# ConfigMap that contains common environment variables for browser nodes
nodeConfigMap:
name: selenium-node-config
name: "{{ .Release.Name }}-selenium-node-config"
# Default mode for ConfigMap is mounted as file
defaultMode: 0755
# File name of preStop script in ConfigMap
Expand All @@ -111,7 +111,7 @@ nodeConfigMap:
annotations: {}

recorderConfigMap:
name: selenium-recorder-config
name: "{{ .Release.Name }}-selenium-recorder-config"
# Default mode for ConfigMap is mounted as file
defaultMode: 0755
# Directory where the extra scripts are mounted to
Expand All @@ -127,7 +127,7 @@ recorderConfigMap:
annotations: {}

uploaderConfigMap:
name: selenium-uploader-config
name: "{{ .Release.Name }}-selenium-uploader-config"
# Default mode for ConfigMap is mounted as file
defaultMode: 0755
# Directory where the extra scripts are mounted to
Expand All @@ -148,13 +148,13 @@ uploaderConfigMap:

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

# ConfigMap that contains common environment variables for Server (https://www.selenium.dev/documentation/grid/configuration/cli_options/#server)
serverConfigMap:
name: selenium-server-config
name: "{{ .Release.Name }}-selenium-server-config"
certVolumeMountPath: /etc/ssl/certs/selenium
certificateFile: selenium.pem
privateKeyFile: selenium.pkcs8
Expand Down
2 changes: 1 addition & 1 deletion tests/charts/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ helm template dummy --values tests/charts/templates/render/dummy.yaml \
--set-file 'uploaderConfigMap.secretFiles.upload\.conf=tests/charts/templates/render/dummy_external.sh' \
charts/selenium-grid > ./tests/tests/dummy_template_manifests.yaml

python tests/charts/templates/test.py "./tests/tests/dummy_template_manifests.yaml"
python tests/charts/templates/test.py "./tests/tests/dummy_template_manifests.yaml" dummy
ret_code=$?

if [ "${CI:-false}" = "false" ]; then
Expand Down
37 changes: 26 additions & 11 deletions tests/charts/templates/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,14 @@ def load_template(yaml_file):

class ChartTemplateTests(unittest.TestCase):
def test_set_affinity(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']
resources_name = ['{0}-selenium-chrome-node'.format(RELEASE_NAME),
'{0}-selenium-distributor'.format(RELEASE_NAME),
'{0}-selenium-edge-node'.format(RELEASE_NAME),
'{0}-selenium-firefox-node'.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)]
count = 0
logger.info(f"Assert affinity is set in global and nodes")
for doc in LIST_OF_DOCUMENTS:
Expand All @@ -29,7 +35,7 @@ def test_set_affinity(self):
self.assertEqual(count, len(resources_name), "Not all resources have affinity set")

def test_ingress_nginx_annotations(self):
resources_name = ['selenium-ingress']
resources_name = ['{0}-selenium-ingress'.format(RELEASE_NAME)]
count = 0
for doc in LIST_OF_DOCUMENTS:
if doc['metadata']['name'] in resources_name and doc['kind'] == 'Ingress':
Expand All @@ -46,7 +52,7 @@ def test_ingress_nginx_annotations(self):
self.assertEqual(count, len(resources_name), "No ingress resources found")

def test_sub_path_append_to_node_grid_url(self):
resources_name = ['selenium-node-config']
resources_name = ['{0}-selenium-node-config'.format(RELEASE_NAME)]
count = 0
for doc in LIST_OF_DOCUMENTS:
if doc['metadata']['name'] in resources_name and doc['kind'] == 'ConfigMap':
Expand All @@ -56,7 +62,7 @@ def test_sub_path_append_to_node_grid_url(self):
self.assertEqual(count, len(resources_name), "No node config resources found")

def test_sub_path_set_to_grid_env_var(self):
resources_name = ['selenium-router']
resources_name = ['{0}-selenium-router'.format(RELEASE_NAME)]
is_present = False
for doc in LIST_OF_DOCUMENTS:
if doc['metadata']['name'] in resources_name and doc['kind'] == 'Deployment':
Expand All @@ -68,7 +74,7 @@ def test_sub_path_set_to_grid_env_var(self):
self.assertTrue(is_present, "ENV variable SE_SUB_PATH is not populated")

def test_disable_ui_set_to_grid_env_var(self):
resources_name = ['selenium-router']
resources_name = ['{0}-selenium-router'.format(RELEASE_NAME)]
is_present = False
for doc in LIST_OF_DOCUMENTS:
if doc['metadata']['name'] in resources_name and doc['kind'] == 'Deployment':
Expand All @@ -80,12 +86,18 @@ def test_disable_ui_set_to_grid_env_var(self):
self.assertTrue(is_present, "ENV variable SE_DISABLE_UI 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']
resources_name = ['{0}-selenium-chrome-node'.format(RELEASE_NAME),
'{0}-selenium-distributor'.format(RELEASE_NAME),
'{0}-selenium-edge-node'.format(RELEASE_NAME),
'{0}-selenium-firefox-node'.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)]
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':
if doc['metadata']['name'] == '{0}-selenium-logging-config'.format(RELEASE_NAME) and doc['kind'] == 'ConfigMap':
self.assertTrue(doc['data']['SE_LOG_LEVEL'] == 'FINE')
count_config += 1
self.assertEqual(count_config, 1, "No logging ConfigMap found")
Expand All @@ -97,14 +109,16 @@ def test_log_level_set_to_logging_config_map(self):
list_env_from = doc['spec']['template']['spec']['containers'][0]['envFrom']
for env in list_env_from:
if env.get('configMapRef') is not None:
if env['configMapRef']['name'] == 'selenium-logging-config':
if env['configMapRef']['name'] == '{0}-selenium-logging-config'.format(RELEASE_NAME):
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")

def test_node_port_set_when_service_type_is_node_port(self):
single_node_port = {'selenium-distributor': 30553, 'selenium-router': 30444, 'selenium-session-queue': 30559}
single_node_port = {'{0}-selenium-distributor'.format(RELEASE_NAME): 30553,
'{0}-selenium-router'.format(RELEASE_NAME): 30444,
'{0}-selenium-session-queue'.format(RELEASE_NAME): 30559}
count = 0
logger.info(f"Assert NodePort is set to components service")
for doc in LIST_OF_DOCUMENTS:
Expand All @@ -118,6 +132,7 @@ def test_node_port_set_when_service_type_is_node_port(self):
failed = False
try:
FILE_NAME = sys.argv[1]
RELEASE_NAME = sys.argv[2]
LIST_OF_DOCUMENTS = load_template(FILE_NAME)
suite = unittest.TestLoader().loadTestsFromTestCase(ChartTemplateTests)
test_runner = unittest.TextTestRunner(verbosity=3)
Expand Down

0 comments on commit 646e5c5

Please sign in to comment.