diff --git a/test/e2e/air_gapped_test.go b/test/e2e/air_gapped_test.go index 8168287e0..20a63d1f3 100644 --- a/test/e2e/air_gapped_test.go +++ b/test/e2e/air_gapped_test.go @@ -37,6 +37,9 @@ import ( var _ = Describe("Install Core Provider in an air-gapped environment", func() { It("should successfully create config maps with Core Provider manifests", func() { + // Ensure that there are no Cluster API installed + deleteClusterAPICRDs(bootstrapClusterProxy) + bootstrapCluster := bootstrapClusterProxy.GetClient() configMaps := []corev1.ConfigMap{} diff --git a/test/e2e/e2e_suite_test.go b/test/e2e/e2e_suite_test.go index c6aa0b2b5..8fd778ba9 100644 --- a/test/e2e/e2e_suite_test.go +++ b/test/e2e/e2e_suite_test.go @@ -30,8 +30,10 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" appsv1 "k8s.io/api/apps/v1" + apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/runtime" "k8s.io/klog/v2" operatorv1alpha1 "sigs.k8s.io/cluster-api-operator/api/v1alpha1" @@ -42,6 +44,7 @@ import ( "sigs.k8s.io/cluster-api/test/framework/bootstrap" "sigs.k8s.io/cluster-api/test/framework/clusterctl" ctrl "sigs.k8s.io/controller-runtime" + "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/yaml" ) @@ -334,6 +337,25 @@ func ensureCertManager(clusterProxy framework.ClusterProxy, config *clusterctl.E }) } +func deleteClusterAPICRDs(clusterProxy framework.ClusterProxy) { + // To get all Cluster API CRDs we need filter them by labels: + // cluster.x-k8s.io/provider: cluster-api + // clusterctl.cluster.x-k8s.io: "" + crds := &apiextensionsv1.CustomResourceDefinitionList{} + Expect(clusterProxy.GetClient().List(ctx, crds, &client.ListOptions{ + LabelSelector: labels.SelectorFromSet( + map[string]string{ + "cluster.x-k8s.io/provider": "cluster-api", + "clusterctl.cluster.x-k8s.io": "", + }, + ), + })).To(Succeed()) + + for _, crd := range crds.Items { + Expect(clusterProxy.GetClient().Delete(ctx, &crd)).To(Succeed()) + } +} + func initHelmChart() { helmChart = &HelmChart{ BinaryPath: helmBinaryPath, diff --git a/test/go.mod b/test/go.mod index 0c6c53f12..be10ed7f8 100644 --- a/test/go.mod +++ b/test/go.mod @@ -9,6 +9,7 @@ require ( github.com/onsi/gomega v1.30.0 golang.org/x/tools v0.14.0 k8s.io/api v0.28.4 + k8s.io/apiextensions-apiserver v0.28.4 k8s.io/apimachinery v0.28.4 k8s.io/klog/v2 v2.100.1 k8s.io/utils v0.0.0-20230726121419-3b25d923346b @@ -121,7 +122,6 @@ require ( gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect - k8s.io/apiextensions-apiserver v0.28.4 // indirect k8s.io/apiserver v0.28.4 // indirect k8s.io/client-go v0.28.4 // indirect k8s.io/cluster-bootstrap v0.28.4 // indirect