Skip to content

Commit d17c3e8

Browse files
1gtmhmsayem
andauthored
Add support for cross-namespace target (#39) (#40)
/cherry-pick Signed-off-by: hmsayem hmsayem@appscode.com Co-authored-by: Hossain Mahmud <hmsayem@appscode.com>
1 parent 8300c3a commit d17c3e8

36 files changed

+1835
-614
lines changed

go.mod

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ 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/pointer v0.1.0
1312
gomodules.xyz/x v0.0.13
1413
k8s.io/api v0.21.1
@@ -17,8 +16,8 @@ require (
1716
k8s.io/klog/v2 v2.9.0
1817
kmodules.xyz/client-go v0.0.0-20220404224906-af7b092cfac5
1918
kmodules.xyz/custom-resources v0.0.0-20220317220154-7beb809b1f5e
20-
kmodules.xyz/offshoot-api v0.0.0-20220329041708-c076b2bcb0f8
21-
stash.appscode.dev/apimachinery v0.19.0
19+
kmodules.xyz/offshoot-api v0.0.0-20220419215722-c7fc995091d3
20+
stash.appscode.dev/apimachinery v0.19.1-0.20220425033401-c840c081133c
2221
)
2322

2423
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=
@@ -1099,7 +1100,6 @@ k8s.io/utils v0.0.0-20201110183641-67b214c5f920/go.mod h1:jPW/WVKK9YHAvNhRxK0md/
10991100
kmodules.xyz/client-go v0.0.0-20210617233340-13d22e91512b/go.mod h1:A6GAK6xP5zBuWK6A/vUkkjKzcuywkms7fIxRf5wblO4=
11001101
kmodules.xyz/client-go v0.0.0-20211107190155-5bb4090d2728/go.mod h1:ENUu8pPK19xzBkVpAJHoGCI2QRvb1SqffWRt0K2sV5I=
11011102
kmodules.xyz/client-go v0.0.0-20220215012708-9963581d69a7/go.mod h1:sOq5P3AkZdv6D/skvUPwEG15NDYy5olwBllH/JXfhGI=
1102-
kmodules.xyz/client-go v0.0.0-20220317213815-2a6d5a5784f2/go.mod h1:7pExIHGzUdu8ZGveYvAaXEhS4GdczoOy8z+hq6x6K9A=
11031103
kmodules.xyz/client-go v0.0.0-20220404224906-af7b092cfac5 h1:UkXLQ5SMS98RwnJffKAU0ANXVq9AHSLabQ9NKUhkCgA=
11041104
kmodules.xyz/client-go v0.0.0-20220404224906-af7b092cfac5/go.mod h1:7pExIHGzUdu8ZGveYvAaXEhS4GdczoOy8z+hq6x6K9A=
11051105
kmodules.xyz/constants v0.0.0-20210218100002-2c304bfda278/go.mod h1:DbiFk1bJ1KEO94t1SlAn7tzc+Zz95rSXgyUKa2nzPmY=
@@ -1110,8 +1110,8 @@ kmodules.xyz/custom-resources v0.0.0-20220317220154-7beb809b1f5e/go.mod h1:OCLml
11101110
kmodules.xyz/objectstore-api v0.0.0-20220317220441-f1d593d0a778 h1:1biCLf6zjBzg9YI9xDjrH6RrKtizpKVB7iuo/5NWOo0=
11111111
kmodules.xyz/objectstore-api v0.0.0-20220317220441-f1d593d0a778/go.mod h1:rJ3QmHvS0CCJAhhdbXh+O2nlEY5gEmgYdpo3vA4nAm4=
11121112
kmodules.xyz/offshoot-api v0.0.0-20210829122105-6f4d481b0c61/go.mod h1:3LECbAL3FgbyK80NP3V3Pmiuo/a3hFWg/PR6SPFhTns=
1113-
kmodules.xyz/offshoot-api v0.0.0-20220329041708-c076b2bcb0f8 h1:epLCcaqw60QQ+VbNawJrhM9Y4DpumaLSGzRebsfBCkE=
1114-
kmodules.xyz/offshoot-api v0.0.0-20220329041708-c076b2bcb0f8/go.mod h1:9i9RrFY0BtU9jSm70nxhWlLdl9TSZ8pxTnfyPUicq90=
1113+
kmodules.xyz/offshoot-api v0.0.0-20220419215722-c7fc995091d3 h1:jgOE/YqNIIMzh+4hXGgqvnx5JQKI4+WyfK2AAPL+1S4=
1114+
kmodules.xyz/offshoot-api v0.0.0-20220419215722-c7fc995091d3/go.mod h1:9i9RrFY0BtU9jSm70nxhWlLdl9TSZ8pxTnfyPUicq90=
11151115
kmodules.xyz/prober v0.0.0-20220317043828-5ae0114adcad h1:bMfimFOEgmaKCN/gnSxLIRvQbWg4dqBgcWrMnHWQgyc=
11161116
kmodules.xyz/prober v0.0.0-20220317043828-5ae0114adcad/go.mod h1:QC3O1p+sU/8NnpLKI0VCAO3IQwPlwuimf9l6+Qp3Vt8=
11171117
kmodules.xyz/resource-metrics v0.0.8/go.mod h1:M7rWuo2qh3BpHhogiEVPnvGY9Xx4Pfygqn1Rex8YbgM=
@@ -1141,5 +1141,5 @@ sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc=
11411141
sigs.k8s.io/yaml v1.3.0 h1:a2VclLzOGrwOHDiV8EfBGhvjHvP46CtW5j6POvhYGGo=
11421142
sigs.k8s.io/yaml v1.3.0/go.mod h1:GeOyir5tyXNByN85N/dRIT9es5UQNerPYEKK56eTBm8=
11431143
sourcegraph.com/sourcegraph/appdash v0.0.0-20190731080439-ebfcffb1b5c0/go.mod h1:hI742Nqp5OhwiqlzhgfbWU4mW4yO10fP+LoT9WOswdU=
1144-
stash.appscode.dev/apimachinery v0.19.0 h1:G4oBu55042Ewigtwz/7iICWSiamvomJD8SuFlrEm7x8=
1145-
stash.appscode.dev/apimachinery v0.19.0/go.mod h1:vgzwLa2KFxfbcrTS3gzhJLYmx4WdZpHfW9n8a7Hzhzc=
1144+
stash.appscode.dev/apimachinery v0.19.1-0.20220425033401-c840c081133c h1:lF8fUoGuSGoZfA2L/dSMVD3uWBiSgkD3r0WKAlMfRvQ=
1145+
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
@@ -90,6 +90,7 @@ func NewCmdBackup() *cobra.Command {
9090
APIVersion: appcatalog.SchemeGroupVersion.String(),
9191
Kind: appcatalog.ResourceKindApp,
9292
Name: opt.appBindingName,
93+
Namespace: opt.appBindingNamespace,
9394
}
9495
var backupOutput *restic.BackupOutput
9596
backupOutput, err = opt.backupEtcd(targetRef)
@@ -125,6 +126,7 @@ func NewCmdBackup() *cobra.Command {
125126
cmd.Flags().StringVar(&opt.namespace, "namespace", "default", "Namespace of Backup/Restore Session")
126127
cmd.Flags().StringVar(&opt.backupSessionName, "backupsession", opt.backupSessionName, "Name of the Backup Session")
127128
cmd.Flags().StringVar(&opt.appBindingName, "appbinding", opt.appBindingName, "Name of the app binding")
129+
cmd.Flags().StringVar(&opt.appBindingNamespace, "appbinding-namespace", opt.appBindingNamespace, "Namespace of the app binding")
128130
cmd.Flags().StringVar(&opt.storageSecret.Name, "storage-secret-name", opt.storageSecret.Name, "Name of the storage secret")
129131
cmd.Flags().StringVar(&opt.storageSecret.Namespace, "storage-secret-namespace", opt.storageSecret.Namespace, "Namespace of the storage secret")
130132

@@ -187,7 +189,7 @@ func (opt *options) backupEtcd(targetRef api_v1beta1.TargetRef) (*restic.BackupO
187189
return nil, err
188190
}
189191

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

pkg/restore.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ func NewCmdRestore() *cobra.Command {
100100
APIVersion: appcatalog.SchemeGroupVersion.String(),
101101
Kind: appcatalog.ResourceKindApp,
102102
Name: opt.appBindingName,
103+
Namespace: opt.appBindingNamespace,
103104
}
104105

105106
targetStats := api_v1beta1.RestoreMemberStatus{
@@ -151,6 +152,7 @@ func NewCmdRestore() *cobra.Command {
151152
cmd.Flags().StringVar(&kubeconfigPath, "kubeconfig", kubeconfigPath, "Path to kubeconfig file with authorization information (the master location is set by the master flag).")
152153
cmd.Flags().StringVar(&opt.namespace, "namespace", "default", "Namespace of Backup/Restore Session")
153154
cmd.Flags().StringVar(&opt.appBindingName, "appbinding", opt.appBindingName, "Name of the app binding")
155+
cmd.Flags().StringVar(&opt.appBindingNamespace, "appbinding-namespace", opt.appBindingNamespace, "Namespace of the app binding")
154156
cmd.Flags().StringVar(&opt.storageSecret.Name, "storage-secret-name", opt.storageSecret.Name, "Name of the storage secret")
155157
cmd.Flags().StringVar(&opt.storageSecret.Namespace, "storage-secret-namespace", opt.storageSecret.Namespace, "Namespace of the storage secret")
156158

@@ -188,6 +190,10 @@ func NewCmdRestore() *cobra.Command {
188190
}
189191

190192
func (opt *options) restoreEtcd() error {
193+
if opt.appBindingNamespace != opt.namespace {
194+
return fmt.Errorf("RestoreSession and targetted Appbinding must be in the same namespace. Found RestoreSession in %q namespace and Appbinding in %q namespace", opt.appBindingNamespace, opt.namespace)
195+
}
196+
191197
appBinding, err := opt.catalogClient.AppcatalogV1alpha1().AppBindings(opt.namespace).Get(context.TODO(), opt.appBindingName, metav1.GetOptions{})
192198
if err != nil {
193199
return err

pkg/restore_member.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ func NewCmdRestoreMember() *cobra.Command {
8585
APIVersion: appcatalog.SchemeGroupVersion.String(),
8686
Kind: appcatalog.ResourceKindApp,
8787
Name: opt.appBindingName,
88+
Namespace: opt.namespace,
8889
}
8990

9091
// Get the restore invoker information
@@ -117,6 +118,7 @@ func NewCmdRestoreMember() *cobra.Command {
117118
},
118119
}
119120
cmd.Flags().StringVar(&opt.appBindingName, "appbinding", opt.appBindingName, "Name of the app binding")
121+
cmd.Flags().StringVar(&opt.appBindingNamespace, "appbinding-namespace", opt.appBindingNamespace, "Namespace of the app binding")
120122
cmd.Flags().StringVar(&masterURL, "master", masterURL, "The address of the Kubernetes API server (overrides any value in kubeconfig)")
121123
cmd.Flags().StringVar(&kubeconfigPath, "kubeconfig", kubeconfigPath, "Path to kubeconfig file with authorization information (the master location is set by the master flag).")
122124
cmd.Flags().StringVar(&opt.namespace, "namespace", "default", "Namespace of Backup/Restore Session")

pkg/util.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,14 @@ type options struct {
7979

8080
repositorySecretName string
8181

82-
namespace string
83-
backupSessionName string
84-
appBindingName string
85-
etcdArgs string
86-
waitTimeout int32
87-
outputDir string
88-
storageSecret kmapi.ObjectReference
82+
namespace string
83+
backupSessionName string
84+
appBindingName string
85+
appBindingNamespace string
86+
etcdArgs string
87+
waitTimeout int32
88+
outputDir string
89+
storageSecret kmapi.ObjectReference
8990

9091
etcd etcd
9192

@@ -512,7 +513,7 @@ func (opt *options) getCredential(appBinding *appcatalog.AppBinding) ([]string,
512513
return args, nil
513514
}
514515

515-
appBindingSecret, err := opt.kubeClient.CoreV1().Secrets(opt.namespace).Get(context.TODO(), appBinding.Spec.Secret.Name, metav1.GetOptions{})
516+
appBindingSecret, err := opt.kubeClient.CoreV1().Secrets(appBinding.Namespace).Get(context.TODO(), appBinding.Spec.Secret.Name, metav1.GetOptions{})
516517
if err != nil {
517518
return nil, err
518519
}

0 commit comments

Comments
 (0)