Skip to content

Commit 7e4fc91

Browse files
1gtmhmsayem
andauthored
Add support for cross-namespace target (#1160) (#1162)
/cherry-pick Signed-off-by: hmsayem hmsayem@appscode.com Co-authored-by: Hossain Mahmud <hmsayem@appscode.com>
1 parent 5ece077 commit 7e4fc91

34 files changed

+1829
-615
lines changed

go.mod

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,15 @@ require (
88
gomodules.xyz/flags v0.1.3
99
gomodules.xyz/go-sh v0.1.0
1010
gomodules.xyz/logs v0.0.6
11-
gomodules.xyz/mergo v0.3.13-0.20220214162359-48efe39fd402 // indirect
1211
gomodules.xyz/x v0.0.13
1312
k8s.io/api v0.21.1
1413
k8s.io/apimachinery v0.21.1
1514
k8s.io/client-go v0.21.1
1615
k8s.io/klog/v2 v2.9.0
1716
kmodules.xyz/client-go v0.0.0-20220404224906-af7b092cfac5
1817
kmodules.xyz/custom-resources v0.0.0-20220317220154-7beb809b1f5e
19-
kmodules.xyz/offshoot-api v0.0.0-20220329041708-c076b2bcb0f8
20-
stash.appscode.dev/apimachinery v0.19.0
18+
kmodules.xyz/offshoot-api v0.0.0-20220419215722-c7fc995091d3
19+
stash.appscode.dev/apimachinery v0.19.1-0.20220425033401-c840c081133c
2120
)
2221

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

go.sum

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ github.com/docker/libtrust v0.0.0-20150114040149-fa567046d9b1/go.mod h1:cyGadeNE
165165
github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815/go.mod h1:WwZ+bS3ebgob9U8Nd0kOddGdZWjyMGR8Wziv+TBNwSE=
166166
github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
167167
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
168+
github.com/dustin/go-humanize v1.0.1-0.20220316001817-d5090ed65664/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
168169
github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs=
169170
github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1:+020luEh2TKB4/GOp8oxxtq0Daoen/Cii55CzbTV6DU=
170171
github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I=
@@ -1097,7 +1098,6 @@ k8s.io/utils v0.0.0-20201110183641-67b214c5f920/go.mod h1:jPW/WVKK9YHAvNhRxK0md/
10971098
kmodules.xyz/client-go v0.0.0-20210617233340-13d22e91512b/go.mod h1:A6GAK6xP5zBuWK6A/vUkkjKzcuywkms7fIxRf5wblO4=
10981099
kmodules.xyz/client-go v0.0.0-20211107190155-5bb4090d2728/go.mod h1:ENUu8pPK19xzBkVpAJHoGCI2QRvb1SqffWRt0K2sV5I=
10991100
kmodules.xyz/client-go v0.0.0-20220215012708-9963581d69a7/go.mod h1:sOq5P3AkZdv6D/skvUPwEG15NDYy5olwBllH/JXfhGI=
1100-
kmodules.xyz/client-go v0.0.0-20220317213815-2a6d5a5784f2/go.mod h1:7pExIHGzUdu8ZGveYvAaXEhS4GdczoOy8z+hq6x6K9A=
11011101
kmodules.xyz/client-go v0.0.0-20220404224906-af7b092cfac5 h1:UkXLQ5SMS98RwnJffKAU0ANXVq9AHSLabQ9NKUhkCgA=
11021102
kmodules.xyz/client-go v0.0.0-20220404224906-af7b092cfac5/go.mod h1:7pExIHGzUdu8ZGveYvAaXEhS4GdczoOy8z+hq6x6K9A=
11031103
kmodules.xyz/constants v0.0.0-20210218100002-2c304bfda278/go.mod h1:DbiFk1bJ1KEO94t1SlAn7tzc+Zz95rSXgyUKa2nzPmY=
@@ -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.0 h1:G4oBu55042Ewigtwz/7iICWSiamvomJD8SuFlrEm7x8=
1143-
stash.appscode.dev/apimachinery v0.19.0/go.mod h1:vgzwLa2KFxfbcrTS3gzhJLYmx4WdZpHfW9n8a7Hzhzc=
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: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ func NewCmdBackup() *cobra.Command {
8989
APIVersion: appcatalog.SchemeGroupVersion.String(),
9090
Kind: appcatalog.ResourceKindApp,
9191
Name: opt.appBindingName,
92+
Namespace: opt.appBindingNamespace,
9293
}
9394
var backupOutput *restic.BackupOutput
9495
backupOutput, err = opt.backupElasticsearch(targetRef)
@@ -122,6 +123,7 @@ func NewCmdBackup() *cobra.Command {
122123
cmd.Flags().StringVar(&opt.namespace, "namespace", "default", "Namespace of Backup/Restore Session")
123124
cmd.Flags().StringVar(&opt.backupSessionName, "backupsession", opt.backupSessionName, "Name of the Backup Session")
124125
cmd.Flags().StringVar(&opt.appBindingName, "appbinding", opt.appBindingName, "Name of the app binding")
126+
cmd.Flags().StringVar(&opt.appBindingNamespace, "appbinding-namespace", opt.appBindingNamespace, "Namespace of the app binding")
125127
cmd.Flags().StringVar(&opt.storageSecret.Name, "storage-secret-name", opt.storageSecret.Name, "Name of the storage secret")
126128
cmd.Flags().StringVar(&opt.storageSecret.Namespace, "storage-secret-namespace", opt.storageSecret.Namespace, "Namespace of the storage secret")
127129

@@ -186,7 +188,7 @@ func (opt *esOptions) backupElasticsearch(targetRef api_v1beta1.TargetRef) (*res
186188
return nil, err
187189
}
188190

189-
appBinding, err := opt.catalogClient.AppcatalogV1alpha1().AppBindings(opt.namespace).Get(context.TODO(), opt.appBindingName, metav1.GetOptions{})
191+
appBinding, err := opt.catalogClient.AppcatalogV1alpha1().AppBindings(opt.appBindingNamespace).Get(context.TODO(), opt.appBindingName, metav1.GetOptions{})
190192
if err != nil {
191193
return nil, err
192194
}

pkg/restore.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ func NewCmdRestore() *cobra.Command {
8181
APIVersion: appcatalog.SchemeGroupVersion.String(),
8282
Kind: appcatalog.ResourceKindApp,
8383
Name: opt.appBindingName,
84+
Namespace: opt.appBindingNamespace,
8485
}
8586
var restoreOutput *restic.RestoreOutput
8687
restoreOutput, err = opt.restoreElasticsearch(targetRef)
@@ -113,6 +114,7 @@ func NewCmdRestore() *cobra.Command {
113114
cmd.Flags().StringVar(&kubeconfigPath, "kubeconfig", kubeconfigPath, "Path to kubeconfig file with authorization information (the master location is set by the master flag).")
114115
cmd.Flags().StringVar(&opt.namespace, "namespace", "default", "Namespace of Backup/Restore Session")
115116
cmd.Flags().StringVar(&opt.appBindingName, "appbinding", opt.appBindingName, "Name of the app binding")
117+
cmd.Flags().StringVar(&opt.appBindingNamespace, "appbinding-namespace", opt.appBindingNamespace, "Namespace of the app binding")
116118
cmd.Flags().StringVar(&opt.storageSecret.Name, "storage-secret-name", opt.storageSecret.Name, "Name of the storage secret")
117119
cmd.Flags().StringVar(&opt.storageSecret.Namespace, "storage-secret-namespace", opt.storageSecret.Namespace, "Namespace of the storage secret")
118120

@@ -152,7 +154,7 @@ func (opt *esOptions) restoreElasticsearch(targetRef api_v1beta1.TargetRef) (*re
152154
return nil, err
153155
}
154156

155-
appBinding, err := opt.catalogClient.AppcatalogV1alpha1().AppBindings(opt.namespace).Get(context.TODO(), opt.appBindingName, metav1.GetOptions{})
157+
appBinding, err := opt.catalogClient.AppcatalogV1alpha1().AppBindings(opt.appBindingNamespace).Get(context.TODO(), opt.appBindingName, metav1.GetOptions{})
156158
if err != nil {
157159
return nil, err
158160
}

pkg/utils.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,15 @@ type esOptions struct {
5353
stashClient stash.Interface
5454
catalogClient appcatalog_cs.Interface
5555

56-
namespace string
57-
backupSessionName string
58-
appBindingName string
59-
esArgs string
60-
interimDataDir string
61-
outputDir string
62-
storageSecret kmapi.ObjectReference
63-
waitTimeout int32
56+
namespace string
57+
backupSessionName string
58+
appBindingName string
59+
appBindingNamespace string
60+
esArgs string
61+
interimDataDir string
62+
outputDir string
63+
storageSecret kmapi.ObjectReference
64+
waitTimeout int32
6465

6566
setupOptions restic.SetupOptions
6667
backupOptions restic.BackupOptions

0 commit comments

Comments
 (0)