Repository: cloudnative-pg/cloudnative-pg

Issue:
[Test]: E2E failures when using barman-cloud 3.16.1
### Is there an existing issue already for this bug?

- [x] I have searched for an existing issue, and could not find anything. I believe this is a new bug.

### I have read the troubleshooting guide

- [x] I have read the troubleshooting guide and I think this is a new bug.

### I am running a supported version of CloudNativePG

- [x] I have read the troubleshooting guide and I think this is a new bug.

### Contact Details

_No response_

### Version

1.27 (latest patch)

### What version of Kubernetes are you using?

1.34

### What is your Kubernetes environment?

Self-managed: kind (evaluation)

### How did you install the operator?

YAML manifest

### What happened?

When using operands with Barman 3.16.1, the barman-cloud connectivity assertion can sometimes fail with:  
```
exit status 1 - 2025-10-21 20:53:28,983 [740] ERROR: Bucket cluster-backups does not exist
command terminated with exit code 1

msg: "exit status 1 - 2025-10-21 20:53:28,983 [740] ERROR: Bucket cluster-backups does not exist\ncommand terminated with exit code 1\n"
```


### Cluster resource

```shell

```

### Relevant log output

```shell

```

### Code of Conduct

- [x] I agree to follow this project's Code of Conduct

Discussion:
@dosubot: <!-- Answer -->
There are no existing tickets or documented bugs specifically about E2E failures or "Bucket does not exist" errors with barman-cloud 3.16.1 and CloudNativePG 1.27. However, similar issues have been reported and resolved by correcting the ObjectStore configuration—especially the `endpointURL` and `destinationPath` fields. For MinIO, the endpoint should match the actual service name (for example, `http://minio-service:9000` instead of `http://minio:9000`). Misconfigured endpoints or bucket names are the most common cause of this error [example](https://github.com/cloudnative-pg/plugin-barman-cloud/issues/535).

Other frequent causes include missing environment variables for MinIO compatibility (`AWS_REQUEST_CHECKSUM_CALCULATION` and `AWS_RESPONSE_CHECKSUM_VALIDATION` set to `when_required`), resource constraints (OOMKilled pods), and namespace mismatches between your Cluster, ObjectStore, and Secret resources [details](https://github.com/cloudnative-pg/plugin-barman-cloud/issues/535).

Recent plugin and operator updates have improved error reporting and backup status visibility, but there is no direct fix for this error in the latest releases [changelog](https://github.com/cloudnative-pg/plugin-barman-cloud/pull/506).

If you continue to see this error, double-check your ObjectStore configuration and ensure the bucket exists and is accessible from your cluster. If possible, share your Cluster and ObjectStore manifests and relevant logs for more targeted troubleshooting.


<!-- Dosu Comment Footer -->
*To reply, just mention [@dosu](https://go.dosu.dev/dosubot).*

---
<sup>How did I do? [Good](https://app.dosu.dev/response-feedback/dda0b115-30c7-4d37-b503-92bcd520e6f0?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/dda0b115-30c7-4d37-b503-92bcd520e6f0?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/dda0b115-30c7-4d37-b503-92bcd520e6f0?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/dda0b115-30c7-4d37-b503-92bcd520e6f0?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/dda0b115-30c7-4d37-b503-92bcd520e6f0?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/dda0b115-30c7-4d37-b503-92bcd520e6f0?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/dda0b115-30c7-4d37-b503-92bcd520e6f0?feedback_type=other)</sup>&nbsp;&nbsp;[![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/89b818f3-8b5e-449b-bfb3-64a9360d9665/ask?utm_source=github)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/cloudnative-pg/cloudnative-pg/issues/8908)

Solution patch:
diff --git a/docs/src/appendixes/backup_barmanobjectstore.md b/docs/src/appendixes/backup_barmanobjectstore.md
index 85733155..76969785 100644
--- a/docs/src/appendixes/backup_barmanobjectstore.md
+++ b/docs/src/appendixes/backup_barmanobjectstore.md
@@ -35,6 +35,15 @@ as it is composed of a community PostgreSQL image and the latest
     in your system to take advantage of the improvements introduced in
     Barman cloud (as well as improve the security aspects of your cluster).
 
+!!! Warning "Changes in Barman Cloud 3.16+ and Bucket Creation"
+    Starting with Barman Cloud 3.16, most Barman Cloud commands no longer
+    automatically create the target bucket, assuming it already exists. Only the
+    `barman-cloud-check-wal-archive` command creates the bucket now. Whenever this
+    is not the first operation run on an empty bucket, CloudNativePG will throw an
+    error. As a result, to ensure reliable, future-proof operations and avoid
+    potential issues, we strongly recommend that you create and configure your
+    object store bucket *before* creating a `Cluster` resource that references it.
+
 A backup is performed from a primary or a designated primary instance in a
 `Cluster` (please refer to
 [replica clusters](../replica_cluster.md)



Test patch:
diff --git a/tests/e2e/backup_restore_minio_test.go b/tests/e2e/backup_restore_minio_test.go
index bf56b9a6..173db1c5 100644
--- a/tests/e2e/backup_restore_minio_test.go
+++ b/tests/e2e/backup_restore_minio_test.go
@@ -100,16 +100,14 @@ var _ = Describe("MinIO - Backup and restore", Label(tests.LabelBackupRestore),
 			// Create the cluster
 			AssertCreateCluster(namespace, clusterName, clusterWithMinioSampleFile, env)
 
-			By("verify test connectivity to minio using barman-cloud-wal-archive script", func() {
+			By("verify connectivity of barman to minio", func() {
 				primaryPod, err := clusterutils.GetPrimary(env.Ctx, env.Client, namespace, clusterName)
 				Expect(err).ToNot(HaveOccurred())
 				Eventually(func() (bool, error) {
-					connectionStatus, err := minio.TestConnectivityUsingBarmanCloudWalArchive(
-						namespace, clusterName, primaryPod.GetName(), "minio", "minio123", minioEnv.ServiceName)
-					if err != nil {
-						return false, err
-					}
-					return connectionStatus, nil
+					connectionStatus, err := minio.TestBarmanConnectivity(
+						namespace, clusterName, primaryPod.Name,
+						"minio", "minio123", minioEnv.ServiceName)
+					return connectionStatus, err
 				}, 60).Should(BeTrue())
 			})
 		})
@@ -609,16 +607,14 @@ var _ = Describe("MinIO - Clusters Recovery from Barman Object Store", Label(tes
 			// Create the cluster
 			AssertCreateCluster(namespace, clusterName, clusterSourceFileMinio, env)
 
-			By("verify test connectivity to minio using barman-cloud-wal-archive script", func() {
+			By("verify connectivity of barman to minio", func() {
 				primaryPod, err := clusterutils.GetPrimary(env.Ctx, env.Client, namespace, clusterName)
 				Expect(err).ToNot(HaveOccurred())
 				Eventually(func() (bool, error) {
-					connectionStatus, err := minio.TestConnectivityUsingBarmanCloudWalArchive(
-						namespace, clusterName, primaryPod.GetName(), "minio", "minio123", minioEnv.ServiceName)
-					if err != nil {
-						return false, err
-					}
-					return connectionStatus, nil
+					connectionStatus, err := minio.TestBarmanConnectivity(
+						namespace, clusterName, primaryPod.Name,
+						"minio", "minio123", minioEnv.ServiceName)
+					return connectionStatus, err
 				}, 60).Should(BeTrue())
 			})
 		})
diff --git a/tests/e2e/volume_snapshot_test.go b/tests/e2e/volume_snapshot_test.go
index 2bbda5e2..b7cc6d8f 100644
--- a/tests/e2e/volume_snapshot_test.go
+++ b/tests/e2e/volume_snapshot_test.go
@@ -222,18 +222,14 @@ var _ = Describe("Verify Volume Snapshot",
 					AssertCreateCluster(namespace, clusterToSnapshotName, clusterToSnapshot, env)
 				})
 
-				By("verify test connectivity to minio using barman-cloud-wal-archive script", func() {
-					primaryPod, err := clusterutils.GetPrimary(env.Ctx, env.Client, namespace,
-						clusterToSnapshotName)
+				By("verify connectivity of barman to minio", func() {
+					primaryPod, err := clusterutils.GetPrimary(env.Ctx, env.Client, namespace, clusterToSnapshotName)
 					Expect(err).ToNot(HaveOccurred())
 					Eventually(func() (bool, error) {
-						connectionStatus, err := minio.TestConnectivityUsingBarmanCloudWalArchive(
-							namespace, clusterToSnapshotName, primaryPod.GetName(), "minio", "minio123",
-							minioEnv.ServiceName)
-						if err != nil {
-							return false, err
-						}
-						return connectionStatus, nil
+						connectionStatus, err := minio.TestBarmanConnectivity(
+							namespace, clusterToSnapshotName, primaryPod.Name,
+							"minio", "minio123", minioEnv.ServiceName)
+						return connectionStatus, err
 					}, 60).Should(BeTrue())
 				})
 
@@ -672,18 +668,14 @@ var _ = Describe("Verify Volume Snapshot",
 					AssertCreateCluster(namespace, clusterToSnapshotName, clusterToSnapshot, env)
 				})
 
-				By("verify test connectivity to minio using barman-cloud-wal-archive script", func() {
-					primaryPod, err := clusterutils.GetPrimary(env.Ctx, env.Client, namespace,
-						clusterToSnapshotName)
+				By("verify connectivity of barman to minio", func() {
+					primaryPod, err := clusterutils.GetPrimary(env.Ctx, env.Client, namespace, clusterToSnapshotName)
 					Expect(err).ToNot(HaveOccurred())
 					Eventually(func() (bool, error) {
-						connectionStatus, err := minio.TestConnectivityUsingBarmanCloudWalArchive(
-							namespace, clusterToSnapshotName, primaryPod.GetName(), "minio", "minio123",
-							minioEnv.ServiceName)
-						if err != nil {
-							return false, err
-						}
-						return connectionStatus, nil
+						connectionStatus, err := minio.TestBarmanConnectivity(
+							namespace, clusterToSnapshotName, primaryPod.Name,
+							"minio", "minio123", minioEnv.ServiceName)
+						return connectionStatus, err
 					}, 60).Should(BeTrue())
 				})
 			})
diff --git a/tests/utils/minio/minio.go b/tests/utils/minio/minio.go
index 796ae4d6..8ae851b2 100644
--- a/tests/utils/minio/minio.go
+++ b/tests/utils/minio/minio.go
@@ -606,28 +606,32 @@ func GetFileTags(minioEnv *Env, path string) (TagSet, error) {
 	return output, nil
 }
 
-// TestConnectivityUsingBarmanCloudWalArchive returns true if test connection is successful else false
-func TestConnectivityUsingBarmanCloudWalArchive(
+// TestBarmanConnectivity validates the barman connectivity to the minio endpoint
+func TestBarmanConnectivity(
 	namespace,
 	clusterName,
-	podName,
-	id,
-	key string,
+	primaryPodName,
+	minioID,
+	minioKey string,
 	minioSvcName string,
 ) (bool, error) {
-	// test connectivity should work with valid sample "000000010000000000000000" wal file
-	// using barman-cloud-wal-archive script
-	cmd := fmt.Sprintf("export AWS_CA_BUNDLE=%s;export AWS_ACCESS_KEY_ID=%s;export AWS_SECRET_ACCESS_KEY=%s;"+
-		"barman-cloud-wal-archive --cloud-provider aws-s3 --endpoint-url https://%s:9000 s3://cluster-backups/ %s "+
-		"000000010000000000000000 --test", postgres.BarmanBackupEndpointCACertificateLocation, id, key,
-		minioSvcName, clusterName)
-	_, _, err := run.Unchecked(fmt.Sprintf(
-		"kubectl exec -n %v %v -c postgres -- /bin/bash -c \"%v\"",
+	env := fmt.Sprintf("export AWS_CA_BUNDLE=%s;export AWS_ACCESS_KEY_ID=%s;export AWS_SECRET_ACCESS_KEY=%s;",
+		postgres.BarmanBackupEndpointCACertificateLocation, minioID, minioKey)
+
+	endpointURL := fmt.Sprintf("https://%s:9000", minioSvcName)
+	destinationPath := fmt.Sprintf("s3://%s/", "not-evaluated")
+	cmd := fmt.Sprintf("barman-cloud-check-wal-archive --cloud-provider aws-s3 --endpoint-url %s %s %s --test",
+		endpointURL, destinationPath, clusterName)
+
+	stdout, stderr, err := run.Unchecked(fmt.Sprintf(
+		"kubectl exec -n %v %v -c postgres -- /bin/bash -c \"%s %s\"",
 		namespace,
-		podName,
-		cmd))
+		primaryPodName,
+		env,
+		cmd,
+	))
 	if err != nil {
-		return false, err
+		return false, fmt.Errorf("barman connectivity test failed: %w (stdout: %s, stderr: %s)", err, stdout, stderr)
 	}
 	return true, nil
 }