Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(chart): Sanity tests Selenium Grid chart via Makefile commands #2029

Merged
merged 2 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
143 changes: 42 additions & 101 deletions .github/workflows/helm-chart-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,105 +13,46 @@ permissions:
contents: read

jobs:
lint-test:
name: "Lint Tests with ct"
runs-on: ubuntu-latest
build-and-test:
# Skip job based on the commit message, only works in push to branches for now
if: contains(toJson(github.event.commits), '[skip ci]') == false
name: Build & test Docker images with Helm charts
runs-on: ubuntu-20.04
VietND96 marked this conversation as resolved.
Show resolved Hide resolved
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Helm
uses: azure/setup-helm@v3
with:
version: v3.13.2

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10'
check-latest: true

- name: Set up chart-testing
uses: helm/[email protected]

- name: Run chart-testing (list-changed)
id: list-changed
run: |
changed=$(ct list-changed --config tests/chart-test.yaml)
if [[ -n "$changed" ]]; then
echo "{changed}={true}" >> $GITHUB_OUTPUT
fi

- name: Run chart-testing (lint)
run: ct lint --config tests/chart-test.yaml

- name: Create kind cluster
uses: helm/[email protected]
with:
config: ./tests/kind-cluster-config.yaml

- name: Run chart-testing (install)
run: ct install --all --config tests/chart-test.yaml

deploy-grid-selenium-tests:
name: "Run Selenium Tests on K8s"
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
browser: [NodeChrome,NodeEdge,NodeFirefox]
steps:

- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Helm
uses: azure/setup-helm@v3
with:
version: v3.13.2

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10'
check-latest: true

- name: Create kind cluster
uses: helm/[email protected]
with:
config: ./tests/kind-cluster-config.yaml

# 👋 Documentation link for Ingress Installation on kind k8s cluster https://kind.sigs.k8s.io/docs/user/ingress
- name: Install ingress-nginx on kind kubernetes cluster
run: |
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/main/deploy/static/provider/kind/deploy.yaml
kubectl wait --namespace ingress-nginx \
--for=condition=ready pod \
--selector=app.kubernetes.io/component=controller \
--timeout=90s

- name: Deploy Selenium Grid Chart
run: |
helm repo add kedacore https://kedacore.github.io/charts
helm repo update
helm dependency build charts/selenium-grid
helm upgrade --install selenium-grid -f ./tests/override-kind-auth-${{matrix.browser}}-values.yaml charts/selenium-grid --namespace selenium-grid-test --create-namespace
kubectl get ingress --all-namespaces

- name: Verify Post Deployment Grid Health and k8s pods status
run: |
sleep 20 # Allow Kubernetes to pull Docker Images and start Pods
python ./tests/K8sSmokeTest.py "http://localhost"
kubectl get pods -n selenium-grid-test
kubectl get events -n selenium-grid-test

