Skip to content

Commit

Permalink
Add support for cross-namespace target (#1512) (#1517)
Browse files Browse the repository at this point in the history
/cherry-pick
Signed-off-by: hmsayem <[email protected]>

Co-authored-by: Hossain Mahmud <[email protected]>
  • Loading branch information
1gtm and hmsayem authored Apr 28, 2022
1 parent d4e7f6d commit 731a900
Show file tree
Hide file tree
Showing 35 changed files with 1,824 additions and 609 deletions.
5 changes: 2 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ require (
gomodules.xyz/flags v0.1.3
gomodules.xyz/go-sh v0.1.0
gomodules.xyz/logs v0.0.6
gomodules.xyz/mergo v0.3.13-0.20220214162359-48efe39fd402 // indirect
gomodules.xyz/pointer v0.1.0
gomodules.xyz/x v0.0.13
k8s.io/api v0.21.1
Expand All @@ -18,9 +17,9 @@ require (
k8s.io/klog/v2 v2.9.0
kmodules.xyz/client-go v0.0.0-20220404224906-af7b092cfac5
kmodules.xyz/custom-resources v0.0.0-20220317220154-7beb809b1f5e
kmodules.xyz/offshoot-api v0.0.0-20220329041708-c076b2bcb0f8
kmodules.xyz/offshoot-api v0.0.0-20220419215722-c7fc995091d3
kubedb.dev/apimachinery v0.23.0
stash.appscode.dev/apimachinery v0.19.0
stash.appscode.dev/apimachinery v0.19.1-0.20220425033401-c840c081133c
)

replace bitbucket.org/ww/goautoneg => gomodules.xyz/goautoneg v0.0.0-20120707110453-a547fc61f48d
Expand Down
10 changes: 5 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ github.com/docker/libtrust v0.0.0-20150114040149-fa567046d9b1/go.mod h1:cyGadeNE
github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815/go.mod h1:WwZ+bS3ebgob9U8Nd0kOddGdZWjyMGR8Wziv+TBNwSE=
github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/dustin/go-humanize v1.0.1-0.20220316001817-d5090ed65664/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs=
github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1:+020luEh2TKB4/GOp8oxxtq0Daoen/Cii55CzbTV6DU=
github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I=
Expand Down Expand Up @@ -1207,7 +1208,6 @@ kmodules.xyz/client-go v0.0.0-20211013093146-1fbfd52e78c9/go.mod h1:0gkPeALtYjB2
kmodules.xyz/client-go v0.0.0-20211107190155-5bb4090d2728/go.mod h1:ENUu8pPK19xzBkVpAJHoGCI2QRvb1SqffWRt0K2sV5I=
kmodules.xyz/client-go v0.0.0-20211110065417-091bd089a92d/go.mod h1:ENUu8pPK19xzBkVpAJHoGCI2QRvb1SqffWRt0K2sV5I=
kmodules.xyz/client-go v0.0.0-20220215012708-9963581d69a7/go.mod h1:sOq5P3AkZdv6D/skvUPwEG15NDYy5olwBllH/JXfhGI=
kmodules.xyz/client-go v0.0.0-20220317213815-2a6d5a5784f2/go.mod h1:7pExIHGzUdu8ZGveYvAaXEhS4GdczoOy8z+hq6x6K9A=
kmodules.xyz/client-go v0.0.0-20220404224906-af7b092cfac5 h1:UkXLQ5SMS98RwnJffKAU0ANXVq9AHSLabQ9NKUhkCgA=
kmodules.xyz/client-go v0.0.0-20220404224906-af7b092cfac5/go.mod h1:7pExIHGzUdu8ZGveYvAaXEhS4GdczoOy8z+hq6x6K9A=
kmodules.xyz/constants v0.0.0-20210218100002-2c304bfda278/go.mod h1:DbiFk1bJ1KEO94t1SlAn7tzc+Zz95rSXgyUKa2nzPmY=
Expand All @@ -1222,8 +1222,8 @@ kmodules.xyz/objectstore-api v0.0.0-20220317220441-f1d593d0a778 h1:1biCLf6zjBzg9
kmodules.xyz/objectstore-api v0.0.0-20220317220441-f1d593d0a778/go.mod h1:rJ3QmHvS0CCJAhhdbXh+O2nlEY5gEmgYdpo3vA4nAm4=
kmodules.xyz/offshoot-api v0.0.0-20210829122105-6f4d481b0c61/go.mod h1:3LECbAL3FgbyK80NP3V3Pmiuo/a3hFWg/PR6SPFhTns=
kmodules.xyz/offshoot-api v0.0.0-20211103060642-3e217667cf41/go.mod h1:sJYyxf84ZvbVz4SivxMgSelGRYn19wOLUtObiEncCxk=
kmodules.xyz/offshoot-api v0.0.0-20220329041708-c076b2bcb0f8 h1:epLCcaqw60QQ+VbNawJrhM9Y4DpumaLSGzRebsfBCkE=
kmodules.xyz/offshoot-api v0.0.0-20220329041708-c076b2bcb0f8/go.mod h1:9i9RrFY0BtU9jSm70nxhWlLdl9TSZ8pxTnfyPUicq90=
kmodules.xyz/offshoot-api v0.0.0-20220419215722-c7fc995091d3 h1:jgOE/YqNIIMzh+4hXGgqvnx5JQKI4+WyfK2AAPL+1S4=
kmodules.xyz/offshoot-api v0.0.0-20220419215722-c7fc995091d3/go.mod h1:9i9RrFY0BtU9jSm70nxhWlLdl9TSZ8pxTnfyPUicq90=
kmodules.xyz/openshift v0.0.0-20210618001443-f2507caa512f/go.mod h1:8E5ckbd1KMNmR4hc7ScvmQnGfx1ULUUp+UTmoDdxRkc=
kmodules.xyz/prober v0.0.0-20210618020259-5836fb959027/go.mod h1:H4NcvS1RQxeXtQONALbU6r9OT3Xa7cMhfamX/k9t9wo=
kmodules.xyz/prober v0.0.0-20220317043828-5ae0114adcad h1:bMfimFOEgmaKCN/gnSxLIRvQbWg4dqBgcWrMnHWQgyc=
Expand Down Expand Up @@ -1271,5 +1271,5 @@ software.sslmate.com/src/go-pkcs12 v0.0.0-20180114231543-2291e8f0f237/go.mod h1:
software.sslmate.com/src/go-pkcs12 v0.0.0-20200830195227-52f69702a001/go.mod h1:/xvNRWUqm0+/ZMiF4EX00vrSCMsE4/NHb+Pt3freEeQ=
sourcegraph.com/sourcegraph/appdash v0.0.0-20190731080439-ebfcffb1b5c0/go.mod h1:hI742Nqp5OhwiqlzhgfbWU4mW4yO10fP+LoT9WOswdU=
stash.appscode.dev/apimachinery v0.16.0/go.mod h1:unpV/YyHVECNrAdFjFg/SetmPeUjfvc2+P8cnGjih/U=
stash.appscode.dev/apimachinery v0.19.0 h1:G4oBu55042Ewigtwz/7iICWSiamvomJD8SuFlrEm7x8=
stash.appscode.dev/apimachinery v0.19.0/go.mod h1:vgzwLa2KFxfbcrTS3gzhJLYmx4WdZpHfW9n8a7Hzhzc=
stash.appscode.dev/apimachinery v0.19.1-0.20220425033401-c840c081133c h1:lF8fUoGuSGoZfA2L/dSMVD3uWBiSgkD3r0WKAlMfRvQ=
stash.appscode.dev/apimachinery v0.19.1-0.20220425033401-c840c081133c/go.mod h1:LYvEexF9dSGr9+NmeED+LOo6+6xb+6lMfgyLoEKrPbs=
6 changes: 4 additions & 2 deletions pkg/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ func NewCmdBackup() *cobra.Command {
APIVersion: appcatalog.SchemeGroupVersion.String(),
Kind: appcatalog.ResourceKindApp,
Name: opt.appBindingName,
Namespace: opt.appBindingNamespace,
}
var backupOutput *restic.BackupOutput
backupOutput, err = opt.backupMongoDB(targetRef)
Expand Down Expand Up @@ -171,6 +172,7 @@ func NewCmdBackup() *cobra.Command {
cmd.Flags().StringVar(&kubeconfigPath, "kubeconfig", kubeconfigPath, "Path to kubeconfig file with authorization information (the master location is set by the master flag).")
cmd.Flags().StringVar(&opt.namespace, "namespace", "default", "Namespace of Backup/Restore Session")
cmd.Flags().StringVar(&opt.appBindingName, "appbinding", opt.appBindingName, "Name of the app binding")
cmd.Flags().StringVar(&opt.appBindingNamespace, "appbinding-namespace", opt.appBindingNamespace, "Namespace of the app binding")
cmd.Flags().StringVar(&opt.backupSessionName, "backupsession", opt.backupSessionName, "Name of the respective BackupSession object")
cmd.Flags().IntVar(&opt.maxConcurrency, "max-concurrency", 3, "maximum concurrent backup process to run to take backup from each replicasets")

Expand Down Expand Up @@ -237,12 +239,12 @@ func (opt *mongoOptions) backupMongoDB(targetRef api_v1beta1.TargetRef) (*restic
return nil, err
}

appBinding, err := opt.catalogClient.AppcatalogV1alpha1().AppBindings(opt.namespace).Get(context.TODO(), opt.appBindingName, metav1.GetOptions{})
appBinding, err := opt.catalogClient.AppcatalogV1alpha1().AppBindings(opt.appBindingNamespace).Get(context.TODO(), opt.appBindingName, metav1.GetOptions{})
if err != nil {
return nil, err
}

appBindingSecret, err := opt.kubeClient.CoreV1().Secrets(opt.namespace).Get(context.TODO(), appBinding.Spec.Secret.Name, metav1.GetOptions{})
appBindingSecret, err := opt.kubeClient.CoreV1().Secrets(opt.appBindingNamespace).Get(context.TODO(), appBinding.Spec.Secret.Name, metav1.GetOptions{})
if err != nil {
return nil, err
}
Expand Down
6 changes: 4 additions & 2 deletions pkg/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ func NewCmdRestore() *cobra.Command {
APIVersion: appcatalog.SchemeGroupVersion.String(),
Kind: appcatalog.ResourceKindApp,
Name: opt.appBindingName,
Namespace: opt.appBindingNamespace,
}
var restoreOutput *restic.RestoreOutput
restoreOutput, err = opt.restoreMongoDB(targetRef)
Expand Down Expand Up @@ -134,6 +135,7 @@ func NewCmdRestore() *cobra.Command {
cmd.Flags().StringVar(&kubeconfigPath, "kubeconfig", kubeconfigPath, "Path to kubeconfig file with authorization information (the master location is set by the master flag).")
cmd.Flags().StringVar(&opt.namespace, "namespace", "default", "Namespace of Backup/Restore Session")
cmd.Flags().StringVar(&opt.appBindingName, "appbinding", opt.appBindingName, "Name of the app binding")
cmd.Flags().StringVar(&opt.appBindingNamespace, "appbinding-namespace", opt.appBindingNamespace, "Namespace of the app binding")
cmd.Flags().StringVar(&opt.restoreSessionName, "restoresession", opt.restoreSessionName, "Name of the respective RestoreSession object")
cmd.Flags().IntVar(&opt.maxConcurrency, "max-concurrency", 3, "maximum concurrent backup process to run to take backup from each replicasets")

Expand Down Expand Up @@ -176,12 +178,12 @@ func (opt *mongoOptions) restoreMongoDB(targetRef api_v1beta1.TargetRef) (*resti
return nil, err
}

appBinding, err := opt.catalogClient.AppcatalogV1alpha1().AppBindings(opt.namespace).Get(context.TODO(), opt.appBindingName, metav1.GetOptions{})
appBinding, err := opt.catalogClient.AppcatalogV1alpha1().AppBindings(opt.appBindingNamespace).Get(context.TODO(), opt.appBindingName, metav1.GetOptions{})
if err != nil {
return nil, err
}

appBindingSecret, err := opt.kubeClient.CoreV1().Secrets(opt.namespace).Get(context.TODO(), appBinding.Spec.Secret.Name, metav1.GetOptions{})
appBindingSecret, err := opt.kubeClient.CoreV1().Secrets(opt.appBindingNamespace).Get(context.TODO(), appBinding.Spec.Secret.Name, metav1.GetOptions{})
if err != nil {
return nil, err
}
Expand Down
1 change: 1 addition & 0 deletions pkg/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ type mongoOptions struct {
backupSessionName string
restoreSessionName string
appBindingName string
appBindingNamespace string
mongoArgs string
maxConcurrency int
waitTimeout int32
Expand Down
Loading

0 comments on commit 731a900

Please sign in to comment.