Skip to content

Commit bd34ed7

Browse files
authored
Dynamically calculate CAPI and CAPA versions to install CRDs from the right paths (#219)
1 parent eaddec6 commit bd34ed7

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Changed
11+
12+
- Dynamically calculate CAPI and CAPA versions from go cache, so that we use the right path when installing the CRDs during tests.
13+
1014
## [0.17.0] - 2024-09-30
1115

1216
### Changed

controllers/controllers_suite_test.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
. "github.com/onsi/ginkgo/v2"
3030
. "github.com/onsi/gomega"
3131
"go.uber.org/zap/zapcore"
32+
"golang.org/x/tools/go/packages"
3233
corev1 "k8s.io/api/core/v1"
3334
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3435
"k8s.io/kubectl/pkg/scheme"
@@ -72,11 +73,18 @@ var _ = BeforeSuite(func() {
7273

7374
tests.GetEnvOrSkip("KUBEBUILDER_ASSETS")
7475

76+
// We need to calculate the cluster-api version to load the CRDs from the right path
77+
capiModule, err := packages.Load(&packages.Config{Mode: packages.NeedModule}, "sigs.k8s.io/cluster-api")
78+
Expect(err).NotTo(HaveOccurred())
79+
// We need to calculate the cluster-api-provider-aws version to load the CRDs from the right path
80+
capaModule, err := packages.Load(&packages.Config{Mode: packages.NeedModule}, "sigs.k8s.io/cluster-api-provider-aws/v2")
81+
Expect(err).NotTo(HaveOccurred())
82+
7583
By("bootstrapping test environment")
7684
testEnv = &envtest.Environment{
7785
CRDDirectoryPaths: []string{
78-
filepath.Join(build.Default.GOPATH, "pkg", "mod", "sigs.k8s.io", "cluster-api@v1.8.3", "config", "crd", "bases"),
79-
filepath.Join(build.Default.GOPATH, "pkg", "mod", "sigs.k8s.io", "cluster-api-provider-aws", "v2@v2.6.1", "config", "crd", "bases"),
86+
filepath.Join(build.Default.GOPATH, "pkg", "mod", "sigs.k8s.io", fmt.Sprintf("cluster-api@%s", capiModule[0].Module.Version), "config", "crd", "bases"),
87+
filepath.Join(build.Default.GOPATH, "pkg", "mod", "sigs.k8s.io", "cluster-api-provider-aws", fmt.Sprintf("v2@%s", capaModule[0].Module.Version), "config", "crd", "bases"),
8088
},
8189
ErrorIfCRDPathMissing: true,
8290
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ require (
1717
github.com/pkg/errors v0.9.1
1818
github.com/prometheus/client_golang v1.20.4
1919
go.uber.org/zap v1.27.0
20+
golang.org/x/tools v0.24.0
2021
k8s.io/api v0.31.0
2122
k8s.io/apimachinery v0.31.0
2223
k8s.io/client-go v0.31.0
@@ -75,7 +76,6 @@ require (
7576
golang.org/x/term v0.23.0 // indirect
7677
golang.org/x/text v0.17.0 // indirect
7778
golang.org/x/time v0.5.0 // indirect
78-
golang.org/x/tools v0.24.0 // indirect
7979
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
8080
google.golang.org/protobuf v1.34.2 // indirect
8181
gopkg.in/inf.v0 v0.9.1 // indirect

0 commit comments

Comments
 (0)