Skip to content

Commit

Permalink
Merge pull request #1066 from replicatedhq/divolgin/restic
Browse files Browse the repository at this point in the history
Fix incplete snapshot error after settings are changed
  • Loading branch information
divolgin committed Sep 4, 2020
2 parents d2fd769 + c8cf2a3 commit b464644
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
7 changes: 7 additions & 0 deletions kotsadm/pkg/handlers/snapshots.go
Expand Up @@ -303,6 +303,13 @@ func UpdateGlobalSnapshotSettings(w http.ResponseWriter, r *http.Request) {
return
}

if err := snapshot.ResetResticRepositories(); err != nil {
logger.Error(err)
globalSnapshotSettingsResponse.Error = "failed to try to reset restic repositories"
JSON(w, 500, globalSnapshotSettingsResponse)
return
}

// most plugins (all?) require that velero be restared after updating
if err := snapshot.RestartVelero(); err != nil {
logger.Error(err)
Expand Down
2 changes: 1 addition & 1 deletion kotsadm/pkg/snapshot/backup.go
Expand Up @@ -12,12 +12,12 @@ import (
"github.com/pkg/errors"
apptypes "github.com/replicatedhq/kots/kotsadm/pkg/app/types"
"github.com/replicatedhq/kots/kotsadm/pkg/downstream"
"github.com/replicatedhq/kots/pkg/kotsutil"
"github.com/replicatedhq/kots/kotsadm/pkg/logger"
"github.com/replicatedhq/kots/kotsadm/pkg/render"
"github.com/replicatedhq/kots/kotsadm/pkg/snapshot/types"
"github.com/replicatedhq/kots/kotsadm/pkg/store"
kotstypes "github.com/replicatedhq/kots/pkg/kotsadm/types"
"github.com/replicatedhq/kots/pkg/kotsutil"
velerov1 "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
veleroclientv1 "github.com/vmware-tanzu/velero/pkg/generated/clientset/versioned/typed/velero/v1"
velerolabel "github.com/vmware-tanzu/velero/pkg/label"
Expand Down
34 changes: 34 additions & 0 deletions kotsadm/pkg/snapshot/store.go
Expand Up @@ -818,3 +818,37 @@ func Redact(store *types.Store) error {

return nil
}

func ResetResticRepositories() error {
// ResticRepositories store the previous snapshot location which breaks volume backup when location changes.
cfg, err := config.GetConfig()
if err != nil {
return errors.Wrap(err, "failed to get cluster config")
}

storageLocation, err := FindBackupStoreLocation()
if err != nil {
return errors.Wrap(err, "failed to find backupstoragelocations")
}

veleroClient, err := veleroclientv1.NewForConfig(cfg)
if err != nil {
return errors.Wrap(err, "failed to create clientset")
}

repos, err := veleroClient.ResticRepositories(storageLocation.Namespace).List(context.TODO(), metav1.ListOptions{
LabelSelector: "velero.io/storage-location=default",
})
if err != nil {
return errors.Wrap(err, "failed to list resticrepositories")
}

for _, repo := range repos.Items {
err := veleroClient.ResticRepositories(storageLocation.Namespace).Delete(context.TODO(), repo.Name, metav1.DeleteOptions{})
if err != nil {
return errors.Wrapf(err, "failed to delete resticrepository %s", repo.Name)
}
}

return nil
}

0 comments on commit b464644

Please sign in to comment.