Skip to content

Commit ade7c75

Browse files
authored
feat: integration tests (#94)
1 parent c4ed890 commit ade7c75

File tree

17 files changed

+1419
-9
lines changed

17 files changed

+1419
-9
lines changed

.github/workflows/test-e2e.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ on:
1010
- main
1111

1212
jobs:
13-
test-e2e:
13+
test-e2e-controller:
1414
name: E2E Tests
1515
runs-on: ubuntu-latest
1616
steps:
@@ -34,7 +34,7 @@ jobs:
3434
- name: Create kind cluster
3535
run: kind create cluster
3636

37-
- name: Running Test e2e
37+
- name: Running Test e2e-controller
3838
run: |
3939
go mod tidy
40-
make test-e2e
40+
make test-e2e-controller

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
*.dylib
77
bin/*
88
test/external-crds
9+
test/e2e/frmwrk/artifacts
10+
_artifacts
911
Dockerfile.cross
1012
.release
1113

@@ -17,6 +19,7 @@ infrastructure-components.yaml
1719

1820
# Output of the go coverage tool, specifically when used with LiteIDE
1921
*.out
22+
junit.e2e_suite.xml
2023

2124
# Go workspace file
2225
go.work

Makefile

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,15 @@ vet: ## Run go vet against code.
8888
go vet ./...
8989

9090
.PHONY: test
91-
test: manifests generate update-test-crds fmt vet envtest ## Run tests.
92-
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test $$(go list ./... | grep -v /e2e) -coverprofile cover.out
91+
test: manifests generate update-test-crds fmt vet envtest ginkgo ## Run tests.
92+
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" $(GINKGO) -r --junit-report="junit.e2e_suite.xml" --cover -coverprofile cover.out $$(go list ./... | grep -v /e2e | sed "s|github.com/metal-stack/cluster-api-provider-metal-stack|.|")
9393

9494
# The default setup assumes Kind is pre-installed and builds/loads the Manager Docker image locally.
9595
# Prometheus and CertManager are installed by default; skip with:
9696
# - PROMETHEUS_INSTALL_SKIP=true
9797
# - CERT_MANAGER_INSTALL_SKIP=true
98-
.PHONY: test-e2e
99-
test-e2e: manifests generate update-test-crds fmt vet ## Run the e2e tests. Expected an isolated environment using Kind.
98+
.PHONY: test-e2e-controller
99+
test-e2e-controller: manifests generate update-test-crds fmt vet ## Run the e2e tests. Expected an isolated environment using Kind.
100100
@command -v kind >/dev/null 2>&1 || { \
101101
echo "Kind is not installed. Please install Kind manually."; \
102102
exit 1; \
@@ -107,6 +107,46 @@ test-e2e: manifests generate update-test-crds fmt vet ## Run the e2e tests. Expe
107107
}
108108
go test ./test/e2e/ -v -ginkgo.v
109109

110+
E2E_METAL_API_URL ?= "$(METALCTL_API_URL)"
111+
E2E_METAL_API_HMAC ?= "$(METALCTL_HMAC)"
112+
E2E_METAL_API_HMAC_AUTH_TYPE ?= "$(or $(METALCTL_HMAC_AUTH_TYPE),Metal-Admin)"
113+
E2E_METAL_PROJECT_ID ?= "00000000-0000-0000-0000-000000000001"
114+
E2E_METAL_PARTITION ?= "mini-lab"
115+
E2E_METAL_PUBLIC_NETWORK ?= "internet-mini-lab"
116+
E2E_KUBERNETES_VERSIONS ?= "v1.32.9"
117+
E2E_CONTROL_PLANE_MACHINE_IMAGE_PREFIX ?= "capms-ubuntu-"
118+
E2E_CONTROL_PLANE_MACHINE_SIZE ?= "v1-small-x86"
119+
E2E_WORKER_MACHINE_IMAGE_PREFIX ?= "capms-ubuntu-"
120+
E2E_WORKER_MACHINE_SIZE ?= "v1-small-x86"
121+
E2E_FIREWALL_IMAGE ?= "firewall-ubuntu-3.0"
122+
E2E_FIREWALL_SIZE ?= "v1-small-x86"
123+
E2E_FIREWALL_NETWORKS ?= "internet-mini-lab"
124+
ARTIFACTS ?= "$(PWD)/_artifacts"
125+
126+
.PHONY: test-e2e
127+
test-e2e: manifests generate fmt vet ginkgo
128+
rm -rf test/e2e/frmwrk/artifacts
129+
130+
mkdir -p $(ARTIFACTS)/config/target
131+
kubectl kustomize test/e2e/frmwrk/config/target/base -o $(ARTIFACTS)/config/target/base.yaml
132+
133+
@METAL_API_URL=$(E2E_METAL_API_URL) \
134+
METAL_API_HMAC=$(E2E_METAL_API_HMAC) \
135+
METAL_API_HMAC_AUTH_TYPE=$(E2E_METAL_API_HMAC_AUTH_TYPE) \
136+
METAL_PROJECT_ID=$(E2E_METAL_PROJECT_ID) \
137+
METAL_PARTITION=$(E2E_METAL_PARTITION) \
138+
METAL_PUBLIC_NETWORK=$(E2E_METAL_PUBLIC_NETWORK) \
139+
E2E_KUBERNETES_VERSIONS=$(E2E_KUBERNETES_VERSIONS) \
140+
E2E_CONTROL_PLANE_MACHINE_IMAGE_PREFIX=$(E2E_CONTROL_PLANE_MACHINE_IMAGE_PREFIX) \
141+
CONTROL_PLANE_MACHINE_SIZE=$(E2E_CONTROL_PLANE_MACHINE_SIZE) \
142+
E2E_WORKER_MACHINE_IMAGE_PREFIX=$(E2E_WORKER_MACHINE_IMAGE_PREFIX) \
143+
WORKER_MACHINE_SIZE=$(E2E_WORKER_MACHINE_SIZE) \
144+
FIREWALL_IMAGE=$(E2E_FIREWALL_IMAGE) \
145+
FIREWALL_SIZE=$(E2E_FIREWALL_SIZE) \
146+
FIREWALL_NETWORKS=$(E2E_FIREWALL_NETWORKS) \
147+
ARTIFACTS=$(ARTIFACTS) \
148+
$(GINKGO) -vv -r --junit-report="junit.e2e_suite.xml" --output-dir="$(ARTIFACTS)" -timeout 60m ./test/e2e/frmwrk
149+
110150
.PHONY: lint
111151
lint: golangci-lint ## Run golangci-lint linter
112152
$(GOLANGCI_LINT) run
@@ -199,13 +239,15 @@ KUBECTL ?= kubectl
199239
KUSTOMIZE ?= $(LOCALBIN)/kustomize
200240
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
201241
ENVTEST ?= $(LOCALBIN)/setup-envtest
242+
GINKGO ?= $(LOCALBIN)/ginkgo
202243
GOLANGCI_LINT = $(LOCALBIN)/golangci-lint
203244

204245
## Tool Versions
205246
KUSTOMIZE_VERSION ?= v5.4.3
206247
CONTROLLER_TOOLS_VERSION ?= v0.16.4
207248
ENVTEST_VERSION ?= release-0.19
208249
GOLANGCI_LINT_VERSION ?= v1.61.0
250+
GINKGO_VERSION ?= v2.23.3
209251

210252
.PHONY: kustomize
211253
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.
@@ -227,6 +269,11 @@ golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary.
227269
$(GOLANGCI_LINT): $(LOCALBIN)
228270
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION))
229271

272+
.PHONY: ginkgo
273+
ginkgo: $(GINKGO) ## Download setup-envtest locally if necessary.
274+
$(GINKGO): $(LOCALBIN)
275+
$(call go-install-tool,$(GINKGO),github.com/onsi/ginkgo/v2/ginkgo,$(GINKGO_VERSION))
276+
230277
# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
231278
# $1 - target path with name of binary
232279
# $2 - package url which can be installed

capi-lab/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ cleanup:
4646
dev-env:
4747
@echo "export METALCTL_API_URL=${METALCTL_API_URL}"
4848
@echo "export METALCTL_HMAC=${METALCTL_HMAC}"
49+
@echo "export METALCTL_HMAC_AUTH_TYPE=${METALCTL_HMAC_AUTH_TYPE}"
4950
@echo "export KUBECONFIG=${KUBECONFIG}"
5051

5152
.PHONY: controller
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
resources:
2+
- ./metal-ccm.yaml

go.mod

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module github.com/metal-stack/cluster-api-provider-metal-stack
33
go 1.23.0
44

55
require (
6+
github.com/drone/envsubst/v2 v2.0.0-20210730161058-179042472c46
67
github.com/go-logr/logr v1.4.2
78
github.com/metal-stack/metal-go v0.40.4
89
github.com/metal-stack/metal-lib v0.20.2
@@ -13,24 +14,42 @@ require (
1314
k8s.io/api v0.32.3
1415
k8s.io/apimachinery v0.32.3
1516
k8s.io/client-go v0.32.3
17+
k8s.io/klog/v2 v2.130.1
1618
k8s.io/utils v0.0.0-20241104100929-3ea5e8cea738
1719
sigs.k8s.io/cluster-api v1.10.6
20+
sigs.k8s.io/cluster-api/test v1.10.6
1821
sigs.k8s.io/controller-runtime v0.20.4
1922
)
2023

2124
require (
25+
al.essio.dev/pkg/shellescape v1.5.1 // indirect
2226
cel.dev/expr v0.18.0 // indirect
27+
dario.cat/mergo v1.0.1 // indirect
28+
github.com/BurntSushi/toml v1.4.0 // indirect
29+
github.com/MakeNowJust/heredoc v1.0.0 // indirect
30+
github.com/Masterminds/goutils v1.1.1 // indirect
31+
github.com/Masterminds/semver/v3 v3.3.0 // indirect
32+
github.com/Masterminds/sprig/v3 v3.3.0 // indirect
33+
github.com/Microsoft/go-winio v0.6.2 // indirect
34+
github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8 // indirect
35+
github.com/adrg/xdg v0.5.3 // indirect
2336
github.com/antlr4-go/antlr/v4 v4.13.0 // indirect
2437
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect
2538
github.com/beorn7/perks v1.0.1 // indirect
2639
github.com/blang/semver/v4 v4.0.0 // indirect
2740
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
2841
github.com/cespare/xxhash/v2 v2.3.0 // indirect
42+
github.com/cloudflare/circl v1.6.1 // indirect
2943
github.com/coreos/go-oidc/v3 v3.12.0 // indirect
3044
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
3145
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect
46+
github.com/distribution/reference v0.6.0 // indirect
47+
github.com/docker/docker v28.0.2+incompatible // indirect
48+
github.com/docker/go-connections v0.5.0 // indirect
49+
github.com/docker/go-units v0.5.0 // indirect
3250
github.com/emicklei/go-restful/v3 v3.12.2 // indirect
3351
github.com/evanphx/json-patch/v5 v5.9.11 // indirect
52+
github.com/fatih/color v1.18.0 // indirect
3453
github.com/felixge/httpsnoop v1.0.4 // indirect
3554
github.com/fsnotify/fsnotify v1.8.0 // indirect
3655
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
@@ -48,6 +67,7 @@ require (
4867
github.com/go-openapi/swag v0.23.0 // indirect
4968
github.com/go-openapi/validate v0.24.0 // indirect
5069
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
70+
github.com/go-viper/mapstructure/v2 v2.4.0 // indirect
5171
github.com/gobuffalo/flect v1.0.3 // indirect
5272
github.com/goccy/go-json v0.10.4 // indirect
5373
github.com/gogo/protobuf v1.3.2 // indirect
@@ -57,11 +77,15 @@ require (
5777
github.com/google/cel-go v0.22.0 // indirect
5878
github.com/google/gnostic-models v0.6.9-0.20230804172637-c7be7c783f49 // indirect
5979
github.com/google/go-cmp v0.7.0 // indirect
80+
github.com/google/go-github/v53 v53.2.0 // indirect
81+
github.com/google/go-querystring v1.1.0 // indirect
6082
github.com/google/gofuzz v1.2.0 // indirect
6183
github.com/google/pprof v0.0.0-20241210010833-40e02aabc2ad // indirect
84+
github.com/google/safetext v0.0.0-20220905092116-b49f7bc46da2 // indirect
6285
github.com/google/uuid v1.6.0 // indirect
6386
github.com/gorilla/mux v1.8.1 // indirect
6487
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 // indirect
88+
github.com/huandu/xstrings v1.5.0 // indirect
6589
github.com/inconshreveable/mousetrap v1.1.0 // indirect
6690
github.com/josharian/intern v1.0.0 // indirect
6791
github.com/json-iterator/go v1.1.12 // indirect
@@ -73,24 +97,44 @@ require (
7397
github.com/lestrrat-go/jwx/v2 v2.1.3 // indirect
7498
github.com/lestrrat-go/option v1.0.1 // indirect
7599
github.com/mailru/easyjson v0.9.0 // indirect
100+
github.com/mattn/go-colorable v0.1.13 // indirect
101+
github.com/mattn/go-isatty v0.0.20 // indirect
102+
github.com/mattn/go-runewidth v0.0.15 // indirect
76103
github.com/metal-stack/security v0.9.3 // indirect
104+
github.com/mitchellh/copystructure v1.2.0 // indirect
77105
github.com/mitchellh/mapstructure v1.5.0 // indirect
106+
github.com/mitchellh/reflectwalk v1.0.2 // indirect
107+
github.com/moby/docker-image-spec v1.3.1 // indirect
78108
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
79109
github.com/modern-go/reflect2 v1.0.2 // indirect
80110
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
81111
github.com/oklog/ulid v1.3.1 // indirect
112+
github.com/olekukonko/tablewriter v0.0.5 // indirect
113+
github.com/opencontainers/go-digest v1.0.0 // indirect
114+
github.com/opencontainers/image-spec v1.1.0 // indirect
82115
github.com/opentracing/opentracing-go v1.2.0 // indirect
116+
github.com/pelletier/go-toml v1.9.5 // indirect
117+
github.com/pelletier/go-toml/v2 v2.2.3 // indirect
83118
github.com/pkg/errors v0.9.1 // indirect
84119
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
85120
github.com/prometheus/client_golang v1.20.5 // indirect
86121
github.com/prometheus/client_model v0.6.1 // indirect
87122
github.com/prometheus/common v0.60.0 // indirect
88123
github.com/prometheus/procfs v0.15.1 // indirect
124+
github.com/rivo/uniseg v0.4.4 // indirect
125+
github.com/sagikazarmark/locafero v0.7.0 // indirect
89126
github.com/segmentio/asm v1.2.0 // indirect
127+
github.com/shopspring/decimal v1.4.0 // indirect
128+
github.com/sourcegraph/conc v0.3.0 // indirect
129+
github.com/spf13/afero v1.12.0 // indirect
130+
github.com/spf13/cast v1.7.1 // indirect
90131
github.com/spf13/cobra v1.9.1 // indirect
91132
github.com/spf13/pflag v1.0.6 // indirect
133+
github.com/spf13/viper v1.20.0 // indirect
92134
github.com/stoewer/go-strcase v1.3.0 // indirect
93135
github.com/stretchr/objx v0.5.2 // indirect
136+
github.com/subosito/gotenv v1.6.0 // indirect
137+
github.com/valyala/fastjson v1.6.4 // indirect
94138
github.com/x448/float16 v0.8.4 // indirect
95139
go.mongodb.org/mongo-driver v1.17.1 // indirect
96140
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.54.0 // indirect
@@ -122,11 +166,12 @@ require (
122166
gopkg.in/yaml.v3 v3.0.1 // indirect
123167
k8s.io/apiextensions-apiserver v0.32.3 // indirect
124168
k8s.io/apiserver v0.32.3 // indirect
169+
k8s.io/cluster-bootstrap v0.32.3 // indirect
125170
k8s.io/component-base v0.32.3 // indirect
126-
k8s.io/klog/v2 v2.130.1 // indirect
127171
k8s.io/kube-openapi v0.0.0-20241105132330-32ad38e42d3f // indirect
128172
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.31.0 // indirect
129173
sigs.k8s.io/json v0.0.0-20241010143419-9aa6b5e7a4b3 // indirect
174+
sigs.k8s.io/kind v0.27.0 // indirect
130175
sigs.k8s.io/structured-merge-diff/v4 v4.4.2 // indirect
131176
sigs.k8s.io/yaml v1.4.0 // indirect
132177
)

0 commit comments

Comments
 (0)