@@ -18,13 +18,15 @@ package k8sclient_test
18
18
19
19
import (
20
20
"context"
21
+ "fmt"
21
22
"go/build"
22
23
"path/filepath"
23
24
"testing"
24
25
25
26
"github.com/google/uuid"
26
27
. "github.com/onsi/ginkgo/v2"
27
28
. "github.com/onsi/gomega"
29
+ "golang.org/x/tools/go/packages"
28
30
corev1 "k8s.io/api/core/v1"
29
31
"k8s.io/client-go/kubernetes/scheme"
30
32
capa "sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2"
@@ -58,11 +60,18 @@ var _ = BeforeSuite(func() {
58
60
59
61
tests .GetEnvOrSkip ("KUBEBUILDER_ASSETS" )
60
62
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
+
61
70
By ("bootstrapping test environment" )
62
71
testEnv = & envtest.Environment {
63
72
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" ),
66
75
},
67
76
ErrorIfCRDPathMissing : true ,
68
77
}
0 commit comments