diff --git a/.github/renovate.json5 b/.github/renovate.json5 index 9fd89b679f..d7aa3dd264 100644 --- a/.github/renovate.json5 +++ b/.github/renovate.json5 @@ -8,7 +8,7 @@ "prConcurrentLimit": 5, // The branches renovate should target // PLEASE UPDATE THIS WHEN RELEASING. - "baseBranches": ["main","release-1.22", "release-1.23"], + "baseBranches": ["main","release-1.22", "release-1.23", "release-1.24"], "ignorePaths": ["docs/**", "releases/**", "contribute/**", "licenses/**", "pkg/versions/**"], "postUpdateOptions": ["gomodTidy"], "semanticCommits": "enabled", diff --git a/.github/workflows/backport.yml b/.github/workflows/backport.yml index de44ffb5d3..9660753a82 100644 --- a/.github/workflows/backport.yml +++ b/.github/workflows/backport.yml @@ -33,6 +33,7 @@ jobs: backport-requested :arrow_backward: release-1.22 release-1.23 + release-1.24 - name: Create comment uses: peter-evans/create-or-update-comment@v4 @@ -56,6 +57,7 @@ jobs: backport-requested :arrow_backward: release-1.22 release-1.23 + release-1.24 ## backport pull request in condition when pr contains 'backport-requested' label and contains target branches labels back-porting-pr: @@ -71,7 +73,7 @@ jobs: strategy: fail-fast: false matrix: - branch: [release-1.22, release-1.23] + branch: [release-1.22, release-1.23, release-1.24] env: PR: ${{ github.event.pull_request.number }} outputs: diff --git a/.github/workflows/continuous-delivery.yml b/.github/workflows/continuous-delivery.yml index 17647aee63..495cf2d660 100644 --- a/.github/workflows/continuous-delivery.yml +++ b/.github/workflows/continuous-delivery.yml @@ -69,7 +69,7 @@ jobs: strategy: fail-fast: false matrix: - branch: [release-1.22, release-1.23] + branch: [release-1.22, release-1.23, release-1.24] steps: - name: Invoke workflow with inputs uses: benc-uk/workflow-dispatch@v1 diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 71bd910bff..361375cc20 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -52,7 +52,7 @@ jobs: strategy: fail-fast: false matrix: - branch: [release-1.22, release-1.23] + branch: [release-1.22, release-1.23, release-1.24] steps: - name: Invoke workflow with inputs diff --git a/ADOPTERS.md b/ADOPTERS.md index f3a108e6d2..849d9ebb80 100644 --- a/ADOPTERS.md +++ b/ADOPTERS.md @@ -44,3 +44,5 @@ This list is sorted in chronological order, based on the submission date. | [ParadeDB](https://paradedb.com) | @philippemnoel | 2024-07-10 | ParadeDB is an Elasticsearch alternative on Postgres. It leverages CloudNativePG to manage ParadeDB Postgres clusters which connect to a customer's existing Postgres infrastructure via logical (streaming) replication. | | [REWE International AG](https://rewe-group.at/en) | @rewemkris | 2024-08-21 |Hello! 👋 We are the DBMS Team of RIAG IT, responsible for managing databases worldwide for our stores, warehouses, and online shops. We leverage CloudNativePG to provide PostgreSQL as a Service, creating highly available databases running on Kubernetes in both Google Cloud and on-premises environments.| | [Microsoft Azure](https://azure.microsoft.com/en-us/) | @KenKilty | 2024-08-22 | Learn how to [deploy](https://learn.microsoft.com/azure/aks/postgresql-ha-overview) PostgreSQL on [Azure Kubernetes Services (AKS)](https://learn.microsoft.com/azure/aks/what-is-aks) with [EDB commercial support](https://azuremarketplace.microsoft.com/en-us/marketplace/apps/enterprisedb-corp.edb-enterprise) and [EDB Postgres-as-a-Service](https://azuremarketplace.microsoft.com/en-us/marketplace/apps/enterprisedb-corp.biganimal-prod-v1) offerings available in the [Azure Marketplace](https://azuremarketplace.microsoft.com/).| +| [PZU Group](https://www.pzu.pl) | @MichaluxPL | 2024-08-26 | PZU is one of the largest financial institutions in Poland and also the largest insurance company in Central and Eastern Europe. CloudNativePG is used as on-premise cloud solution/DBaaS to provide highly available PostgreSQL clusters.| + diff --git a/api/v1/cluster_types.go b/api/v1/cluster_types.go index ddb6741533..02967164f4 100644 --- a/api/v1/cluster_types.go +++ b/api/v1/cluster_types.go @@ -563,7 +563,7 @@ const ( // PhaseUnknownPlugin is triggered when the required CNPG-i plugin have not been // loaded still - PhaseUnknownPlugin = "Unknown plugin" + PhaseUnknownPlugin = "Cluster cannot proceed to reconciliation due to an unknown plugin being required" // PhaseImageCatalogError is triggered when the cluster cannot select the image to // apply because of an invalid or incomplete catalog diff --git a/internal/cmd/plugin/destroy/destroy.go b/internal/cmd/plugin/destroy/destroy.go index 89a710125a..11fbb036db 100644 --- a/internal/cmd/plugin/destroy/destroy.go +++ b/internal/cmd/plugin/destroy/destroy.go @@ -43,6 +43,7 @@ func Destroy(ctx context.Context, clusterName, instanceName string, keepPVC bool if err := plugin.Client.List( ctx, &jobList, + client.InNamespace(plugin.Namespace), client.MatchingLabels{ utils.InstanceNameLabelName: instanceName, }, diff --git a/internal/cnpi/plugin/repository/setup.go b/internal/cnpi/plugin/repository/setup.go index 8329eccef2..3b4b18a854 100644 --- a/internal/cnpi/plugin/repository/setup.go +++ b/internal/cnpi/plugin/repository/setup.go @@ -84,7 +84,10 @@ func (r *data) setPluginProtocol(name string, protocol connection.Protocol) erro } }() - constructorLogger := log.FromContext(ctx).WithValues("pluginName", name) + constructorLogger := log. + FromContext(ctx). + WithName("setPluginProtocol"). + WithValues("pluginName", name) ctx = log.IntoContext(ctx, constructorLogger) if handler, err = protocol.Dial(ctx); err != nil { @@ -98,7 +101,9 @@ func (r *data) setPluginProtocol(name string, protocol connection.Protocol) erro destructor := func(res connection.Interface) { err := res.Close() if err != nil { - destructorLogger := log.FromContext(context.Background()).WithValues("pluginName", res.Name()) + destructorLogger := log.FromContext(context.Background()). + WithName("setPluginProtocol"). + WithValues("pluginName", res.Name()) destructorLogger.Warning("Error while closing plugin connection", "err", err) } } diff --git a/internal/controller/cluster_controller.go b/internal/controller/cluster_controller.go index 64d8f19055..c12ee8ba17 100644 --- a/internal/controller/cluster_controller.go +++ b/internal/controller/cluster_controller.go @@ -164,7 +164,9 @@ func (r *ClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct ctx, cluster, apiv1.PhaseUnknownPlugin, - fmt.Sprintf("Unknown plugin %s", errUnknownPlugin.Name), + fmt.Sprintf("Unknown plugin: '%s'. "+ + "This may be caused by the plugin not being loaded correctly by the operator. "+ + "Check the operator and plugin logs for errors", errUnknownPlugin.Name), ) } diff --git a/internal/management/istio/istio.go b/internal/management/istio/istio.go index 29e365ffb3..83e2427025 100644 --- a/internal/management/istio/istio.go +++ b/internal/management/istio/istio.go @@ -31,14 +31,16 @@ import ( // the service exists func TryInvokeQuitEndpoint(ctx context.Context) error { const endpoint = "http://localhost:15000/quitquitquit" - logger := log.FromContext(ctx) + logger := log.FromContext(ctx).WithName("try_invoke_quit_quit_endpoint") clientHTTP := http.Client{Timeout: 5 * time.Second} resp, err := clientHTTP.Post(endpoint, "", nil) if errors.Is(err, syscall.ECONNREFUSED) || os.IsTimeout(err) { + logger.Debug("received ECONNREFUSED, ignoring the error", "endpoint", endpoint) return nil } if err != nil { + logger.Error(err, "while invoking the /quitquitquit endpoint", "endpoint", endpoint) return err } if closeErr := resp.Body.Close(); closeErr != nil { diff --git a/pkg/management/catalog/catalog.go b/pkg/management/catalog/catalog.go index 521860c897..49bc29c3b2 100644 --- a/pkg/management/catalog/catalog.go +++ b/pkg/management/catalog/catalog.go @@ -219,13 +219,15 @@ type BarmanBackup struct { // The backup label Label string `json:"backup_label"` - // The moment where the backup started + // The moment where the backup started, this value is retrieved from barman command output + // and is in the format "Mon Jan 2 15:04:05 2006" with the timezone being the local one BeginTimeString string `json:"begin_time"` - // The moment where the backup ended + // The moment where the backup ended, his value is retrieved from barman command output + // and is in the format "Mon Jan 2 15:04:05 2006" with the timezone being the local one EndTimeString string `json:"end_time"` - // The moment where the backup ended + // The moment where the backup started BeginTime time.Time // The moment where the backup ended @@ -281,17 +283,16 @@ func (b *BarmanBackup) deserializeBackupTimeStrings() error { const ( barmanTimeLayout = "Mon Jan 2 15:04:05 2006" ) - var err error if b.BeginTimeString != "" { - b.BeginTime, err = time.Parse(barmanTimeLayout, b.BeginTimeString) + b.BeginTime, err = time.ParseInLocation(barmanTimeLayout, b.BeginTimeString, time.Local) if err != nil { return err } } if b.EndTimeString != "" { - b.EndTime, err = time.Parse(barmanTimeLayout, b.EndTimeString) + b.EndTime, err = time.ParseInLocation(barmanTimeLayout, b.EndTimeString, time.Local) if err != nil { return err } diff --git a/pkg/management/catalog/catalog_test.go b/pkg/management/catalog/catalog_test.go index 77f4bfce04..6f16436b55 100644 --- a/pkg/management/catalog/catalog_test.go +++ b/pkg/management/catalog/catalog_test.go @@ -245,5 +245,44 @@ var _ = Describe("barman-cloud-backup-show parsing", func() { Expect(result.SystemID).To(Equal("6885668674852188181")) Expect(result.BeginTimeString).To(Equal("Tue Jan 19 03:14:08 2038")) Expect(result.EndTimeString).To(Equal("Tue Jan 19 04:14:08 2038")) + + // Test timezone set in the parsed time is equal to local one + Expect(result.BeginTime.Location()).To(Equal(time.Now().Location())) + Expect(result.EndTime.Location()).To(Equal(time.Now().Location())) + }) + + It("parses valid begin and end time strings correctly", func() { + backup := &BarmanBackup{ + BeginTimeString: "Mon Jan 2 15:04:05 2006", + EndTimeString: "Tue Jan 3 15:04:05 2006", + } + err := backup.deserializeBackupTimeStrings() + Expect(err).ToNot(HaveOccurred()) + Expect(backup.BeginTime).To(Equal(time.Date(2006, time.January, 2, 15, 4, 5, 0, time.Local))) + Expect(backup.EndTime).To(Equal(time.Date(2006, time.January, 3, 15, 4, 5, 0, time.Local))) + }) + + It("returns an error for invalid begin time string", func() { + backup := &BarmanBackup{ + BeginTimeString: "invalid time string", + } + err := backup.deserializeBackupTimeStrings() + Expect(err).To(HaveOccurred()) + }) + + It("returns an error for invalid end time string", func() { + backup := &BarmanBackup{ + EndTimeString: "invalid time string", + } + err := backup.deserializeBackupTimeStrings() + Expect(err).To(HaveOccurred()) + }) + + It("handles empty begin and end time strings gracefully", func() { + backup := &BarmanBackup{} + err := backup.deserializeBackupTimeStrings() + Expect(err).ToNot(HaveOccurred()) + Expect(backup.BeginTime.IsZero()).To(BeTrue()) + Expect(backup.EndTime.IsZero()).To(BeTrue()) }) }) diff --git a/pkg/utils/logs/logs.go b/pkg/utils/logs/logs.go index afac7b391b..d8fc0c37e7 100644 --- a/pkg/utils/logs/logs.go +++ b/pkg/utils/logs/logs.go @@ -35,9 +35,9 @@ type StreamingRequest struct { Pod *v1.Pod Options *v1.PodLogOptions Previous bool `json:"previous,omitempty"` - // NOTE: the client argument may be omitted, but it is good practice to pass it + // NOTE: the Client argument may be omitted, but it is good practice to pass it // Importantly, it makes the logging functions testable - client kubernetes.Interface + Client kubernetes.Interface } func (spl *StreamingRequest) getPodName() string { @@ -63,14 +63,14 @@ func (spl *StreamingRequest) getLogOptions() *v1.PodLogOptions { } func (spl *StreamingRequest) getKubernetesClient() kubernetes.Interface { - if spl.client != nil { - return spl.client + if spl.Client != nil { + return spl.Client } conf := ctrl.GetConfigOrDie() - spl.client = kubernetes.NewForConfigOrDie(conf) + spl.Client = kubernetes.NewForConfigOrDie(conf) - return spl.client + return spl.Client } // getStreamToPod opens the REST request to the pod @@ -125,7 +125,7 @@ func TailPodLogs( Follow: true, SinceTime: &now, }, - client: client, + Client: client, } return streamPodLog.Stream(ctx, writer) } @@ -154,7 +154,7 @@ func GetPodLogs( Pod: &pod, Previous: getPrevious, Options: &v1.PodLogOptions{}, - client: client, + Client: client, } logsRequest := streamPodLog.getStreamToPod() diff --git a/pkg/utils/logs/logs_test.go b/pkg/utils/logs/logs_test.go index 53ab0a96c9..8631c1c998 100644 --- a/pkg/utils/logs/logs_test.go +++ b/pkg/utils/logs/logs_test.go @@ -56,7 +56,7 @@ var _ = Describe("Pod logging tests", func() { streamPodLog := StreamingRequest{ Pod: nil, Options: podLogOptions, - client: client, + Client: client, } var logBuffer bytes.Buffer err := streamPodLog.Stream(ctx, &logBuffer) @@ -95,7 +95,7 @@ var _ = Describe("Pod logging tests", func() { Pod: pod, Options: podLogOptions, Previous: false, - client: client, + Client: client, } var logBuffer bytes.Buffer diff --git a/tests/e2e/affinity_test.go b/tests/e2e/affinity_test.go index 13061b7b94..4bc32f8b91 100644 --- a/tests/e2e/affinity_test.go +++ b/tests/e2e/affinity_test.go @@ -47,10 +47,12 @@ var _ = Describe("E2E Affinity", Serial, Label(tests.LabelPodScheduling), func() namespace, err = env.CreateUniqueNamespace(namespacePrefix) Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - if CurrentSpecReport().Failed() { - env.DumpNamespaceObjects(namespace, "out/"+CurrentSpecReport().LeafNodeText+".log") - } - return env.DeleteNamespace(namespace) + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) AssertCreateCluster(namespace, clusterName, clusterFile, env) diff --git a/tests/e2e/apparmor_test.go b/tests/e2e/apparmor_test.go index 94d22597f4..4292832300 100644 --- a/tests/e2e/apparmor_test.go +++ b/tests/e2e/apparmor_test.go @@ -51,10 +51,12 @@ var _ = Describe("AppArmor support", Serial, Label(tests.LabelNoOpenshift, tests namespace, err = env.CreateUniqueNamespace(namespacePrefix) Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - if CurrentSpecReport().Failed() { - env.DumpNamespaceObjects(namespace, "out/"+CurrentSpecReport().LeafNodeText+".log") - } - return env.DeleteNamespace(namespace) + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) AssertCreateCluster(namespace, clusterName, clusterAppArmorFile, env) diff --git a/tests/e2e/architecture_test.go b/tests/e2e/architecture_test.go index ca2aa5131f..b191d15fc3 100644 --- a/tests/e2e/architecture_test.go +++ b/tests/e2e/architecture_test.go @@ -74,10 +74,12 @@ var _ = Describe("Available Architectures", Label(tests.LabelBasic), func() { namespace, err := env.CreateUniqueNamespace(namespacePrefix) Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - if CurrentSpecReport().Failed() { - env.DumpNamespaceObjects(namespace, "out/"+CurrentSpecReport().LeafNodeText+".log") - } - return env.DeleteNamespace(namespace) + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) clusterName, err := env.GetResourceNameFromYAML(clusterManifest) diff --git a/tests/e2e/backup_restore_test.go b/tests/e2e/backup_restore_test.go index 2cbe766daa..732b2b1751 100644 --- a/tests/e2e/backup_restore_test.go +++ b/tests/e2e/backup_restore_test.go @@ -79,7 +79,12 @@ var _ = Describe("Backup and restore", Label(tests.LabelBackupRestore), func() { namespace, err = env.CreateUniqueNamespace(namespacePrefix) Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - return env.DeleteNamespace(namespace) + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) By("create the certificates for MinIO", func() { @@ -533,7 +538,12 @@ var _ = Describe("Backup and restore", Label(tests.LabelBackupRestore), func() { namespace, err = env.CreateUniqueNamespace(namespacePrefix) Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - return env.DeleteNamespace(namespace) + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) // The Azure Blob Storage should have been created ad-hoc for the test. @@ -673,7 +683,12 @@ var _ = Describe("Backup and restore", Label(tests.LabelBackupRestore), func() { namespace, err = env.CreateUniqueNamespace(namespacePrefix) Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - return env.DeleteNamespace(namespace) + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) // Create and assert ca and tls certificate secrets on Azurite @@ -809,7 +824,12 @@ var _ = Describe("Clusters Recovery From Barman Object Store", Label(tests.Label namespace, err = env.CreateUniqueNamespace(namespacePrefix) Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - return env.DeleteNamespace(namespace) + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) AssertStorageCredentialsAreCreated(namespace, "backup-storage-creds", "minio", "minio123") @@ -968,7 +988,12 @@ var _ = Describe("Clusters Recovery From Barman Object Store", Label(tests.Label namespace, err = env.CreateUniqueNamespace(namespacePrefix) Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - return env.DeleteNamespace(namespace) + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) // The Azure Blob Storage should have been created ad-hoc for the test. @@ -1052,7 +1077,12 @@ var _ = Describe("Clusters Recovery From Barman Object Store", Label(tests.Label namespace, err = env.CreateUniqueNamespace(namespacePrefix) Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - return env.DeleteNamespace(namespace) + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) // The Azure Blob Storage should have been created ad-hoc for the test, @@ -1139,7 +1169,12 @@ var _ = Describe("Clusters Recovery From Barman Object Store", Label(tests.Label namespace, err = env.CreateUniqueNamespace(namespacePrefix) Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - return env.DeleteNamespace(namespace) + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) // Create and assert ca and tls certificate secrets on Azurite diff --git a/tests/e2e/certificates_test.go b/tests/e2e/certificates_test.go index 87a833b360..344ff7f62e 100644 --- a/tests/e2e/certificates_test.go +++ b/tests/e2e/certificates_test.go @@ -91,7 +91,12 @@ var _ = Describe("Certificates", func() { namespace, err = env.CreateUniqueNamespace(namespacePrefix) Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - return env.DeleteNamespace(namespace) + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) clusterName, err = env.GetResourceNameFromYAML(sampleFile) Expect(err).ToNot(HaveOccurred()) @@ -254,7 +259,12 @@ var _ = Describe("Certificates", func() { namespace, err = env.CreateUniqueNamespace(namespacePrefix) Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - return env.DeleteNamespace(namespace) + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) CreateAndAssertServerCertificatesSecrets( namespace, @@ -302,7 +312,12 @@ var _ = Describe("Certificates", func() { namespace, err = env.CreateUniqueNamespace(namespacePrefix) Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - return env.DeleteNamespace(namespace) + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) // Create certificates secret for client @@ -338,7 +353,12 @@ var _ = Describe("Certificates", func() { namespace, err = env.CreateUniqueNamespace(namespacePrefix) Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - return env.DeleteNamespace(namespace) + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) // Create certificates secret for server diff --git a/tests/e2e/cluster_microservice_test.go b/tests/e2e/cluster_microservice_test.go index ccd4ca7bd8..d55e5891cd 100644 --- a/tests/e2e/cluster_microservice_test.go +++ b/tests/e2e/cluster_microservice_test.go @@ -77,7 +77,12 @@ var _ = Describe("Imports with Microservice Approach", Label(tests.LabelImportin namespace, err = env.CreateUniqueNamespace(namespacePrefix) Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - return env.DeleteNamespace(namespace) + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) AssertCreateCluster(namespace, sourceClusterName, sourceSampleFile, env) AssertCreateTestData(namespace, sourceClusterName, tableName, psqlClientPod) @@ -101,7 +106,12 @@ var _ = Describe("Imports with Microservice Approach", Label(tests.LabelImportin namespace, err = env.CreateUniqueNamespace(namespacePrefix) Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - return env.DeleteNamespace(namespace) + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) AssertCreateCluster(namespace, sourceClusterName, sourceSampleFile, env) assertCreateTableWithDataOnSourceCluster(namespace, tableName, sourceClusterName) @@ -120,7 +130,12 @@ var _ = Describe("Imports with Microservice Approach", Label(tests.LabelImportin namespace, err = env.CreateUniqueNamespace(namespacePrefix) Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - return env.DeleteNamespace(namespace) + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) assertImportRenamesSelectedDatabase(namespace, sourceSampleFile, importedClusterName, tableName, "") @@ -136,7 +151,12 @@ var _ = Describe("Imports with Microservice Approach", Label(tests.LabelImportin namespace, err = env.CreateUniqueNamespace(namespacePrefix) Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - return env.DeleteNamespace(namespace) + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) AssertCreateCluster(namespace, sourceClusterName, sourceSampleFile, env) @@ -183,7 +203,12 @@ var _ = Describe("Imports with Microservice Approach", Label(tests.LabelImportin namespace, err = env.CreateUniqueNamespace(namespacePrefix) Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - return env.DeleteNamespace(namespace) + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) assertImportRenamesSelectedDatabase(namespace, sourceSampleFile, importedClusterName, tableName, targetImage) diff --git a/tests/e2e/cluster_monolithic_test.go b/tests/e2e/cluster_monolithic_test.go index 7515422f56..292858f08f 100644 --- a/tests/e2e/cluster_monolithic_test.go +++ b/tests/e2e/cluster_monolithic_test.go @@ -78,7 +78,12 @@ var _ = Describe("Imports with Monolithic Approach", Label(tests.LabelImportingD namespace, err = env.CreateUniqueNamespace(namespacePrefix) Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - return env.DeleteNamespace(namespace) + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) AssertCreateCluster(namespace, sourceClusterName, sourceClusterFile, env) }) diff --git a/tests/e2e/cluster_setup_test.go b/tests/e2e/cluster_setup_test.go index d76da9f1ed..d77918c865 100644 --- a/tests/e2e/cluster_setup_test.go +++ b/tests/e2e/cluster_setup_test.go @@ -56,10 +56,12 @@ var _ = Describe("Cluster setup", Label(tests.LabelSmoke, tests.LabelBasic), fun namespace, err = env.CreateUniqueNamespace(namespacePrefix) Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - if CurrentSpecReport().Failed() { - env.DumpNamespaceObjects(namespace, "out/"+CurrentSpecReport().LeafNodeText+".log") - } - return env.DeleteNamespace(namespace) + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) AssertCreateCluster(namespace, clusterName, sampleFile, env) @@ -170,10 +172,12 @@ var _ = Describe("Cluster setup", Label(tests.LabelSmoke, tests.LabelBasic), fun namespace, err = env.CreateUniqueNamespace(namespacePrefix) Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - if CurrentSpecReport().Failed() { - env.DumpNamespaceObjects(namespace, "out/"+CurrentSpecReport().LeafNodeText+".log") - } - return env.DeleteNamespace(namespace) + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) By(fmt.Sprintf("having a %v namespace", namespace), func() { diff --git a/tests/e2e/config_support_test.go b/tests/e2e/config_support_test.go index 23b3e6a4d2..7491f31ba8 100644 --- a/tests/e2e/config_support_test.go +++ b/tests/e2e/config_support_test.go @@ -122,7 +122,12 @@ var _ = Describe("Config support", Serial, Ordered, Label(tests.LabelDisruptive, namespace, err = env.CreateUniqueNamespace(namespacePrefix) Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - return env.DeleteNamespace(namespace) + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) AssertCreateCluster(namespace, clusterName, clusterWithInheritedLabelsFile, env) diff --git a/tests/e2e/configuration_update_test.go b/tests/e2e/configuration_update_test.go index c777fd5057..885f8df670 100644 --- a/tests/e2e/configuration_update_test.go +++ b/tests/e2e/configuration_update_test.go @@ -138,7 +138,12 @@ var _ = Describe("Configuration update", Ordered, Label(tests.LabelClusterMetada namespace, err = env.CreateUniqueNamespace(namespacePrefix) Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - return env.DeleteNamespace(namespace) + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) AssertCreateCluster(namespace, clusterName, sampleFile, env) }) @@ -483,7 +488,12 @@ var _ = Describe("Configuration update with primaryUpdateMethod", Label(tests.La namespace, err = env.CreateUniqueNamespace(namespacePrefix) Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - return env.DeleteNamespace(namespace) + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) clusterName, err = env.GetResourceNameFromYAML(clusterFileWithPrimaryUpdateRestart) diff --git a/tests/e2e/connection_test.go b/tests/e2e/connection_test.go index 1a7530f8c2..b3e9af8cd7 100644 --- a/tests/e2e/connection_test.go +++ b/tests/e2e/connection_test.go @@ -85,7 +85,12 @@ var _ = Describe("Connection via services", Label(tests.LabelServiceConnectivity namespace, err = env.CreateUniqueNamespace(namespacePrefix) Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - return env.DeleteNamespace(namespace) + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) AssertCreateCluster(namespace, clusterName, sampleFile, env) @@ -137,7 +142,12 @@ var _ = Describe("Connection via services", Label(tests.LabelServiceConnectivity namespace, err = env.CreateUniqueNamespace(namespacePrefix) Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - return env.DeleteNamespace(namespace) + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) AssertCreateCluster(namespace, clusterName, sampleFile, env) AssertServices(namespace, clusterName, appDBName, appDBUser, diff --git a/tests/e2e/declarative_hibernation_test.go b/tests/e2e/declarative_hibernation_test.go index c505d500ac..06dba77cf4 100644 --- a/tests/e2e/declarative_hibernation_test.go +++ b/tests/e2e/declarative_hibernation_test.go @@ -53,10 +53,12 @@ var _ = Describe("Cluster declarative hibernation", func() { Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - if CurrentSpecReport().Failed() { - env.DumpNamespaceObjects(namespace, "out/"+CurrentSpecReport().LeafNodeText+".log") - } - return env.DeleteNamespace(namespace) + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) By("creating a new cluster", func() { diff --git a/tests/e2e/disk_space_test.go b/tests/e2e/disk_space_test.go index 08d34dc79c..0836599745 100644 --- a/tests/e2e/disk_space_test.go +++ b/tests/e2e/disk_space_test.go @@ -193,10 +193,12 @@ var _ = Describe("Volume space unavailable", Label(tests.LabelStorage), func() { namespace, err = env.CreateUniqueNamespace(namespacePrefix) Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - if CurrentSpecReport().Failed() { - env.DumpNamespaceObjects(namespace, "out/"+CurrentSpecReport().LeafNodeText+".log") - } - return env.DeleteNamespace(namespace) + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) clusterName, err := env.GetResourceNameFromYAML(sampleFile) diff --git a/tests/e2e/drain_node_test.go b/tests/e2e/drain_node_test.go index 70f6079ffc..d9889e83f7 100644 --- a/tests/e2e/drain_node_test.go +++ b/tests/e2e/drain_node_test.go @@ -112,7 +112,12 @@ var _ = Describe("E2E Drain Node", Serial, Label(tests.LabelDisruptive, tests.La namespace, err = env.CreateUniqueNamespace(namespacePrefix) Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - return env.DeleteNamespace(namespace) + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) AssertCreateCluster(namespace, clusterName, sampleFile, env) @@ -229,7 +234,12 @@ var _ = Describe("E2E Drain Node", Serial, Label(tests.LabelDisruptive, tests.La namespace, err = env.CreateUniqueNamespace(namespacePrefix) Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - return env.DeleteNamespace(namespace) + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) AssertCreateCluster(namespace, clusterName, sampleFile, env) @@ -358,7 +368,12 @@ var _ = Describe("E2E Drain Node", Serial, Label(tests.LabelDisruptive, tests.La namespace, err = env.CreateUniqueNamespace(namespacePrefix) Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - return env.DeleteNamespace(namespace) + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) AssertCreateCluster(namespace, clusterName, sampleFile, env) @@ -444,7 +459,12 @@ var _ = Describe("E2E Drain Node", Serial, Label(tests.LabelDisruptive, tests.La namespace, err = env.CreateUniqueNamespace(namespacePrefix) Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - return env.DeleteNamespace(namespace) + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) }) diff --git a/tests/e2e/eviction_test.go b/tests/e2e/eviction_test.go index e9d37cb7ca..1df11d522f 100644 --- a/tests/e2e/eviction_test.go +++ b/tests/e2e/eviction_test.go @@ -126,7 +126,12 @@ var _ = Describe("Pod eviction", Serial, Label(tests.LabelDisruptive), func() { namespace, err = env.CreateUniqueNamespace(namespacePrefix) Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - return env.DeleteNamespace(namespace) + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) By("creating a cluster", func() { // Create a cluster in a namespace we'll delete after the test @@ -190,7 +195,12 @@ var _ = Describe("Pod eviction", Serial, Label(tests.LabelDisruptive), func() { namespace, err = env.CreateUniqueNamespace(namespacePrefix) Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - return env.DeleteNamespace(namespace) + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) By("Creating a cluster with multiple instances", func() { // Create a cluster in a namespace and shared in containers, we'll delete after the test diff --git a/tests/e2e/failover_test.go b/tests/e2e/failover_test.go index 87614a7f8b..2b2b3c5722 100644 --- a/tests/e2e/failover_test.go +++ b/tests/e2e/failover_test.go @@ -217,10 +217,12 @@ var _ = Describe("Failover", Label(tests.LabelSelfHealing), func() { namespace, err = env.CreateUniqueNamespace(namespacePrefix) Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - if CurrentSpecReport().Failed() { - env.DumpNamespaceObjects(namespace, "out/"+CurrentSpecReport().LeafNodeText+".log") - } - return env.DeleteNamespace(namespace) + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) clusterName, err := env.GetResourceNameFromYAML(sampleFile) @@ -241,10 +243,12 @@ var _ = Describe("Failover", Label(tests.LabelSelfHealing), func() { namespace, err = env.CreateUniqueNamespace(namespacePrefix) Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - if CurrentSpecReport().Failed() { - env.DumpNamespaceObjects(namespace, "out/"+CurrentSpecReport().LeafNodeText+".log") - } - return env.DeleteNamespace(namespace) + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) clusterName, err := env.GetResourceNameFromYAML(sampleFile) diff --git a/tests/e2e/fastfailover_test.go b/tests/e2e/fastfailover_test.go index 72dd6e49d6..36b6f6d976 100644 --- a/tests/e2e/fastfailover_test.go +++ b/tests/e2e/fastfailover_test.go @@ -77,7 +77,12 @@ var _ = Describe("Fast failover", Serial, Label(tests.LabelPerformance, tests.La namespace, err = env.CreateUniqueNamespace(namespacePrefix) Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - return env.DeleteNamespace(namespace) + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) AssertFastFailOver(namespace, sampleFileWithoutReplicationSlots, clusterName, webTestFile, webTestJob, maxReattachTime, maxFailoverTime) @@ -98,7 +103,12 @@ var _ = Describe("Fast failover", Serial, Label(tests.LabelPerformance, tests.La namespace, err = env.CreateUniqueNamespace(namespacePrefix) Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - return env.DeleteNamespace(namespace) + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) AssertFastFailOver(namespace, sampleFileWithReplicationSlots, clusterName, webTestFile, webTestJob, maxReattachTime, maxFailoverTime) @@ -115,7 +125,12 @@ var _ = Describe("Fast failover", Serial, Label(tests.LabelPerformance, tests.La namespace, err = env.CreateUniqueNamespace(namespacePrefix) Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - return env.DeleteNamespace(namespace) + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) AssertFastFailOver( namespace, sampleFileSyncReplicas, clusterName, webTestSyncReplicas, webTestJob, maxReattachTime, maxFailoverTime) diff --git a/tests/e2e/fastswitchover_test.go b/tests/e2e/fastswitchover_test.go index ea15ddbb63..a46998ae10 100644 --- a/tests/e2e/fastswitchover_test.go +++ b/tests/e2e/fastswitchover_test.go @@ -66,10 +66,12 @@ var _ = Describe("Fast switchover", Serial, Label(tests.LabelPerformance, tests. namespace, err = env.CreateUniqueNamespace(namespacePrefix) Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - if CurrentSpecReport().Failed() { - env.DumpNamespaceObjects(namespace, "out/"+CurrentSpecReport().LeafNodeText+".log") - } - return env.DeleteNamespace(namespace) + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) assertFastSwitchover(namespace, sampleFileWithoutReplicationSlots, clusterName, webTestFile, webTestJob) }) @@ -82,10 +84,12 @@ var _ = Describe("Fast switchover", Serial, Label(tests.LabelPerformance, tests. namespace, err = env.CreateUniqueNamespace(namespacePrefix) Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - if CurrentSpecReport().Failed() { - env.DumpNamespaceObjects(namespace, "out/"+CurrentSpecReport().LeafNodeText+".log") - } - return env.DeleteNamespace(namespace) + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) assertFastSwitchover(namespace, sampleFileWithReplicationSlots, clusterName, webTestFile, webTestJob) AssertClusterHAReplicationSlots(namespace, clusterName) diff --git a/tests/e2e/fencing_test.go b/tests/e2e/fencing_test.go index 6eb323cadd..f9dcbd3796 100644 --- a/tests/e2e/fencing_test.go +++ b/tests/e2e/fencing_test.go @@ -256,7 +256,12 @@ var _ = Describe("Fencing", Label(tests.LabelPlugin), func() { namespace, err = env.CreateUniqueNamespace(namespacePrefix) Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - return env.DeleteNamespace(namespace) + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) AssertCreateCluster(namespace, clusterName, sampleFile, env) }) @@ -275,7 +280,12 @@ var _ = Describe("Fencing", Label(tests.LabelPlugin), func() { namespace, err = env.CreateUniqueNamespace(namespacePrefix) Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - return env.DeleteNamespace(namespace) + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) AssertCreateCluster(namespace, clusterName, sampleFile, env) }) diff --git a/tests/e2e/hibernation_test.go b/tests/e2e/hibernation_test.go index 402d9292c3..544dfb21c5 100644 --- a/tests/e2e/hibernation_test.go +++ b/tests/e2e/hibernation_test.go @@ -301,10 +301,12 @@ var _ = Describe("Cluster Hibernation with plugin", Label(tests.LabelPlugin), fu namespace, err = env.CreateUniqueNamespace(namespacePrefix) Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - if CurrentSpecReport().Failed() { - env.DumpNamespaceObjects(namespace, "out/"+CurrentSpecReport().LeafNodeText+".log") - } - return env.DeleteNamespace(namespace) + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) AssertCreateCluster(namespace, clusterName, sampleFileClusterWithPGWalVolume, env) assertHibernation(namespace, clusterName, tableName) @@ -321,10 +323,12 @@ var _ = Describe("Cluster Hibernation with plugin", Label(tests.LabelPlugin), fu namespace, err = env.CreateUniqueNamespace(namespacePrefix) Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - if CurrentSpecReport().Failed() { - env.DumpNamespaceObjects(namespace, "out/"+CurrentSpecReport().LeafNodeText+".log") - } - return env.DeleteNamespace(namespace) + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) AssertCreateCluster(namespace, clusterName, sampleFileClusterWithOutPGWalVolume, env) // Write a table and some data on the "app" database @@ -387,10 +391,12 @@ var _ = Describe("Cluster Hibernation with plugin", Label(tests.LabelPlugin), fu namespace, err = env.CreateUniqueNamespace(namespacePrefix) Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - if CurrentSpecReport().Failed() { - env.DumpNamespaceObjects(namespace, "out/"+CurrentSpecReport().LeafNodeText+".log") - } - return env.DeleteNamespace(namespace) + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) AssertCreateCluster(namespace, clusterName, sampleFileClusterWithPGWalVolume, env) AssertSwitchover(namespace, clusterName, env) diff --git a/tests/e2e/initdb_test.go b/tests/e2e/initdb_test.go index ae9940d656..b94263fd96 100644 --- a/tests/e2e/initdb_test.go +++ b/tests/e2e/initdb_test.go @@ -91,10 +91,12 @@ var _ = Describe("InitDB settings", Label(tests.LabelSmoke, tests.LabelBasic), f namespace, err = env.CreateUniqueNamespace(namespacePrefix) Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - if CurrentSpecReport().Failed() { - env.DumpNamespaceObjects(namespace, "out/"+CurrentSpecReport().LeafNodeText+".log") - } - return env.DeleteNamespace(namespace) + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) CreateResourceFromFile(namespace, postInitSQLSecretRef) @@ -163,10 +165,12 @@ var _ = Describe("InitDB settings", Label(tests.LabelSmoke, tests.LabelBasic), f namespace, err = env.CreateUniqueNamespace(namespacePrefix) Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - if CurrentSpecReport().Failed() { - env.DumpNamespaceObjects(namespace, "out/"+CurrentSpecReport().LeafNodeText+".log") - } - return env.DeleteNamespace(namespace) + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) AssertCreateCluster(namespace, clusterName, postInitSQLCluster, env) diff --git a/tests/e2e/logs_test.go b/tests/e2e/logs_test.go index 76fd47edb8..4938c13eb1 100644 --- a/tests/e2e/logs_test.go +++ b/tests/e2e/logs_test.go @@ -59,7 +59,12 @@ var _ = Describe("JSON log output", Label(tests.LabelObservability), func() { namespace, namespaceErr = env.CreateUniqueNamespace(namespacePrefix) Expect(namespaceErr).ToNot(HaveOccurred()) DeferCleanup(func() error { - return env.DeleteNamespace(namespace) + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) AssertCreateCluster(namespace, clusterName, sampleFile, env) diff --git a/tests/e2e/managed_roles_test.go b/tests/e2e/managed_roles_test.go index 06f651029b..eefb000bd1 100644 --- a/tests/e2e/managed_roles_test.go +++ b/tests/e2e/managed_roles_test.go @@ -78,7 +78,12 @@ var _ = Describe("Managed roles tests", Label(tests.LabelSmoke, tests.LabelBasic namespace, err = env.CreateUniqueNamespace(namespacePrefix) Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - return env.DeleteNamespace(namespace) + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) clusterName, err = env.GetResourceNameFromYAML(clusterManifest) diff --git a/tests/e2e/managed_services_test.go b/tests/e2e/managed_services_test.go index a02e8f5b04..1d42225b28 100644 --- a/tests/e2e/managed_services_test.go +++ b/tests/e2e/managed_services_test.go @@ -60,9 +60,13 @@ var _ = Describe("Managed services tests", Label(tests.LabelSmoke, tests.LabelBa const serviceName = "test-rw" namespace, err := env.CreateUniqueNamespace(namespacePrefix) Expect(err).ToNot(HaveOccurred()) - DeferCleanup(func() error { - return env.DeleteNamespace(namespace) + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) clusterName, err := env.GetResourceNameFromYAML(clusterManifest) @@ -107,9 +111,13 @@ var _ = Describe("Managed services tests", Label(tests.LabelSmoke, tests.LabelBa namespace, err := env.CreateUniqueNamespace(namespacePrefix) Expect(err).ToNot(HaveOccurred()) - DeferCleanup(func() error { - return env.DeleteNamespace(namespace) + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) clusterName, err := env.GetResourceNameFromYAML(clusterManifest) @@ -170,9 +178,13 @@ var _ = Describe("Managed services tests", Label(tests.LabelSmoke, tests.LabelBa const serviceName = "test-rw" namespace, err := env.CreateUniqueNamespace(namespacePrefix) Expect(err).ToNot(HaveOccurred()) - DeferCleanup(func() error { - return env.DeleteNamespace(namespace) + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) clusterName, err := env.GetResourceNameFromYAML(clusterManifest) diff --git a/tests/e2e/metrics_test.go b/tests/e2e/metrics_test.go index fede3edc29..8c51de304f 100644 --- a/tests/e2e/metrics_test.go +++ b/tests/e2e/metrics_test.go @@ -103,7 +103,12 @@ var _ = Describe("Metrics", Label(tests.LabelObservability), func() { namespace, err = env.CreateUniqueNamespace(namespacePrefix) Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - return env.DeleteNamespace(namespace) + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) AssertCustomMetricsResourcesExist(namespace, fixturesDir+"/metrics/custom-queries.yaml", 2, 1) @@ -141,7 +146,12 @@ var _ = Describe("Metrics", Label(tests.LabelObservability), func() { namespace, err = env.CreateUniqueNamespace(namespacePrefix) Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - return env.DeleteNamespace(namespace) + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) AssertCustomMetricsResourcesExist(namespace, customQueriesSampleFile, 1, 1) @@ -165,7 +175,12 @@ var _ = Describe("Metrics", Label(tests.LabelObservability), func() { namespace, err = env.CreateUniqueNamespace(namespacePrefix) Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - return env.DeleteNamespace(namespace) + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) AssertCreateCluster(namespace, metricsClusterName, clusterWithDefaultMetricsFile, env) @@ -193,7 +208,12 @@ var _ = Describe("Metrics", Label(tests.LabelObservability), func() { namespace, err = env.CreateUniqueNamespace(namespacePrefix) Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - return env.DeleteNamespace(namespace) + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) AssertCustomMetricsResourcesExist(namespace, fixturesDir+"/metrics/custom-queries-with-predicate-query.yaml", 1, 0) @@ -240,7 +260,12 @@ var _ = Describe("Metrics", Label(tests.LabelObservability), func() { namespace, err = env.CreateUniqueNamespace(namespacePrefix) Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - return env.DeleteNamespace(namespace) + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) // Create the cluster @@ -272,7 +297,12 @@ var _ = Describe("Metrics", Label(tests.LabelObservability), func() { namespace, err = env.CreateUniqueNamespace(namespacePrefix) Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - return env.DeleteNamespace(namespace) + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) // Creating and verifying custom queries configmap diff --git a/tests/e2e/monitoring_test.go b/tests/e2e/monitoring_test.go index 4ad1548d33..fa730557bb 100644 --- a/tests/e2e/monitoring_test.go +++ b/tests/e2e/monitoring_test.go @@ -56,10 +56,12 @@ var _ = Describe("PodMonitor support", Serial, Label(tests.LabelObservability), namespace, err = env.CreateUniqueNamespace(namespacePrefix) Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - if CurrentSpecReport().Failed() { - env.DumpNamespaceObjects(namespace, "out/"+CurrentSpecReport().LeafNodeText+".log") - } - return env.DeleteNamespace(namespace) + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) AssertCreateCluster(namespace, clusterDefaultName, clusterDefaultMonitoringFile, env) diff --git a/tests/e2e/nodeselector_test.go b/tests/e2e/nodeselector_test.go index e24d02dc1d..9b126dead5 100644 --- a/tests/e2e/nodeselector_test.go +++ b/tests/e2e/nodeselector_test.go @@ -55,7 +55,12 @@ var _ = Describe("nodeSelector", Label(tests.LabelPodScheduling), func() { namespace, err = env.CreateUniqueNamespace(namespacePrefix) Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - return env.DeleteNamespace(namespace) + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) // Creating a namespace should be quick @@ -122,7 +127,12 @@ var _ = Describe("nodeSelector", Label(tests.LabelPodScheduling), func() { namespace, err = env.CreateUniqueNamespace(namespacePrefix) Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - return env.DeleteNamespace(namespace) + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) // We label one node with the label we have defined in the cluster diff --git a/tests/e2e/operator_ha_test.go b/tests/e2e/operator_ha_test.go index f95cbdeb71..6ca34a2d04 100644 --- a/tests/e2e/operator_ha_test.go +++ b/tests/e2e/operator_ha_test.go @@ -71,10 +71,12 @@ var _ = Describe("Operator High Availability", Serial, namespace, err = env.CreateUniqueNamespace(namespacePrefix) Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - if CurrentSpecReport().Failed() { - env.DumpNamespaceObjects(namespace, "out/"+CurrentSpecReport().LeafNodeText+".log") - } - return env.DeleteNamespace(namespace) + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) // Create Cluster diff --git a/tests/e2e/operator_unavailable_test.go b/tests/e2e/operator_unavailable_test.go index 29ffab2aa3..eea9188c5e 100644 --- a/tests/e2e/operator_unavailable_test.go +++ b/tests/e2e/operator_unavailable_test.go @@ -61,7 +61,12 @@ var _ = Describe("Operator unavailable", Serial, Label(tests.LabelDisruptive, te namespace, err = env.CreateUniqueNamespace(namespacePrefix) Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - return env.DeleteNamespace(namespace) + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) AssertCreateCluster(namespace, clusterName, sampleFile, env) @@ -152,7 +157,12 @@ var _ = Describe("Operator unavailable", Serial, Label(tests.LabelDisruptive, te namespace, err = env.CreateUniqueNamespace(namespacePrefix) Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - return env.DeleteNamespace(namespace) + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) AssertCreateCluster(namespace, clusterName, sampleFile, env) diff --git a/tests/e2e/pg_basebackup_test.go b/tests/e2e/pg_basebackup_test.go index 18d16f8cfa..9df9da7bcd 100644 --- a/tests/e2e/pg_basebackup_test.go +++ b/tests/e2e/pg_basebackup_test.go @@ -54,7 +54,12 @@ var _ = Describe("Bootstrap with pg_basebackup", Label(tests.LabelRecovery), fun namespace, err = env.CreateUniqueNamespace(namespacePrefix) Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - return env.DeleteNamespace(namespace) + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) // Create the source Cluster srcClusterName, err = env.GetResourceNameFromYAML(srcCluster) diff --git a/tests/e2e/pg_data_corruption_test.go b/tests/e2e/pg_data_corruption_test.go index b0f0c1ad44..c4face6e83 100644 --- a/tests/e2e/pg_data_corruption_test.go +++ b/tests/e2e/pg_data_corruption_test.go @@ -47,7 +47,12 @@ var _ = Describe("PGDATA Corruption", Label(tests.LabelRecovery), Ordered, func( namespace, err = env.CreateUniqueNamespace(namespacePrefix) Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - return env.DeleteNamespace(namespace) + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) }) diff --git a/tests/e2e/pg_wal_volume_test.go b/tests/e2e/pg_wal_volume_test.go index f892e1f03c..8ef49cdef1 100644 --- a/tests/e2e/pg_wal_volume_test.go +++ b/tests/e2e/pg_wal_volume_test.go @@ -121,10 +121,12 @@ var _ = Describe("Separate pg_wal volume", Label(tests.LabelStorage), func() { namespace, err = env.CreateUniqueNamespace(namespacePrefix) Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - if CurrentSpecReport().Failed() { - env.DumpNamespaceObjects(namespace, "out/"+CurrentSpecReport().LeafNodeText+".log") - } - return env.DeleteNamespace(namespace) + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) AssertCreateCluster(namespace, clusterName, sampleFileWithPgWal, env) verifyPgWal(namespace) @@ -137,10 +139,12 @@ var _ = Describe("Separate pg_wal volume", Label(tests.LabelStorage), func() { namespace, err = env.CreateUniqueNamespace(namespacePrefix) Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - if CurrentSpecReport().Failed() { - env.DumpNamespaceObjects(namespace, "out/"+CurrentSpecReport().LeafNodeText+".log") - } - return env.DeleteNamespace(namespace) + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) AssertCreateCluster(namespace, clusterName, sampleFileWithoutPgWal, env) By(fmt.Sprintf("adding pg_wal volume in existing cluster: %v", clusterName), func() { diff --git a/tests/e2e/pgbouncer_metrics_test.go b/tests/e2e/pgbouncer_metrics_test.go index 67c39c9c04..9da4e6a4ea 100644 --- a/tests/e2e/pgbouncer_metrics_test.go +++ b/tests/e2e/pgbouncer_metrics_test.go @@ -52,10 +52,12 @@ var _ = Describe("PGBouncer Metrics", Label(tests.LabelObservability), func() { namespace, err = env.CreateUniqueNamespace(namespacePrefix) Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - if CurrentSpecReport().Failed() { - env.DumpNamespaceObjects(namespace, "out/"+CurrentSpecReport().LeafNodeText+".log") - } - return env.DeleteNamespace(namespace) + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) clusterName, err = env.GetResourceNameFromYAML(cnpgCluster) diff --git a/tests/e2e/pgbouncer_test.go b/tests/e2e/pgbouncer_test.go index 60d86e3a88..403a7b30ba 100644 --- a/tests/e2e/pgbouncer_test.go +++ b/tests/e2e/pgbouncer_test.go @@ -52,7 +52,12 @@ var _ = Describe("PGBouncer Connections", Label(tests.LabelServiceConnectivity), namespace, err = env.CreateUniqueNamespace("pgbouncer-auth-no-user-certs") Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - return env.DeleteNamespace(namespace) + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) clusterName, err = env.GetResourceNameFromYAML(sampleFile) Expect(err).ToNot(HaveOccurred()) @@ -151,7 +156,12 @@ var _ = Describe("PGBouncer Connections", Label(tests.LabelServiceConnectivity), namespace, err = env.CreateUniqueNamespace("pgbouncer-separate-certificates") Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - return env.DeleteNamespace(namespace) + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) clusterName, err = env.GetResourceNameFromYAML(sampleFileWithCertificate) Expect(err).ToNot(HaveOccurred()) diff --git a/tests/e2e/pgbouncer_types_test.go b/tests/e2e/pgbouncer_types_test.go index f2a3a7f7f9..5aff907e43 100644 --- a/tests/e2e/pgbouncer_types_test.go +++ b/tests/e2e/pgbouncer_types_test.go @@ -62,7 +62,12 @@ var _ = Describe("PGBouncer Types", Ordered, Label(tests.LabelServiceConnectivit namespace, err = env.CreateUniqueNamespace("pgbouncer-types") Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - return env.DeleteNamespace(namespace) + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) clusterName, err = env.GetResourceNameFromYAML(sampleFile) Expect(err).ToNot(HaveOccurred()) diff --git a/tests/e2e/pvc_deletion_test.go b/tests/e2e/pvc_deletion_test.go index c0e8a15daa..83794479f7 100644 --- a/tests/e2e/pvc_deletion_test.go +++ b/tests/e2e/pvc_deletion_test.go @@ -51,10 +51,12 @@ var _ = Describe("PVC Deletion", Label(tests.LabelSelfHealing), func() { namespace, err = env.CreateUniqueNamespace(namespacePrefix) Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - if CurrentSpecReport().Failed() { - env.DumpNamespaceObjects(namespace, "out/"+CurrentSpecReport().LeafNodeText+".log") - } - return env.DeleteNamespace(namespace) + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) AssertCreateCluster(namespace, clusterName, sampleFile, env) diff --git a/tests/e2e/replica_mode_cluster_test.go b/tests/e2e/replica_mode_cluster_test.go index 859773e174..502ca24d5a 100644 --- a/tests/e2e/replica_mode_cluster_test.go +++ b/tests/e2e/replica_mode_cluster_test.go @@ -77,10 +77,12 @@ var _ = Describe("Replica Mode", Label(tests.LabelReplication), func() { replicaNamespace, err := env.CreateUniqueNamespace(replicaNamespacePrefix) Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - if CurrentSpecReport().Failed() { - env.DumpNamespaceObjects(replicaNamespace, "out/"+CurrentSpecReport().LeafNodeText+".log") - } - return env.DeleteNamespace(replicaNamespace) + return env.CleanupNamespace( + replicaNamespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) AssertCreateCluster(replicaNamespace, srcClusterName, srcClusterSample, env) @@ -116,10 +118,12 @@ var _ = Describe("Replica Mode", Label(tests.LabelReplication), func() { replicaNamespace, err := env.CreateUniqueNamespace(replicaNamespacePrefix) Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - if CurrentSpecReport().Failed() { - env.DumpNamespaceObjects(replicaNamespace, "out/"+CurrentSpecReport().LeafNodeText+".log") - } - return env.DeleteNamespace(replicaNamespace) + return env.CleanupNamespace( + replicaNamespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) AssertCreateCluster(replicaNamespace, srcClusterName, srcClusterSample, env) @@ -165,10 +169,12 @@ var _ = Describe("Replica Mode", Label(tests.LabelReplication), func() { namespace, err := env.CreateUniqueNamespace("replica-promotion-demotion") Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - if CurrentSpecReport().Failed() { - env.DumpNamespaceObjects(namespace, "out/"+CurrentSpecReport().LeafNodeText+".log") - } - return env.DeleteNamespace(namespace) + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) AssertCreateCluster(namespace, clusterOneName, clusterOneFile, env) @@ -255,10 +261,12 @@ var _ = Describe("Replica Mode", Label(tests.LabelReplication), func() { replicaNamespace, err := env.CreateUniqueNamespace(replicaNamespacePrefix) Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - if CurrentSpecReport().Failed() { - env.DumpNamespaceObjects(replicaNamespace, "out/"+CurrentSpecReport().LeafNodeText+".log") - } - return env.DeleteNamespace(replicaNamespace) + return env.CleanupNamespace( + replicaNamespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) By("creating the credentials for minio", func() { AssertStorageCredentialsAreCreated(replicaNamespace, "backup-storage-creds", "minio", "minio123") @@ -318,7 +326,14 @@ var _ = Describe("Replica Mode", Label(tests.LabelReplication), func() { var err error namespace, err = env.CreateUniqueNamespace(namespacePrefix) Expect(err).ToNot(HaveOccurred()) - DeferCleanup(func() error { return env.DeleteNamespace(namespace) }) + DeferCleanup(func() error { + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) + }) By("creating the credentials for minio", func() { AssertStorageCredentialsAreCreated(namespace, "backup-storage-creds", "minio", "minio123") @@ -534,10 +549,15 @@ var _ = Describe("Replica switchover", Label(tests.LabelReplication), Ordered, f namespace, err = env.CreateUniqueNamespace(namespacePrefix) Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - err := env.DeleteNamespaceAndWait(namespace, 120) - if err != nil { - return err - } + return env.CleanupNamespaceAndWait( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + 120, + GinkgoWriter, + ) + }) + DeferCleanup(func() error { // Since we use multiple times the same cluster names for the same minio instance, we need to clean it up // between tests _, err = testUtils.CleanFilesOnMinio(minioEnv, path.Join("minio", "cluster-backups", clusterAName)) diff --git a/tests/e2e/replication_slot_test.go b/tests/e2e/replication_slot_test.go index 8ed449453f..c828ea0c85 100644 --- a/tests/e2e/replication_slot_test.go +++ b/tests/e2e/replication_slot_test.go @@ -50,10 +50,12 @@ var _ = Describe("Replication Slot", Label(tests.LabelReplication), func() { namespace, err = env.CreateUniqueNamespace(namespacePrefix) Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - if CurrentSpecReport().Failed() { - env.DumpNamespaceObjects(namespace, "out/"+CurrentSpecReport().LeafNodeText+".log") - } - return env.DeleteNamespace(namespace) + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) AssertCreateCluster(namespace, clusterName, sampleFile, env) diff --git a/tests/e2e/rolling_update_test.go b/tests/e2e/rolling_update_test.go index e1f812cf4c..de3a7749d3 100644 --- a/tests/e2e/rolling_update_test.go +++ b/tests/e2e/rolling_update_test.go @@ -479,10 +479,12 @@ var _ = Describe("Rolling updates", Label(tests.LabelPostgresConfiguration), fun namespace, err := env.CreateUniqueNamespace(namespacePrefix) Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - if CurrentSpecReport().Failed() { - env.DumpNamespaceObjects(namespace, "out/"+CurrentSpecReport().LeafNodeText+".log") - } - return env.DeleteNamespace(namespace) + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) clusterName, err := env.GetResourceNameFromYAML(sampleFile) Expect(err).ToNot(HaveOccurred()) @@ -504,10 +506,12 @@ var _ = Describe("Rolling updates", Label(tests.LabelPostgresConfiguration), fun namespace, err := env.CreateUniqueNamespace(namespacePrefix) Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - if CurrentSpecReport().Failed() { - env.DumpNamespaceObjects(namespace, "out/"+CurrentSpecReport().LeafNodeText+".log") - } - return env.DeleteNamespace(namespace) + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) clusterName, err := env.GetResourceNameFromYAML(sampleFile) Expect(err).ToNot(HaveOccurred()) @@ -524,10 +528,12 @@ var _ = Describe("Rolling updates", Label(tests.LabelPostgresConfiguration), fun namespace, err := env.CreateUniqueNamespace(namespacePrefix) Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - if CurrentSpecReport().Failed() { - env.DumpNamespaceObjects(namespace, "out/"+CurrentSpecReport().LeafNodeText+".log") - } - return env.DeleteNamespace(namespace) + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) clusterName, err := env.GetResourceNameFromYAML(sampleFile) Expect(err).ToNot(HaveOccurred()) @@ -575,10 +581,12 @@ var _ = Describe("Rolling updates", Label(tests.LabelPostgresConfiguration), fun namespace, err := env.CreateUniqueNamespace(namespacePrefix) Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - if CurrentSpecReport().Failed() { - env.DumpNamespaceObjects(namespace, "out/"+CurrentSpecReport().LeafNodeText+".log") - } - return env.DeleteNamespace(namespace) + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) // Create a new image catalog and a new cluster @@ -601,10 +609,12 @@ var _ = Describe("Rolling updates", Label(tests.LabelPostgresConfiguration), fun namespace, err := env.CreateUniqueNamespace(namespacePrefix) Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - if CurrentSpecReport().Failed() { - env.DumpNamespaceObjects(namespace, "out/"+CurrentSpecReport().LeafNodeText+".log") - } - return env.DeleteNamespace(namespace) + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) catalog := newImageCatalog(namespace, clusterName, major, preRollingImg) @@ -643,10 +653,12 @@ var _ = Describe("Rolling updates", Label(tests.LabelPostgresConfiguration), fun namespace, err := env.CreateUniqueNamespace(namespacePrefix) Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - if CurrentSpecReport().Failed() { - env.DumpNamespaceObjects(namespace, "out/"+CurrentSpecReport().LeafNodeText+".log") - } - return env.DeleteNamespace(namespace) + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) cluster := newImageCatalogCluster(namespace, clusterName, major, 3, storageClass) @@ -667,10 +679,12 @@ var _ = Describe("Rolling updates", Label(tests.LabelPostgresConfiguration), fun namespace, err := env.CreateUniqueNamespace(namespacePrefix) Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - if CurrentSpecReport().Failed() { - env.DumpNamespaceObjects(namespace, "out/"+CurrentSpecReport().LeafNodeText+".log") - } - return env.DeleteNamespace(namespace) + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) cluster := newImageCatalogCluster(namespace, clusterName, major, 1, storageClass) diff --git a/tests/e2e/scaling_test.go b/tests/e2e/scaling_test.go index 9db3e955aa..4001f0f465 100644 --- a/tests/e2e/scaling_test.go +++ b/tests/e2e/scaling_test.go @@ -47,10 +47,12 @@ var _ = Describe("Cluster scale up and down", Serial, Label(tests.LabelReplicati namespace, err := env.CreateUniqueNamespace(namespacePrefix) Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - if CurrentSpecReport().Failed() { - env.DumpNamespaceObjects(namespace, "out/"+CurrentSpecReport().LeafNodeText+".log") - } - return env.DeleteNamespaceAndWait(namespace, 60) + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) AssertCreateCluster(namespace, clusterName, sampleFileWithReplicationSlots, env) @@ -89,10 +91,12 @@ var _ = Describe("Cluster scale up and down", Serial, Label(tests.LabelReplicati namespace, err := env.CreateUniqueNamespace(namespacePrefix) Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - if CurrentSpecReport().Failed() { - env.DumpNamespaceObjects(namespace, "out/"+CurrentSpecReport().LeafNodeText+".log") - } - return env.DeleteNamespaceAndWait(namespace, 60) + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) AssertCreateCluster(namespace, clusterName, sampleFileWithoutReplicationSlots, env) diff --git a/tests/e2e/storage_expansion_test.go b/tests/e2e/storage_expansion_test.go index 3b1942c327..c97d2739d4 100644 --- a/tests/e2e/storage_expansion_test.go +++ b/tests/e2e/storage_expansion_test.go @@ -64,10 +64,12 @@ var _ = Describe("Verify storage", Label(tests.LabelStorage), func() { namespace, err = env.CreateUniqueNamespace(namespacePrefix) Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - if CurrentSpecReport().Failed() { - env.DumpNamespaceObjects(namespace, "out/"+CurrentSpecReport().LeafNodeText+".log") - } - return env.DeleteNamespace(namespace) + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) // Creating a cluster with three nodes AssertCreateCluster(namespace, clusterName, sampleFile, env) @@ -94,10 +96,12 @@ var _ = Describe("Verify storage", Label(tests.LabelStorage), func() { namespace, err = env.CreateUniqueNamespace(namespacePrefix) Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - if CurrentSpecReport().Failed() { - env.DumpNamespaceObjects(namespace, "out/"+CurrentSpecReport().LeafNodeText+".log") - } - return env.DeleteNamespace(namespace) + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) AssertCreateCluster(namespace, clusterName, sampleFile, env) By("update cluster for resizeInUseVolumes as false", func() { diff --git a/tests/e2e/suite_test.go b/tests/e2e/suite_test.go index aaa9746d3f..a19c76a56a 100644 --- a/tests/e2e/suite_test.go +++ b/tests/e2e/suite_test.go @@ -19,7 +19,6 @@ package e2e import ( "bufio" "bytes" - "context" "encoding/json" "fmt" "io" @@ -38,7 +37,6 @@ import ( // +kubebuilder:scaffold:imports apiv1 "github.com/cloudnative-pg/cloudnative-pg/api/v1" "github.com/cloudnative-pg/cloudnative-pg/pkg/management/log" - "github.com/cloudnative-pg/cloudnative-pg/pkg/utils/logs" "github.com/cloudnative-pg/cloudnative-pg/tests" "github.com/cloudnative-pg/cloudnative-pg/tests/utils" @@ -257,27 +255,6 @@ var _ = BeforeEach(func() { operatorPod, err := env.GetOperatorPod() Expect(err).ToNot(HaveOccurred()) - GinkgoWriter.Println("Putting Tail on the operator log") - var buf bytes.Buffer - go func() { - // get logs without timestamp parsing; for JSON parseability - err = logs.TailPodLogs(context.TODO(), env.Interface, operatorPod, &buf, false) - if err != nil { - _, _ = fmt.Fprintf(&buf, "Error tailing logs, dumping operator logs: %v\n", err) - } - }() - DeferCleanup(func(_ SpecContext) { - if CurrentSpecReport().Failed() { - specName := CurrentSpecReport().FullText() - capLines := 10 - GinkgoWriter.Printf("DUMPING tailed Operator Logs with error/warning (at most %v lines ). Failed Spec: %v\n", - capLines, specName) - GinkgoWriter.Println("================================================================================") - saveLogs(&buf, "operator_logs", strings.ReplaceAll(specName, " ", "_"), GinkgoWriter, capLines) - GinkgoWriter.Println("================================================================================") - } - }) - if operatorPodWasRenamed { Skip("Skipping test. Operator was renamed") } diff --git a/tests/e2e/switchover_test.go b/tests/e2e/switchover_test.go index 8bf59a331a..1e5eb4c994 100644 --- a/tests/e2e/switchover_test.go +++ b/tests/e2e/switchover_test.go @@ -43,10 +43,12 @@ var _ = Describe("Switchover", Serial, Label(tests.LabelSelfHealing), func() { namespace, err = env.CreateUniqueNamespace(namespacePrefix) Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - if CurrentSpecReport().Failed() { - env.DumpNamespaceObjects(namespace, "out/"+CurrentSpecReport().LeafNodeText+".log") - } - return env.DeleteNamespace(namespace) + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) clusterName, err := env.GetResourceNameFromYAML(sampleFileWithReplicationSlots) Expect(err).ToNot(HaveOccurred()) @@ -65,10 +67,12 @@ var _ = Describe("Switchover", Serial, Label(tests.LabelSelfHealing), func() { namespace, err = env.CreateUniqueNamespace(namespacePrefix) Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - if CurrentSpecReport().Failed() { - env.DumpNamespaceObjects(namespace, "out/"+CurrentSpecReport().LeafNodeText+".log") - } - return env.DeleteNamespace(namespace) + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) clusterName, err := env.GetResourceNameFromYAML(sampleFileWithoutReplicationSlots) Expect(err).ToNot(HaveOccurred()) diff --git a/tests/e2e/syncreplicas_test.go b/tests/e2e/syncreplicas_test.go index f3a35fecd7..bb44d36b24 100644 --- a/tests/e2e/syncreplicas_test.go +++ b/tests/e2e/syncreplicas_test.go @@ -91,10 +91,12 @@ var _ = Describe("Synchronous Replicas", Label(tests.LabelReplication), func() { namespace, err := env.CreateUniqueNamespace(namespacePrefix) Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - if CurrentSpecReport().Failed() { - env.DumpNamespaceObjects(namespace, "out/"+CurrentSpecReport().LeafNodeText+".log") - } - return env.DeleteNamespace(namespace) + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) AssertCreateCluster(namespace, clusterName, sampleFile, env) @@ -163,10 +165,12 @@ var _ = Describe("Synchronous Replicas", Label(tests.LabelReplication), func() { namespace, err := env.CreateUniqueNamespace(namespacePrefix) Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - if CurrentSpecReport().Failed() { - env.DumpNamespaceObjects(namespace, "out/"+CurrentSpecReport().LeafNodeText+".log") - } - return env.DeleteNamespace(namespace) + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) AssertCreateCluster(namespace, clusterName, sampleFile, env) @@ -192,10 +196,12 @@ var _ = Describe("Synchronous Replicas", Label(tests.LabelReplication), func() { namespace, err := env.CreateUniqueNamespace(namespacePrefix) Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - if CurrentSpecReport().Failed() { - env.DumpNamespaceObjects(namespace, "out/"+CurrentSpecReport().LeafNodeText+".log") - } - return env.DeleteNamespace(namespace) + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) AssertCreateCluster(namespace, clusterName, sampleFile, env) diff --git a/tests/e2e/tablespaces_test.go b/tests/e2e/tablespaces_test.go index b6d4c577f8..68d98fb1eb 100644 --- a/tests/e2e/tablespaces_test.go +++ b/tests/e2e/tablespaces_test.go @@ -124,7 +124,14 @@ var _ = Describe("Tablespaces tests", Label(tests.LabelTablespaces, // Create a cluster in a namespace we'll delete after the test namespace, err = env.CreateUniqueNamespace(namespacePrefix) Expect(err).ToNot(HaveOccurred()) - + DeferCleanup(func() error { + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) + }) // We create the MinIO credentials required to login into the system AssertStorageCredentialsAreCreated(namespace, "backup-storage-creds", "minio", "minio123") @@ -133,9 +140,6 @@ var _ = Describe("Tablespaces tests", Label(tests.LabelTablespaces, Expect(err).ToNot(HaveOccurred()) }) - DeferCleanup(func() error { - return env.DeleteNamespace(namespace) - }) clusterSetup(clusterManifest) }) @@ -391,7 +395,14 @@ var _ = Describe("Tablespaces tests", Label(tests.LabelTablespaces, // Create a cluster in a namespace we'll delete after the test namespace, err = env.CreateUniqueNamespace(namespacePrefix) Expect(err).ToNot(HaveOccurred()) - + DeferCleanup(func() error { + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) + }) // We create the required credentials for MinIO AssertStorageCredentialsAreCreated(namespace, "backup-storage-creds", "minio", "minio123") @@ -400,9 +411,6 @@ var _ = Describe("Tablespaces tests", Label(tests.LabelTablespaces, Expect(err).ToNot(HaveOccurred()) }) - DeferCleanup(func() error { - return env.DeleteNamespace(namespace) - }) clusterSetup(clusterManifest) }) @@ -631,7 +639,12 @@ var _ = Describe("Tablespaces tests", Label(tests.LabelTablespaces, namespace, err = env.CreateUniqueNamespace(namespacePrefix) Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - return env.DeleteNamespace(namespace) + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) clusterSetup(clusterManifest) }) @@ -769,7 +782,12 @@ var _ = Describe("Tablespaces tests", Label(tests.LabelTablespaces, namespace, err = env.CreateUniqueNamespace(namespacePrefix) Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - return env.DeleteNamespace(namespace) + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) clusterSetup(clusterManifest) }) diff --git a/tests/e2e/tolerations_test.go b/tests/e2e/tolerations_test.go index 7946703a15..c5fe70ff97 100644 --- a/tests/e2e/tolerations_test.go +++ b/tests/e2e/tolerations_test.go @@ -60,10 +60,12 @@ var _ = Describe("E2E Tolerations Node", Serial, Label(tests.LabelDisruptive, te namespace, err = env.CreateUniqueNamespace(namespacePrefix) Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - if CurrentSpecReport().Failed() { - env.DumpNamespaceObjects(namespace, "out/"+CurrentSpecReport().LeafNodeText+".log") - } - return env.DeleteNamespace(namespace) + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) By("tainting all the nodes", func() { diff --git a/tests/e2e/update_user_test.go b/tests/e2e/update_user_test.go index e23a4869aa..ad58a8b32c 100644 --- a/tests/e2e/update_user_test.go +++ b/tests/e2e/update_user_test.go @@ -50,10 +50,12 @@ var _ = Describe("Update user and superuser password", Label(tests.LabelServiceC namespace, err := env.CreateUniqueNamespace(namespacePrefix) Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - if CurrentSpecReport().Failed() { - env.DumpNamespaceObjects(namespace, "out/"+CurrentSpecReport().LeafNodeText+".log") - } - return env.DeleteNamespace(namespace) + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) clusterName, err := env.GetResourceNameFromYAML(sampleFile) Expect(err).ToNot(HaveOccurred()) @@ -134,10 +136,12 @@ var _ = Describe("Enable superuser password", Label(tests.LabelServiceConnectivi namespace, err := env.CreateUniqueNamespace(namespacePrefix) Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - if CurrentSpecReport().Failed() { - env.DumpNamespaceObjects(namespace, "out/"+CurrentSpecReport().LeafNodeText+".log") - } - return env.DeleteNamespace(namespace) + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) clusterName, err := env.GetResourceNameFromYAML(sampleFile) Expect(err).ToNot(HaveOccurred()) diff --git a/tests/e2e/volume_snapshot_test.go b/tests/e2e/volume_snapshot_test.go index c899554db9..507f412c09 100644 --- a/tests/e2e/volume_snapshot_test.go +++ b/tests/e2e/volume_snapshot_test.go @@ -83,10 +83,12 @@ var _ = Describe("Verify Volume Snapshot", Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - if CurrentSpecReport().Failed() { - env.DumpNamespaceObjects(namespace, "out/"+CurrentSpecReport().LeafNodeText+".log") - } - return env.DeleteNamespace(namespace) + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) // Creating a cluster with three nodes @@ -171,10 +173,12 @@ var _ = Describe("Verify Volume Snapshot", Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - if CurrentSpecReport().Failed() { - env.DumpNamespaceObjects(namespace, "out/"+CurrentSpecReport().LeafNodeText+".log") - } - return env.DeleteNamespace(namespace) + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) By("create the certificates for MinIO", func() { @@ -358,16 +362,14 @@ var _ = Describe("Verify Volume Snapshot", namespace, err = env.CreateUniqueNamespace(namespacePrefix) Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - if CurrentSpecReport().Failed() { - env.DumpNamespaceObjects(namespace, "out/"+CurrentSpecReport().LeafNodeText+".log") - } - if err := os.Unsetenv(snapshotDataEnv); err != nil { - return err - } - if err := os.Unsetenv(snapshotWalEnv); err != nil { - return err - } - return env.DeleteNamespace(namespace) + _ = os.Unsetenv(snapshotDataEnv) + _ = os.Unsetenv(snapshotWalEnv) + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) clusterToBackupName, err = env.GetResourceNameFromYAML(clusterToBackupFilePath) Expect(err).ToNot(HaveOccurred()) @@ -581,10 +583,12 @@ var _ = Describe("Verify Volume Snapshot", Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - if CurrentSpecReport().Failed() { - env.DumpNamespaceObjects(namespace, "out/"+CurrentSpecReport().LeafNodeText+".log") - } - return env.DeleteNamespace(namespace) + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) By("create the certificates for MinIO", func() { diff --git a/tests/e2e/wal_restore_parallel_test.go b/tests/e2e/wal_restore_parallel_test.go index fd3fe43acd..b1e1db7ca8 100644 --- a/tests/e2e/wal_restore_parallel_test.go +++ b/tests/e2e/wal_restore_parallel_test.go @@ -68,10 +68,12 @@ var _ = Describe("Wal-restore in parallel", Label(tests.LabelBackupRestore), fun namespace, err = env.CreateUniqueNamespace(namespacePrefix) Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - if CurrentSpecReport().Failed() { - env.DumpNamespaceObjects(namespace, "out/"+CurrentSpecReport().LeafNodeText+".log") - } - return env.DeleteNamespace(namespace) + return env.CleanupNamespace( + namespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) By("creating the credentials for minio", func() { diff --git a/tests/e2e/webhook_test.go b/tests/e2e/webhook_test.go index ba4e09b5dc..d764988e7e 100644 --- a/tests/e2e/webhook_test.go +++ b/tests/e2e/webhook_test.go @@ -84,10 +84,12 @@ var _ = Describe("webhook", Serial, Label(tests.LabelDisruptive, tests.LabelOper webhookNamespace, err = env.CreateUniqueNamespace(webhookNamespacePrefix) Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - if CurrentSpecReport().Failed() { - env.DumpNamespaceObjects(webhookNamespace, "out/"+CurrentSpecReport().LeafNodeText+".log") - } - return env.DeleteNamespace(webhookNamespace) + return env.CleanupNamespace( + webhookNamespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) AssertCreateCluster(webhookNamespace, clusterName, sampleFile, env) // Check if cluster is ready and the default values are populated @@ -128,10 +130,12 @@ var _ = Describe("webhook", Serial, Label(tests.LabelDisruptive, tests.LabelOper webhookNamespace, err = env.CreateUniqueNamespace(webhookNamespacePrefix) Expect(err).ToNot(HaveOccurred()) DeferCleanup(func() error { - if CurrentSpecReport().Failed() { - env.DumpNamespaceObjects(webhookNamespace, "out/"+CurrentSpecReport().LeafNodeText+".log") - } - return env.DeleteNamespace(webhookNamespace) + return env.CleanupNamespace( + webhookNamespace, + CurrentSpecReport().LeafNodeText, + CurrentSpecReport().Failed(), + GinkgoWriter, + ) }) AssertCreateCluster(webhookNamespace, clusterName, sampleFile, env) // Check if cluster is ready and has no default value in the object diff --git a/tests/utils/namespace.go b/tests/utils/namespace.go index c333925bb4..f48a5b4b02 100644 --- a/tests/utils/namespace.go +++ b/tests/utils/namespace.go @@ -17,16 +17,210 @@ limitations under the License. package utils import ( + "bufio" + "bytes" + "encoding/json" "errors" "fmt" + "io" + "os" + "path/filepath" "strings" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/runtime/schema" "sigs.k8s.io/controller-runtime/pkg/client" + + "github.com/cloudnative-pg/cloudnative-pg/pkg/management/log" + "github.com/cloudnative-pg/cloudnative-pg/pkg/utils/logs" ) +func writeInlineOutput(linesToShow, bufferIdx, capLines int, lineBuffer []string, output io.Writer) error { + // print the last `capLines` lines of logs to the `output` + _, _ = fmt.Fprintln(output, "-- OPERATOR LOGS for this namespace, with error/warning --") + var switchErr error + switch { + case linesToShow == 0: + _, switchErr = fmt.Fprintln(output, "-- no error / warning logs --") + case linesToShow <= capLines: + _, switchErr = fmt.Fprintln(output, strings.Join(lineBuffer[:linesToShow], "\n")) + case bufferIdx == 0: + // if bufferIdx == 0, the buffer just finished filling and is in order + _, switchErr = fmt.Fprintln(output, strings.Join(lineBuffer, "\n")) + default: + // the line buffer cycled back and the items 0 to bufferIdx - 1 are newer than the rest + _, switchErr = fmt.Fprintln(output, strings.Join( + append(lineBuffer[bufferIdx:], lineBuffer[:bufferIdx]...), + "\n")) + } + + return switchErr +} + +type logLine map[string]interface{} + +func (l logLine) isAtLeastWarningLevel() bool { + rawLevel := l["level"] + return rawLevel == log.WarningLevelString || rawLevel == log.ErrorLevelString +} + +func (l logLine) getNamespace() string { + s, ok := l["namespace"].(string) + if !ok { + return "" + } + + return s +} + +func (l logLine) matchesNamespace(ns string) bool { + return l.getNamespace() == ns +} + +// saveNamespaceLogs does 2 things: +// - displays the last `capLines` of error/warning logs on the `output` io.Writer (likely GinkgoWriter) +// - saves the full logs to a file +func saveNamespaceLogs( + buf *bytes.Buffer, + logsType string, + specName string, + namespace string, + output io.Writer, + capLines int, +) { + scanner := bufio.NewScanner(buf) + scanner.Buffer(make([]byte, 0, 64*1024), 1024*1024) + filename := fmt.Sprintf("out/%s_ns-%s_%s.log", logsType, namespace, specName) + f, createErr := os.Create(filepath.Clean(filename)) + if createErr != nil { + fmt.Println(createErr) + return + } + defer func() { + if syncErr := f.Sync(); syncErr != nil { + if _, err := fmt.Fprintln(output, "ERROR while flushing file:", syncErr); err != nil { + fmt.Println(err) + } + } + + if closeErr := f.Close(); closeErr != nil { + if _, err := fmt.Fprintln(output, "ERROR while closing file:", closeErr); err != nil { + fmt.Println(err) + } + } + }() + + // circular buffer to hold the last `capLines` of non-DEBUG operator logs + importantLogsBuffer := make([]string, capLines) + importantLogsIdx := 0 + // insertion point in the lineBuffer: values 0 to capLines - 1 (i.e. modulo capLines) + importantLogsBufferIdx := 0 + + for scanner.Scan() { + rawLine := scanner.Text() + + var parsedLine logLine + if unmarshalErr := json.Unmarshal([]byte(rawLine), &parsedLine); unmarshalErr != nil { + if _, err := fmt.Fprintln(output, "ERROR parsing log:", unmarshalErr, rawLine); err != nil { + fmt.Println(err) + continue + } + } + + if !parsedLine.matchesNamespace(namespace) { + continue + } + + // write every matching line to the file stream + if _, err := fmt.Fprintln(f, rawLine); err != nil { + fmt.Println(err) + continue + } + if parsedLine.isAtLeastWarningLevel() { + importantLogsBuffer[importantLogsBufferIdx] = rawLine + importantLogsIdx++ + // `bufferIdx` walks from `0` to `capLines-1` and then to `0` in a cycle + importantLogsBufferIdx = importantLogsIdx % capLines + } + } + + // print the last `capLines` lines of logs to the `output` + _ = writeInlineOutput(importantLogsIdx, importantLogsBufferIdx, capLines, importantLogsBuffer, output) + + if scanErr := scanner.Err(); scanErr != nil { + if _, err := fmt.Fprintln(output, "ERROR while scanning:", scanErr); err != nil { + fmt.Println(err) + } + } +} + +// GetOperatorLogs collects the operator logs +func (env TestingEnvironment) GetOperatorLogs(buf *bytes.Buffer) error { + operatorPod, err := env.GetOperatorPod() + if err != nil { + return err + } + + streamPodLog := logs.StreamingRequest{ + Pod: &operatorPod, + Options: &corev1.PodLogOptions{ + Timestamps: false, + Follow: false, + }, + Client: env.Interface, + } + return streamPodLog.Stream(env.Ctx, buf) +} + +// DumpNamespaceOperatorLogs writes the operator logs related to a namespace into a writer +// and also into a file +func (env TestingEnvironment) DumpNamespaceOperatorLogs(namespace, testName string, output io.Writer) { + var buf bytes.Buffer + err := env.GetOperatorLogs(&buf) + if err != nil { + return + } + capLines := 5 + sanitizedTestName := strings.ReplaceAll(testName, " ", "_") + saveNamespaceLogs(&buf, "operator_logs", sanitizedTestName, namespace, output, capLines) +} + +// CleanupNamespace does cleanup duty related to the tear-down of a namespace, +// and is intended to be called in a DeferCleanup clause +func (env TestingEnvironment) CleanupNamespace( + namespace string, + testName string, + testFailed bool, + output io.Writer, +) error { + if testFailed { + env.DumpNamespaceOperatorLogs(namespace, testName, output) + env.DumpNamespaceObjects(namespace, "out/"+testName+".log") + } + return env.DeleteNamespace(namespace) +} + +// CleanupNamespaceAndWait does cleanup just like CleanupNamespace, but waits for +// the namespace to be deleted, with a timeout +func (env TestingEnvironment) CleanupNamespaceAndWait( + namespace string, + testName string, + testFailed bool, + timeoutSeconds int, + output io.Writer, +) error { + lines, err := env.DumpOperatorLogs(false, 10) + if err != nil { + _, _ = fmt.Fprintf(output, "cleanupNamespace: error dumping opertor logs: %v\n", err) + } + _, _ = fmt.Fprintln(output, strings.Join(lines, "\n")) + if testFailed { + env.DumpNamespaceObjects(namespace, "out/"+testName+".log") + } + return env.DeleteNamespaceAndWait(namespace, timeoutSeconds) +} + // CreateUniqueNamespace creates a namespace by using the passed prefix. // Return the namespace name and any errors encountered. func (env TestingEnvironment) CreateUniqueNamespace(