Skip to content

Commit

Permalink
feat: Add e2e tests for simple gerrit deployment (#68)
Browse files Browse the repository at this point in the history
* Update GH Actions and add e2e tests
* Do simple deployment, which guaranies no issue with deployment
  and Tekton Tasks/Piplines references

Signed-off-by: Sergiy Kulanov <[email protected]>
Change-Id: I34ef2d3c8090245bb7d91afe8699893b048c02f5
  • Loading branch information
SergK committed Nov 9, 2023
1 parent 75701ac commit 1d233d5
Show file tree
Hide file tree
Showing 15 changed files with 238 additions and 6 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/codecov.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v3
uses: actions/setup-go@v4
with:
go-version: ${{ env.GOLANG_VERSION }}

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codeql.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
Expand Down
59 changes: 59 additions & 0 deletions .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: "Run End-to-end tests"

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

jobs:
e2e-tests:
name: End-to-end tests
runs-on: ubuntu-20.04
strategy:
fail-fast: false
matrix:
# The e2e tests are run on the lowest and highest supported k8s version.
# All Kubernetes version in between expose the same APIs, hence the operator
# should be compatible with them.
kube-version:
- "1.27"

steps:

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: "1.20"

- name: Check out code into the Go module directory
uses: actions/checkout@v4

- name: "install kuttl"
run: ./hack/install-kuttl.sh

- name: "run tests"
env:
KUBE_VERSION: ${{ matrix.kube-version }}
run: make start-kind KUBE_VERSION=$KUBE_VERSION && make e2e

e2e-tests-check:
runs-on: ubuntu-20.04
if: always()
needs: [e2e-tests]
steps:
- name: Print result
run: echo ${{ needs.e2e-tests.result }}
- name: Interpret result
run: |
if [[ success == ${{ needs.e2e-tests.result }} ]]
then
echo "All matrix jobs passed!"
else
echo "One or more matrix jobs failed."
false
fi
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ coverage.out
### Python test
.venv
__pycache__/

kubeconfig
25 changes: 23 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,17 @@ BUILD_DATE=$(shell date -u +'%Y-%m-%dT%H:%M:%SZ')
GIT_COMMIT=$(shell git rev-parse HEAD)
GIT_TAG=$(shell if [ -z "`git status --porcelain`" ]; then git describe --exact-match --tags HEAD 2>/dev/null; fi)
KUBECTL_VERSION=$(shell go list -m all | grep k8s.io/client-go| cut -d' ' -f2)
HOST_OS:=$(shell go env GOOS)
HOST_ARCH:=$(shell go env GOARCH)
HOST_OS?=$(shell go env GOOS)
HOST_ARCH?=$(shell go env GOARCH)

# Use kind cluster for testing
START_KIND_CLUSTER?=true
KIND_CLUSTER_NAME?="tekton"
KUBE_VERSION?=1.27
KIND_CONFIG?=./hack/kind-$(KUBE_VERSION).yaml

E2E_IMAGE_REPOSITORY?="tekton-image"
E2E_IMAGE_TAG?="latest"

override LDFLAGS += \
-X ${PACKAGE}.version=${VERSION} \
Expand Down Expand Up @@ -91,6 +100,12 @@ test-chart: ${CURRENT_DIR}/.venv/bin/activate
${CURRENT_DIR}/.venv/bin/activate:
python3 -m venv ${CURRENT_DIR}/.venv

## Run e2e tests. Requires kind with running cluster and kuttl tool.
e2e: build
docker build --no-cache -t ${E2E_IMAGE_REPOSITORY}:${E2E_IMAGE_TAG} .
kind load --name $(KIND_CLUSTER_NAME) docker-image ${E2E_IMAGE_REPOSITORY}:${E2E_IMAGE_TAG}
E2E_IMAGE_REPOSITORY=${E2E_IMAGE_REPOSITORY} E2E_IMAGE_TAG=${E2E_IMAGE_TAG} kubectl-kuttl test

GOLANGCILINT = ${CURRENT_DIR}/bin/golangci-lint
.PHONY: golangci-lint
golangci-lint: ## Download golangci-lint locally if necessary.
Expand All @@ -110,3 +125,9 @@ GOBIN=$(PROJECT_DIR)/bin go install $(2) ;\
rm -rf $$TMP_DIR ;\
}
endef

.PHONY: start-kind
start-kind: ## Start kind cluster
ifeq (true,$(START_KIND_CLUSTER))
kind create cluster --name $(KIND_CLUSTER_NAME) --config $(KIND_CONFIG)
endif
30 changes: 30 additions & 0 deletions hack/cluster.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
# patch the generated kubeadm config with some extra settings
kubeadmConfigPatches:
- |
apiVersion: kubelet.config.k8s.io/v1beta1
kind: KubeletConfiguration
evictionHard:
nodefs.available: "0%"
# patch it further using a JSON 6902 patch
kubeadmConfigPatchesJSON6902:
- group: kubeadm.k8s.io
version: v1beta3
kind: ClusterConfiguration
patch: |
- op: add
path: /apiServer/certSANs/-
value: my-hostname
# 1 control plane node and 3 workers
nodes:
# the control plane node config
- role: control-plane
image: kindest/node:v1.26.3@sha256:61b92f38dff6ccc29969e7aa154d34e38b89443af1a2c14e6cfbd2df6419c66f
# the three workers
- role: worker
image: kindest/node:v1.26.3@sha256:61b92f38dff6ccc29969e7aa154d34e38b89443af1a2c14e6cfbd2df6419c66f
# - role: worker
# image: kindest/node:v1.26.3@sha256:61b92f38dff6ccc29969e7aa154d34e38b89443af1a2c14e6cfbd2df6419c66f
# - role: worker
# image: kindest/node:v1.26.3@sha256:61b92f38dff6ccc29969e7aa154d34e38b89443af1a2c14e6cfbd2df6419c66f
5 changes: 5 additions & 0 deletions hack/install-kuttl.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