- name: Run Selenium Tests Against Kubernetes
run: |
export SELENIUM_GRID_HOST=localhost
export SELENIUM_GRID_PORT=80
export RUN_IN_DOCKER_COMPOSE=true
./tests/bootstrap.sh ${{matrix.browser}}
- uses: actions/checkout@v4
- name: Output Docker info
run: docker info
- name: Set up Python 3.8
uses: actions/[email protected]
with:
python-version: 3.8
VietND96 marked this conversation as resolved.
Show resolved Hide resolved
- name: Get branch name (only for push to branch)
if: github.event_name == 'push'
run: echo "BRANCH=$(echo ${PUSH_BRANCH##*/})" >> $GITHUB_ENV
env:
PUSH_BRANCH: ${{ github.ref }}
- name: Get target branch name (only for PRs)
if: github.event_name == 'pull_request'
run: echo "BRANCH=$(echo ${TARGET_BRANCH##*/})" >> $GITHUB_ENV
env:
TARGET_BRANCH: ${{ github.head_ref }}
- name: Output branch name
run: echo ${BRANCH}
- name: Sets build date
run: echo "BUILD_DATE=$(date '+%Y%m%d')" >> $GITHUB_ENV
- name: Build Docker images
run: VERSION=${BRANCH} BUILD_DATE=${BUILD_DATE} make build
- name: Setup Kubernetes environment
run: make chart_setup_env
- name: Setup Kubernetes cluster
run: VERSION=${BRANCH} BUILD_DATE=${BUILD_DATE} make chart_cluster_setup
- name: Test Selenium Grid on Kubernetes
uses: nick-invision/[email protected]
with:
timeout_minutes: 20
max_attempts: 3
command: |
VERSION=${BRANCH} BUILD_DATE=${BUILD_DATE} make chart_test
- name: Cleanup Kubernetes cluster
if: always()
run: make chart_cluster_cleanup
28 changes: 27 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
NAME := $(or $(NAME),$(NAME),selenium)
CURRENT_DATE := $(shell date '+%Y%m%d')
BUILD_DATE := $(or $(BUILD_DATE),$(BUILD_DATE),$(CURRENT_DATE))
VERSION := $(or $(VERSION),$(VERSION),4.11.0)
VERSION := $(or $(VERSION),$(VERSION),4.15.0)
TAG_VERSION := $(VERSION)-$(BUILD_DATE)
NAMESPACE := $(or $(NAMESPACE),$(NAMESPACE),$(NAME))
AUTHORS := $(or $(AUTHORS),$(AUTHORS),SeleniumHQ)
Expand Down Expand Up @@ -361,6 +361,32 @@ test_video: video hub chrome firefox edge
docker run -v $$(pwd):$$(pwd) -w $$(pwd) jrottenberg/ffmpeg:6.0-alpine -v error -i ./tests/videos/firefox_video.mp4 -f null - 2>error.log
docker run -v $$(pwd):$$(pwd) -w $$(pwd) jrottenberg/ffmpeg:6.0-alpine -v error -i ./tests/videos/edge_video.mp4 -f null - 2>error.log

chart_setup_env:
./tests/K8s/chart_setup_env.sh

chart_test: chart_lint \
chart_install_chrome \
chart_install_firefox \
chart_install_edge

chart_cluster_setup:
VERSION=$(TAG_VERSION) NAMESPACE=$(NAMESPACE) ./tests/K8s/chart_cluster_setup.sh

chart_lint:
./tests/K8s/chart_lint.sh

chart_install_chrome:
VERSION=$(TAG_VERSION) NAMESPACE=$(NAMESPACE) ./tests/K8s/chart_install.sh NodeChrome

chart_install_firefox:
VERSION=$(TAG_VERSION) NAMESPACE=$(NAMESPACE) ./tests/K8s/chart_install.sh NodeFirefox

chart_install_edge:
VERSION=$(TAG_VERSION) NAMESPACE=$(NAMESPACE) ./tests/K8s/chart_install.sh NodeEdge

chart_cluster_cleanup:
./tests/K8s/chart_cluster_cleanup.sh

.PHONY: \
all \
base \
Expand Down
44 changes: 44 additions & 0 deletions charts/selenium-grid/TESTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Testing Selenium Grid Helm Chart

All related testing to this helm chart will be documented in this file.

## Test Traceability Matrix

| Features | TC Description | Coverage |
|------------------------|----------------------------------------------------------------------|----------|
| Basic Auth | Basic Auth is disabled | ✓ |
| | Basic Auth is enabled | ✗ |
| Auto scaling | Auto scaling with `enableWithExistingKEDA` is `true` | ✓ |
| | Auto scaling with `scalingType` is `job` | ✓ |
| | Auto scaling with `scalingType` is `deployment` | ✗ |
| | Auto scaling with `autoscaling.scaledOptions.minReplicaCount` is `0` | ✓ |
| Ingress | Ingress is enabled without `hostname` | ✓ |
| | Hub `sub-path` is set with Ingress `ImplementationSpecific` paths | ✓ |
| Distributed components | `isolateComponents` is enabled | ✓ |
| Browser Nodes | Node `nameOverride` is set | ✓ |
| | Sanity tests in node | ✓ |
| | Video recorder is enabled in node | ✗ |

## Build & test Docker images with Helm charts
Noted: These `make` commands are composed and tested on Linux x86_64.
Run entire commands to build and test Docker images with Helm charts in local environment.

