@@ -135,6 +135,7 @@ func (e2e *E2ECluster) SetupMetalStackPreconditions(ctx context.Context) {
135135}
136136
137137func (e2e * E2ECluster ) Teardown (ctx context.Context ) {
138+ e2e .teardownAddons (ctx )
138139 e2e .teardownCluster (ctx )
139140 e2e .teardownControlPlaneIP (ctx )
140141 e2e .teardownFirewall (ctx )
@@ -317,7 +318,6 @@ func (e2e *E2ECluster) GenerateAndApplyClusterTemplate(ctx context.Context) {
317318 Flavor : e2e .E2EContext .Environment .Flavor ,
318319 LogFolder : path .Join (e2e .E2EContext .Environment .artifactsPath , "clusters" , e2e .ClusterName ),
319320 ClusterctlVariables : e2e .Variables (),
320- InfrastructureProvider : "metal-stack:v0.6.2" ,
321321 })
322322
323323 By ("Apply cluster template" )
@@ -341,54 +341,75 @@ func (e2e *E2ECluster) GenerateAndApplyClusterTemplate(ctx context.Context) {
341341 Expect (e2e .Refs .Cluster ).NotTo (BeNil (), "failed to get cluster" )
342342}
343343
344- func (e2e * E2ECluster ) teardownCluster (ctx context.Context ) {
345- if e2e .Refs .Cluster == nil {
346- return
347- }
348- Expect (e2e .Refs .Cluster ).NotTo (BeNil (), "cluster not created yet" )
344+ func (e2e * E2ECluster ) teardownAddons (ctx context.Context ) {
345+ By ("Teardown Addons" )
349346
350- resources := framework .GetCAPIResources (ctx , framework.GetCAPIResourcesInput {
351- Lister : e2e .E2EContext .Environment .Bootstrap .GetClient (),
352- Namespace : e2e .NamespaceName ,
353- IncludeTypes : []metav1.TypeMeta {
354- {
355- Kind : "HelmReleaseProxy" ,
356- APIVersion : "addons.cluster.x-k8s.io/v1alpha1" ,
357- },
358- {
359- Kind : "HelmChartProxy" ,
360- APIVersion : "addons.cluster.x-k8s.io/v1alpha1" ,
361- },
362- {
363- Kind : "ClusterResourceSetBinding" ,
364- APIVersion : "addons.cluster.x-k8s.io/v1beta1" ,
365- },
366- {
367- Kind : "ClusterResourceSet" ,
368- APIVersion : "addons.cluster.x-k8s.io/v1beta1" ,
369- },
347+ includeTypes := []metav1.TypeMeta {
348+ {
349+ Kind : "HelmChartProxy" ,
350+ APIVersion : "addons.cluster.x-k8s.io/v1alpha1" ,
370351 },
371- })
352+ {
353+ Kind : "HelmReleaseProxy" ,
354+ APIVersion : "addons.cluster.x-k8s.io/v1alpha1" ,
355+ },
356+ {
357+ Kind : "ClusterResourceSet" ,
358+ APIVersion : "addons.cluster.x-k8s.io/v1beta1" ,
359+ },
360+ {
361+ Kind : "ClusterResourceSetBinding" ,
362+ APIVersion : "addons.cluster.x-k8s.io/v1beta1" ,
363+ },
364+ }
365+
366+ resources := []* unstructured.Unstructured {}
367+ for _ , typ := range includeTypes {
368+ typeList := new (unstructured.UnstructuredList )
369+ typeList .SetAPIVersion (typ .APIVersion )
370+ typeList .SetKind (typ .Kind )
371+
372+ if err := e2e .E2EContext .Environment .Bootstrap .GetClient ().List (ctx , typeList , client .InNamespace (e2e .NamespaceName )); err != nil {
373+ if apierrors .IsNotFound (err ) {
374+ continue
375+ }
376+ if apierrors .IsForbidden (err ) {
377+ fmt .Printf ("Warning: failed to list %s resources due to a rbac issue: %v" , typeList .GroupVersionKind (), err )
378+ continue
379+ }
380+ Fail (fmt .Sprintf ("failed to list %q resources: %v" , typeList .GroupVersionKind (), err ))
381+ }
382+ for i := range typeList .Items {
383+ obj := typeList .Items [i ]
384+ resources = append (resources , & obj )
385+ }
386+ }
372387
373388 for _ , r := range resources {
389+ By (fmt .Sprintf ("Deleting resource %s/%s of kind %s" , r .GetNamespace (), r .GetName (), r .GetObjectKind ().GroupVersionKind ().Kind ))
374390 err := e2e .E2EContext .Environment .Bootstrap .GetClient ().Delete (ctx , r )
375391 Expect (err ).To (Or (
376392 Not (HaveOccurred ()),
377393 Satisfy (apierrors .IsNotFound )),
378394 fmt .Sprintf ("failed to delete resource %s/%s of kind %s" , r .GetNamespace (), r .GetName (), r .GetObjectKind ().GroupVersionKind ().Kind ),
379395 )
380- }
381-
382- for _ , r := range resources {
383396 Eventually (func () bool {
397+ By (fmt .Sprintf ("Waiting for resource %s/%s of kind %s to be deleted" , r .GetNamespace (), r .GetName (), r .GetObjectKind ().GroupVersionKind ().Kind ))
384398 err := e2e .E2EContext .Environment .Bootstrap .GetClient ().Get (ctx , client .ObjectKeyFromObject (r ), r )
385399 return apierrors .IsNotFound (err )
386400 }, e2e .E2EContext .E2EConfig .GetIntervals ("default" , "wait-delete-resource" )... ).Should (BeTrue (),
387401 fmt .Sprintf ("resource %s/%s of kind %s still exists" , r .GetNamespace (), r .GetName (), r .GetObjectKind ().GroupVersionKind ().Kind ),
388402 )
389403 }
404+ }
405+
406+ func (e2e * E2ECluster ) teardownCluster (ctx context.Context ) {
407+ if e2e .Refs .Cluster == nil {
408+ return
409+ }
410+ Expect (e2e .Refs .Cluster ).NotTo (BeNil (), "cluster not created yet" )
390411
391- deleteClusterAndWait (ctx , framework.DeleteClusterAndWaitInput {
412+ capi_e2e_DeleteClusterAndWait (ctx , framework.DeleteClusterAndWaitInput {
392413 ClusterProxy : e2e .E2EContext .Environment .Bootstrap ,
393414 ClusterctlConfigPath : e2e .E2EContext .Environment .ClusterctlConfigPath ,
394415 ArtifactFolder : e2e .E2EContext .Environment .artifactsPath ,
@@ -430,9 +451,9 @@ func (ec *E2ECluster) Dump(ctx context.Context) {
430451 })
431452}
432453
433- // deleteClusterAndWait deletes a cluster object and waits for it to be gone.
454+ // capi_e2e_DeleteClusterAndWait deletes a cluster object and waits for it to be gone.
434455// TODO: remove once cluster expectation has been fixed in framework
435- func deleteClusterAndWait (ctx context.Context , input framework.DeleteClusterAndWaitInput , intervals ... any ) {
456+ func capi_e2e_DeleteClusterAndWait (ctx context.Context , input framework.DeleteClusterAndWaitInput , intervals ... any ) {
436457 var (
437458 retryableOperationInterval = 3 * time .Second
438459 // retryableOperationTimeout requires a higher value especially for self-hosted upgrades.
0 commit comments