Skip to content

Commit ddb4db5

Browse files
committed
add e2e test
1 parent f8c0ae7 commit ddb4db5

File tree

14 files changed

+1087
-145
lines changed

14 files changed

+1087
-145
lines changed

.gitignore

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,11 @@ coverage.*
2727
*~
2828

2929
# release
30-
out
30+
out
31+
32+
# test artifact
33+
ginkgo-log.txt
34+
internal/test/e2e/clusters
35+
internal/test/e2e/kind
36+
internal/test/e2e/repository
37+
internal/test/e2e/data/infrastructure-proxmox/*/cluster-template.yaml

Makefile

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11

22
# Image URL to use all building/pushing image targets
3-
IMG ?= controller:latest
3+
REGISTRY := ghcr.io
4+
PROJECT := sp-yduck/cluster-api-provider-proxmox
5+
RELEASE_TAG := latest
6+
IMG ?= $(REGISTRY)/$(PROJECT):$(RELEASE_TAG)
47
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
58
ENVTEST_K8S_VERSION = 1.26.1
69

10+
# add localbin to PATH
11+
LOCALBIN ?= $(shell pwd)/bin
12+
export PATH := $(abspath $(LOCALBIN)):$(PATH)
13+
714
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
815
ifeq (,$(shell go env GOBIN))
916
GOBIN=$(shell go env GOPATH)/bin
@@ -75,14 +82,15 @@ delete-workload-cluster: $(KUBECTL)
7582

7683
SETUP_ENVTEST_VER := v0.0.0-20211110210527-619e6b92dab9
7784
SETUP_ENVTEST := $(LOCALBIN)/setup-envtest
85+
GINKGO_TIMEOUT ?= 30m
7886

7987
.PHONY: test
8088
test: generate manifests fmt $(SETUP_ENVTEST) ## Run unit and integration test
81-
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test ./... $(TEST_ARGS)
89+
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test ./api/... ./cloud/... ./controllers/... $(TEST_ARGS)
8290

8391
.PHONY: unit-test ## Run unit tests
8492
unit-test: generate manifests fmt $(SETUP_ENVTEST)
85-
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test ./... --ginkgo.label-filter=unit $(TEST_ARGS)
93+
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test ./api/... ./cloud/... ./controllers/... --ginkgo.label-filter=unit $(TEST_ARGS)
8694

8795
.PHONY: test-cover
8896
test-cover: ## Run unit and integration tests and generate coverage report
@@ -96,6 +104,29 @@ unit-test-cover: ## Run unit tests and generate coverage report
96104
go tool cover -func=coverage.out -o coverage.txt
97105
go tool cover -html=coverage.out -o coverage.html
98106

107+
E2E_DIR = $(shell pwd)/internal/test/e2e
108+
E2E_IMG := ghcr.io/sp-yduck/cluster-api-provider-proxmox:e2e
109+
.PHONY: generate-e2e-templates
110+
generate-e2e-templates: $(KUSTOMIZE) ## Generate cluster-templates for e2e
111+
cp templates/cluster-template* $(E2E_DIR)/data/infrastructure-proxmox/templates
112+
$(KUSTOMIZE) build $(E2E_DIR)/data/infrastructure-proxmox/templates > $(E2E_DIR)/data/infrastructure-proxmox/main/cluster-template.yaml
113+
114+
.PHONY: build-e2e-image
115+
build-e2e-image: ## Build cappx image to be used for e2e test
116+
IMG=${E2E_IMG} $(MAKE) docker-build
117+
118+
.PHONY: e2e
119+
e2e: generate-e2e-templates build-e2e-image cleanup-e2e-artifacts ## Run e2e test
120+
go test $(E2E_DIR)/... -v \
121+
-timeout=$(GINKGO_TIMEOUT) \
122+
--e2e.artifacts-folder=$(E2E_DIR) \
123+
--e2e.use-existing-cluster="$(USE_EXISTING_CLUSTER)"
124+
125+
.PHONY: cleanup-e2e-artifacts
126+
cleanup-e2e-artifacts: ## delete some e2e artifacts
127+
rm -rf $(E2E_DIR)/clusters
128+
rm -rf $(E2E_DIR)/kind
129+
99130
##@ Build
100131

101132
.PHONY: build
@@ -150,7 +181,6 @@ uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified
150181

151182
.PHONY: deploy
152183
deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
153-
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
154184
$(KUSTOMIZE) build config/default | kubectl apply -f -
155185

156186
.PHONY: undeploy
@@ -160,16 +190,20 @@ undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/confi
160190
##@ Release
161191

162192
## Location to output for release
163-
RELEASE_DIR := out
193+
RELEASE_DIR := $(shell pwd)/out
164194
$(RELEASE_DIR):
165195
mkdir -p $(RELEASE_DIR)
166196

167-
# RELEASE_TAG := $(shell git describe --abbrev=0 2>/dev/null)
197+
RELEASE_TAG := $(shell git describe --abbrev=0 2>/dev/null)
168198

169-
# .PHONY: release
199+
.PHONY: release ## Builds all the manifests/config files to publish with a release
200+
$(MAKE) release-manifests
201+
$(MAKE) release-metadata
202+
$(MAKE) release-templates
170203

171204
.PHONY: release-manifests
172205
release-manifests: $(KUSTOMIZE) $(RELEASE_DIR) ## Builds the manifests to publish with a release
206+
cd config/manager && $(KUSTOMIZE) edit set image controller=${REGISTRY}/${PROJECT}:${RELEASE_TAG}
173207
$(KUSTOMIZE) build config/default > $(RELEASE_DIR)/infrastructure-components.yaml
174208

175209
.PHONY: release-metadata
@@ -184,7 +218,6 @@ release-templates: $(RELEASE_DIR)
184218
##@ Build Dependencies
185219

186220
## Location to install dependencies to
187-
LOCALBIN ?= $(shell pwd)/bin
188221
$(LOCALBIN):
189222
mkdir -p $(LOCALBIN)
190223

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ ProxmoxMachine controller follows the [typical infra-machine logic](https://clus
109109
```
110110
make unit-test
111111
```
112+
112113
#### Unit and Integration Testing
113114
```
114115
export PROXMOX_URL=https://X.X.X.X:8006/api2/json
@@ -118,6 +119,16 @@ export PROXMOX_USER=user@pam
118119
make test
119120
```
120121

122+
### E2E Testing
123+
```
124+
export CONTROLPLANE_HOST=X.X.X.X
125+
export PROXMOX_URL=https://X.X.X.X:8006/api2/json
126+
export PROXMOX_PASSWORD=password
127+
export PROXMOX_USER=user@pam
128+
129+
make e2e
130+
```
131+
121132
## Contributing
122133

123134
Are you interested in contributing to cluster-api-provider-proxmox? Do not hesitate to open GitHub issues.

cloud/scope/machine.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,11 @@ func (m *MachineScope) SetInstanceStatus(v infrav1.InstanceStatus) {
140140
}
141141

142142
func (m *MachineScope) GetBiosUUID() *string {
143-
parsed, err := noderefutil.NewProviderID(m.GetProviderID())
143+
parsed, err := noderefutil.NewProviderID(m.GetProviderID()) //nolint: staticcheck
144144
if err != nil {
145145
return nil
146146
}
147-
return pointer.String(parsed.ID())
147+
return pointer.String(parsed.ID()) //nolint: staticcheck
148148
}
149149

150150
func (m *MachineScope) GetProviderID() string {

go.mod

Lines changed: 74 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,71 +9,121 @@ require (
99
github.com/pkg/errors v0.9.1
1010
github.com/sp-yduck/proxmox-go v0.0.0-20230807140547-f03780ca1110
1111
gopkg.in/yaml.v3 v3.0.1
12-
k8s.io/api v0.26.1
13-
k8s.io/apimachinery v0.26.1
14-
k8s.io/client-go v0.26.1
15-
k8s.io/utils v0.0.0-20221128185143-99ec85e7a448
16-
sigs.k8s.io/cluster-api v1.4.1
17-
sigs.k8s.io/controller-runtime v0.14.5
12+
k8s.io/api v0.27.2
13+
k8s.io/apimachinery v0.27.2
14+
k8s.io/client-go v0.27.2
15+
k8s.io/utils v0.0.0-20230209194617-a36077c30491
16+
sigs.k8s.io/cluster-api v1.5.2
17+
sigs.k8s.io/cluster-api/test v1.5.2
18+
sigs.k8s.io/controller-runtime v0.15.1
1819
)
1920

2021
require (
22+
github.com/BurntSushi/toml v1.0.0 // indirect
23+
github.com/MakeNowJust/heredoc v1.0.0 // indirect
24+
github.com/Masterminds/goutils v1.1.1 // indirect
25+
github.com/Masterminds/semver/v3 v3.2.0 // indirect
26+
github.com/Masterminds/sprig/v3 v3.2.3 // indirect
27+
github.com/Microsoft/go-winio v0.5.0 // indirect
28+
github.com/adrg/xdg v0.4.0 // indirect
29+
github.com/alessio/shellescape v1.4.1 // indirect
30+
github.com/antlr/antlr4/runtime/Go/antlr v1.4.10 // indirect
31+
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a // indirect
2132
github.com/beorn7/perks v1.0.1 // indirect
2233
github.com/blang/semver v3.5.1+incompatible // indirect
34+
github.com/blang/semver/v4 v4.0.0 // indirect
2335
github.com/cespare/xxhash/v2 v2.2.0 // indirect
36+
github.com/coredns/caddy v1.1.0 // indirect
37+
github.com/coredns/corefile-migration v1.0.21 // indirect
2438
github.com/davecgh/go-spew v1.1.1 // indirect
25-
github.com/emicklei/go-restful/v3 v3.9.0 // indirect
39+
github.com/docker/distribution v2.8.2+incompatible // indirect
40+
github.com/docker/docker v24.0.5+incompatible // indirect
41+
github.com/docker/go-connections v0.4.0 // indirect
42+
github.com/docker/go-units v0.4.0 // indirect
43+
github.com/drone/envsubst/v2 v2.0.0-20210730161058-179042472c46 // indirect
44+
github.com/emicklei/go-restful/v3 v3.10.2 // indirect
45+
github.com/evanphx/json-patch v5.6.0+incompatible // indirect
2646
github.com/evanphx/json-patch/v5 v5.6.0 // indirect
2747
github.com/fsnotify/fsnotify v1.6.0 // indirect
2848
github.com/go-logr/logr v1.2.4 // indirect
29-
github.com/go-logr/zapr v1.2.3 // indirect
30-
github.com/go-openapi/jsonpointer v0.19.5 // indirect
31-
github.com/go-openapi/jsonreference v0.20.0 // indirect
49+
github.com/go-logr/zapr v1.2.4 // indirect
50+
github.com/go-openapi/jsonpointer v0.19.6 // indirect
51+
github.com/go-openapi/jsonreference v0.20.1 // indirect
3252
github.com/go-openapi/swag v0.22.3 // indirect
3353
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect
3454
github.com/gobuffalo/flect v1.0.2 // indirect
3555
github.com/gogo/protobuf v1.3.2 // indirect
3656
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
3757
github.com/golang/protobuf v1.5.3 // indirect
58+
github.com/google/cel-go v0.12.6 // indirect
3859
github.com/google/gnostic v0.6.9 // indirect
3960
github.com/google/go-cmp v0.5.9 // indirect
61+
github.com/google/go-github/v48 v48.2.0 // indirect
62+
github.com/google/go-querystring v1.1.0 // indirect
4063
github.com/google/gofuzz v1.2.0 // indirect
4164
github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 // indirect
65+
github.com/google/safetext v0.0.0-20220905092116-b49f7bc46da2 // indirect
4266
github.com/google/uuid v1.3.0 // indirect
4367
github.com/gorilla/websocket v1.5.0 // indirect
68+
github.com/hashicorp/hcl v1.0.0 // indirect
69+
github.com/huandu/xstrings v1.3.3 // indirect
70+
github.com/inconshreveable/mousetrap v1.1.0 // indirect
4471
github.com/josharian/intern v1.0.0 // indirect
4572
github.com/json-iterator/go v1.1.12 // indirect
73+
github.com/magiconair/properties v1.8.7 // indirect
4674
github.com/mailru/easyjson v0.7.7 // indirect
47-
github.com/matttproud/golang_protobuf_extensions v1.0.2 // indirect
75+
github.com/mattn/go-isatty v0.0.17 // indirect
76+
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
77+
github.com/mitchellh/copystructure v1.2.0 // indirect
78+
github.com/mitchellh/mapstructure v1.5.0 // indirect
79+
github.com/mitchellh/reflectwalk v1.0.2 // indirect
4880
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
4981
github.com/modern-go/reflect2 v1.0.2 // indirect
5082
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
51-
github.com/prometheus/client_golang v1.14.0 // indirect
52-
github.com/prometheus/client_model v0.3.0 // indirect
53-
github.com/prometheus/common v0.37.0 // indirect
54-
github.com/prometheus/procfs v0.8.0 // indirect
83+
github.com/opencontainers/go-digest v1.0.0 // indirect
84+
github.com/opencontainers/image-spec v1.0.2 // indirect
85+
github.com/pelletier/go-toml v1.9.5 // indirect
86+
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
87+
github.com/prometheus/client_golang v1.16.0 // indirect
88+
github.com/prometheus/client_model v0.4.0 // indirect
89+
github.com/prometheus/common v0.42.0 // indirect
90+
github.com/prometheus/procfs v0.10.1 // indirect
91+
github.com/shopspring/decimal v1.3.1 // indirect
92+
github.com/spf13/afero v1.9.5 // indirect
93+
github.com/spf13/cast v1.5.1 // indirect
94+
github.com/spf13/cobra v1.7.0 // indirect
95+
github.com/spf13/jwalterweatherman v1.1.0 // indirect
5596
github.com/spf13/pflag v1.0.5 // indirect
97+
github.com/spf13/viper v1.16.0 // indirect
98+
github.com/stoewer/go-strcase v1.2.0 // indirect
99+
github.com/subosito/gotenv v1.4.2 // indirect
100+
github.com/valyala/fastjson v1.6.4 // indirect
56101
go.uber.org/atomic v1.9.0 // indirect
57102
go.uber.org/multierr v1.8.0 // indirect
58103
go.uber.org/zap v1.24.0 // indirect
104+
golang.org/x/crypto v0.12.0 // indirect
59105
golang.org/x/net v0.14.0 // indirect
60-
golang.org/x/oauth2 v0.6.0 // indirect
106+
golang.org/x/oauth2 v0.10.0 // indirect
61107
golang.org/x/sys v0.12.0 // indirect
62108
golang.org/x/term v0.11.0 // indirect
63109
golang.org/x/text v0.12.0 // indirect
64110
golang.org/x/time v0.3.0 // indirect
65111
golang.org/x/tools v0.12.0 // indirect
66-
gomodules.xyz/jsonpatch/v2 v2.2.0 // indirect
112+
gomodules.xyz/jsonpatch/v2 v2.3.0 // indirect
67113
google.golang.org/appengine v1.6.7 // indirect
68-
google.golang.org/genproto v0.0.0-20230303212802-e74f57abe488 // indirect
69-
google.golang.org/protobuf v1.28.1 // indirect
114+
google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 // indirect
115+
google.golang.org/protobuf v1.31.0 // indirect
70116
gopkg.in/inf.v0 v0.9.1 // indirect
117+
gopkg.in/ini.v1 v1.67.0 // indirect
71118
gopkg.in/yaml.v2 v2.4.0 // indirect
72-
k8s.io/apiextensions-apiserver v0.26.1 // indirect
73-
k8s.io/component-base v0.26.1 // indirect
74-
k8s.io/klog/v2 v2.80.1 // indirect
75-
k8s.io/kube-openapi v0.0.0-20221012153701-172d655c2280 // indirect
76-
sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2 // indirect
119+
k8s.io/apiextensions-apiserver v0.27.2 // indirect
120+
k8s.io/apiserver v0.27.2 // indirect
121+
k8s.io/cluster-bootstrap v0.27.2 // indirect
122+
k8s.io/component-base v0.27.2 // indirect
123+
k8s.io/klog/v2 v2.90.1 // indirect
124+
k8s.io/kube-openapi v0.0.0-20230501164219-8b0f38b5fd1f // indirect
125+
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
126+
sigs.k8s.io/kind v0.20.0 // indirect
77127
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
78128
sigs.k8s.io/yaml v1.3.0 // indirect
79129
)

0 commit comments

Comments
 (0)