mirror of
https://github.com/vmware-tanzu/velero.git
synced 2026-09-05 23:57:12 +00:00
sync controller: fill in missing .spec.storageLocation
Signed-off-by: Steve Kriss <steve@heptio.com>
This commit is contained in:
@@ -163,16 +163,27 @@ func (c *backupSyncController) run() {
|
||||
|
||||
// use the controller's namespace when getting the backup because that's where we
|
||||
// are syncing backups to, regardless of the namespace of the cloud backup.
|
||||
_, err := c.backupClient.Backups(c.namespace).Get(backupName, metav1.GetOptions{})
|
||||
backup, err := c.backupClient.Backups(c.namespace).Get(backupName, metav1.GetOptions{})
|
||||
if err == nil {
|
||||
log.Debug("Backup already exists in cluster")
|
||||
|
||||
if backup.Spec.StorageLocation != "" {
|
||||
continue
|
||||
}
|
||||
|
||||
// pre-v0.10 backups won't initially have a .spec.storageLocation so fill it in
|
||||
log.Debug("Patching backup's .spec.storageLocation because it's missing")
|
||||
if err := patchStorageLocation(backup, c.backupClient.Backups(c.namespace), location.Name); err != nil {
|
||||
log.WithError(err).Error("Error patching backup's .spec.storageLocation")
|
||||
}
|
||||
|
||||
continue
|
||||
}
|
||||
if !kuberrs.IsNotFound(err) {
|
||||
log.WithError(errors.WithStack(err)).Error("Error getting backup from client, proceeding with sync into cluster")
|
||||
}
|
||||
|
||||
backup, err := backupStore.GetBackupMetadata(backupName)
|
||||
backup, err = backupStore.GetBackupMetadata(backupName)
|
||||
if err != nil {
|
||||
log.WithError(errors.WithStack(err)).Error("Error getting backup metadata from backup store")
|
||||
continue
|
||||
@@ -233,6 +244,25 @@ func (c *backupSyncController) run() {
|
||||
}
|
||||
}
|
||||
|
||||
func patchStorageLocation(backup *arkv1api.Backup, client arkv1client.BackupInterface, location string) error {
|
||||
patch := map[string]interface{}{
|
||||
"spec": map[string]interface{}{
|
||||
"storageLocation": location,
|
||||
},
|
||||
}
|
||||
|
||||
patchBytes, err := json.Marshal(patch)
|
||||
if err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
|
||||
if _, err := client.Patch(backup.Name, types.MergePatchType, patchBytes); err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// deleteOrphanedBackups deletes backup objects from Kubernetes that have the specified location
|
||||
// and a phase of Completed, but no corresponding backup in object storage.
|
||||
func (c *backupSyncController) deleteOrphanedBackups(locationName string, cloudBackupNames sets.String, log logrus.FieldLogger) {
|
||||
|
||||
Reference in New Issue
Block a user