-
Notifications
You must be signed in to change notification settings - Fork 88
/
util.go
36 lines (29 loc) · 1.06 KB
/
util.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package snapshot
import (
"context"
"github.com/pkg/errors"
velerov1 "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
veleroclientv1 "github.com/vmware-tanzu/velero/pkg/generated/clientset/versioned/typed/velero/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client/config"
)
func findBackupStoreLocation() (*velerov1.BackupStorageLocation, error) {
cfg, err := config.GetConfig()
if err != nil {
return nil, errors.Wrap(err, "failed to get cluster config")
}
veleroClient, err := veleroclientv1.NewForConfig(cfg)
if err != nil {
return nil, errors.Wrap(err, "failed to create velero clientset")
}
backupStorageLocations, err := veleroClient.BackupStorageLocations("").List(context.TODO(), metav1.ListOptions{})
if err != nil {
return nil, errors.Wrap(err, "failed to list backupstoragelocations")
}
for _, backupStorageLocation := range backupStorageLocations.Items {
if backupStorageLocation.Name == "default" {
return &backupStorageLocation, nil
}
}
return nil, errors.New("global config not found")
}