Skip to content

Commit

Permalink
test(chart): test extra scripts import when import as sub-chart
Browse files Browse the repository at this point in the history
[deploy]

Signed-off-by: Viet Nguyen Duc <[email protected]>
  • Loading branch information
VietND96 committed Feb 24, 2024
1 parent 7662ace commit 99c6c72
Show file tree
Hide file tree
Showing 11 changed files with 225 additions and 11 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/helm-chart-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ jobs:
- name: Checkout
uses: actions/checkout@main
with:
persist-credentials: false
fetch-depth: 0

- name: Configure Git
Expand All @@ -28,6 +29,18 @@ jobs:
- name: Get chart release notes (chart_release_notes.md)
run: ./generate_chart_changelog.sh HEAD

- name: Commit files
run: |
git config --local user.email "[email protected]"
git config --local user.name "Selenium CI Bot"
git commit -m "Update tag in docs and files" -a
- name: Push changes
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.SELENIUM_CI_TOKEN }}
branch: trunk

- name: Run chart-releaser
uses: helm/chart-releaser-action@main
with:
Expand Down
5 changes: 2 additions & 3 deletions charts/selenium-grid/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,12 +225,11 @@ By default, ingress is enabled without annotations set. If NGINX ingress control

To make the user experience better, there are few annotations will be set by default if NGINX ingress controller is used. Mostly relates to timeouts and buffer sizes.

If you are not using NGINX ingress controller, you can disable these default annotations by setting `ingress.nginx` to `nil` (aka null) via Helm CLI `--set ingress.nginx=null`) or via an override-values.yaml as below:
If you are not using NGINX ingress controller, you can disable these default annotations by setting `ingress.nginx` to `nil` (aka null) via Helm CLI `--set ingress.nginx=!`) or via an override-values.yaml as below:

```yaml
ingress:
nginx:
# nginx: null (alternative way)
nginx: !
```

Similarly, if you want to disable a sub-config of `ingress.nginx`. For example: `--set ingress.nginx.proxyBuffer=null`)
Expand Down
30 changes: 23 additions & 7 deletions tests/charts/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,33 @@ python -m pip install pyyaml==6.0.1 \
| grep -v 'Requirement already satisfied'

cd ..

helm template dummy --values tests/charts/templates/render/dummy.yaml \
--set-file 'nodeConfigMap.extraScripts.nodePreStop\.sh=tests/charts/templates/render/dummy_external.sh' \
--set-file 'recorderConfigMap.extraScripts.video\.sh=tests/charts/templates/render/dummy_external.sh' \
--set-file 'recorderConfigMap.extraScripts.video_graphQLQuery\.sh=tests/charts/templates/render/dummy_external.sh' \
--set-file 'recorderConfigMap.extraScripts.newInsertScript\.sh=tests/charts/templates/render/dummy_external.sh' \
--set-file 'uploaderConfigMap.extraScripts.upload\.sh=tests/charts/templates/render/dummy_external.sh' \
--set-file 'uploaderConfigMap.secretFiles.upload\.conf=tests/charts/templates/render/dummy_external.sh' \
--set-file 'nodeConfigMap.extraScripts.setFromCommand\.sh=tests/charts/templates/render/dummy_external.sh' \
--set-file 'recorderConfigMap.extraScripts.setFromCommand\.sh=tests/charts/templates/render/dummy_external.sh' \
--set-file 'uploaderConfigMap.extraScripts.setFromCommand\.sh=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" dummy
ret_code=$?
if [ $? -ne 0 ]; then
echo "Failed to validate the chart"
exit 1
fi

helm dependency update tests/charts/umbrella-charts
helm dependency build tests/charts/umbrella-charts

helm template dummy --values tests/charts/templates/render/dummy_solution.yaml \
--set-file 'selenium-grid.nodeConfigMap.extraScripts.setFromCommand\.sh=tests/charts/templates/render/dummy_external.sh' \
--set-file 'selenium-grid.recorderConfigMap.extraScripts.setFromCommand\.sh=tests/charts/templates/render/dummy_external.sh' \
--set-file 'selenium-grid.uploaderConfigMap.extraScripts.setFromCommand\.sh=tests/charts/templates/render/dummy_external.sh' \
tests/charts/umbrella-charts > ./tests/tests/dummy_solution_template_manifests.yaml