sudo curl -Lo /usr/local/bin/kubectl-kuttl https://github.com/kudobuilder/kuttl/releases/download/v0.15.0/kubectl-kuttl_0.15.0_linux_x86_64
sudo chmod +x /usr/local/bin/kubectl-kuttl
export PATH=$PATH:/usr/local/bin
5 changes: 5 additions & 0 deletions hack/kind-1.27.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
image: kindest/node:v1.27.3@sha256:3966ac761ae0136263ffdb6cfd4db23ef8a83cba8a463690e98317add2c9ba72
6 changes: 6 additions & 0 deletions kuttl-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: kuttl.dev/v1beta1
kind: TestSuite
testDirs:
- ./tests/e2e/
skipClusterDelete: false
timeout: 100
2 changes: 1 addition & 1 deletion sonar-project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ sonar.projectKey=edp-tekton
sonar.projectName=edp-tekton
sonar.go.coverage.reportPaths=coverage.out
sonar.test.inclusions=**/*_test.go
sonar.exclusions=**/charts/**,**/cmd/**
sonar.exclusions=**/charts/**,**/cmd/**,**/tests/**,**/hack/**
43 changes: 43 additions & 0 deletions tests/e2e/gerrit/00-assert.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: cert-manager
namespace: cert-manager
status:
readyReplicas: 1

---
apiVersion: apps/v1
kind: Deployment
metadata:
name: tekton-pipelines-controller
namespace: tekton-pipelines
status:
readyReplicas: 1

---
apiVersion: apps/v1
kind: Deployment
metadata:
name: tekton-pipelines-webhook
namespace: tekton-pipelines
status:
readyReplicas: 1

---
apiVersion: apps/v1
kind: Deployment
metadata:
name: tekton-triggers-controller
namespace: tekton-pipelines
status:
readyReplicas: 1

---
apiVersion: apps/v1
kind: Deployment
metadata:
name: tekton-triggers-webhook
namespace: tekton-pipelines
status:
readyReplicas: 1
23 changes: 23 additions & 0 deletions tests/e2e/gerrit/00-install.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
apiVersion: kuttl.dev/v1beta1
kind: TestStep
commands:
# install EDPComponent CRD first
- command: kubectl apply -f https://raw.githubusercontent.com/epam/edp-component-operator/master/deploy-templates/crds/v1.edp.epam.com_edpcomponents.yaml
namespaced: false
# install GitServer CRD
- command: kubectl apply -f https://raw.githubusercontent.com/epam/edp-codebase-operator/master/deploy-templates/crds/v2.edp.epam.com_gitservers.yaml
namespaced: false
# Install Cert manager which is used by Interceptor
- command: kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.13.2/cert-manager.yaml
namespaced: false
# install Tekton
- command: kubectl create ns tekton-pipelines
namespaced: false
- command: kubectl create ns tekton-pipelines-resolvers
namespaced: false
- command: kubectl apply -f https://storage.googleapis.com/tekton-releases/triggers/latest/release.yaml
namespaced: false
- command: kubectl apply -f https://storage.googleapis.com/tekton-releases/triggers/latest/interceptors.yaml
namespaced: false
- command: kubectl apply -f https://storage.googleapis.com/tekton-releases/pipeline/latest/release.yaml
namespaced: false
22 changes: 22 additions & 0 deletions tests/e2e/gerrit/01-assert.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: edp-tekton-dashboard
status:
readyReplicas: 1

---
apiVersion: apps/v1
kind: Deployment
metadata:
name: edp-tekton-interceptor
status:
readyReplicas: 1

---
apiVersion: apps/v1
kind: Deployment
metadata:
name: el-gerrit-listener
status:
readyReplicas: 1
11 changes: 11 additions & 0 deletions tests/e2e/gerrit/01-install.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: kuttl.dev/v1beta1
kind: TestStep
commands:
- command: |
helm install tekton-e2e ../../../charts/pipelines-library --set interceptor.image.repository=${E2E_IMAGE_REPOSITORY} --set interceptor.image.tag=${E2E_IMAGE_TAG}
--set global.dnsWildCard=example.com
--set global.gitProvider=gerrit
--set global.dockerRegistry.type=harbor
--set global.dockerRegistry.url=harbor.example.com
--replace --wait
namespaced: true
5 changes: 5 additions & 0 deletions tests/e2e/gerrit/99-cleanup.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apiVersion: kuttl.dev/v1beta1
kind: TestStep
commands:
- command: helm uninstall tekton-e2e
namespaced: true

0 comments on commit 1d233d5

Please sign in to comment.