Skip to content

Commit

Permalink
test(gatewayapi): cleanup resources manually after dumping debug info (
Browse files Browse the repository at this point in the history
…#11542)

cleanup resources manually after dumping debug info

Signed-off-by: Jay Chen <[email protected]>
  • Loading branch information
jijiechen committed Sep 25, 2024
1 parent 7112af4 commit 9c5165b
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions test/e2e_env/gatewayapi/conformance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,29 +51,32 @@ func TestConformance(t *testing.T) {
opts := cluster.GetKubectlOptions()

t.Cleanup(func() {
if t.Failed() {
var namespaces []string
clientset, err := k8s.GetKubernetesClientFromOptionsE(t, opts)
if err == nil {
if nsList, err := clientset.CoreV1().Namespaces().List(context.Background(),
metav1.ListOptions{
LabelSelector: fmt.Sprintf("%s=%s", metadata.KumaSidecarInjectionAnnotation, metadata.AnnotationEnabled),
}); err == nil {
for _, ns := range nsList.Items {
namespaces = append(namespaces, ns.Name)
}
var meshNamespaces []string
clientset, err := k8s.GetKubernetesClientFromOptionsE(t, opts)
if err == nil {
if nsList, err := clientset.CoreV1().Namespaces().List(context.Background(),
metav1.ListOptions{
LabelSelector: fmt.Sprintf("%s=%s", metadata.KumaSidecarInjectionAnnotation, metadata.AnnotationEnabled),
}); err == nil {
for _, ns := range nsList.Items {
meshNamespaces = append(meshNamespaces, ns.Name)
}
}
}

if len(namespaces) > 0 {
if t.Failed() {
if len(meshNamespaces) > 0 {
g.Expect(func() error { //nolint:unparam // we need this return type to be included in the Expect block
RegisterFailHandler(g.Fail)
DebugKube(cluster, "default", namespaces...)
DebugKube(cluster, "default", meshNamespaces...)
return nil
}()).To(Succeed())
}
}

for _, ns := range meshNamespaces {
g.Expect(cluster.DeleteNamespace(ns)).To(Succeed())
}
g.Expect(cluster.DeleteKuma()).To(Succeed())
g.Expect(cluster.DismissCluster()).To(Succeed())
})
Expand Down Expand Up @@ -106,7 +109,7 @@ func TestConformance(t *testing.T) {
RestConfig: clientConfig,
Clientset: clientset,
GatewayClassName: "kuma",
CleanupBaseResources: true,
CleanupBaseResources: false, // we want to collect details when test fails, so don't clean up here, we'll clean up resources by ourselves.
Debug: Config.Debug, // controls if request details should be printed to stdout
NamespaceLabels: map[string]string{
metadata.KumaSidecarInjectionAnnotation: metadata.AnnotationEnabled,
Expand Down

0 comments on commit 9c5165b

Please sign in to comment.