Skip to content

Commit 34a9d38

Browse files
authored
Merge pull request #359 from Fedosin/delete_crds_e2e_tests
🐛 Delete all Cluster API CRDs before running air-gapped tests
2 parents b435490 + 9c71f37 commit 34a9d38

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

test/e2e/air_gapped_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ import (
3737

3838
var _ = Describe("Install Core Provider in an air-gapped environment", func() {
3939
It("should successfully create config maps with Core Provider manifests", func() {
40+
// Ensure that there are no Cluster API installed
41+
deleteClusterAPICRDs(bootstrapClusterProxy)
42+
4043
bootstrapCluster := bootstrapClusterProxy.GetClient()
4144
configMaps := []corev1.ConfigMap{}
4245

test/e2e/e2e_suite_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@ import (
3030
. "github.com/onsi/ginkgo/v2"
3131
. "github.com/onsi/gomega"
3232
appsv1 "k8s.io/api/apps/v1"
33+
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
3334
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3435

36+
"k8s.io/apimachinery/pkg/labels"
3537
"k8s.io/apimachinery/pkg/runtime"
3638
"k8s.io/klog/v2"
3739
operatorv1alpha1 "sigs.k8s.io/cluster-api-operator/api/v1alpha1"
@@ -42,6 +44,7 @@ import (
4244
"sigs.k8s.io/cluster-api/test/framework/bootstrap"
4345
"sigs.k8s.io/cluster-api/test/framework/clusterctl"
4446
ctrl "sigs.k8s.io/controller-runtime"
47+
"sigs.k8s.io/controller-runtime/pkg/client"
4548
"sigs.k8s.io/yaml"
4649
)
4750

@@ -334,6 +337,25 @@ func ensureCertManager(clusterProxy framework.ClusterProxy, config *clusterctl.E
334337
})
335338
}
336339

340+
func deleteClusterAPICRDs(clusterProxy framework.ClusterProxy) {
341+
// To get all Cluster API CRDs we need filter them by labels:
342+
// cluster.x-k8s.io/provider: cluster-api
343+
// clusterctl.cluster.x-k8s.io: ""
344+
crds := &apiextensionsv1.CustomResourceDefinitionList{}
345+
Expect(clusterProxy.GetClient().List(ctx, crds, &client.ListOptions{
346+
LabelSelector: labels.SelectorFromSet(
347+
map[string]string{
348+
"cluster.x-k8s.io/provider": "cluster-api",
349+
"clusterctl.cluster.x-k8s.io": "",
350+
},
351+
),
352+
})).To(Succeed())
353+
354+
for _, crd := range crds.Items {
355+
Expect(clusterProxy.GetClient().Delete(ctx, &crd)).To(Succeed())
356+
}
357+
}
358+
337359
func initHelmChart() {
338360
helmChart = &HelmChart{
339361
BinaryPath: helmBinaryPath,

test/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ require (
99
github.com/onsi/gomega v1.30.0
1010
golang.org/x/tools v0.14.0
1111
k8s.io/api v0.28.4
12+
k8s.io/apiextensions-apiserver v0.28.4
1213
k8s.io/apimachinery v0.28.4
1314
k8s.io/klog/v2 v2.100.1
1415
k8s.io/utils v0.0.0-20230726121419-3b25d923346b
@@ -121,7 +122,6 @@ require (
121122
gopkg.in/ini.v1 v1.67.0 // indirect
122123
gopkg.in/yaml.v2 v2.4.0 // indirect
123124
gopkg.in/yaml.v3 v3.0.1 // indirect
124-
k8s.io/apiextensions-apiserver v0.28.4 // indirect
125125
k8s.io/apiserver v0.28.4 // indirect
126126
k8s.io/client-go v0.28.4 // indirect
127127
k8s.io/cluster-bootstrap v0.28.4 // indirect

0 commit comments

Comments
 (0)