-
Notifications
You must be signed in to change notification settings - Fork 463
/
backup.go
63 lines (56 loc) · 1.31 KB
/
backup.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
62
63
package databases
import (
"github.com/caos/orbos/mntr"
"github.com/caos/orbos/pkg/git"
"github.com/caos/orbos/pkg/kubernetes"
"github.com/caos/orbos/pkg/tree"
"github.com/zitadel/zitadel/operator/api/database"
orbdb "github.com/zitadel/zitadel/operator/database/kinds/orb"
)
func GitOpsInstantBackup(
monitor mntr.Monitor,
k8sClient kubernetes.ClientInt,
gitClient *git.Client,
name string,
) error {
desired, err := gitClient.ReadTree(git.DatabaseFile)
if err != nil {
return err
}
return instantBackup(monitor, k8sClient, desired, name)
}
func CrdInstantBackup(
monitor mntr.Monitor,
k8sClient kubernetes.ClientInt,
name string,
) error {
desired, err := database.ReadCrd(k8sClient)
if err != nil {
return err
}
return instantBackup(monitor, k8sClient, desired, name)
}
func instantBackup(
monitor mntr.Monitor,
k8sClient kubernetes.ClientInt,
desired *tree.Tree,
name string,
) error {
current := &tree.Tree{}
query, _, _, _, _, _, err := orbdb.AdaptFunc(name, nil, false, "instantbackup")(monitor, desired, current)
if err != nil {
monitor.Error(err)
return err
}
queried := map[string]interface{}{}
ensure, err := query(k8sClient, queried)
if err != nil {
monitor.Error(err)
return err
}
if err := ensure(k8sClient); err != nil {
monitor.Error(err)
return err
}
return nil
}