Skip to content

Commit

Permalink
Dynamically calculate CAPI and CAPA versions to install CRDs from the…
Browse files Browse the repository at this point in the history
… right paths (#219)
  • Loading branch information
fiunchinho authored Oct 10, 2024
1 parent eaddec6 commit bd34ed7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed

- Dynamically calculate CAPI and CAPA versions from go cache, so that we use the right path when installing the CRDs during tests.

## [0.17.0] - 2024-09-30

### Changed
Expand Down
12 changes: 10 additions & 2 deletions controllers/controllers_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"go.uber.org/zap/zapcore"
"golang.org/x/tools/go/packages"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/kubectl/pkg/scheme"
Expand Down Expand Up @@ -72,11 +73,18 @@ var _ = BeforeSuite(func() {

tests.GetEnvOrSkip("KUBEBUILDER_ASSETS")

// We need to calculate the cluster-api version to load the CRDs from the right path
capiModule, err := packages.Load(&packages.Config{Mode: packages.NeedModule}, "sigs.k8s.io/cluster-api")
Expect(err).NotTo(HaveOccurred())
// We need to calculate the cluster-api-provider-aws version to load the CRDs from the right path
capaModule, err := packages.Load(&packages.Config{Mode: packages.NeedModule}, "sigs.k8s.io/cluster-api-provider-aws/v2")
Expect(err).NotTo(HaveOccurred())

By("bootstrapping test environment")
testEnv = &envtest.Environment{
CRDDirectoryPaths: []string{
filepath.Join(build.Default.GOPATH, "pkg", "mod", "sigs.k8s.io", "cluster-api@v1.8.3", "config", "crd", "bases"),
filepath.Join(build.Default.GOPATH, "pkg", "mod", "sigs.k8s.io", "cluster-api-provider-aws", "v2@v2.6.1", "config", "crd", "bases"),
filepath.Join(build.Default.GOPATH, "pkg", "mod", "sigs.k8s.io", fmt.Sprintf("cluster-api@%s", capiModule[0].Module.Version), "config", "crd", "bases"),
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"),
},
ErrorIfCRDPathMissing: true,
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ require (
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.20.4
go.uber.org/zap v1.27.0
golang.org/x/tools v0.24.0
k8s.io/api v0.31.0
k8s.io/apimachinery v0.31.0
k8s.io/client-go v0.31.0
Expand Down Expand Up @@ -75,7 +76,6 @@ require (
golang.org/x/term v0.23.0 // indirect
golang.org/x/text v0.17.0 // indirect
golang.org/x/time v0.5.0 // indirect
golang.org/x/tools v0.24.0 // indirect
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
google.golang.org/protobuf v1.34.2 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
Expand Down

0 comments on commit bd34ed7

Please sign in to comment.