Skip to content

Commit

Permalink
Merge pull request #359 from Fedosin/delete_crds_e2e_tests
Browse files Browse the repository at this point in the history
🐛 Delete all Cluster API CRDs before running air-gapped tests
  • Loading branch information
k8s-ci-robot authored Dec 16, 2023
2 parents b435490 + 9c71f37 commit 34a9d38
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
3 changes: 3 additions & 0 deletions test/e2e/air_gapped_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}

Expand Down
22 changes: 22 additions & 0 deletions test/e2e/e2e_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
)

Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion test/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 34a9d38

Please sign in to comment.