Skip to content

Commit 8c33614

Browse files
author
Emruz Hossain
committed
Update flags
Signed-off-by: Emruz Hossain <emruz@appscode.com>
1 parent 9dbfd9f commit 8c33614

24 files changed

+1767
-602
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@
1515
# vendor/
1616
.go/
1717
bin/
18+
.idea/

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ require (
1515
k8s.io/klog/v2 v2.9.0
1616
kmodules.xyz/client-go v0.0.0-20220404224906-af7b092cfac5
1717
kmodules.xyz/custom-resources v0.0.0-20220317220154-7beb809b1f5e
18-
kmodules.xyz/offshoot-api v0.0.0-20220329041708-c076b2bcb0f8
18+
kmodules.xyz/offshoot-api v0.0.0-20220419215722-c7fc995091d3
1919
sigs.k8s.io/yaml v1.3.0
20-
stash.appscode.dev/apimachinery v0.19.1-0.20220413043008-5fa3647ef8f8
20+
stash.appscode.dev/apimachinery v0.19.1-0.20220425033401-c840c081133c
2121
)
2222

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

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,8 +1108,8 @@ kmodules.xyz/custom-resources v0.0.0-20220317220154-7beb809b1f5e/go.mod h1:OCLml
11081108
kmodules.xyz/objectstore-api v0.0.0-20220317220441-f1d593d0a778 h1:1biCLf6zjBzg9YI9xDjrH6RrKtizpKVB7iuo/5NWOo0=
11091109
kmodules.xyz/objectstore-api v0.0.0-20220317220441-f1d593d0a778/go.mod h1:rJ3QmHvS0CCJAhhdbXh+O2nlEY5gEmgYdpo3vA4nAm4=
11101110
kmodules.xyz/offshoot-api v0.0.0-20210829122105-6f4d481b0c61/go.mod h1:3LECbAL3FgbyK80NP3V3Pmiuo/a3hFWg/PR6SPFhTns=
1111-
kmodules.xyz/offshoot-api v0.0.0-20220329041708-c076b2bcb0f8 h1:epLCcaqw60QQ+VbNawJrhM9Y4DpumaLSGzRebsfBCkE=
1112-
kmodules.xyz/offshoot-api v0.0.0-20220329041708-c076b2bcb0f8/go.mod h1:9i9RrFY0BtU9jSm70nxhWlLdl9TSZ8pxTnfyPUicq90=
1111+
kmodules.xyz/offshoot-api v0.0.0-20220419215722-c7fc995091d3 h1:jgOE/YqNIIMzh+4hXGgqvnx5JQKI4+WyfK2AAPL+1S4=
1112+
kmodules.xyz/offshoot-api v0.0.0-20220419215722-c7fc995091d3/go.mod h1:9i9RrFY0BtU9jSm70nxhWlLdl9TSZ8pxTnfyPUicq90=
11131113
kmodules.xyz/prober v0.0.0-20220317043828-5ae0114adcad h1:bMfimFOEgmaKCN/gnSxLIRvQbWg4dqBgcWrMnHWQgyc=
11141114
kmodules.xyz/prober v0.0.0-20220317043828-5ae0114adcad/go.mod h1:QC3O1p+sU/8NnpLKI0VCAO3IQwPlwuimf9l6+Qp3Vt8=
11151115
kmodules.xyz/resource-metrics v0.0.8/go.mod h1:M7rWuo2qh3BpHhogiEVPnvGY9Xx4Pfygqn1Rex8YbgM=
@@ -1139,5 +1139,5 @@ sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc=
11391139
sigs.k8s.io/yaml v1.3.0 h1:a2VclLzOGrwOHDiV8EfBGhvjHvP46CtW5j6POvhYGGo=
11401140
sigs.k8s.io/yaml v1.3.0/go.mod h1:GeOyir5tyXNByN85N/dRIT9es5UQNerPYEKK56eTBm8=
11411141
sourcegraph.com/sourcegraph/appdash v0.0.0-20190731080439-ebfcffb1b5c0/go.mod h1:hI742Nqp5OhwiqlzhgfbWU4mW4yO10fP+LoT9WOswdU=
1142-
stash.appscode.dev/apimachinery v0.19.1-0.20220413043008-5fa3647ef8f8 h1:fI1VWIsVCa0VVpFBBCICSRiMi+d3FmLixIpyxmHm7rU=
1143-
stash.appscode.dev/apimachinery v0.19.1-0.20220413043008-5fa3647ef8f8/go.mod h1:Wvh/C9ZGQXWex8d6LKU8TodOriuPcirMuTnzgBQooLk=
1142+
stash.appscode.dev/apimachinery v0.19.1-0.20220425033401-c840c081133c h1:lF8fUoGuSGoZfA2L/dSMVD3uWBiSgkD3r0WKAlMfRvQ=
1143+
stash.appscode.dev/apimachinery v0.19.1-0.20220425033401-c840c081133c/go.mod h1:LYvEexF9dSGr9+NmeED+LOo6+6xb+6lMfgyLoEKrPbs=

