This repository has been archived by the owner on Jan 3, 2024. It is now read-only.
forked from longhorn/longhorn-manager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsystemrestore.go
61 lines (49 loc) · 1.59 KB
/
systemrestore.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package manager
import (
"github.com/sirupsen/logrus"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"github.com/longhorn/longhorn-manager/util"
longhorn "github.com/longhorn/longhorn-manager/k8s/pkg/apis/longhorn/v1beta2"
)
func (m *VolumeManager) CreateSystemRestore(name, systemBackup string) (*longhorn.SystemRestore, error) {
log := logrus.WithFields(logrus.Fields{
"systemBackup": systemBackup,
"systemRestore": name,
})
log.Info("Creating SystemRestore")
return m.ds.CreateSystemRestore(&longhorn.SystemRestore{
ObjectMeta: metav1.ObjectMeta{
Name: name,
},
Spec: longhorn.SystemRestoreSpec{
SystemBackup: systemBackup,
},
})
}
func (m *VolumeManager) DeleteSystemRestore(name string) error {
logrus.WithField("systemRestore", name).Info("Deleting SystemRestore")
err := m.ds.DeleteSystemRestore(name)
if err != nil && !apierrors.IsNotFound(err) {
return err
}
return nil
}
func (m *VolumeManager) GetSystemRestore(name string) (*longhorn.SystemRestore, error) {
return m.ds.GetSystemRestoreRO(name)
}
func (m *VolumeManager) ListSystemRestoresSorted() ([]*longhorn.SystemRestore, error) {
systemRestores, err := m.ds.ListSystemRestores()
if err != nil {
return []*longhorn.SystemRestore{}, err
}
systemRestoreNames, err := util.SortKeys(systemRestores)
if err != nil {
return []*longhorn.SystemRestore{}, err
}
sortedSystemRestores := make([]*longhorn.SystemRestore, len(systemRestores))
for i, name := range systemRestoreNames {
sortedSystemRestores[i] = systemRestores[name]
}
return sortedSystemRestores, nil
}