Skip to content

Commit 2218549

Browse files
1gtmEmruz Hossain
andauthored
[cherry-pick] Support multiple commands in backup/restore pipeline (#335) (#341)
/cherry-pick Signed-off-by: Emruz Hossain <emruz@appscode.com> Co-authored-by: Emruz Hossain <emruz@appscode.com>
1 parent 5e38d81 commit 2218549

File tree

66 files changed

+2212
-2798
lines changed

Some content is hidden

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

66 files changed

+2212
-2798
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ jobs:
7878
helm repo add appscode https://charts.appscode.com/stable/
7979
helm repo update
8080
helm install stash-crds appscode/stash-crds
81+
helm install kubedb-crds appscode/kubedb-crds
8182
helm install kmodules-crds appscode/kmodules-crds
8283
kubectl wait --for=condition=NamesAccepted crds --all --timeout=5m
8384

docs/examples/restore/restored-mysql.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,6 @@ spec:
1515
resources:
1616
requests:
1717
storage: 50Mi
18+
init:
19+
waitForInitialRestore: true
1820
terminationPolicy: WipeOut

docs/examples/restore/restoresession.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ metadata:
44
name: restore-sample-mysql
55
namespace: demo
66
labels:
7-
kubedb.com/kind: MySQL # this label is mandatory if you are using KubeDB to deploy the database.
7+
app.kubernetes.io/name: mysqls.kubedb.com # this label is mandatory if you are using KubeDB to deploy the database.
88
spec:
99
task:
1010
name: mysql-restore-8.0.14-v6

docs/mysql.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,7 @@ metadata:
130130
app.kubernetes.io/component: database
131131
app.kubernetes.io/instance: sample-mysql
132132
app.kubernetes.io/managed-by: kubedb.com
133-
app.kubernetes.io/name: mysql
134-
app.kubernetes.io/version: 8.0.14
135-
kubedb.com/kind: MySQL
136-
kubedb.com/name: sample-mysql
133+
app.kubernetes.io/name: mysqls.kubedb.com
137134
name: sample-mysql
138135
namespace: demo
139136
spec:
@@ -456,12 +453,14 @@ spec:
456453
resources:
457454
requests:
458455
storage: 50Mi
456+
init:
457+
waitForInitialRestore: true
459458
terminationPolicy: WipeOut
460459
```
461460

462461
Here,
463462

464-
- `spec.init.stashRestoreSession.name` specifies the `RestoreSession` CRD name that we will use later to restore the database.
463+
- `spec.init.waitForInitialRestore` tells KubeDB to wait for the first restore to complete before marking this database as ready to use.
465464

466465
Let's create the above database,
467466

@@ -501,7 +500,7 @@ metadata:
501500
name: sample-mysql-restore
502501
namespace: demo
503502
labels:
504-
kubedb.com/kind: MySQL # this label is mandatory if you are using KubeDB to deploy the database.
503+
app.kubernetes.io/name: mysqls.kubedb.com # this label is mandatory if you are using KubeDB to deploy the database.
505504
spec:
506505
task:
507506
name: mysql-restore-{{< param "info.subproject_version" >}}
@@ -518,13 +517,13 @@ spec:
518517

519518
Here,
520519

521-
- `.metadata.labels` specifies a `kubedb.com/kind: MySQL` label that is used by KubeDB to watch this RestoreSession object.
520+
- `.metadata.labels` specifies a `app.kubernetes.io/name: mysqls.kubedb.com` label that is used by KubeDB to watch this RestoreSession object.
522521
- `.spec.task.name` specifies the name of the Task CRD that specifies the necessary Functions and their execution order to restore a MySQL database.
523522
- `.spec.repository.name` specifies the Repository CRD that holds the backend information where our backed up data has been stored.
524523
- `.spec.target.ref` refers to the newly created AppBinding object for the `restored-mysql` MySQL object.
525524
- `.spec.rules` specifies that we are restoring data from the latest backup snapshot of the database.
526525

527-
> **Warning:** Label `kubedb.com/kind: MySQL` is mandatory if you are using KubeDB to deploy the database. Otherwise, the database will be stuck in **`Initializing`** state.
526+
> **Warning:** Label `app.kubernetes.io/name: mysqls.kubedb.com` is mandatory if you are using KubeDB to deploy the database. Otherwise, the database will be stuck in **`Provisioning`** state.
528527

529528
Let's create the RestoreSession CRD object we have shown above,
530529

go.mod

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ require (
1111
k8s.io/api v0.18.9
1212
k8s.io/apimachinery v0.18.9
1313
k8s.io/client-go v0.18.9
14-
kmodules.xyz/client-go v0.0.0-20210118094617-273ba20ad7ca
15-
kmodules.xyz/custom-resources v0.0.0-20201124062543-bd8d35c21b0c
16-
kmodules.xyz/offshoot-api v0.0.0-20201105074700-8675f5f686f2
14+
kmodules.xyz/client-go v0.0.0-20210218100652-8f345ddfe801
15+
kmodules.xyz/custom-resources v0.0.0-20210222100152-7426e3678989
16+
kmodules.xyz/offshoot-api v0.0.0-20210218144050-e1d794cb382a
1717
kmodules.xyz/schema-checker v0.1.0
18-
stash.appscode.dev/apimachinery v0.11.9
18+
stash.appscode.dev/apimachinery v0.11.10-0.20210223054644-c403645d9bc1
1919
)
2020

2121
replace bitbucket.org/ww/goautoneg => gomodules.xyz/goautoneg v0.0.0-20120707110453-a547fc61f48d

go.sum

Lines changed: 20 additions & 57 deletions
Large diffs are not rendered by default.

pkg/backup.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ func (opt *mysqlOptions) backupMySQL(targetRef api_v1beta1.TargetRef) (*restic.B
211211
// set env for mysqldump
212212
resticWrapper.SetEnv(EnvMySqlPassword, string(appBindingSecret.Data[MySqlPassword]))
213213
// setup pipe command
214-
opt.backupOptions.StdinPipeCommand = restic.Command{
214+
backupCmd := restic.Command{
215215
Name: MySqlDumpCMD,
216216
Args: []interface{}{
217217
"-u", string(appBindingSecret.Data[MySqlUser]),
@@ -220,10 +220,10 @@ func (opt *mysqlOptions) backupMySQL(targetRef api_v1beta1.TargetRef) (*restic.B
220220
}
221221
// if port is specified, append port in the arguments
222222
if appBinding.Spec.ClientConfig.Service.Port != 0 {
223-
opt.backupOptions.StdinPipeCommand.Args = append(opt.backupOptions.StdinPipeCommand.Args, fmt.Sprintf("--port=%d", appBinding.Spec.ClientConfig.Service.Port))
223+
backupCmd.Args = append(backupCmd.Args, fmt.Sprintf("--port=%d", appBinding.Spec.ClientConfig.Service.Port))
224224
}
225225
for _, arg := range strings.Fields(opt.myArgs) {
226-
opt.backupOptions.StdinPipeCommand.Args = append(opt.backupOptions.StdinPipeCommand.Args, arg)
226+
backupCmd.Args = append(backupCmd.Args, arg)
227227
}
228228

229229
// if ssl enabled, add ca.crt in the arguments
@@ -235,7 +235,7 @@ func (opt *mysqlOptions) backupMySQL(targetRef api_v1beta1.TargetRef) (*restic.B
235235
fmt.Sprintf("--ssl-ca=%v", filepath.Join(opt.setupOptions.ScratchDir, MySQLTLSRootCA)),
236236
}
237237

238-
opt.backupOptions.StdinPipeCommand.Args = append(opt.backupOptions.StdinPipeCommand.Args, tlsCreds...)
238+
backupCmd.Args = append(backupCmd.Args, tlsCreds...)
239239
}
240240

241241
// wait for DB ready
@@ -244,6 +244,9 @@ func (opt *mysqlOptions) backupMySQL(targetRef api_v1beta1.TargetRef) (*restic.B
244244
return nil, err
245245
}
246246

247+
// add backup command in the pipeline
248+
opt.backupOptions.StdinPipeCommands = append(opt.backupOptions.StdinPipeCommands, backupCmd)
249+
247250
// Run backup
248251
return resticWrapper.RunBackup(opt.backupOptions, targetRef)
249252
}

pkg/restore.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ func (opt *mysqlOptions) restoreMySQL(targetRef api_v1beta1.TargetRef) (*restic.
177177
// set env for mysql
178178
resticWrapper.SetEnv(EnvMySqlPassword, string(appBindingSecret.Data[MySqlPassword]))
179179
// setup pipe command
180-
opt.dumpOptions.StdoutPipeCommand = restic.Command{
180+
restoreCmd := restic.Command{
181181
Name: MySqlRestoreCMD,
182182
Args: []interface{}{
183183
"-u", string(appBindingSecret.Data[MySqlUser]),
@@ -186,10 +186,10 @@ func (opt *mysqlOptions) restoreMySQL(targetRef api_v1beta1.TargetRef) (*restic.
186186
}
187187
// if port is specified, append port in the arguments
188188
if appBinding.Spec.ClientConfig.Service.Port != 0 {
189-
opt.dumpOptions.StdoutPipeCommand.Args = append(opt.dumpOptions.StdoutPipeCommand.Args, fmt.Sprintf("--port=%d", appBinding.Spec.ClientConfig.Service.Port))
189+
restoreCmd.Args = append(restoreCmd.Args, fmt.Sprintf("--port=%d", appBinding.Spec.ClientConfig.Service.Port))
190190
}
191191
for _, arg := range strings.Fields(opt.myArgs) {
192-
opt.dumpOptions.StdoutPipeCommand.Args = append(opt.dumpOptions.StdoutPipeCommand.Args, arg)
192+
restoreCmd.Args = append(restoreCmd.Args, arg)
193193
}
194194

195195
// if ssl enabled, add ca.crt in the arguments
@@ -201,7 +201,7 @@ func (opt *mysqlOptions) restoreMySQL(targetRef api_v1beta1.TargetRef) (*restic.
201201
fmt.Sprintf("--ssl-ca=%v", filepath.Join(opt.setupOptions.ScratchDir, MySQLTLSRootCA)),
202202
}
203203

204-
opt.dumpOptions.StdoutPipeCommand.Args = append(opt.dumpOptions.StdoutPipeCommand.Args, tlsCreds...)
204+
restoreCmd.Args = append(restoreCmd.Args, tlsCreds...)
205205
}
206206

207207
// wait for DB ready
@@ -210,6 +210,9 @@ func (opt *mysqlOptions) restoreMySQL(targetRef api_v1beta1.TargetRef) (*restic.
210210
return nil, err
211211
}
212212

213+
// append the restore command to the pipeline
214+
opt.dumpOptions.StdoutPipeCommands = append(opt.dumpOptions.StdoutPipeCommands, restoreCmd)
215+
213216
// Run dump
214217
return resticWrapper.Dump(opt.dumpOptions, targetRef)
215218
}

vendor/github.com/gophercloud/gophercloud/.travis.yml

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

vendor/github.com/gophercloud/gophercloud/.zuul.yaml

Lines changed: 13 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)