```bash
# Back to root directory
cd ../..

# Build Docker images
make build

# Setup Kubernetes environment
make chart_setup_env

# Setup Kubernetes cluster
make chart_cluster_setup

# Test Selenium Grid on Kubernetes
make chart_test

# Cleanup Kubernetes cluster
make chart_cluster_cleanup
```
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
# This is used in Helm chart testing. This disables the basic auth on seleneium grid
# Basic auth settings for Selenium Grid
basicAuth:
# Enable or disable basic auth
enabled: false
# This is used in Helm chart testing. This disables the basic auth on selenium grid
# Configuration for chrome nodes
chromeNode:
# Enable chrome nodes
nameOverride: my-chrome-name
# Configuration for edge nodes
edgeNode:
enabled: false
# Configuration for firefox nodes
firefoxNode:
# Enable firefox nodes
enabled: false
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
# This is used in Helm chart testing. This disables the basic auth on seleneium grid
# Basic auth settings for Selenium Grid
basicAuth:
# Enable or disable basic auth
# This is used in Helm chart testing. This disables the basic auth on selenium grid
# Configuration for chrome nodes
chromeNode:
enabled: false
# Configuration for edge nodes
edgeNode:
# Enable edge nodes
enabled: false
nameOverride: my-edge-name
# Configuration for firefox nodes
firefoxNode:
# Enable firefox nodes
enabled: false
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
# This is used in Helm chart testing. This disables the basic auth on seleneium grid
# Basic auth settings for Selenium Grid
basicAuth:
# Enable or disable basic auth
enabled: false
# This is used in Helm chart testing. This disables the basic auth on selenium grid
# Configuration for chrome nodes
chromeNode:
# Enable chrome nodes
enabled: false
enabled: false
# Configuration for edge nodes
edgeNode:
# Enable edge nodes
enabled: false
# Configuration for firefox nodes
firefoxNode:
nameOverride: my-firefox-name
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ ingress:
hostname: ""
paths:
- path: /selenium(/|$)(.*)
pathType: Prefix
pathType: ImplementationSpecific
backend:
service:
name: '{{ template "seleniumGrid.router.fullname" $ }}'
port:
number: 4444
- path: /(/?)(session/.*/se/vnc)
pathType: Prefix
pathType: ImplementationSpecific
backend:
service:
name: '{{ template "seleniumGrid.router.fullname" $ }}'
Expand All @@ -29,24 +29,3 @@ hub:

components:
subPath: *gridAppRoot

chromeNode:
enabled: true
extraEnvironmentVariables:
- name: SE_NODE_OVERRIDE_MAX_SESSIONS
value: "true"
- name: SE_NODE_MAX_SESSIONS
value: "5"
startupProbe:
exec:
command:
- bash
- -c
- if [ $(curl --write-out %{http_code} --silent --output /dev/null http://selenium-router:4444/selenium/wd/hub/status) -ne 200 ]; then exit 1; fi
failureThreshold: 15
periodSeconds: 5

edgeNode:
enabled: false
firefoxNode:
enabled: false
5 changes: 5 additions & 0 deletions charts/selenium-grid/ci/autoscaling-values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
autoscaling:
enableWithExistingKEDA: true
scalingType: job
scaledOptions:
minReplicaCount: 0
9 changes: 0 additions & 9 deletions charts/selenium-grid/ci/overrideNameChrome-values.yaml

This file was deleted.

9 changes: 0 additions & 9 deletions charts/selenium-grid/ci/overrideNameEdge-values.yaml

This file was deleted.

9 changes: 0 additions & 9 deletions charts/selenium-grid/ci/overrideNameFirefox-values.yaml

This file was deleted.

2 changes: 2 additions & 0 deletions tests/chart-test.yaml → tests/K8s/chart-testing.yaml
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# This is config file for chart-testing tool. It is used to test Helm charts.
# https://github.com/helm/chart-testing
target-branch: trunk
chart-dirs:
- charts
Expand Down
11 changes: 11 additions & 0 deletions tests/K8s/chart_cluster_cleanup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

echo "Set ENV variables"
CLUSTER_NAME=${CLUSTER_NAME:-"chart-testing"}

cleanup() {
echo "Clean up kind cluster"
kind delete clusters ${CLUSTER_NAME}
}

cleanup
Loading