python tests/charts/templates/test.py "./tests/tests/dummy_solution_template_manifests.yaml" dummy
if [ $? -ne 0 ]; then
echo "Failed to validate the umbrella chart"
exit 1
fi

if [ "${CI:-false}" = "false" ]; then
deactivate
Expand Down
21 changes: 20 additions & 1 deletion tests/charts/templates/render/dummy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ ingress:
proxyTimeout: 360 # Set different proxy timout
proxyBuffer:
# size: 512M # Keep using sub-config default
number: # Disable sub-config
number: ! # Disable sub-config
annotations: # Add you own annotations
nginx.ingress.kubernetes.io/use-regex: "true" # Add new key
nginx.ingress.kubernetes.io/rewrite-target: /$2
Expand Down Expand Up @@ -87,6 +87,7 @@ videoRecorder:
enabled: true
uploader:
enabled: true
name: s3
destinationPrefix: "s3://bucket-name"
secrets:
RCLONE_CONFIG_S3_TYPE: "s3"
Expand All @@ -97,3 +98,21 @@ videoRecorder:
RCLONE_CONFIG_S3_ACL: "private"
RCLONE_CONFIG_S3_ACCESS_KEY_ID: "xxx"
RCLONE_CONFIG_S3_SECRET_ACCESS_KEY: "xxx"

nodeConfigMap:
extraScripts:
nodeCustomTask.sh: |
#!/bin/bash
echo "This is a custom task"
recorderConfigMap:
extraScripts:
video.sh: |
#!/bin/bash
echo "This is override script"
uploaderConfigMap:
extraScripts:
upload.sh: |
#!/bin/bash
echo "This is override script"
118 changes: 118 additions & 0 deletions tests/charts/templates/render/dummy_solution.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
# This is dummy values file for chart template testing
global:
K8S_PUBLIC_IP: "10.10.10.10"
seleniumGrid:
logLevel: FINE
affinity: &affinity
podAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: app
operator: In
values:
- selenium
topologyKey: "kubernetes.io/hostname"

selenium-grid:
autoscaling:
enableWithExistingKEDA: true
scalingType: deployment

basicAuth:
username: sysadmin
password: strongPassword

tls:
enabled: true
generateTLS: false

ingress:
nginx:
proxyTimeout: 360 # Set different proxy timout
proxyBuffer:
# size: 512M # Keep using sub-config default
number: ! # Disable sub-config
annotations: # Add you own annotations
nginx.ingress.kubernetes.io/use-regex: "true" # Add new key
nginx.ingress.kubernetes.io/rewrite-target: /$2
nginx.ingress.kubernetes.io/app-root: &gridAppRoot "/selenium"
nginx.ingress.kubernetes.io/proxy-connect-timeout: "3600" # Override default key
nginx.ingress.kubernetes.io/proxy-send-timeout: "3600" # Override default key
hostname: ""
ports:
http: 8081
https: 8443
paths:
- path: /selenium(/|$)(.*)
pathType: ImplementationSpecific
backend:
service:
name: '{{ ternary (include "seleniumGrid.router.fullname" $ ) (include "seleniumGrid.hub.fullname" $ ) $.Values.isolateComponents }}'
port:
number: 4444
- path: /(/?)(session/.*/se/vnc)
pathType: ImplementationSpecific
backend:
service:
name: '{{ ternary (include "seleniumGrid.router.fullname" $ ) (include "seleniumGrid.hub.fullname" $ ) $.Values.isolateComponents }}'
port:
number: 4444

isolateComponents: true

components:
subPath: *gridAppRoot
disableUI: true
router:
serviceType: NodePort
distributor:
serviceType: NodePort
eventBus:
serviceType: NodePort
sessionQueue:
serviceType: NodePort
sessionMap:
serviceType: NodePort

