Skip to content

Commit 19c8053

Browse files
authored
Fix dynamic calculation of CAPI and CAPA versions (#223)
1 parent ecf14be commit 19c8053

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

pkg/k8sclient/k8sclient_suite_test.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@ package k8sclient_test
1818

1919
import (
2020
"context"
21+
"fmt"
2122
"go/build"
2223
"path/filepath"
2324
"testing"
2425

2526
"github.com/google/uuid"
2627
. "github.com/onsi/ginkgo/v2"
2728
. "github.com/onsi/gomega"
29+
"golang.org/x/tools/go/packages"
2830
corev1 "k8s.io/api/core/v1"
2931
"k8s.io/client-go/kubernetes/scheme"
3032
capa "sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2"
@@ -58,11 +60,18 @@ var _ = BeforeSuite(func() {
5860

5961
tests.GetEnvOrSkip("KUBEBUILDER_ASSETS")
6062

63+
// We need to calculate the cluster-api version to load the CRDs from the right path
64+
capiModule, err := packages.Load(&packages.Config{Mode: packages.NeedModule}, "sigs.k8s.io/cluster-api")
65+
Expect(err).NotTo(HaveOccurred())
66+
// We need to calculate the cluster-api-provider-aws version to load the CRDs from the right path
67+
capaModule, err := packages.Load(&packages.Config{Mode: packages.NeedModule}, "sigs.k8s.io/cluster-api-provider-aws/v2")
68+
Expect(err).NotTo(HaveOccurred())
69+
6170
By("bootstrapping test environment")
6271
testEnv = &envtest.Environment{
6372
CRDDirectoryPaths: []string{
64-
filepath.Join(build.Default.GOPATH, "pkg", "mod", "sigs.k8s.io", "cluster-api@v1.8.3", "config", "crd", "bases"),
65-
filepath.Join(build.Default.GOPATH, "pkg", "mod", "sigs.k8s.io", "cluster-api-provider-aws", "v2@v2.6.1", "config", "crd", "bases"),
73+
filepath.Join(build.Default.GOPATH, "pkg", "mod", "sigs.k8s.io", fmt.Sprintf("cluster-api@%s", capiModule[0].Module.Version), "config", "crd", "bases"),
74+
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"),
6675
},
6776
ErrorIfCRDPathMissing: true,
6877
}

0 commit comments

Comments
 (0)