Compare commits

...

3 Commits

Author SHA1 Message Date
Gabriel José Mouallem Rodrigues
f210f3721d
Merge eefb45ca5a into 4a94cb9dae 2026-04-01 19:27:57 +02:00
Kenny Root
4a94cb9dae
fix(metrics): announce sidecar injection capability (#776)
Some checks failed
release-please / release-please (push) Failing after 5s
The operator was not announcing the TYPE_INSTANCE_SIDECAR_INJECTION
capability so the CNPG operator did not consider the plugin enabled
for instance pods. The instance manager never queried the plugin's
metrics endpoint, and the barman_cloud_cloudnative_pg_io_* metrics
were missing entirely.

This bug was masked when isWALArchiver was set to true in the plugin
configuration, because the backward compatibility code in CNPG would
mark the plugin as enabled as a side-effect. Users with isWALArchiver
set to false (or omitted) never saw the new metrics.

Closes #682 

Signed-off-by: Kenny Root <kenny@the-b.org>
2026-03-31 15:36:09 +02:00
Gabriel Jose Mouallem Rodrigues
eefb45ca5a fix: add retry logic to updateRecoveryWindow for concurrent status updates
When backup completion and retention policy enforcement run concurrently,
both call updateRecoveryWindow to update the ObjectStore status. This can
cause "object has been modified" errors due to Kubernetes optimistic
concurrency control.

This change wraps the status update in retry.RetryOnConflict, matching
the pattern already used in setLastFailedBackupTime in the same file.
The retry logic fetches a fresh copy of the ObjectStore before each
update attempt, ensuring the resourceVersion is current.

Fixes #758

Signed-off-by: Gabriel Mouallem <gabriel@latitude.sh>
2026-02-03 15:01:30 -03:00
2 changed files with 32 additions and 15 deletions

View File

@ -33,7 +33,8 @@ import (
) )
// updateRecoveryWindow updates the recovery window inside the object // updateRecoveryWindow updates the recovery window inside the object
// store status subresource // store status subresource. It uses retry logic to handle concurrent
// updates from backup completion and retention policy enforcement.
func updateRecoveryWindow( func updateRecoveryWindow(
ctx context.Context, ctx context.Context,
c client.Client, c client.Client,
@ -41,6 +42,14 @@ func updateRecoveryWindow(
objectStore *barmancloudv1.ObjectStore, objectStore *barmancloudv1.ObjectStore,
serverName string, serverName string,
) error { ) error {
objectStoreKey := client.ObjectKeyFromObject(objectStore)
return retry.RetryOnConflict(retry.DefaultBackoff, func() error {
var freshObjectStore barmancloudv1.ObjectStore
if err := c.Get(ctx, objectStoreKey, &freshObjectStore); err != nil {
return err
}
// Set the recovery window inside the barman object store object // Set the recovery window inside the barman object store object
convertTime := func(t *time.Time) *metav1.Time { convertTime := func(t *time.Time) *metav1.Time {
if t == nil { if t == nil {
@ -49,16 +58,17 @@ func updateRecoveryWindow(
return ptr.To(metav1.NewTime(*t)) return ptr.To(metav1.NewTime(*t))
} }
recoveryWindow := objectStore.Status.ServerRecoveryWindow[serverName] recoveryWindow := freshObjectStore.Status.ServerRecoveryWindow[serverName]
recoveryWindow.FirstRecoverabilityPoint = convertTime(backupList.GetFirstRecoverabilityPoint()) recoveryWindow.FirstRecoverabilityPoint = convertTime(backupList.GetFirstRecoverabilityPoint())
recoveryWindow.LastSuccessfulBackupTime = convertTime(backupList.GetLastSuccessfulBackupTime()) recoveryWindow.LastSuccessfulBackupTime = convertTime(backupList.GetLastSuccessfulBackupTime())
if objectStore.Status.ServerRecoveryWindow == nil { if freshObjectStore.Status.ServerRecoveryWindow == nil {
objectStore.Status.ServerRecoveryWindow = make(map[string]barmancloudv1.RecoveryWindow) freshObjectStore.Status.ServerRecoveryWindow = make(map[string]barmancloudv1.RecoveryWindow)
} }
objectStore.Status.ServerRecoveryWindow[serverName] = recoveryWindow freshObjectStore.Status.ServerRecoveryWindow[serverName] = recoveryWindow
return c.Status().Update(ctx, objectStore) return c.Status().Update(ctx, &freshObjectStore)
})
} }
// setLastFailedBackupTime sets the last failed backup time in the // setLastFailedBackupTime sets the last failed backup time in the

View File

@ -62,6 +62,13 @@ func (i IdentityImplementation) GetPluginCapabilities(
}, },
}, },
}, },
{
Type: &identity.PluginCapability_Service_{
Service: &identity.PluginCapability_Service{
Type: identity.PluginCapability_Service_TYPE_INSTANCE_SIDECAR_INJECTION,
},
},
},
}, },
}, nil }, nil
} }