@@ -19,13 +19,16 @@ import (
1919 metalmodels "github.com/metal-stack/metal-go/api/models"
2020
2121 corev1 "k8s.io/api/core/v1"
22+ apierrors "k8s.io/apimachinery/pkg/api/errors"
23+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2224 "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
2325 "k8s.io/utils/ptr"
2426
2527 clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
2628 kubeadmvbootstrap1 "sigs.k8s.io/cluster-api/bootstrap/kubeadm/api/v1beta1"
2729 "sigs.k8s.io/cluster-api/test/framework"
2830 "sigs.k8s.io/cluster-api/test/framework/clusterctl"
31+ "sigs.k8s.io/controller-runtime/pkg/client"
2932
3033 capmsv1alpha1 "github.com/metal-stack/cluster-api-provider-metal-stack/api/v1alpha1"
3134)
@@ -310,10 +313,9 @@ func (e2e *E2ECluster) GenerateAndApplyClusterTemplate(ctx context.Context) {
310313 WorkerMachineCount : & e2e .WorkerMachineCount ,
311314 ClusterctlConfigPath : e2e .E2EContext .Environment .ClusterctlConfigPath ,
312315 Flavor : e2e .E2EContext .Environment .Flavor ,
313- // TODO: why does this not work with clusterctl.DefaultInfrastructureProvider?
314- InfrastructureProvider : "capms:v0.6.2" ,
315- LogFolder : path .Join (e2e .E2EContext .Environment .artifactsPath , "clusters" , e2e .ClusterName ),
316- ClusterctlVariables : e2e .Variables (),
316+ LogFolder : path .Join (e2e .E2EContext .Environment .artifactsPath , "clusters" , e2e .ClusterName ),
317+ ClusterctlVariables : e2e .Variables (),
318+ InfrastructureProvider : "metal-stack:v0.6.2" ,
317319 })
318320
319321 By ("Apply cluster template" )
@@ -343,6 +345,47 @@ func (e2e *E2ECluster) teardownCluster(ctx context.Context) {
343345 }
344346 Expect (e2e .Refs .Cluster ).NotTo (BeNil (), "cluster not created yet" )
345347
348+ resources := framework .GetCAPIResources (ctx , framework.GetCAPIResourcesInput {
349+ Lister : e2e .E2EContext .Environment .Bootstrap .GetClient (),
350+ Namespace : e2e .NamespaceName ,
351+ IncludeTypes : []metav1.TypeMeta {
352+ {
353+ Kind : "HelmReleaseProxy" ,
354+ APIVersion : "addons.cluster.x-k8s.io/v1alpha1" ,
355+ },
356+ {
357+ Kind : "HelmChartProxy" ,
358+ APIVersion : "addons.cluster.x-k8s.io/v1alpha1" ,
359+ },
360+ {
361+ Kind : "ClusterResourceSetBinding" ,
362+ APIVersion : "addons.cluster.x-k8s.io/v1beta1" ,
363+ },
364+ {
365+ Kind : "ClusterResourceSet" ,
366+ APIVersion : "addons.cluster.x-k8s.io/v1beta1" ,
367+ },
368+ },
369+ })
370+
371+ for _ , r := range resources {
372+ err := e2e .E2EContext .Environment .Bootstrap .GetClient ().Delete (ctx , r )
373+ Expect (err ).To (Or (
374+ Not (HaveOccurred ()),
375+ Satisfy (apierrors .IsNotFound )),
376+ fmt .Sprintf ("failed to delete resource %s/%s of kind %s" , r .GetNamespace (), r .GetName (), r .GetObjectKind ().GroupVersionKind ().Kind ),
377+ )
378+ }
379+
380+ for _ , r := range resources {
381+ Eventually (func () bool {
382+ err := e2e .E2EContext .Environment .Bootstrap .GetClient ().Get (ctx , client .ObjectKeyFromObject (r ), r )
383+ return apierrors .IsNotFound (err )
384+ }, e2e .E2EContext .E2EConfig .GetIntervals ("default" , "wait-delete-resource" )... ).Should (BeTrue (),
385+ fmt .Sprintf ("resource %s/%s of kind %s still exists" , r .GetNamespace (), r .GetName (), r .GetObjectKind ().GroupVersionKind ().Kind ),
386+ )
387+ }
388+
346389 deleteClusterAndWait (ctx , framework.DeleteClusterAndWaitInput {
347390 ClusterProxy : e2e .E2EContext .Environment .Bootstrap ,
348391 ClusterctlConfigPath : e2e .E2EContext .Environment .ClusterctlConfigPath ,
0 commit comments