chromeNode:
affinity: *affinity

firefoxNode:
affinity: *affinity

edgeNode:
affinity: *affinity

videoRecorder:
enabled: true
uploader:
enabled: true
destinationPrefix: "s3://bucket-name"
secrets:
RCLONE_CONFIG_S3_TYPE: "s3"
RCLONE_CONFIG_S3_PROVIDER: "AWS"
RCLONE_CONFIG_S3_ENV_AUTH: "true"
RCLONE_CONFIG_S3_REGION: "ap-southeast-1"
RCLONE_CONFIG_S3_LOCATION_CONSTRAINT: "ap-southeast-1"
RCLONE_CONFIG_S3_ACL: "private"
RCLONE_CONFIG_S3_ACCESS_KEY_ID: "xxx"
RCLONE_CONFIG_S3_SECRET_ACCESS_KEY: "xxx"

nodeConfigMap:
extraScripts:
nodeCustomTask.sh: |
#!/bin/bash
echo "This is a custom task"
recorderConfigMap:
extraScripts:
video.sh: |
#!/bin/bash
echo "This is override script"
uploaderConfigMap:
extraScripts:
upload.sh: |
#!/bin/bash
echo "This is override script"
35 changes: 35 additions & 0 deletions tests/charts/templates/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,41 @@ def test_all_metadata_name_is_prefixed_with_release_name(self):
self.assertTrue(doc['metadata']['name'].startswith(RELEASE_NAME),
f"Metadata name {doc['metadata']['name']} is not prefixed with RELEASE NAME: {RELEASE_NAME}")

def test_extra_script_import_to_node_configmap(self):
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':
logger.info(f"Assert default file is imported to Node ConfigMap")
self.assertTrue(doc['data']['nodeProbe.sh'] is not None)
self.assertTrue(doc['data']['nodePreStop.sh'] is not None)
self.assertTrue(doc['data']['nodeCustomTask.sh'] is not None)
self.assertTrue(doc['data']['setFromCommand.sh'] is not None)
count += 1
self.assertEqual(count, len(resources_name), "No node config resources found")

def test_extra_script_import_to_uploader_configmap(self):
resources_name = ['{0}-selenium-uploader-config'.format(RELEASE_NAME)]
count = 0
for doc in LIST_OF_DOCUMENTS:
if doc['metadata']['name'] in resources_name and doc['kind'] == 'ConfigMap':
logger.info(f"Assert extra script is imported to Uploader ConfigMap")
self.assertTrue(doc['data']['upload.sh'] is not None)
self.assertTrue(doc['data']['setFromCommand.sh'] is not None)
count += 1
self.assertEqual(count, len(resources_name), "No uploader config resources found")

def test_extra_script_import_to_recorder_configmap(self):
resources_name = ['{0}-selenium-recorder-config'.format(RELEASE_NAME)]
count = 0
for doc in LIST_OF_DOCUMENTS:
if doc['metadata']['name'] in resources_name and doc['kind'] == 'ConfigMap':
logger.info(f"Assert extra script is imported to Recorder ConfigMap")
self.assertTrue(doc['data']['video.sh'] is not None)
self.assertTrue(doc['data']['setFromCommand.sh'] is not None)
count += 1
self.assertEqual(count, len(resources_name), "No recorder config resources found")

if __name__ == '__main__':
failed = False
try:
Expand Down
2 changes: 2 additions & 0 deletions tests/charts/umbrella-charts/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
charts
Chart.lock
2 changes: 2 additions & 0 deletions tests/charts/umbrella-charts/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.git/
.gitignore
10 changes: 10 additions & 0 deletions tests/charts/umbrella-charts/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: v2
name: umbrella-charts
description: A Helm chart for Umbrella Chart Test
type: application
version: 0.0.1
appVersion: "1.0.0"
dependencies:
- name: selenium-grid
version: 0.28.1
repository: file://../../../charts/selenium-grid
Empty file.
Empty file.

0 comments on commit 99c6c72

Please sign in to comment.