mirror of
https://github.com/cozystack/cozystack.git
synced 2026-11-21 12:13:55 +09:00
fix(backups): release a MariaDB Backup when the operator CRDs are gone
Listing the operator Restores of a Backup before reading its operator Backup made the cleanup fail on a cluster without the mariadb-operator CRDs, retried for good, so the Backup and its namespace never went away. The operator Backup read that follows already releases the Backup in that case; with no Restore kind no restore can run, so the listing now lets the cleanup reach it. Assisted-by: LLM Signed-off-by: Alexey Artamonov <aleksei.artamonov@aenix.io>
This commit is contained in:
1 parent
8246808289
commit
0195a66fae
2 files changed
+14
No files matched your search
@@ -231,6 +231,11 @@ func (r *BackupReconciler) activeRestoreOf(ctx context.Context, backup *backupsv
|
||||
}
|
||||
restores := &mariadbtypes.RestoreList{}
|
||||
if err := r.apiReader().List(ctx, restores, client.InNamespace(backup.Namespace)); err != nil {
|
||||
// Without the operator's CRDs no Restore can run; the operator
|
||||
// Backup read that follows releases the Backup.
|
||||
if apimeta.IsNoMatchError(err) {
|
||||
return "", nil
|
||||
}
|
||||
return "", fmt.Errorf("list k8s.mariadb.com/Restores: %w", err)
|
||||
}
|
||||
for i := range restores.Items {
|
||||
|
||||
@@ -1148,6 +1148,9 @@ func TestCleanupMariaDBBackup_BoundsAnUnreachableEndpoint(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// Without the mariadb-operator CRDs every k8s.mariadb.com read fails, the
|
||||
// listing of operator Restores included: no Restore can run then, so the
|
||||
// Backup is released rather than held for good.
|
||||
func TestCleanupMariaDBBackup_ReleasesWhenTheOperatorCRDIsGone(t *testing.T) {
|
||||
bucket := &fakeS3Bucket{}
|
||||
c := interceptor.NewClient(newMariaDBStrategyTestClient(t, tenantNamespace()).(client.WithWatch), interceptor.Funcs{
|
||||
@@ -1157,6 +1160,12 @@ func TestCleanupMariaDBBackup_ReleasesWhenTheOperatorCRDIsGone(t *testing.T) {
|
||||
}
|
||||
return c.Get(ctx, key, obj, opts...)
|
||||
},
|
||||
List: func(ctx context.Context, c client.WithWatch, list client.ObjectList, opts ...client.ListOption) error {
|
||||
if _, ok := list.(*mariadbtypes.RestoreList); ok {
|
||||
return &apimeta.NoKindMatchError{GroupKind: mariadbtypes.GroupVersion.WithKind("Restore").GroupKind()}
|
||||
}
|
||||
return c.List(ctx, list, opts...)
|
||||
},
|
||||
})
|
||||
r, rec := cleanupReconcilerWithClient(c, bucket)
|
||||
res, err := r.cleanupMariaDBBackup(context.Background(), cleanupBackup(cleanupDumpName))
|
||||
|
||||
Reference in new issue
Block a user