Skip to content

Commit c2a5b66

Browse files
authored
test(chart): Chart template render and assert output (#2043)
Signed-off-by: Viet Nguyen Duc <nguyenducviet4496@gmail.com>
1 parent e5d0aa6 commit c2a5b66

19 files changed

+156
-40
lines changed

Makefile

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -364,30 +364,34 @@ test_video: video hub chrome firefox edge
364364
docker run -v $$(pwd):$$(pwd) -w $$(pwd) $(FFMPEG_BASED_NAME)/ffmpeg:$(FFMPEG_BASED_TAG) -v error -i ./tests/videos/edge_video.mp4 -f null - 2>error.log
365365

366366
chart_setup_env:
367-
./tests/K8s/chart_setup_env.sh
367+
./tests/charts/make/chart_setup_env.sh
368368

369369
chart_test: chart_lint \
370+
chart_test_template \
370371
chart_install_chrome \
371372
chart_install_firefox \
372373
chart_install_edge
373374

375+
chart_test_template:
376+
./tests/charts/bootstrap.sh
377+
374378
chart_cluster_setup:
375-
VERSION=$(TAG_VERSION) NAMESPACE=$(NAMESPACE) ./tests/K8s/chart_cluster_setup.sh
379+
VERSION=$(TAG_VERSION) NAMESPACE=$(NAMESPACE) ./tests/charts/make/chart_cluster_setup.sh
376380

377381
chart_lint:
378-
./tests/K8s/chart_lint.sh
382+
./tests/charts/make/chart_lint.sh
379383

380384
chart_install_chrome:
381-
VERSION=$(TAG_VERSION) NAMESPACE=$(NAMESPACE) ./tests/K8s/chart_install.sh NodeChrome
385+
VERSION=$(TAG_VERSION) NAMESPACE=$(NAMESPACE) ./tests/charts/make/chart_install.sh NodeChrome
382386

383387
chart_install_firefox:
384-
VERSION=$(TAG_VERSION) NAMESPACE=$(NAMESPACE) ./tests/K8s/chart_install.sh NodeFirefox
388+
VERSION=$(TAG_VERSION) NAMESPACE=$(NAMESPACE) ./tests/charts/make/chart_install.sh NodeFirefox
385389

386390
chart_install_edge:
387-
VERSION=$(TAG_VERSION) NAMESPACE=$(NAMESPACE) ./tests/K8s/chart_install.sh NodeEdge
391+
VERSION=$(TAG_VERSION) NAMESPACE=$(NAMESPACE) ./tests/charts/make/chart_install.sh NodeEdge
388392

389393
chart_cluster_cleanup:
390-
./tests/K8s/chart_cluster_cleanup.sh
394+
./tests/charts/make/chart_cluster_cleanup.sh
391395

392396
.PHONY: \
393397
all \

charts/selenium-grid/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ helm install selenium-grid --set ingress.hostname=selenium-grid.k8s.local docker
3636
Selenium Grid has the ability to autoscaling browser nodes up/down based on the pending requests in the
3737
session queue.
3838

39-
To do this [KEDA](https://keda.sh/docs/2.12/scalers/selenium-grid-scaler/) is used. When enabling
39+
To do this [KEDA](https://keda.sh/docs/latest/scalers/selenium-grid-scaler/) is used. When enabling
4040
autoscaling using `autoscaling.enabling` KEDA is installed automatically. To instead use an existing
4141
installation of KEDA you can enable autoscaling with `autoscaling.enableWithExistingKEDA` instead.
4242

4343
KEDA can scale either with
44-
[deployments](https://keda.sh/docs/2.12/concepts/scaling-deployments/#scaling-of-deployments-and-statefulsets)
45-
or [jobs](https://keda.sh/docs/2.12/concepts/scaling-jobs/) and the charts support both types. This
44+
[deployments](https://keda.sh/docs/latest/concepts/scaling-deployments/#scaling-of-deployments-and-statefulsets)
45+
or [jobs](https://keda.sh/docs/latest/concepts/scaling-jobs/) and the charts support both types. This
4646
chart support both modes. It is controlled with `autoscaling.scalingType` that can be set to either
4747
job (default) or deployment.
4848

charts/selenium-grid/TESTING.md

Lines changed: 42 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,46 @@ All related testing to this helm chart will be documented in this file.
44

55
## Test Traceability Matrix
66

7-
| Features | TC Description | Coverage |
8-
|------------------------|----------------------------------------------------------------------|----------|
9-
| Basic Auth | Basic Auth is disabled | &check; |
10-
| | Basic Auth is enabled | &cross; |
11-
| Auto scaling | Auto scaling with `enableWithExistingKEDA` is `true` | &check; |
12-
| | Auto scaling with `scalingType` is `job` | &check; |
13-
| | Auto scaling with `scalingType` is `deployment` | &cross; |
14-
| | Auto scaling with `autoscaling.scaledOptions.minReplicaCount` is `0` | &check; |
15-
| Ingress | Ingress is enabled without `hostname` | &check; |
16-
| | Ingress is enabled with `hostname` is set | &cross; |
17-
| | Hub `sub-path` is set with Ingress `ImplementationSpecific` paths | &check; |
18-
| Distributed components | `isolateComponents` is enabled | &check; |
19-
| | `isolateComponents` is disabled | &cross; |
20-
| Browser Nodes | Node `nameOverride` is set | &check; |
21-
| | Sanity tests in node | &check; |
22-
| | Video recorder is enabled in node | &cross; |
23-
| | Node `extraEnvironmentVariables` is set value | &check; |
24-
| General | Set new image registry via `global.seleniumGrid.imageRegistry` | &check; |
25-
| Tracing | Enable tracing via `SE_ENABLE_TRACING` | &check; |
26-
| | Disable tracing via `SE_ENABLE_TRACING` | &cross; |
27-
28-
## Build & test Docker images with Helm charts
7+
| Features | TC Description | Coverage | Test via |
8+
|------------------------|----------------------------------------------------------------------|----------|----------|
9+
| Basic Auth | Basic Auth is disabled | &check; | Cluster |
10+
| | Basic Auth is enabled | &cross; | |
11+
| Auto scaling | Auto scaling with `enableWithExistingKEDA` is `true` | &check; | Cluster |
12+
| | Auto scaling with `scalingType` is `job` | &check; | Cluster |
13+
| | Auto scaling with `scalingType` is `deployment` | &cross; | |
14+
| | Auto scaling with `autoscaling.scaledOptions.minReplicaCount` is `0` | &check; | Cluster |
15+
| Ingress | Ingress is enabled without `hostname` | &check; | Cluster |
16+
| | Ingress is enabled with `hostname` is set | &cross; | |
17+
| | Hub `sub-path` is set with Ingress `ImplementationSpecific` paths | &check; | Cluster |
18+
| Distributed components | `isolateComponents` is enabled | &check; | Cluster |
19+
| | `isolateComponents` is disabled | &cross; | |
20+
| Browser Nodes | Node `nameOverride` is set | &check; | Cluster |
21+
| | Sanity tests in node | &check; | Cluster |
22+
| | Video recorder is enabled in node | &cross; | |
23+
| | Node `extraEnvironmentVariables` is set value | &check; | Cluster |
24+
| General | Set new image registry via `global.seleniumGrid.imageRegistry` | &check; | Cluster |
25+
| | Components are able to set `.affinity` | &check; | Template |
26+
| Tracing | Enable tracing via `SE_ENABLE_TRACING` | &check; | Cluster |
27+
| | Disable tracing via `SE_ENABLE_TRACING` | &cross; | |
28+
29+
## Test Chart Template
30+
- By using `helm template` command, the chart template is tested without installing it to Kubernetes cluster.
31+
- Templates are rendered and the output as a YAML manifest file. The manifest file is then asserted with [pyyaml](https://pyyaml.org/wiki/PyYAMLDocumentation).
32+
- Set of values are used to render the templates located in [tests/charts/templates/render](../../tests/charts/templates/render).
33+
34+
```bash
35+
# Back to root directory
36+
cd ../..
37+
38+
# Build chart dependencies and lint
39+
make chart_lint
40+
41+
# Test chart template
42+
make chart_test_template
43+
```
44+
- Build chart dependencies and lint requires [Chart Testing `ct`](https://github.com/helm/chart-testing). There is a config file [ct.yaml](../../tests/charts/config/ct.yaml) to configure the chart testing.
45+
46+
## Build & test Docker images with deploy to Kubernetes cluster
2947
Noted: These `make` commands are composed and tested on Linux x86_64.
3048
Run entire commands to build and test Docker images with Helm charts in local environment.
3149

@@ -48,3 +66,5 @@ make chart_test
4866
# Cleanup Kubernetes cluster
4967
make chart_cluster_cleanup
5068
```
69+
- Setup Kubernetes environment requires [Kind](https://kind.sigs.k8s.io/docs/user/quick-start/) and [Kubectl](https://kubernetes.io/docs/tasks/tools/install-kubectl/).
70+
- Set of values are used to deploy the chart to Kubernetes cluster located in [tests/charts/ci](../../tests/charts/ci).

tests/charts/bootstrap.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env bash
2+
mkdir -p tests/tests
3+
cd tests || true
4+
5+
if [ "${CI:-false}" = "false" ]; then
6+
pip3 install virtualenv | grep -v 'Requirement already satisfied'
7+
virtualenv docker-selenium-tests
8+
source docker-selenium-tests/bin/activate
9+
fi
10+
11+
python -m pip install pyyaml==6.0.1 \
12+
| grep -v 'Requirement already satisfied'
13+
14+
cd ..
15+
helm template dummy --values tests/charts/templates/render/dummy.yaml \
16+
charts/selenium-grid > ./tests/tests/output_deployment.yaml
17+
18+
python tests/charts/templates/test.py "./tests/tests/output_deployment.yaml"
19+
ret_code=$?
20+
21+
if [ "${CI:-false}" = "false" ]; then
22+
deactivate
23+
fi
24+
25+
exit $ret_code

charts/selenium-grid/ci/NodeChrome-values.yaml renamed to tests/charts/ci/NodeChrome-values.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# This is used in Helm chart testing. This disables the basic auth on selenium grid
1+
# This is used in Helm chart testing
22
# Configuration for chrome nodes
33
chromeNode:
44
nameOverride: my-chrome-name

charts/selenium-grid/ci/NodeEdge-values.yaml renamed to tests/charts/ci/NodeEdge-values.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# This is used in Helm chart testing. This disables the basic auth on selenium grid
1+
# This is used in Helm chart testing
22
# Configuration for chrome nodes
33
chromeNode:
44
enabled: false

charts/selenium-grid/ci/NodeFirefox-values.yaml renamed to tests/charts/ci/NodeFirefox-values.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# This is used in Helm chart testing. This disables the basic auth on selenium grid
1+
# This is used in Helm chart testing
22
# Configuration for chrome nodes
33
chromeNode:
44
enabled: false

0 commit comments

Comments
 (0)