Skip to content

Commit

Permalink
@ teracyhq#2 | Create zalenium helm-chart
Browse files Browse the repository at this point in the history
  • Loading branch information
hieptranquoc committed Oct 15, 2018
1 parent b28b7da commit f723251
Show file tree
Hide file tree
Showing 16 changed files with 708 additions and 0 deletions.
6 changes: 6 additions & 0 deletions incubator/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.DS_Store
.idea

!.gitkeep

.vscode
24 changes: 24 additions & 0 deletions incubator/zalenium/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*~
# Various IDEs
.project
.idea/
*.tmproj

# OWNERS file for Kubernetes
OWNERS
11 changes: 11 additions & 0 deletions incubator/zalenium/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: zalenium
apiVersion: v1
appVersion: 3.14.0
version: 0.1.0
description: zalenium helm chart for selenium grid
home: https://opensource.zalando.com/zalenium
sources:
- https://github.com/teracyhq/helm-charts
maintainers:
- name: hieptq
email: [email protected]
5 changes: 5 additions & 0 deletions incubator/zalenium/OWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
approvers:
- hieptq
reviewers:
- hoatle
- teracy
125 changes: 125 additions & 0 deletions incubator/zalenium/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
# ZALENIUM-HELM-CHART

## Introduction

This chart bootstraps a zalenium deployment on a kubernetes cluster using the [Helm](https://helm.sh) package manager.

## Prerequisites

- `vagrant` https://www.vagrantup.com/docs/installation/.
- `virtualbox` https://www.virtualbox.org/wiki/Downloads.
- `teracy-dev` v0.6.0-a4+. Fork repo https://github.com/teracyhq/dev and its extensions in https://github.com/teracyhq-incubator to set up `teracy-dev`.
- `helm` v2.10.0+. Default installed in teracy-dev.
- Follow the docs on https://github.com/teracyhq-incubator/teracy-dev-entry-k8s to set up a local k8s cluster.

## How to get it works

### Setup `zalenium` from the scratch

- Installing the chart

To install the chart with the release name `example-name`:

```console
$ helm install --name example-name teracy-incubator/zalenium
```

The command deploys Zalenium on the Kubernetes cluster in the default configuration. The [configuration](#configuration) section lists the parameters that can be configured during installation.

> **Tip**: List all releases using `helm list`
- Uninstalling the chart

To uninstall/delete the `example-name` deployment:

```console
$ helm delete example-name --purge
```

The command removes all the Kubernetes components associated with the chart and deletes the release.

- Configuration

The following tables lists the configurable parameters of the Selenium chart and their default values.

| Parameter | Description | Default |
| --------- | ----------- | ------- |
| `rbac.create` | If your cluster has RBAC enabled, set rbac.create to true | false |
| `rbac.clusterWideAccess` | Set true to use ClusterRole and ClusterRoleBinding instead of Role and RoleBinding | true |
| `serviceAccount.create` | Set serviceAccount.create to true if you want to create an service account for zalenium | true |
| `serviceAccount.name` | Set serviceAccount.name | zalenium |
| `hub.image.repository` | The zalenium hub image | `dosel/zalenium` |
| `hub.image.tag` | The zalenium hub image tag | `3` |
| `hub.image.pullPolicy` | The pull policy for the hub image | `IfNotPresent` |
| `hub.port` | The port the hub listens on | `4444` |
| `hub.livenessProbe.enabled` | Set hub.livenessProbe.enabled to true if you want to use livenessProbe | true |
| `hub.readinessProbe.enabled` | Set hub.readinessProbe.enabled to true if you want to use readinessProbe | true |
| `hub.javaOpts` | The java options for the selenium hub JVM, default sets the maximum heap size to 400 mb | `-Xmx400m -XX:+UseSerialGC` |
| `hub.localVolumesRoot` | The root directory to store HostPath volumes (e.g. if running in minikube) | `/tmp` |
| `hub.resources` | The resources for the hub container, defaults to minimum half a cpu and maximum 512 mb RAM | `{"limits":{"cpu":".5", "memory":"512Mi"}}` |
| `hub.desiredContainers` | How many pods to launch at start | 2 |
| `hub.maxDockerSeleniumContainers` | Maximum number of Selenium containers to run simultaneously | 10 |
| `hub.sauceLabsEnabled` | Enable SauceLabs | false |
| `hub.browserStackEnabled` | Enable BrowserStack | false |
| `hub.testingBotEnabled` | Enable TestingBot | false |
| `hub.videoRecordingEnabled` | Enable video recording | true |
| `hub.cpuRequest` | CPU requested for browser pods. The hub passes this value to the k8s API | 200m |
| `hub.cpuLimit` | CPU limit for browser pods. The hub passes this value to the k8s API | 400m |
| `hub.memRequest` | Memory requested for browser pods. The hub passes this value to the k8s API | 200Mi |
| `hub.screenWidth` | Screen resolution to use | 1440 |
| `hub.screenHeight` | Screen resolution to use | 900 |
| `hub.timeZone` | Time zone | UTC |
| `hub.seleniumImageName` | The Selenium grid image | `elgalu/selenium` |
| `hub.maxTestSessions` | The number of tests to run on each grid container before killing it and starting a new one | 1 |
| `hub.debugEnabled` | Enables LogLevel.FINE | false |
| `hub.keepOnlyFailedTests` | Keeps only failed tests on the dashboard (you need to send a cookie with the test result) | false |
| `hub.sendAnonymousUsageInfo` | Allows sending anonymous usage info | true |
| `hub.sauceUserName` | Username to log into saucelabs. Use if hub.sauceLabsEnabled set to true | blank |
| `hub.sauceAccessKey` | Access key to log into saucelabs. Use if hub.sauceLabsEnabled set to true | blank |
| `hub.browserStackUser` | Credentials for browserstack. Use if hub.browserStackEnabled set to true | blank |
| `hub.browserStackKey` | Credentials for browserstack. Use if hub.browserStackEnabled set to true | blank |
| `hub.testingBotKey` | Credentials for testingbot. Use if hub.testingBotEnabled set to true | blank |
| `hub.testingBotSecret` | Credentials for testingbot. Use if hub.testingBotEnabled set to true | blank |
| `ingress.enabled` | Set ingress.enabled to true if you want to create an ingress entry for zalenium | false |
| `ingress.hostname` | Set ingress.hostname to which host you want | `#` |
| `services.type` | Set services.type | `ClusterIP` |
| `mountStorage.videos.enabled` | Whether to use a videos mount volume. Set mountStorage.videos.enabled to true | true |
| `mountStorage.data.enabled` | Whether to use a data mount volume. Set mountStorage.data.enabled to true | true |
| `mountStorage.videos.pvcs.enabled` | Whether to use a persistent volume claim for storage. Set mountStorage.videos.pvcs.enabled to true | false |
| `mountStorage.data.pvcs.enabled` | Whether to use a persistent volume claim for storage. Set mountStorage.data.pvcs.enabled to true | false |

Specify each parameter using the `--set key0=value0,key1=value1,key..n=value..n` argument to `helm install`. For example,

```console
$ helm install --name example-name \
--set rbac.create=false \
teracy-incubator/zelenium
```

Alternatively, a YAML file that specifies the values for the above parameters can be provided while installing the chart.

### How to run

- Live Preview

Displaying the live preview.

Go to http://k8s.local:4444/grid/admin/live.

> **Tip**: You can replace k8s.local for the IP/machine name where Zalenium is running.
Auto-refresh, add ?refresh=numberOfSeconds to refresh the view automatically.

E.g. http://k8s.local:4444/grid/admin/live?refresh=20 will refresh the page every 20 seconds.

- Dashboard

Go to http://k8s.local:4444/grid/dashboard.

> **Tip**: You can replace k8s.local for the IP/machine name where Zalenium is running.
Check all the recorded videos and aggregated logs after your tests completed.

Click on Cleanup to remove all videos and logs from the local drive and the dashboard.

> **Tip**: Also reset the dashboard via http://k8s.local:4444/dashboard/cleanup?action=doReset or cleanup via http://k8s.local:4444/dashboard/cleanup?action=doCleanup.
1 change: 1 addition & 0 deletions incubator/zalenium/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Helm chart for zalenium. Enjoy!
34 changes: 34 additions & 0 deletions incubator/zalenium/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define "name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
*/}}
{{- define "fullname" -}}
{{- $name := default .Chart.Name .Values.nameOverride -}}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Create the name of the service account
*/}}
{{- define "serviceAccountName" -}}
{{- if .Values.serviceAccount.create -}}
{{ default (include "name" .) .Values.serviceAccount.name }}
{{- else -}}
{{ default "default" .Values.serviceAccount.name }}
{{- end -}}
{{- end -}}
139 changes: 139 additions & 0 deletions incubator/zalenium/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
{{- $fullName := include "fullname" . -}}
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ $fullName }}
labels:
app: {{ $fullName }}
chart: {{ template "chart" . }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
spec:
replicas: {{ .Values.hub.replicaCount }}
strategy:
type: {{ default "RollingUpdate" .Values.hub.strategyType }}
selector:
matchLabels:
app: {{ $fullName }}
zalenium: {{ .Values.hub.name }}
template:
metadata:
labels:
app: {{ $fullName }}
zalenium: {{ .Values.hub.name }}
{{- with .Values.hub.annotations }}
annotations:
{{ toYaml .Values.hub.annotations | indent 8 }}
{{- end }}
spec:
initContainers:
- name: zalenium-prepare
image: dosel/zalenium:latest
command: ['sh', '-c', 'sudo chown -R seluser:seluser /home/seluser/videos']
volumeMounts:
- name: {{ $fullName }}-videos
mountPath: /home/seluser/videos
serviceAccountName: {{ template "serviceAccountName" . }}
containers:
- name: {{ template "name" . }}-{{ .Values.hub.name }}
image: "{{ .Values.hub.image.repository }}:{{ .Values.hub.image.tag }}"
imagePullPolicy: {{ .Values.hub.image.pullPolicy }}
ports:
- containerPort: {{ .Values.hub.port }}
protocol: TCP
{{- if .Values.hub.livenessProbe.enabled }}
livenessProbe:
httpGet:
path: /grid/console
port: {{ .Values.hub.port }}
initialDelaySeconds: 90
periodSeconds: 5
{{- end }}
{{- if .Values.hub.readinessProbe.enabled }}
readinessProbe:
httpGet:
path: /grid/console
port: {{ .Values.hub.port }}
timeoutSeconds: 1
{{- end }}
resources:
{{ toYaml .Values.hub.resources | indent 12 }}
env:
- name: ZALENIUM_KUBERNETES_CPU_REQUEST
value: {{ .Values.hub.cpuRequest }}
- name: ZALENIUM_KUBERNETES_CPU_LIMIT
value: {{ .Values.hub.cpuLimit }}
- name: ZALENIUM_KUBERNETES_MEMORY_REQUEST
value: {{ .Values.hub.memRequest }}
{{- if eq true .Values.hub.sauceLabsEnabled }}
- name: SAUCE_USERNAME
value: {{ .Values.hub.sauceUserName }}
- name: SAUCE_ACCESS_KEY
value: {{ .Values.hub.sauceAccessKey }}
{{- end }}
{{- if eq true .Values.hub.browserStackEnabled }}
- name: BROWSER_STACK_USER
value: {{ .Values.hub.browserStackUser }}
- name: BROWSER_STACK_KEY
value: {{ .Values.hub.browserStackKey }}
{{- end }}
{{- if eq true .Values.hub.testingBotEnabled }}
- name: TESTINGBOT_KEY
value: {{ .Values.hub.testingBotKey }}
- name: TESTINGBOT_SECRET
value: {{ .Values.hub.testingBotSecret }}
{{- end }}
args:
- start
- '--desiredContainers'
- '{{ .Values.hub.desiredContainers }}'
- '--maxDockerSeleniumContainers'
- '{{ .Values.hub.maxDockerSeleniumContainers }}'
- '--sauceLabsEnabled'
- '{{ .Values.hub.sauceLabsEnabled }}'
- '--browserStackEnabled'
- '{{ .Values.hub.browserStackEnabled }}'
- '--testingBotEnabled'
- '{{ .Values.hub.testingBotEnabled }}'
- '--videoRecordingEnabled'
- '{{ .Values.hub.videoRecordingEnabled }}'
- '--screenWidth'
- '{{ .Values.hub.screenWidth }}'
- '--screenHeight'
- '{{ .Values.hub.screenHeight }}'
- '--timeZone'
- '{{ .Values.hub.timeZone }}'
- '--seleniumImageName'
- '{{ .Values.hub.seleniumImageName }}'
- '--maxTestSessions'
- '{{ .Values.hub.maxTestSessions }}'
- '--debugEnabled'
- '{{ .Values.hub.debugEnabled }}'
- '--sendAnonymousUsageInfo'
- '{{ .Values.hub.sendAnonymousUsageInfo }}'
- '--keepOnlyFailedTests'
- '{{ .Values.hub.keepOnlyFailedTests }}'
volumeMounts:
{{- range $key, $val := .Values.mountStorage }}
{{- if .enabled }}
- name: {{ $fullName }}-{{ $key }}
mountPath: {{ .mountPath }}
{{- end }}
{{- end }}
volumes:
{{- range $key, $val := .Values.mountStorage }}
{{- if .enabled }}
- name: {{ $fullName }}-{{ $key }}
{{- if .pvcs.enabled }}
{{- if and (.pvcs.useExisting) (not (empty .pvcs.name))}}
persistentVolumeClaim:
claimName: {{ .pvcs.name }}
{{- else }}
persistentVolumeClaim:
claimName: {{ $fullName }}-{{ $key }}
{{- end }}
{{- else }}
emptyDir: {}
{{- end }}
{{- end }}
{{- end }}
31 changes: 31 additions & 0 deletions incubator/zalenium/templates/ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{{- if .Values.ingress.enabled -}}
{{- $fullName := include "fullname" . -}}
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: {{ $fullName }}-ingress
labels:
app: {{ template "fullname" . }}
chart: {{ template "chart" . }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
{{- with .Values.ingress.annotations }}
annotations:
{{ toYaml .Values.ingress.annotations | indent 4 }}
{{- end }}
spec:
{{- if .Values.ingress.tls }}
tls:
- hosts:
- {{ .Values.ingress.hostname | quote }}
secretName: {{ .Values.ingress.secretName }}
{{- end }}
rules:
- host: {{ .Values.ingress.hostname }}
http:
paths:
- path: {{ .path }}
backend:
serviceName: {{ template "fullname" . }}
servicePort: {{ .Values.hub.port }}
{{- end }}
Loading

0 comments on commit f723251

Please sign in to comment.