Skip to content

Commit 0711cec

Browse files
authored
[cherry-pick] Fix output format + Add PreBackupActions logic (#149) (#165)
Signed-off-by: hossainemruz <emruz@appscode.com>
1 parent cd921b7 commit 0711cec

File tree

106 files changed

+16457
-3543
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

106 files changed

+16457
-3543
lines changed

charts/stash-mongodb/templates/mongodb-backup-task.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ spec:
1616
params:
1717
- name: outputDir
1818
value: /tmp/output
19+
- name: secretVolume
20+
value: secret-volume
1921
volumes:
2022
- name: secret-volume
2123
secret:

charts/stash-mongodb/templates/mongodb-restore-task.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ spec:
1616
params:
1717
- name: outputDir
1818
value: /tmp/output
19+
- name: secretVolume
20+
value: secret-volume
1921
volumes:
2022
- name: secret-volume
2123
secret:

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ require (
1616
k8s.io/apimachinery v0.18.3
1717
k8s.io/client-go v12.0.0+incompatible
1818
k8s.io/kube-openapi v0.0.0-20200410145947-61e04a5be9a6
19-
kmodules.xyz/client-go v0.0.0-20200630053911-20d035822d35
19+
kmodules.xyz/client-go v0.0.0-20200714060506-0b57b4060595
2020
kmodules.xyz/crd-schema-fuzz v0.0.0-20200521005638-2433a187de95
2121
kmodules.xyz/custom-resources v0.0.0-20200604135349-9e9f5c4fdba9
2222
kmodules.xyz/offshoot-api v0.0.0-20200521035628-e135bf07b226
2323
kubedb.dev/apimachinery v0.14.0-alpha.5
2424
sigs.k8s.io/yaml v1.2.0
25-
stash.appscode.dev/apimachinery v0.10.0-beta.1
25+
stash.appscode.dev/apimachinery v0.10.0-beta.1.0.20200717091944-a8f3bb469467
2626
)
2727

2828
replace (

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1257,8 +1257,8 @@ kmodules.xyz/client-go v0.0.0-20200524205059-e986bc44c91b/go.mod h1:sY/eoe4ktxZE
12571257
kmodules.xyz/client-go v0.0.0-20200525012433-99c6914a1eca/go.mod h1:sY/eoe4ktxZEoHpr5NpAQ5s22VSwTE8psJtKVeVgLRY=
12581258
kmodules.xyz/client-go v0.0.0-20200525195850-2fd180961371 h1:PPawDOMyDHGeDPN8j1epNozaIB/Z7MlJsXpwm/r4jgk=
12591259
kmodules.xyz/client-go v0.0.0-20200525195850-2fd180961371/go.mod h1:sY/eoe4ktxZEoHpr5NpAQ5s22VSwTE8psJtKVeVgLRY=
1260-
kmodules.xyz/client-go v0.0.0-20200630053911-20d035822d35 h1:gDzZWVvgAaEBzo4lxMGhPUWqySgFyFDkcqw3NskZiwQ=
1261-
kmodules.xyz/client-go v0.0.0-20200630053911-20d035822d35/go.mod h1:sY/eoe4ktxZEoHpr5NpAQ5s22VSwTE8psJtKVeVgLRY=
1260+
kmodules.xyz/client-go v0.0.0-20200714060506-0b57b4060595 h1:KgvN4M8VbHU6JV4rgYzsUKYhUtF1uCt//dLOyEdG330=
1261+
kmodules.xyz/client-go v0.0.0-20200714060506-0b57b4060595/go.mod h1:sY/eoe4ktxZEoHpr5NpAQ5s22VSwTE8psJtKVeVgLRY=
12621262
kmodules.xyz/constants v0.0.0-20200506032633-a21e58ceec72/go.mod h1:DbiFk1bJ1KEO94t1SlAn7tzc+Zz95rSXgyUKa2nzPmY=
12631263
kmodules.xyz/crd-schema-fuzz v0.0.0-20200521005638-2433a187de95 h1:v0S/+ftzL6Xrs9XevgchAOJyPKlRQXPiZf87xotj3X4=
12641264
kmodules.xyz/crd-schema-fuzz v0.0.0-20200521005638-2433a187de95/go.mod h1:jpu8xFsDKd6kAWUAKk8oTu/GQGBWqhrcaDeOJdaCJnk=
@@ -1307,6 +1307,6 @@ software.sslmate.com/src/go-pkcs12 v0.0.0-20180114231543-2291e8f0f237/go.mod h1:
13071307
sourcegraph.com/sqs/pbtypes v0.0.0-20180604144634-d3ebe8f20ae4/go.mod h1:ketZ/q3QxT9HOBeFhu6RdvsftgpsbFHBF5Cas6cDKZ0=
13081308
stash.appscode.dev/apimachinery v0.10.0-alpha.0 h1:/CBUctjDJyjo9a9lANjAPRq3Fj1KygXddgoJKdGQ0Q8=
13091309
stash.appscode.dev/apimachinery v0.10.0-alpha.0/go.mod h1:su9Q+3/B6+5PdGvVZBIkXoAik6iKKFUcdPNThpZPVV4=
1310-
stash.appscode.dev/apimachinery v0.10.0-beta.1 h1:R1IhAhZ/iUbs2M+v9LYJacDCOmc4lk00JzSjVBrxOG0=
1311-
stash.appscode.dev/apimachinery v0.10.0-beta.1/go.mod h1:v3rBovazmdCv/9rAA5U7LpDRFhVqcLsagnLlbPfD2Eg=
1310+
stash.appscode.dev/apimachinery v0.10.0-beta.1.0.20200717091944-a8f3bb469467 h1:ghoHaD+TRpDGB1sjA6F+4wT4uKNF/hhbulzARzO7AXE=
1311+
stash.appscode.dev/apimachinery v0.10.0-beta.1.0.20200717091944-a8f3bb469467/go.mod h1:lyIgBXoTj0cugPfVQC5IjOsMiQEx0YQuvr3KycGltyU=
13121312
vbom.ml/util v0.0.0-20160121211510-db5cfe13f5cc/go.mod h1:so/NYdZXCz+E3ZpW0uAoCj6uzU2+8OWDFv/HxUSs7kI=

pkg/backup.go

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import (
3434
stash_cs "stash.appscode.dev/apimachinery/client/clientset/versioned"
3535
stash_cs_util "stash.appscode.dev/apimachinery/client/clientset/versioned/typed/stash/v1beta1/util"
3636
"stash.appscode.dev/apimachinery/pkg/restic"
37+
api_util "stash.appscode.dev/apimachinery/pkg/util"
3738

3839
"github.com/appscode/go/flags"
3940
"github.com/appscode/go/log"
@@ -45,6 +46,7 @@ import (
4546
"k8s.io/apimachinery/pkg/util/sets"
4647
"k8s.io/client-go/kubernetes"
4748
"k8s.io/client-go/tools/clientcmd"
49+
appcatalog "kmodules.xyz/custom-resources/apis/appcatalog/v1alpha1"
4850
appcatalog_cs "kmodules.xyz/custom-resources/client/clientset/versioned"
4951
v1 "kmodules.xyz/offshoot-api/api/v1"
5052
"kubedb.dev/apimachinery/apis/config/v1alpha1"
@@ -125,15 +127,23 @@ func NewCmdBackup() *cobra.Command {
125127
return err
126128
}
127129

130+
targetRef := api_v1beta1.TargetRef{
131+
APIVersion: appcatalog.SchemeGroupVersion.String(),
132+
Kind: appcatalog.ResourceKindApp,
133+
Name: opt.appBindingName,
134+
}
128135
var backupOutput *restic.BackupOutput
129-
backupOutput, err = opt.backupMongoDB()
136+
backupOutput, err = opt.backupMongoDB(targetRef)
130137
if err != nil {
131138
backupOutput = &restic.BackupOutput{
132-
HostBackupStats: []api_v1beta1.HostBackupStats{
133-
{
134-
Hostname: opt.defaultBackupOptions.Host,
135-
Phase: api_v1beta1.HostBackupFailed,
136-
Error: err.Error(),
139+
BackupTargetStatus: api_v1beta1.BackupTargetStatus{
140+
Ref: targetRef,
141+
Stats: []api_v1beta1.HostBackupStats{
142+
{
143+
Hostname: opt.defaultBackupOptions.Host,
144+
Phase: api_v1beta1.HostBackupFailed,
145+
Error: err.Error(),
146+
},
137147
},
138148
},
139149
}
@@ -184,9 +194,25 @@ func NewCmdBackup() *cobra.Command {
184194
return cmd
185195
}
186196

187-
func (opt *mongoOptions) backupMongoDB() (*restic.BackupOutput, error) {
197+
func (opt *mongoOptions) backupMongoDB(targetRef api_v1beta1.TargetRef) (*restic.BackupOutput, error) {
198+
// if any pre-backup actions has been assigned to it, execute them
199+
actionOptions := api_util.ActionOptions{
200+
StashClient: opt.stashClient,
201+
TargetRef: targetRef,
202+
SetupOptions: opt.setupOptions,
203+
BackupSessionName: opt.backupSessionName,
204+
Namespace: opt.namespace,
205+
}
206+
err := api_util.ExecutePreBackupActions(actionOptions)
207+
if err != nil {
208+
return nil, err
209+
}
210+
// wait until the backend repository has been initialized.
211+
err = api_util.WaitForBackendRepository(actionOptions)
212+
if err != nil {
213+
return nil, err
214+
}
188215
// apply nice, ionice settings from env
189-
var err error
190216
opt.setupOptions.Nice, err = v1.NiceSettingsFromEnv()
191217
if err != nil {
192218
return nil, err
@@ -438,7 +464,7 @@ func (opt *mongoOptions) backupMongoDB() (*restic.BackupOutput, error) {
438464
resticWrapper.HideCMD()
439465

440466
// Run backup
441-
return resticWrapper.RunParallelBackup(opt.backupOptions, opt.maxConcurrency)
467+
return resticWrapper.RunParallelBackup(opt.backupOptions, targetRef, opt.maxConcurrency)
442468
}
443469

444470
// cleanup usually unlocks the locked servers

pkg/restore.go

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import (
3939
"k8s.io/apimachinery/pkg/util/sets"
4040
"k8s.io/client-go/kubernetes"
4141
"k8s.io/client-go/tools/clientcmd"
42+
appcatalog "kmodules.xyz/custom-resources/apis/appcatalog/v1alpha1"
4243
appcatalog_cs "kmodules.xyz/custom-resources/client/clientset/versioned"
4344
v1 "kmodules.xyz/offshoot-api/api/v1"
4445
"kubedb.dev/apimachinery/apis/config/v1alpha1"
@@ -89,15 +90,23 @@ func NewCmdRestore() *cobra.Command {
8990
return err
9091
}
9192

93+
targetRef := api_v1beta1.TargetRef{
94+
APIVersion: appcatalog.SchemeGroupVersion.String(),
95+
Kind: appcatalog.ResourceKindApp,
96+
Name: opt.appBindingName,
97+
}
9298
var restoreOutput *restic.RestoreOutput
93-
restoreOutput, err = opt.restoreMongoDB()
99+
restoreOutput, err = opt.restoreMongoDB(targetRef)
94100
if err != nil {
95101
restoreOutput = &restic.RestoreOutput{
96-
HostRestoreStats: []api_v1beta1.HostRestoreStats{
97-
{
98-
Hostname: opt.defaultDumpOptions.Host,
99-
Phase: api_v1beta1.HostRestoreFailed,
100-
Error: err.Error(),
102+
RestoreTargetStatus: api_v1beta1.RestoreMemberStatus{
103+
Ref: targetRef,
104+
Stats: []api_v1beta1.HostRestoreStats{
105+
{
106+
Hostname: opt.defaultDumpOptions.Host,
107+
Phase: api_v1beta1.HostRestoreFailed,
108+
Error: err.Error(),
109+
},
101110
},
102111
},
103112
}
@@ -140,7 +149,7 @@ func NewCmdRestore() *cobra.Command {
140149
return cmd
141150
}
142151

143-
func (opt *mongoOptions) restoreMongoDB() (*restic.RestoreOutput, error) {
152+
func (opt *mongoOptions) restoreMongoDB(targetRef api_v1beta1.TargetRef) (*restic.RestoreOutput, error) {
144153
// apply nice, ionice settings from env
145154
var err error
146155
opt.setupOptions.Nice, err = v1.NiceSettingsFromEnv()
@@ -332,5 +341,5 @@ func (opt *mongoOptions) restoreMongoDB() (*restic.RestoreOutput, error) {
332341
resticWrapper.HideCMD()
333342

334343
// Run dump
335-
return resticWrapper.ParallelDump(opt.dumpOptions, opt.maxConcurrency)
344+
return resticWrapper.ParallelDump(opt.dumpOptions, targetRef, opt.maxConcurrency)
336345
}

vendor/kmodules.xyz/client-go/Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
# Copyright 2019 AppsCode Inc.
2-
# Copyright 2016 The Kubernetes Authors.
1+
# Copyright AppsCode Inc. and Contributors
32
#
43
# Licensed under the Apache License, Version 2.0 (the "License");
54
# you may not use this file except in compliance with the License.

vendor/kmodules.xyz/client-go/api/v1/conditions.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright The Kmodules Authors.
2+
Copyright AppsCode Inc. and Contributors
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.

vendor/kmodules.xyz/client-go/api/v1/doc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright The Kmodules Authors.
2+
Copyright AppsCode Inc. and Contributors
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.

vendor/kmodules.xyz/client-go/api/v1/generated.pb.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)