Skip to content

Commit

Permalink
test: implement e2e tests (#64)
Browse files Browse the repository at this point in the history
* test: implement e2e tests

Signed-off-by: Philipp Plotnikov <[email protected]>

* docs: add information about e2e tests in CONTRIBUTING.md

Signed-off-by: Philipp Plotnikov <[email protected]>

* refactor: code linting

Signed-off-by: Philipp Plotnikov <[email protected]>

* refactor: make more stable getMatchHeaderBasedHTTPRouteFetcher; add ability to run specific e2e test; up the timeout constants; set general timeout for process running e2e tests

Signed-off-by: Philipp Plotnikov <[email protected]>

* refactor: up long period to 10 seconds

Signed-off-by: Philipp Plotnikov <[email protected]>

* fix: set concrete traefik chart version

Signed-off-by: Philipp Plotnikov <[email protected]>

* refactor: replace several spaces with tab

Signed-off-by: Philipp Plotnikov <[email protected]>

* refactor: improve make run-e2e-tests command

Signed-off-by: Philipp Plotnikov <[email protected]>

---------

Signed-off-by: Philipp Plotnikov <[email protected]>
  • Loading branch information
Philipp-Plotnikov authored Jul 26, 2024
1 parent 80fd3f5 commit 182280f
Show file tree
Hide file tree
Showing 24 changed files with 1,269 additions and 56 deletions.
39 changes: 30 additions & 9 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,23 @@ env:
GOLANG_VERSION: '1.22'

jobs:
linting:
name: Go code linting
runs-on: ubuntu-latest
steps:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: ${{ env.GOLANG_VERSION }}

- name: Checkout code
uses: actions/[email protected]

- name: Run golangci-lint
uses: golangci/golangci-lint-action@v3
with:
args: --verbose --timeout 6m

unit-tests:
name: Unit tests running
runs-on: ubuntu-latest
Expand All @@ -24,26 +41,30 @@ jobs:

- name: Unit tests running
run: |
go test -v ./...
make unit-tests
linting:
name: Go code linting
e2e-tests:
name: E2E tests running
runs-on: ubuntu-latest
steps:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: ${{ env.GOLANG_VERSION }}

- name: Set up Kind
uses: engineerd/[email protected]
with:
version: "v0.23.0"
skipClusterCreation: true

- name: Checkout code
uses: actions/[email protected]

- name: Run golangci-lint
uses: golangci/golangci-lint-action@v3
with:
args: --verbose --timeout 6m

- name: E2E tests running
run: |
make e2e-tests
build:
name: Build creation
runs-on: ubuntu-latest
Expand Down
70 changes: 59 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,16 +1,40 @@
CURRENT_DIR=$(shell pwd)
DIST_DIR=${CURRENT_DIR}/dist
E2E_CLUSTER_NAME=gatewayapi-plugin-e2e
IS_E2E_CLUSTER=$(shell kind get clusters | grep -e "^${E2E_CLUSTER_NAME}$$")

CLUSTER_DELETE ?= true
RUN ?= ''

define add_helm_repo
helm repo add traefik https://traefik.github.io/charts
helm repo add argo https://argoproj.github.io/argo-helm
endef

define install_helm_charts
helm install argo-rollouts argo/argo-rollouts --values ./test/cluster-setup/argo-rollouts-values.yml --version 2.37.2
helm install traefik traefik/traefik --values ./test/cluster-setup/traefik-values.yml --version 29.0.1
endef

define install_k8s_resources
kubectl apply -f ./examples/traefik/stable.yml
kubectl apply -f ./examples/traefik/canary.yml
endef

.PHONY: install-dependencies
install-dependencies:
go mod download

.PHONY: release
release:
make BIN_NAME=gateway-api-plugin-darwin-amd64 GOOS=darwin gateway-api-plugin-build
make BIN_NAME=gateway-api-plugin-darwin-arm64 GOOS=darwin GOARCH=arm64 gateway-api-plugin-build
make BIN_NAME=gateway-api-plugin-linux-amd64 GOOS=linux gateway-api-plugin-build
make BIN_NAME=gateway-api-plugin-linux-arm64 GOOS=linux GOARCH=arm64 gateway-api-plugin-build
make BIN_NAME=gateway-api-plugin-windows-amd64.exe GOOS=windows gateway-api-plugin-build

.PHONY: gateway-api-plugin-build
gateway-api-plugin-build:
make BIN_NAME=gatewayapi-plugin-darwin-amd64 GOOS=darwin gatewayapi-plugin-build
make BIN_NAME=gatewayapi-plugin-darwin-arm64 GOOS=darwin GOARCH=arm64 gatewayapi-plugin-build
make BIN_NAME=gatewayapi-plugin-linux-amd64 GOOS=linux gatewayapi-plugin-build
make BIN_NAME=gatewayapi-plugin-linux-arm64 GOOS=linux GOARCH=arm64 gatewayapi-plugin-build
make BIN_NAME=gatewayapi-plugin-windows-amd64.exe GOOS=windows gatewayapi-plugin-build

.PHONY: gatewayapi-plugin-build
gatewayapi-plugin-build:
CGO_ENABLED=0 GOOS=${GOOS} GOARCH=${GOARCH} go build -v -o ${DIST_DIR}/${BIN_NAME} .

.PHONY: local-build
Expand All @@ -21,9 +45,33 @@ local-build:
lint:
golangci-lint run --fix

.PHONY: test
test:
go test -v ./...
.PHONY: unit-tests
unit-tests:
go test -v -count=1 ./pkg/...

.PHONY: setup-e2e-cluster
setup-e2e-cluster:
make BIN_NAME=gatewayapi-plugin-linux-amd64 GOOS=linux GOARCH=amd64 gatewayapi-plugin-build
ifeq (${IS_E2E_CLUSTER},)
kind create cluster --name ${E2E_CLUSTER_NAME} --config ./test/cluster-setup/cluster-config.yml
$(call add_helm_repo)
$(call install_helm_charts)
$(call install_k8s_resources)
endif

.PHONY: e2e-tests
e2e-tests: setup-e2e-cluster run-e2e-tests
ifeq (${CLUSTER_DELETE},true)
make clear-e2e-cluster
endif

.PHONY: run-e2e-tests
run-e2e-tests:
go test -v -timeout 1m -count=1 -run ${RUN} ./test/e2e/...

.PHONY: clear-e2e-cluster
clear-e2e-cluster:
kind delete cluster --name ${E2E_CLUSTER_NAME}

# convenience target to run `mkdocs serve` using a docker container
.PHONY: serve-docs
Expand Down
43 changes: 25 additions & 18 deletions docs/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,37 +103,45 @@ To run unit tests:
make test
```

<!-- ## Running E2E tests -->
## Running E2E tests

<!-- The end-to-end tests need to run against a kubernetes cluster with the Argo Rollouts controller
running. The rollout controller can be started with the command:
The e2e tests need to run against a kubernetes cluster with the Argo Rollouts controller. To run e2e tests run in the repository root

```
make start-e2e
make e2e-tests
```

Start and prepare your cluster for e2e tests:
This command will

```
k3d cluster create
kubectl create ns argo-rollouts
kubectl apply -k manifests/crds
kubectl apply -f test/e2e/crds
```
1. Create local cluster **gatewayapi-plugin-e2e** using tools [kind](https://kind.sigs.k8s.io/) and [docker](https://www.docker.com/). You need to install them.
2. Setup cluster using instruments [helm](https://helm.sh/) and [kubectl](https://kubernetes.io/docs/reference/kubectl/). You need to install them.
3. Runs tests in **/test/e2e** folder.
4. Delete all resources from created cluster.
5. Delete created cluster.

Then run the e2e tests:
**Note:** It is used Traefik in e2e tests.

If you want to leave working cluster with needing setup at the end you should run the following command
```
make test-e2e
make CLUSTER_DELETE=false e2e-tests
```

To run a subset of e2e tests, you need to specify the suite with `-run`, and the specific test regex with `-testify.m`.
After this command you can want to run again all tests. Although you can run again **make CLUSTER_DELETE=false e2e-tests** command, it is recommended to use this command
```
make run-e2e-tests
```
as you have already had cluster setup.

If you want to run specific e2e tests then you can these commands
```
E2E_TEST_OPTIONS="-run 'TestCanarySuite' -testify.m 'TestCanaryScaleDownOnAbortNoTrafficRouting'" make test-e2e
```
make RUN=<reg-exp> e2e-tests
```
or
```
make RUN=<reg-exp> run-e2e-tests
```
reg-exp - the value you would set for the **-run** flag of **go test** command

-->

## Creating a Pull Request

Expand All @@ -145,7 +153,6 @@ Please use [meaningful PR names](https://www.conventionalcommits.org/en/v1.0.0/)

When you submit a PR, a couple of CI checks will be run automatically to ensure your changes will build fine and meet certain quality standards. Your contribution needs to pass those checks in order to be merged into the repository.


## Documentation Changes

Install Docker locally.
Expand Down
6 changes: 3 additions & 3 deletions examples/tcproute/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ After we enabled the Gateway API provider in our controller we can create a Gate
- GatewayClass
```yaml
apiVersion: gateway.networking.k8s.io/v1beta1
apiVersion: gateway.networking.k8s.io/v1
kind: GatewayClass
metadata:
name: argo-rollouts-gateway-class
Expand All @@ -113,7 +113,7 @@ spec:
- Gateway
```yaml
apiVersion: gateway.networking.k8s.io/v1beta1
apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
name: argo-rollouts-gateway
Expand Down Expand Up @@ -152,7 +152,7 @@ This concludes the setup that is specific to Traefik Proxy. The rest of the step
Create TCPRoute and connect to the created Gateway resource
```yaml
apiVersion: gateway.networking.k8s.io/v1beta1
apiVersion: gateway.networking.k8s.io/v1alpha2
kind: TCPRoute
metadata:
name: argo-rollouts-tcp-route
Expand Down
6 changes: 3 additions & 3 deletions examples/traefik/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ After we enabled the Gateway API provider in our controller we can create a Gate
apiVersion: gateway.networking.k8s.io/v1beta1
kind: GatewayClass
metadata:
name: argo-rollouts-gateway-class
name: traefik
spec:
controllerName: traefik.io/gateway-controller
```
Expand All @@ -116,9 +116,9 @@ spec:
apiVersion: gateway.networking.k8s.io/v1beta1
kind: Gateway
metadata:
name: argo-rollouts-gateway
name: traefik-gateway
spec:
gatewayClassName: argo-rollouts-gateway-class
gatewayClassName: traefik
listeners:
- protocol: HTTP
name: web
Expand Down
6 changes: 3 additions & 3 deletions examples/traefik/gateway.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
apiVersion: gateway.networking.k8s.io/v1beta1
apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
name: argo-rollouts-gateway
name: traefik-gateway
spec:
gatewayClassName: argo-rollouts-gateway-class
gatewayClassName: traefik
listeners:
- protocol: HTTP
name: web
Expand Down
4 changes: 2 additions & 2 deletions examples/traefik/gatewayclass.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
apiVersion: gateway.networking.k8s.io/v1beta1
apiVersion: gateway.networking.k8s.io/v1
kind: GatewayClass
metadata:
name: argo-rollouts-gateway-class
name: traefik
spec:
controllerName: traefik.io/gateway-controller
4 changes: 2 additions & 2 deletions examples/traefik/httproute.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
apiVersion: gateway.networking.k8s.io/v1beta1
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: argo-rollouts-http-route
spec:
parentRefs:
- name: argo-rollouts-gateway
- name: traefik-gateway
namespace: default
rules:
- backendRefs:
Expand Down
25 changes: 20 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,46 +1,61 @@
module github.com/argoproj-labs/rollouts-plugin-trafficrouter-gatewayapi

go 1.22.0
go 1.22.3

toolchain go1.22.1
toolchain go1.22.5

require (
github.com/argoproj/argo-rollouts v1.6.6
github.com/go-playground/validator/v10 v10.19.0
github.com/hashicorp/go-plugin v1.6.0
github.com/sirupsen/logrus v1.9.3
github.com/stretchr/testify v1.9.0
k8s.io/client-go v0.30.0
k8s.io/client-go v0.30.1
sigs.k8s.io/gateway-api v1.0.0
)

require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/blang/semver/v4 v4.0.0 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/evanphx/json-patch v5.7.0+incompatible // indirect
github.com/evanphx/json-patch/v5 v5.9.0 // indirect
github.com/fatih/color v1.16.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/google/gnostic-models v0.6.8 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/hashicorp/go-hclog v1.6.3 // indirect
github.com/hashicorp/yamux v0.1.1 // indirect
github.com/imdario/mergo v0.3.16 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 // indirect
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
github.com/moby/spdystream v0.2.0 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f // indirect
github.com/oklog/run v1.1.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.18.0 // indirect
github.com/prometheus/client_model v0.5.0 // indirect
github.com/prometheus/common v0.45.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
golang.org/x/crypto v0.22.0 // indirect
golang.org/x/oauth2 v0.19.0 // indirect
golang.org/x/term v0.19.0 // indirect
golang.org/x/time v0.5.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240415180920-8c6c420018be // indirect
google.golang.org/grpc v1.63.2 // indirect
k8s.io/component-base v0.30.1 // indirect
sigs.k8s.io/controller-runtime v0.18.2 // indirect
sigs.k8s.io/e2e-framework v0.4.0 // indirect
sigs.k8s.io/yaml v1.4.0 // indirect
)

Expand All @@ -65,8 +80,8 @@ require (
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/api v0.30.0
k8s.io/apimachinery v0.30.0
k8s.io/api v0.30.1
k8s.io/apimachinery v0.30.1
k8s.io/klog/v2 v2.120.1 // indirect
k8s.io/kube-openapi v0.0.0-20240423202451-8948a665c108 // indirect
k8s.io/utils v0.0.0-20240423183400-0849a56e8f22 // indirect
Expand Down
Loading

0 comments on commit 182280f

Please sign in to comment.