Skip to content

Commit

Permalink
Ensure always deletion occurs in AfterEach
Browse files Browse the repository at this point in the history
Signed-off-by: Kyle Squizzato <[email protected]>
  • Loading branch information
squizzi committed Oct 4, 2024
1 parent 6f8a2b4 commit 821c51f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 22 deletions.
9 changes: 8 additions & 1 deletion test/e2e/kubeclient/kubeclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package kubeclient

import (
"context"
"errors"
"fmt"
"os"
"path/filepath"
Expand Down Expand Up @@ -75,7 +76,13 @@ func (kc *KubeClient) WriteKubeconfig(ctx context.Context, clusterName string) (
To(Succeed())

deleteFunc := func() error {
return os.Remove(filepath.Join(dir, path))
if err = os.Remove(filepath.Join(dir, path)); err != nil {
if errors.Is(err, os.ErrNotExist) {
return nil
}
return err
}
return nil
}

return path, deleteFunc
Expand Down
21 changes: 10 additions & 11 deletions test/e2e/provider_aws_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,17 @@ var _ = Describe("AWS Templates", Label("provider:cloud", "provider:aws"), Order
By("collecting failure logs from hosted controllers")
collectLogArtifacts(standaloneClient, clusterName, managedcluster.ProviderAWS, managedcluster.ProviderCAPI)
}
}

By("deleting resources after failure")
for _, deleteFunc := range []func() error{
kubecfgDeleteFunc,
hostedDeleteFunc,
standaloneDeleteFunc,
} {
if deleteFunc != nil {
err := deleteFunc()
Expect(err).NotTo(HaveOccurred())
}
By("deleting resources")
for _, deleteFunc := range []func() error{
kubecfgDeleteFunc,
hostedDeleteFunc,
standaloneDeleteFunc,
} {
if deleteFunc != nil {
err := deleteFunc()
Expect(err).NotTo(HaveOccurred())
}
}
})
Expand Down Expand Up @@ -165,7 +165,6 @@ var _ = Describe("AWS Templates", Label("provider:cloud", "provider:aws"), Order
Eventually(func() error {
return deletionValidator.Validate(context.Background(), standaloneClient)
}).WithTimeout(10 * time.Minute).WithPolling(10 * time.Second).Should(Succeed())

// Now delete the standalone ManagedCluster and verify it is
// removed, it is deleted last since it is the basis for the hosted
// cluster.
Expand Down
21 changes: 11 additions & 10 deletions test/e2e/provider_azure_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,18 @@ var _ = Context("Azure Templates", Label("provider:cloud", "provider:azure"), Or
if standaloneClient != nil {
collectLogArtifacts(standaloneClient, sdName, managedcluster.ProviderAzure, managedcluster.ProviderCAPI)
}
}

By("deleting resources after failure")
for _, deleteFunc := range []func() error{
kubecfgDeleteFunc,
hostedDeleteFunc,
standaloneDeleteFunc,
} {
if deleteFunc != nil {
err := deleteFunc()
Expect(err).NotTo(HaveOccurred())
}
By("deleting resources")
for _, deleteFunc := range []func() error{
hostedKubecfgDeleteFunc,
kubecfgDeleteFunc,
hostedDeleteFunc,
standaloneDeleteFunc,
} {
if deleteFunc != nil {
err := deleteFunc()
Expect(err).NotTo(HaveOccurred())
}
}
})
Expand Down

0 comments on commit 821c51f

Please sign in to comment.