backup method changed in the output of kubectl get backup
Hi, Team !
I have my CNPG 1.26.1 cluster with Barman Native configured.
tee $cluster_name.yaml << EOF
apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata:
name: $cluster_name
namespace: $oname-system
spec:
instances: 3
imageName: $cnpg_image_name
storage:
size: 1Gi
backup:
retentionPolicy: "1d"
barmanObjectStore:
destinationPath: s3://cluster-backups/
endpointURL: http://minio-service:9000
s3Credentials:
accessKeyId:
name: minio-creds
key: ACCESS_KEY_ID
secretAccessKey:
name: minio-creds
key: ACCESS_SECRET_KEY
wal:
compression: gzip
EOF
tee barman-backup.yaml << EOF
apiVersion: postgresql.cnpg.io/v1
kind: Backup
metadata:
name: barman-backup
namespace: $oname-system
spec:
cluster:
name: $cluster_name
target: prefer-standby
EOF
I have two backups:
barman-backupis done bykubectl apply -f barman-backup.yamlcluster-barman-cnpg-20251016101137is done bykubectl cnpg -n $oname-system backup $cluster_name -m barmanObjectStore
[alexey@wsl2 ~]$ kubectl get -n $oname-system backup
NAME AGE CLUSTER METHOD PHASE ERROR
barman-backup 57s cluster-barman-cnpg barmanObjectStore completed
cluster-barman-cnpg-20251016101137 6s cluster-barman-cnpg barmanObjectStore completed
Now I'm migrating to Barman Plugin 0.7.0:
tee $cluster_name.yaml << EOF
apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata:
name: $cluster_name
namespace: $oname-system
spec:
instances: 3
imagePullPolicy: Always
imageName: $cnpg_image_name
storage:
size: 1Gi
plugins:
- name: barman-cloud.cloudnative-pg.io
isWALArchiver: true
parameters:
barmanObjectName: minio-store
EOF
tee barman-backup.yaml << EOF
apiVersion: postgresql.cnpg.io/v1
kind: Backup
metadata:
name: barman-backup
namespace: $oname-system
spec:
cluster:
name: $cluster_name
method: plugin
pluginConfiguration:
name: barman-cloud.cloudnative-pg.io
target: prefer-standby
EOF
After launching kubectl apply -f barman-backup.yaml I have the following:
[alexey@wsl2 ~]$ kubectl get -n $oname-system backup
NAME AGE CLUSTER METHOD PHASE ERROR
barman-backup 14m cluster-barman-cnpg plugin completed
cluster-barman-cnpg-20251016101137 13m cluster-barman-cnpg barmanObjectStore completed
So, somehow the METHOD for my older barman-backup backup has been changed from barmanObjectStore to plugin:
[alexey@wsl2 ~]$ kubectl get -n $oname-system backup
NAME AGE CLUSTER METHOD PHASE ERROR
barman-backup 57s cluster-barman-cnpg barmanObjectStore completed
cluster-barman-cnpg-20251016101137 6s cluster-barman-cnpg barmanObjectStore completed
Is it by design ? If not, can it be fixed ?
This change is expected if you re-apply a Backup manifest with the same name as an existing Backup resource—even if the backup operation is already completed. When you apply a manifest with a different .spec.method (for example, switching from barmanObjectStore to plugin), Kubernetes updates the resource, and the METHOD field in kubectl get backup reflects the new spec, not the method originally used for the backup. This is standard Kubernetes behavior for custom resources: the latest applied manifest overwrites the resource fields, even for completed backups.
To avoid this, do not re-apply or update manifests for completed Backup resources. Each backup should have a unique name, and completed backups should be treated as immutable records. If you need to keep the historical METHOD value, avoid updating the resource after creation. This behavior is not explicitly documented as a feature or bug, but it is a consequence of how Kubernetes and the CNPG operator handle resource updates and immutability rules for the Backup spec (docs).
To reply, just mention @dosu.
Docs are dead. Just use Dosu.
I think the problem can we solved if we had the Backup.spec.immediate field just like there's ScheduledBackup.spec.immediate