pkg/backup.go

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ import (
3535
"k8s.io/client-go/kubernetes"
3636
"k8s.io/client-go/tools/clientcmd"
3737
"k8s.io/klog/v2"
38-
appcatalog_cs "kmodules.xyz/custom-resources/client/clientset/versioned"
3938
v1 "kmodules.xyz/offshoot-api/api/v1"
4039
)
4140

@@ -81,18 +80,14 @@ func NewCmdBackup() *cobra.Command {
8180
if err != nil {
8281
return err
8382
}
84-
opt.catalogClient, err = appcatalog_cs.NewForConfig(config)
85-
if err != nil {
86-
return err
87-
}
8883

8984
inv, err := invoker.NewBackupInvoker(opt.stashClient, opt.invokerKind, opt.invokerName, opt.namespace)
9085
if err != nil {
9186
return err
9287
}
9388

9489
for _, ti := range inv.GetTargetInfo() {
95-
if ti.Target != nil && targetMatched(ti.Target.Ref, opt.targetKind, opt.targetName) {
90+
if ti.Target != nil && opt.targetMatched(ti.Target.Ref, opt.targetRef) {
9691
var backupOutput *restic.BackupOutput
9792
backupOutput, err = opt.backupManifests(ti.Target.Ref)
9893
if err != nil {
@@ -137,8 +132,9 @@ func NewCmdBackup() *cobra.Command {
137132
cmd.Flags().StringVar(&opt.backupOptions.Host, "hostname", opt.backupOptions.Host, "Name of the host machine")
138133
cmd.Flags().StringVar(&opt.invokerKind, "invoker-kind", opt.invokerKind, "Kind of the backup invoker")
139134
cmd.Flags().StringVar(&opt.invokerName, "invoker-name", opt.invokerName, "Name of the respective backup invoker")
140-
cmd.Flags().StringVar(&opt.targetKind, "target-kind", opt.targetKind, "Kind of the Target")
141-
cmd.Flags().StringVar(&opt.targetName, "target-name", opt.targetName, "Name of the Target")
135+
cmd.Flags().StringVar(&opt.targetRef.Kind, "target-kind", opt.targetRef.Kind, "Kind of the Target")
136+
cmd.Flags().StringVar(&opt.targetRef.Name, "target-name", opt.targetRef.Name, "Name of the Target")
137+
cmd.Flags().StringVar(&opt.targetRef.Namespace, "target-namespace", opt.targetRef.Namespace, "Namespace of the Target")
142138

143139
cmd.Flags().Int64Var(&opt.backupOptions.RetentionPolicy.KeepLast, "retention-keep-last", opt.backupOptions.RetentionPolicy.KeepLast, "Specify value for retention strategy")
144140
cmd.Flags().Int64Var(&opt.backupOptions.RetentionPolicy.KeepHourly, "retention-keep-hourly", opt.backupOptions.RetentionPolicy.KeepHourly, "Specify value for retention strategy")
@@ -151,7 +147,10 @@ func NewCmdBackup() *cobra.Command {
151147
cmd.Flags().BoolVar(&opt.backupOptions.RetentionPolicy.DryRun, "retention-dry-run", opt.backupOptions.RetentionPolicy.DryRun, "Specify whether to test retention policy without deleting actual data")
152148

153149
cmd.Flags().StringVar(&opt.outputDir, "output-dir", opt.outputDir, "Directory where output.json file will be written (keep empty if you don't need to write output in file)")
154-
cmd.Flags().BoolVar(&opt.sanitize, "output-dir", true, "Specify whether to remove the decorators from the manifest (default is true)")
150+
151+
cmd.Flags().BoolVar(&opt.sanitize, "sanitize", true, "Specify whether to remove the decorators from the manifest (default is true)")
152+
cmd.Flags().StringVar(&opt.selector, "label-selector", "", "Specify a label selector to filter the resources.")
153+
cmd.Flags().BoolVar(&opt.includeDependants, "include-dependants", false, "Specify whether to backup the dependants object along with their parent.")
155154

156155
return cmd
157156
}
@@ -197,11 +196,13 @@ func (opt *options) backupManifests(targetRef v1beta1.TargetRef) (*restic.Backup
197196
}
198197

199198
mgOpts := manager.BackupOptions{
200-
Config: opt.config,
201-
Sanitize: opt.sanitize,
202-
DataDir: opt.dataDir,
203-
Target: targetRef,
204-
Storage: manager.NewFileWriter(),
199+
Config: opt.config,
200+
Sanitize: opt.sanitize,
201+
DataDir: opt.dataDir,
202+
Target: targetRef,
203+
Selector: opt.selector,
204+
IncludeDependants: opt.includeDependants,
205+
Storage: manager.NewFileWriter(),
205206
}
206207
mgr := manager.NewBackupManager(mgOpts)
207208
if err = mgr.Dump(); err != nil {
@@ -220,6 +221,9 @@ func (opt *options) backupManifests(targetRef v1beta1.TargetRef) (*restic.Backup
220221
return resticWrapper.RunBackup(opt.backupOptions, targetRef)
221222
}
222223

223-
func targetMatched(tref v1beta1.TargetRef, expectedKind, expectedName string) bool {
224-
return tref.Kind == expectedKind && tref.Name == expectedName
224+
func (opt *options) targetMatched(tref v1beta1.TargetRef, expected v1beta1.TargetRef) bool {
225+
if expected.Namespace == "" {
226+
expected.Namespace = opt.namespace
227+
}
228+
return tref.Kind == expected.Kind && tref.Name == expected.Name && tref.Namespace == expected.Namespace
225229
}

pkg/utils.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,33 +20,33 @@ import (
2020
"fmt"
2121
"os"
2222

23+
"stash.appscode.dev/apimachinery/apis/stash/v1beta1"
2324
stash "stash.appscode.dev/apimachinery/client/clientset/versioned"
2425
"stash.appscode.dev/apimachinery/pkg/restic"
2526

2627
"k8s.io/client-go/kubernetes"
2728
"k8s.io/client-go/rest"
2829
kmapi "kmodules.xyz/client-go/api/v1"
29-
appcatalog_cs "kmodules.xyz/custom-resources/client/clientset/versioned"
3030
)
3131

3232
type options struct {
33-
kubeClient kubernetes.Interface
34-
stashClient stash.Interface
35-
catalogClient appcatalog_cs.Interface
33+
kubeClient kubernetes.Interface
34+
stashClient stash.Interface
3635

3736
namespace string
3837
backupSessionName string
3938
outputDir string
4039
storageSecret kmapi.ObjectReference
4140

42-
sanitize bool
43-
config *rest.Config
44-
dataDir string
41+
sanitize bool
42+
config *rest.Config
43+
dataDir string
44+
selector string
45+
includeDependants bool
4546

4647
invokerKind string
4748
invokerName string
48-
targetKind string
49-
targetName string
49+
targetRef v1beta1.TargetRef
5050

5151
setupOptions restic.SetupOptions
5252
backupOptions restic.BackupOptions

0 commit comments

Comments
 (0)