Skip to content

Commit

Permalink
Add support for cross-namespace target (#1160) (#1161)
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 c28cbac commit 0a7e37f
Show file tree
Hide file tree
Showing 34 changed files with 1,829 additions and 615 deletions.
5 changes: 2 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,15 @@ 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/x v0.0.13
k8s.io/api v0.21.1
k8s.io/apimachinery v0.21.1
k8s.io/client-go v0.21.1
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
stash.appscode.dev/apimachinery v0.19.0
kmodules.xyz/offshoot-api v0.0.0-20220419215722-c7fc995091d3
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 @@ -165,6 +165,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 @@ -1097,7 +1098,6 @@ k8s.io/utils v0.0.0-20201110183641-67b214c5f920/go.mod h1:jPW/WVKK9YHAvNhRxK0md/
kmodules.xyz/client-go v0.0.0-20210617233340-13d22e91512b/go.mod h1:A6GAK6xP5zBuWK6A/vUkkjKzcuywkms7fIxRf5wblO4=
kmodules.xyz/client-go v0.0.0-20211107190155-5bb4090d2728/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 @@ -1108,8 +1108,8 @@ kmodules.xyz/custom-resources v0.0.0-20220317220154-7beb809b1f5e/go.mod h1:OCLml
kmodules.xyz/objectstore-api v0.0.0-20220317220441-f1d593d0a778 h1:1biCLf6zjBzg9YI9xDjrH6RrKtizpKVB7iuo/5NWOo0=
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-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/prober v0.0.0-20220317043828-5ae0114adcad h1:bMfimFOEgmaKCN/gnSxLIRvQbWg4dqBgcWrMnHWQgyc=
kmodules.xyz/prober v0.0.0-20220317043828-5ae0114adcad/go.mod h1:QC3O1p+sU/8NnpLKI0VCAO3IQwPlwuimf9l6+Qp3Vt8=
kmodules.xyz/resource-metrics v0.0.8/go.mod h1:M7rWuo2qh3BpHhogiEVPnvGY9Xx4Pfygqn1Rex8YbgM=
Expand Down Expand Up @@ -1139,5 +1139,5 @@ sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc=
sigs.k8s.io/yaml v1.3.0 h1:a2VclLzOGrwOHDiV8EfBGhvjHvP46CtW5j6POvhYGGo=
sigs.k8s.io/yaml v1.3.0/go.mod h1:GeOyir5tyXNByN85N/dRIT9es5UQNerPYEKK56eTBm8=
sourcegraph.com/sourcegraph/appdash v0.0.0-20190731080439-ebfcffb1b5c0/go.mod h1:hI742Nqp5OhwiqlzhgfbWU4mW4yO10fP+LoT9WOswdU=
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=
4 changes: 3 additions & 1 deletion pkg/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,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.backupElasticsearch(targetRef)
Expand Down Expand Up @@ -122,6 +123,7 @@ func NewCmdBackup() *cobra.Command {
cmd.Flags().StringVar(&opt.namespace, "namespace", "default", "Namespace of Backup/Restore Session")
cmd.Flags().StringVar(&opt.backupSessionName, "backupsession", opt.backupSessionName, "Name of the Backup 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.storageSecret.Name, "storage-secret-name", opt.storageSecret.Name, "Name of the storage secret")
cmd.Flags().StringVar(&opt.storageSecret.Namespace, "storage-secret-namespace", opt.storageSecret.Namespace, "Namespace of the storage secret")

Expand Down Expand Up @@ -186,7 +188,7 @@ func (opt *esOptions) backupElasticsearch(targetRef api_v1beta1.TargetRef) (*res
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
}
Expand Down
4 changes: 3 additions & 1 deletion pkg/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,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.restoreElasticsearch(targetRef)
Expand Down Expand Up @@ -113,6 +114,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.storageSecret.Name, "storage-secret-name", opt.storageSecret.Name, "Name of the storage secret")
cmd.Flags().StringVar(&opt.storageSecret.Namespace, "storage-secret-namespace", opt.storageSecret.Namespace, "Namespace of the storage secret")

Expand Down Expand Up @@ -152,7 +154,7 @@ func (opt *esOptions) restoreElasticsearch(targetRef api_v1beta1.TargetRef) (*re
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
}
Expand Down
17 changes: 9 additions & 8 deletions pkg/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,15 @@ type esOptions struct {
stashClient stash.Interface
catalogClient appcatalog_cs.Interface

namespace string
backupSessionName string
appBindingName string
esArgs string
interimDataDir string
outputDir string
storageSecret kmapi.ObjectReference
waitTimeout int32
namespace string
backupSessionName string
appBindingName string
appBindingNamespace string
esArgs string
interimDataDir string
outputDir string
storageSecret kmapi.ObjectReference
waitTimeout int32

setupOptions restic.SetupOptions
backupOptions restic.BackupOptions
Expand Down
Loading

0 comments on commit 0a7e37f

Please sign in to comment.