diff --git a/test/e2e/e2e_suite_test.go b/test/e2e/e2e_suite_test.go index 0f2bfdf..d4e553f 100644 --- a/test/e2e/e2e_suite_test.go +++ b/test/e2e/e2e_suite_test.go @@ -33,6 +33,7 @@ import ( internalClient "github.com/cloudnative-pg/plugin-barman-cloud/test/e2e/internal/client" "github.com/cloudnative-pg/plugin-barman-cloud/test/e2e/internal/deployment" + "github.com/cloudnative-pg/plugin-barman-cloud/test/e2e/internal/diagnostics" "github.com/cloudnative-pg/plugin-barman-cloud/test/e2e/internal/e2etestenv" "github.com/cloudnative-pg/plugin-barman-cloud/test/e2e/internal/kustomize" @@ -131,6 +132,28 @@ var _ = SynchronizedBeforeSuite(func(ctx SpecContext) []byte { logFlags.ConfigureLogging() }) +// The ephemeral cluster the suite runs against is torn down right after this +// process exits, so this is the only chance to capture the CloudNativePG +// operator and barman-cloud plugin logs for a failed run. +var _ = ReportAfterSuite("dump cnpg-system diagnostics on failure", func(report Report) { + if report.SuiteSucceeded { + return + } + + cl, _, err := internalClient.NewClient() + if err != nil { + _, _ = fmt.Fprintf(GinkgoWriter, "failed to create Kubernetes client for diagnostics: %v\n", err) + return + } + clientSet, _, err := internalClient.NewClientSet() + if err != nil { + _, _ = fmt.Fprintf(GinkgoWriter, "failed to create Kubernetes clientset for diagnostics: %v\n", err) + return + } + + diagnostics.DumpOperatorNamespace(context.Background(), cl, clientSet, "cnpg-system") +}) + // Run e2e tests using the Ginkgo runner. func TestE2E(t *testing.T) { RegisterFailHandler(Fail) diff --git a/test/e2e/internal/tests/backup/backup_restore.go b/test/e2e/internal/tests/backup/backup_restore.go index 09892d0..ff8aaa4 100644 --- a/test/e2e/internal/tests/backup/backup_restore.go +++ b/test/e2e/internal/tests/backup/backup_restore.go @@ -26,11 +26,13 @@ import ( v1 "github.com/cloudnative-pg/api/pkg/api/v1" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/types" + "k8s.io/client-go/kubernetes" "sigs.k8s.io/controller-runtime/pkg/client" internalClient "github.com/cloudnative-pg/plugin-barman-cloud/test/e2e/internal/client" internalCluster "github.com/cloudnative-pg/plugin-barman-cloud/test/e2e/internal/cluster" "github.com/cloudnative-pg/plugin-barman-cloud/test/e2e/internal/command" + "github.com/cloudnative-pg/plugin-barman-cloud/test/e2e/internal/diagnostics" nmsp "github.com/cloudnative-pg/plugin-barman-cloud/test/e2e/internal/namespace" . "github.com/onsi/ginkgo/v2" @@ -40,14 +42,18 @@ import ( var _ = Describe("Backup and restore", func() { var namespace *corev1.Namespace var cl client.Client + var diagClientSet *kubernetes.Clientset BeforeEach(func(ctx SpecContext) { var err error cl, _, err = internalClient.NewClient() Expect(err).NotTo(HaveOccurred()) + diagClientSet, _, err = internalClient.NewClientSet() + Expect(err).NotTo(HaveOccurred()) namespace, err = nmsp.CreateUniqueNamespace(ctx, cl, "backup-restore") Expect(err).NotTo(HaveOccurred()) }) AfterEach(func(ctx SpecContext) { + diagnostics.DumpNamespace(ctx, cl, diagClientSet, namespace.Name) Expect(cl.Delete(ctx, namespace)).To(Succeed()) }) diff --git a/test/e2e/internal/tests/credentialrotation/credential_rotation.go b/test/e2e/internal/tests/credentialrotation/credential_rotation.go index f530259..a920561 100644 --- a/test/e2e/internal/tests/credentialrotation/credential_rotation.go +++ b/test/e2e/internal/tests/credentialrotation/credential_rotation.go @@ -27,6 +27,7 @@ import ( rbacv1 "k8s.io/api/rbac/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" + "k8s.io/client-go/kubernetes" "k8s.io/utils/ptr" "sigs.k8s.io/controller-runtime/pkg/client" @@ -34,6 +35,7 @@ import ( "github.com/cloudnative-pg/plugin-barman-cloud/internal/cnpgi/operator/specs" internalClient "github.com/cloudnative-pg/plugin-barman-cloud/test/e2e/internal/client" internalCluster "github.com/cloudnative-pg/plugin-barman-cloud/test/e2e/internal/cluster" + "github.com/cloudnative-pg/plugin-barman-cloud/test/e2e/internal/diagnostics" nmsp "github.com/cloudnative-pg/plugin-barman-cloud/test/e2e/internal/namespace" "github.com/cloudnative-pg/plugin-barman-cloud/test/e2e/internal/objectstore" @@ -51,16 +53,20 @@ const ( var _ = Describe("Credential rotation", func() { var namespace *corev1.Namespace var cl client.Client + var diagClientSet *kubernetes.Clientset BeforeEach(func(ctx SpecContext) { var err error cl, _, err = internalClient.NewClient() Expect(err).NotTo(HaveOccurred()) + diagClientSet, _, err = internalClient.NewClientSet() + Expect(err).NotTo(HaveOccurred()) namespace, err = nmsp.CreateUniqueNamespace(ctx, cl, "cred-rotation") Expect(err).NotTo(HaveOccurred()) }) AfterEach(func(ctx SpecContext) { + diagnostics.DumpNamespace(ctx, cl, diagClientSet, namespace.Name) Expect(cl.Delete(ctx, namespace)).To(Succeed()) }) diff --git a/test/e2e/internal/tests/replicacluster/replica_cluster.go b/test/e2e/internal/tests/replicacluster/replica_cluster.go index 8888334..f33208c 100644 --- a/test/e2e/internal/tests/replicacluster/replica_cluster.go +++ b/test/e2e/internal/tests/replicacluster/replica_cluster.go @@ -27,12 +27,14 @@ import ( cloudnativepgv1 "github.com/cloudnative-pg/api/pkg/api/v1" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/types" + "k8s.io/client-go/kubernetes" "k8s.io/utils/ptr" "sigs.k8s.io/controller-runtime/pkg/client" internalClient "github.com/cloudnative-pg/plugin-barman-cloud/test/e2e/internal/client" cluster2 "github.com/cloudnative-pg/plugin-barman-cloud/test/e2e/internal/cluster" "github.com/cloudnative-pg/plugin-barman-cloud/test/e2e/internal/command" + "github.com/cloudnative-pg/plugin-barman-cloud/test/e2e/internal/diagnostics" nmsp "github.com/cloudnative-pg/plugin-barman-cloud/test/e2e/internal/namespace" . "github.com/onsi/ginkgo/v2" @@ -42,14 +44,18 @@ import ( var _ = Describe("Replica cluster", func() { var namespace *corev1.Namespace var cl client.Client + var diagClientSet *kubernetes.Clientset BeforeEach(func(ctx SpecContext) { var err error cl, _, err = internalClient.NewClient() Expect(err).NotTo(HaveOccurred()) + diagClientSet, _, err = internalClient.NewClientSet() + Expect(err).NotTo(HaveOccurred()) namespace, err = nmsp.CreateUniqueNamespace(ctx, cl, "replica-cluster") Expect(err).NotTo(HaveOccurred()) }) AfterEach(func(ctx SpecContext) { + diagnostics.DumpNamespace(ctx, cl, diagClientSet, namespace.Name) Expect(cl.Delete(ctx, namespace)).To(Succeed()) }) DescribeTable("can switchover to a replica cluster", diff --git a/test/e2e/internal/tests/walrestore/walrestore.go b/test/e2e/internal/tests/walrestore/walrestore.go index 287748f..e4b4e94 100644 --- a/test/e2e/internal/tests/walrestore/walrestore.go +++ b/test/e2e/internal/tests/walrestore/walrestore.go @@ -38,6 +38,7 @@ import ( internalCluster "github.com/cloudnative-pg/plugin-barman-cloud/test/e2e/internal/cluster" "github.com/cloudnative-pg/plugin-barman-cloud/test/e2e/internal/command" "github.com/cloudnative-pg/plugin-barman-cloud/test/e2e/internal/deployment" + "github.com/cloudnative-pg/plugin-barman-cloud/test/e2e/internal/diagnostics" nmsp "github.com/cloudnative-pg/plugin-barman-cloud/test/e2e/internal/namespace" . "github.com/onsi/ginkgo/v2" @@ -128,6 +129,7 @@ var _ = Describe("Parallel WAL restore", func() { }) AfterEach(func(ctx SpecContext) { + diagnostics.DumpNamespace(ctx, cl, clientSet, namespace.Name) Expect(cl.Delete(ctx, namespace)).To(Succeed()) })