Skip to content

Commit 31444a3

Browse files
committed
Add e2e tests
1 parent 1a98772 commit 31444a3

File tree

21 files changed

+1030
-650
lines changed

21 files changed

+1030
-650
lines changed

.github/workflows/test-e2e.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,8 @@ jobs:
2929
- name: Running Test e2e
3030
run: |
3131
go mod tidy
32-
make test-e2e
32+
bash hack/ci-e2e.sh
33+
env:
34+
E2E_SCW_ACCESS_KEY: ${{ secrets.E2E_SCW_ACCESS_KEY }}
35+
E2E_SCW_SECRET_KEY: ${{ secrets.E2E_SCW_SECRET_KEY }}
36+
E2E_SCW_PROJECT_ID: ${{ vars.E2E_SCW_PROJECT_ID }}

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,9 @@ go.work
2828

2929
# release directory
3030
out/*
31+
dist/*
32+
33+
# e2e files
34+
_artifacts
35+
*-envsubst.yaml
36+
test/e2e/data/infrastructure-scaleway/v1beta1/*.yaml

.golangci.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ linters:
4747
- linters:
4848
- lll
4949
path: api/*
50+
- linters:
51+
- lll
52+
path: test/e2e/*
5053
- linters:
5154
- dupl
5255
- lll
@@ -60,6 +63,10 @@ linters:
6063
- linters:
6164
- staticcheck
6265
text: "QF1008"
66+
- linters:
67+
- staticcheck
68+
text: "ST1001"
69+
path: test/e2e/*
6370
paths:
6471
- third_party$
6572
- builtin$

Makefile

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Image URL to use all building/pushing image targets
2-
IMG ?= controller:latest
2+
IMG ?= ghcr.io/scaleway/cluster-api-provider-scaleway:dev
33

44
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
55
ifeq (,$(shell go env GOBIN))
@@ -8,6 +8,8 @@ else
88
GOBIN=$(shell go env GOBIN)
99
endif
1010

11+
ROOT_DIR := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
12+
1113
# CONTAINER_TOOL defines the container tool to be used for building images.
1214
# Be aware that the target commands are only tested with Docker which is
1315
# scaffolded by default. However, you might want to replace it to use other
@@ -62,28 +64,39 @@ vet: ## Run go vet against code.
6264
test: manifests generate fmt vet setup-envtest ## Run tests.
6365
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test $$(go list ./... | grep -v /e2e | grep -v /mock) -coverprofile cover.out
6466

65-
# TODO(user): To use a different vendor for e2e tests, modify the setup under 'tests/e2e'.
66-
# The default setup assumes Kind is pre-installed and builds/loads the Manager Docker image locally.
67-
# CertManager is installed by default; skip with:
68-
# - CERT_MANAGER_INSTALL_SKIP=true
69-
KIND_CLUSTER ?= cluster-api-provider-scaleway-test-e2e
67+
KIND_CLUSTER ?= caps-e2e
68+
KIND_KUBECONFIG ?= /tmp/caps-e2e-kubeconfig
69+
70+
E2E_ARTIFACTS ?= $(ROOT_DIR)/_artifacts
71+
E2E_CONF_FILE ?= $(ROOT_DIR)/test/e2e/config/scaleway.yaml
72+
E2E_CONF_FILE_ENVSUBST := $(ROOT_DIR)/test/e2e/config/scaleway-envsubst.yaml
73+
E2E_V1BETA1_TEMPLATES := $(ROOT_DIR)/test/e2e/data/infrastructure-scaleway/v1beta1
7074

7175
.PHONY: setup-test-e2e
7276
setup-test-e2e: ## Set up a Kind cluster for e2e tests if it does not exist
7377
@command -v $(KIND) >/dev/null 2>&1 || { \
7478
echo "Kind is not installed. Please install Kind manually."; \
7579
exit 1; \
7680
}
77-
$(KIND) create cluster --name $(KIND_CLUSTER)
81+
$(KIND) create cluster --name $(KIND_CLUSTER) --kubeconfig $(KIND_KUBECONFIG)
82+
83+
.PHONY: generate-e2e
84+
generate-e2e: kustomize ## Generate templates for e2e
85+
$(KUSTOMIZE) build $(E2E_V1BETA1_TEMPLATES)/cluster-template --load-restrictor LoadRestrictionsNone > $(E2E_V1BETA1_TEMPLATES)/cluster-template.yaml
86+
$(KUSTOMIZE) build $(E2E_V1BETA1_TEMPLATES)/cluster-template-private-network --load-restrictor LoadRestrictionsNone > $(E2E_V1BETA1_TEMPLATES)/cluster-template-private-network.yaml
7887

7988
.PHONY: test-e2e
80-
test-e2e: setup-test-e2e manifests generate fmt vet ## Run the e2e tests. Expected an isolated environment using Kind.
81-
KIND_CLUSTER=$(KIND_CLUSTER) go test ./test/e2e/ -v -ginkgo.v
89+
test-e2e: setup-test-e2e generate-e2e docker-build envsubst ginkgo build-installer fmt vet ## Run the e2e tests. Expected an isolated environment using Kind.
90+
MANAGER_IMAGE=$(IMG) $(ENVSUBST) < $(E2E_CONF_FILE) > $(E2E_CONF_FILE_ENVSUBST)
91+
KIND_CLUSTER=$(KIND_CLUSTER) KUBECONFIG=$(KIND_KUBECONFIG) $(GINKGO) run -v --nodes 2 ./test/e2e/ -- \
92+
-e2e.config $(E2E_CONF_FILE_ENVSUBST) \
93+
-e2e.use-existing-cluster \
94+
-e2e.artifacts-folder=$(E2E_ARTIFACTS)
8295
$(MAKE) cleanup-test-e2e
8396

8497
.PHONY: cleanup-test-e2e
8598
cleanup-test-e2e: ## Tear down the Kind cluster used for e2e tests
86-
@$(KIND) delete cluster --name $(KIND_CLUSTER)
99+
@$(KIND) delete cluster --name $(KIND_CLUSTER) --kubeconfig $(KIND_KUBECONFIG)
87100

88101
.PHONY: lint
89102
lint: golangci-lint ## Run golangci-lint linter
@@ -193,6 +206,8 @@ ENVTEST ?= $(LOCALBIN)/setup-envtest
193206
GOLANGCI_LINT = $(LOCALBIN)/golangci-lint
194207
NILAWAY = $(LOCALBIN)/nilaway
195208
MOCKGEN = $(LOCALBIN)/mockgen
209+
ENVSUBST = $(LOCALBIN)/envsubst
210+
GINKGO = $(LOCALBIN)/ginkgo
196211

197212
## Tool Versions
198213
KUSTOMIZE_VERSION ?= v5.6.0
@@ -204,6 +219,8 @@ ENVTEST_K8S_VERSION ?= $(shell go list -m -f "{{ .Version }}" k8s.io/api | awk -
204219
GOLANGCI_LINT_VERSION ?= v2.1.0
205220
NILAWAY_VERSION ?= latest
206221
MOCKGEN_VERSION ?= v0.5.2
222+
ENVSUBST_VERSION ?=latest
223+
GINKGO_VERSION ?= v2.23.4
207224

208225
.PHONY: kustomize
209226
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.
@@ -243,6 +260,16 @@ mockgen: $(MOCKGEN) ## Download mockgen locally if necessary.
243260
$(MOCKGEN): $(LOCALBIN)
244261
$(call go-install-tool,$(MOCKGEN),go.uber.org/mock/mockgen,$(MOCKGEN_VERSION))
245262

263+
.PHONY: envsubst
264+
envsubst: $(ENVSUBST) ## Download envsubst locally if necessary.
265+
$(ENVSUBST): $(LOCALBIN)
266+
$(call go-install-tool,$(ENVSUBST),github.com/drone/envsubst/v2/cmd/envsubst,$(ENVSUBST_VERSION))
267+
268+
.PHONY: ginkgo
269+
ginkgo: $(GINKGO) ## Download ginkgo locally if necessary.
270+
$(GINKGO): $(LOCALBIN)
271+
$(call go-install-tool,$(GINKGO),github.com/onsi/ginkgo/v2/ginkgo,$(GINKGO_VERSION))
272+
246273
# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
247274
# $1 - target path with name of binary
248275
# $2 - package url which can be installed

config/manager/manager.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ spec:
6464
- --leader-elect
6565
- --health-probe-bind-address=:8081
6666
image: controller:latest
67+
imagePullPolicy: Always
6768
name: manager
6869
ports: []
6970
securityContext:

go.mod

Lines changed: 59 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,44 @@ require (
77
github.com/onsi/gomega v1.37.0
88
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.33
99
go.uber.org/mock v0.5.2
10-
k8s.io/api v0.33.1
11-
k8s.io/apimachinery v0.33.1
12-
k8s.io/client-go v0.33.1
10+
k8s.io/api v0.32.6
11+
k8s.io/apimachinery v0.32.6
12+
k8s.io/client-go v0.32.6
13+
k8s.io/klog/v2 v2.130.1
14+
k8s.io/utils v0.0.0-20241104100929-3ea5e8cea738
1315
sigs.k8s.io/cluster-api v1.10.2
14-
sigs.k8s.io/controller-runtime v0.21.0
16+
sigs.k8s.io/cluster-api/test v1.10.2
17+
sigs.k8s.io/controller-runtime v0.20.4
1518
)
1619

1720
require (
21+
al.essio.dev/pkg/shellescape v1.5.1 // indirect
1822
cel.dev/expr v0.19.1 // indirect
23+
dario.cat/mergo v1.0.1 // indirect
24+
github.com/BurntSushi/toml v1.4.0 // indirect
25+
github.com/MakeNowJust/heredoc v1.0.0 // indirect
26+
github.com/Masterminds/goutils v1.1.1 // indirect
27+
github.com/Masterminds/semver/v3 v3.3.0 // indirect
28+
github.com/Masterminds/sprig/v3 v3.3.0 // indirect
29+
github.com/Microsoft/go-winio v0.5.0 // indirect
30+
github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8 // indirect
31+
github.com/adrg/xdg v0.5.3 // indirect
1932
github.com/antlr4-go/antlr/v4 v4.13.0 // indirect
33+
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a // indirect
2034
github.com/beorn7/perks v1.0.1 // indirect
2135
github.com/blang/semver/v4 v4.0.0 // indirect
2236
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
2337
github.com/cespare/xxhash/v2 v2.3.0 // indirect
38+
github.com/cloudflare/circl v1.6.1 // indirect
2439
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
40+
github.com/distribution/reference v0.6.0 // indirect
41+
github.com/docker/docker v28.0.2+incompatible // indirect
42+
github.com/docker/go-connections v0.5.0 // indirect
43+
github.com/docker/go-units v0.4.0 // indirect
44+
github.com/drone/envsubst/v2 v2.0.0-20210730161058-179042472c46 // indirect
2545
github.com/emicklei/go-restful/v3 v3.12.2 // indirect
2646
github.com/evanphx/json-patch/v5 v5.9.11 // indirect
47+
github.com/fatih/color v1.18.0 // indirect
2748
github.com/felixge/httpsnoop v1.0.4 // indirect
2849
github.com/fsnotify/fsnotify v1.8.0 // indirect
2950
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
@@ -34,31 +55,57 @@ require (
3455
github.com/go-openapi/jsonreference v0.20.2 // indirect
3556
github.com/go-openapi/swag v0.23.0 // indirect
3657
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
58+
github.com/go-viper/mapstructure/v2 v2.2.1 // indirect
3759
github.com/gobuffalo/flect v1.0.3 // indirect
3860
github.com/gogo/protobuf v1.3.2 // indirect
61+
github.com/golang/protobuf v1.5.4 // indirect
3962
github.com/google/btree v1.1.3 // indirect
40-
github.com/google/cel-go v0.23.2 // indirect
63+
github.com/google/cel-go v0.22.0 // indirect
4164
github.com/google/gnostic-models v0.6.9 // indirect
4265
github.com/google/go-cmp v0.7.0 // indirect
66+
github.com/google/go-github/v53 v53.2.0 // indirect
67+
github.com/google/go-querystring v1.1.0 // indirect
68+
github.com/google/gofuzz v1.2.0 // indirect
4369
github.com/google/pprof v0.0.0-20250403155104-27863c87afa6 // indirect
70+
github.com/google/safetext v0.0.0-20220905092116-b49f7bc46da2 // indirect
4471
github.com/google/uuid v1.6.0 // indirect
4572
github.com/grpc-ecosystem/grpc-gateway/v2 v2.24.0 // indirect
73+
github.com/huandu/xstrings v1.5.0 // indirect
4674
github.com/inconshreveable/mousetrap v1.1.0 // indirect
4775
github.com/josharian/intern v1.0.0 // indirect
4876
github.com/json-iterator/go v1.1.12 // indirect
4977
github.com/mailru/easyjson v0.7.7 // indirect
78+
github.com/mattn/go-colorable v0.1.13 // indirect
79+
github.com/mattn/go-isatty v0.0.20 // indirect
80+
github.com/mattn/go-runewidth v0.0.14 // indirect
81+
github.com/mitchellh/copystructure v1.2.0 // indirect
82+
github.com/mitchellh/reflectwalk v1.0.2 // indirect
83+
github.com/moby/docker-image-spec v1.3.1 // indirect
5084
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
5185
github.com/modern-go/reflect2 v1.0.2 // indirect
5286
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
87+
github.com/olekukonko/tablewriter v0.0.5 // indirect
88+
github.com/opencontainers/go-digest v1.0.0 // indirect
89+
github.com/opencontainers/image-spec v1.0.2 // indirect
90+
github.com/pelletier/go-toml v1.9.5 // indirect
91+
github.com/pelletier/go-toml/v2 v2.2.3 // indirect
5392
github.com/pkg/errors v0.9.1 // indirect
54-
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
5593
github.com/prometheus/client_golang v1.22.0 // indirect
5694
github.com/prometheus/client_model v0.6.1 // indirect
5795
github.com/prometheus/common v0.62.0 // indirect
5896
github.com/prometheus/procfs v0.15.1 // indirect
97+
github.com/rivo/uniseg v0.4.2 // indirect
98+
github.com/sagikazarmark/locafero v0.7.0 // indirect
99+
github.com/shopspring/decimal v1.4.0 // indirect
100+
github.com/sourcegraph/conc v0.3.0 // indirect
101+
github.com/spf13/afero v1.12.0 // indirect
102+
github.com/spf13/cast v1.7.1 // indirect
59103
github.com/spf13/cobra v1.9.1 // indirect
60104
github.com/spf13/pflag v1.0.6 // indirect
105+
github.com/spf13/viper v1.20.0 // indirect
61106
github.com/stoewer/go-strcase v1.3.0 // indirect
107+
github.com/subosito/gotenv v1.6.0 // indirect
108+
github.com/valyala/fastjson v1.6.4 // indirect
62109
github.com/x448/float16 v0.8.4 // indirect
63110
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
64111
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.58.0 // indirect
@@ -72,6 +119,7 @@ require (
72119
go.uber.org/automaxprocs v1.6.0 // indirect
73120
go.uber.org/multierr v1.11.0 // indirect
74121
go.uber.org/zap v1.27.0 // indirect
122+
golang.org/x/crypto v0.36.0 // indirect
75123
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 // indirect
76124
golang.org/x/net v0.38.0 // indirect
77125
golang.org/x/oauth2 v0.28.0 // indirect
@@ -90,14 +138,14 @@ require (
90138
gopkg.in/inf.v0 v0.9.1 // indirect
91139
gopkg.in/yaml.v2 v2.4.0 // indirect
92140
gopkg.in/yaml.v3 v3.0.1 // indirect
93-
k8s.io/apiextensions-apiserver v0.33.0 // indirect
94-
k8s.io/apiserver v0.33.0 // indirect
95-
k8s.io/component-base v0.33.0 // indirect
96-
k8s.io/klog/v2 v2.130.1 // indirect
141+
k8s.io/apiextensions-apiserver v0.32.6 // indirect
142+
k8s.io/apiserver v0.32.6 // indirect
143+
k8s.io/cluster-bootstrap v0.32.3 // indirect
144+
k8s.io/component-base v0.32.6 // indirect
97145
k8s.io/kube-openapi v0.0.0-20250318190949-c8a335a9a2ff // indirect
98-
k8s.io/utils v0.0.0-20241104100929-3ea5e8cea738 // indirect
99146
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.31.2 // indirect
100147
sigs.k8s.io/json v0.0.0-20241010143419-9aa6b5e7a4b3 // indirect
148+
sigs.k8s.io/kind v0.27.0 // indirect
101149
sigs.k8s.io/randfill v1.0.0 // indirect
102150
sigs.k8s.io/structured-merge-diff/v4 v4.6.0 // indirect
103151
sigs.k8s.io/yaml v1.4.0 // indirect

0 commit comments

Comments
 (0)