Skip to content

Commit

Permalink
Merge pull request #170 from vshn/e2e
Browse files Browse the repository at this point in the history
Add e2e test with bats-detik
  • Loading branch information
ccremer authored Dec 3, 2020
2 parents fc8f39d + 74de155 commit d419f07
Show file tree
Hide file tree
Showing 16 changed files with 761 additions and 20 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ jobs:
restore-keys: |
${{ runner.os }}-go-
- name: Run e2e tests
run: make crd e2e_test -e CRD_SPEC_VERSION=${{ matrix.crd-spec-version }} -e KIND_NODE_VERSION=${{ matrix.kind-node-version }} -e KIND_KUBECTL_ARGS=--validate=false
run: make crd install_bats setup_e2e_test e2e_test -e CRD_SPEC_VERSION=${{ matrix.crd-spec-version }} -e KIND_NODE_VERSION=${{ matrix.kind-node-version }} -e KIND_KUBECTL_ARGS=--validate=false
- name: Show e2e debug logs
run: cat e2e/debug/detik/*
image:
runs-on: ubuntu-latest
steps:
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,6 @@ dist/
k8up-crd*.yaml
k8up
testbin/

node_modules/
e2e/debug
__debug_bin
46 changes: 30 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL)

IMG_TAG ?= latest

# Image URL to use all building/pushing image targets
DOCKER_IMG ?= docker.io/vshn/k8up:$(IMG_TAG)
QUAY_IMG ?= quay.io/vshn/k8up:$(IMG_TAG)
BIN_FILENAME ?= k8up

CRD_SPEC_VERSION ?= v1

Expand All @@ -30,8 +28,16 @@ KIND_KUBECONFIG ?= ./testbin/kind-kubeconfig
KIND_NODE_VERSION ?= v1.18.8
KIND_CLUSTER ?= k8up-$(KIND_NODE_VERSION)
KIND_KUBECTL_ARGS ?= --validate=true
KIND_REGISTRY_NAME ?= kind-registry
KIND_REGISTRY_PORT ?= 5000

# Image URL to use all building/pushing image targets
DOCKER_IMG ?= docker.io/vshn/k8up:$(IMG_TAG)
QUAY_IMG ?= quay.io/vshn/k8up:$(IMG_TAG)
E2E_IMG ?= localhost:$(KIND_REGISTRY_PORT)/vshn/k8up:e2e

antora_preview_cmd ?= docker run --rm --publish 35729:35729 --publish 2020:2020 --volume "${PWD}":/preview/antora docker.io/vshn/antora-preview:2.3.4 --style=syn --antora=docs
build_cmd ?= CGO_ENABLED=0 go build -o $(BIN_FILENAME) main.go

# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
Expand Down Expand Up @@ -67,7 +73,7 @@ integration_test: generate fmt vet $(TESTBIN_DIR)

# Build manager binary
build: generate fmt vet
go build -o k8up main.go
$(build_cmd)

dist: generate fmt vet
goreleaser release --snapshot --rm-dist --skip-sign
Expand Down Expand Up @@ -111,9 +117,13 @@ lint: fmt vet
@echo 'Check for uncommitted changes ...'
git diff --exit-code

# Build the binary without running generators
$(BIN_FILENAME):
$(build_cmd)

# Build the docker image
docker-build: build
docker build . -t $(DOCKER_IMG) -t $(QUAY_IMG)
docker-build: $(BIN_FILENAME)
docker build . -t $(DOCKER_IMG) -t $(QUAY_IMG) -t $(E2E_IMG)

# Push the docker image
docker-push:
Expand All @@ -128,17 +138,15 @@ bundle: generate
$(KUSTOMIZE) build config/manifests | operator-sdk generate bundle -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS)
operator-sdk bundle validate ./bundle

# Build the bundle image.
.PHONY: bundle-build
bundle-build:
docker build -f bundle.Dockerfile -t $(BUNDLE_IMG) .

docs-serve:
$(antora_preview_cmd)

e2e_test: export KUBECONFIG = $(KIND_KUBECONFIG)
e2e_test: setup_e2e_test build
@echo "TODO: Add actual e2e tests!"
install_bats:
$(MAKE) -C e2e install_bats

e2e_test: docker-build
docker push $(E2E_IMG)
$(MAKE) -C e2e run_bats -e KUBECONFIG=../$(KIND_KUBECONFIG)

setup_e2e_test: export KUBECONFIG = $(KIND_KUBECONFIG)
setup_e2e_test: $(KIND_BIN)
Expand All @@ -153,11 +161,17 @@ $(KIND_BIN): export KUBECONFIG = $(KIND_KUBECONFIG)
$(KIND_BIN): $(TESTBIN_DIR)
curl -Lo $(KIND_BIN) "https://kind.sigs.k8s.io/dl/v$(KIND_VERSION)/kind-$$(uname)-amd64"
@chmod +x $(KIND_BIN)
$(KIND_BIN) create cluster --name $(KIND_CLUSTER) --image kindest/node:$(KIND_NODE_VERSION)
docker run -d --restart=always -p "$(KIND_REGISTRY_PORT):5000" --name "$(KIND_REGISTRY_NAME)" docker.io/library/registry:2
$(KIND_BIN) create cluster --name $(KIND_CLUSTER) --image kindest/node:$(KIND_NODE_VERSION) --config=e2e/kind-config.yaml
@docker network connect "kind" "$(KIND_REGISTRY_NAME)" || true
@kubectl version
@kubectl cluster-info

clean: export KUBECONFIG = $(KIND_KUBECONFIG)
clean:
$(KIND_BIN) delete cluster --name $(KIND_CLUSTER) || true
rm -r testbin/ dist/ bin/ cover.out k8up || true
docker stop "$(KIND_REGISTRY_NAME)" || true
docker rm "$(KIND_REGISTRY_NAME)" || true
docker rmi "$(E2E_IMG)" || true
rm -r testbin/ dist/ bin/ cover.out $(BIN_FILENAME) || true
$(MAKE) -C e2e clean
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,14 @@ Best is if you have [minio](https://min.io/download) installed somewhere to be a

## Run E2E tests

K8up supports both OpenShift 3.11 clusters and newer Kubernetes clusters 1.16+.
K8up supports both OpenShift 3.11 clusters and newer Kubernetes clusters 1.16+.
However, to support OpenShift 3.11 a legacy CRD definition with `apiextensions.k8s.io/v1beta1` is needed, while K8s 1.22+ only supports `apiextensions.k8s.io/v1`.
You need `node` and `npm` to run the tests, as it runs with [DETIK][detik].

First, setup a local e2e environment
```
make install_bats setup_e2e_test
```

To run e2e tests for newer K8s versions run
```
Expand All @@ -103,7 +109,12 @@ make e2e_test
To test compatibility of k8up with OpenShift 3.11, we can run end-to-end tests as following:
```
make e2e_test -e CRD_SPEC_VERSION=v1beta1 -e KIND_NODE_VERSION=v1.13.12
```
```

To remove the local KIND cluster and other resources, run
```
make clean
```

## Example configurations

Expand All @@ -113,3 +124,4 @@ There are a number of example configurations in [`config/samples`](config/sample
[releases]: https://github.com/vshn/k8up/releases
[license]: https://github.com/vshn/k8up/blob/master/LICENSE
[dockerhub]: https://hub.docker.com/r/vshn/k8up
[detik]: https://github.com/bats-core/bats-detik
14 changes: 14 additions & 0 deletions e2e/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

# Set Shell to bash, otherwise some targets fail with dash/zsh etc.
SHELL := /bin/bash

install_bats:
@npm install

run_bats: export KUBECONFIG = $(KIND_KUBECONFIG)
run_bats:
@mkdir debug || true
@node_modules/.bin/bats .

clean:
rm -r debug node_modules || true
6 changes: 6 additions & 0 deletions e2e/kind-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: kind.x-k8s.io/v1alpha4
kind: Cluster
containerdConfigPatches:
- |-
[plugins."io.containerd.grpc.v1.cri".registry.mirrors."localhost:5000"]
endpoint = ["http://kind-registry:5000"]
Loading

0 comments on commit d419f07

Please sign in to comment.