Skip to content

Commit eadc54a

Browse files
author
Emruz Hossain
committed
added all
Signed-off-by: Emruz Hossain <emruz@appscode.com>
1 parent c700514 commit eadc54a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+2330
-1312
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ require (
1616
kmodules.xyz/client-go v0.0.0-20220203031013-1de48437aaf3
1717
kmodules.xyz/custom-resources v0.0.0-20220208103158-61b298634e43
1818
kmodules.xyz/offshoot-api v0.0.0-20211207130839-cc7187e020cf
19-
stash.appscode.dev/apimachinery v0.18.0
19+
stash.appscode.dev/apimachinery v0.18.1-0.20220308093046-7df8eca4f066
2020
)
2121

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

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,5 +1108,5 @@ sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
11081108
sigs.k8s.io/yaml v1.2.0 h1:kr/MCeFWJWTwyaHoR9c8EjH9OumOmoF9YGiZd7lFm/Q=
11091109
sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc=
11101110
sourcegraph.com/sourcegraph/appdash v0.0.0-20190731080439-ebfcffb1b5c0/go.mod h1:hI742Nqp5OhwiqlzhgfbWU4mW4yO10fP+LoT9WOswdU=
1111-
stash.appscode.dev/apimachinery v0.18.0 h1:Mo5m3ffLKePJMPVWufGlFXas3rAwu96R9BeswSNkTrI=
1112-
stash.appscode.dev/apimachinery v0.18.0/go.mod h1:MDzqJ66A2QZKAHRksfHT5crOD29a0S5Hfuy/D5hHAjw=
1111+
stash.appscode.dev/apimachinery v0.18.1-0.20220308093046-7df8eca4f066 h1:DFARQYwC8YnSCWlQ0MgBNgPDZFkr4c/zKbmdchIRfWo=
1112+
stash.appscode.dev/apimachinery v0.18.1-0.20220308093046-7df8eca4f066/go.mod h1:R+AE9wyi0sPZ0t3HWwZq+FiA7ewoGbqsdW6atczGf94=

pkg/backup.go

Lines changed: 8 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ package pkg
1818

1919
import (
2020
"context"
21-
"fmt"
21+
v1 "kmodules.xyz/offshoot-api/api/v1"
2222
"path/filepath"
2323
"time"
2424

@@ -34,9 +34,9 @@ import (
3434
"k8s.io/client-go/kubernetes"
3535
"k8s.io/client-go/tools/clientcmd"
3636
"k8s.io/klog/v2"
37+
"kmodules.xyz/client-go/tools/backup"
3738
appcatalog "kmodules.xyz/custom-resources/apis/appcatalog/v1alpha1"
3839
appcatalog_cs "kmodules.xyz/custom-resources/client/clientset/versioned"
39-
v1 "kmodules.xyz/offshoot-api/api/v1"
4040
)
4141

4242
func NewCmdBackup() *cobra.Command {
@@ -68,6 +68,8 @@ func NewCmdBackup() *cobra.Command {
6868
if err != nil {
6969
return err
7070
}
71+
opt.config = config
72+
7173
err = license.CheckLicenseEndpoint(config, licenseApiService, SupportedProducts)
7274
if err != nil {
7375
return err
@@ -191,45 +193,21 @@ func (opt *esOptions) backupElasticsearch(targetRef api_v1beta1.TargetRef) (*res
191193
return nil, err
192194
}
193195

194-
// clear directory before running multielasticdump
195-
session := opt.newSessionWrapper(MultiElasticDumpCMD)
196+
klog.Infoln("ClientConfig: ", appBinding.Spec.ClientConfig)
196197

197-
err = opt.setDatabaseCredentials(appBinding, session.cmd)
198-
if err != nil {
199-
return nil, err
200-
}
201198
klog.Infoln("Cleaning up directory: ", opt.interimDataDir)
202199
if err := clearDir(opt.interimDataDir); err != nil {
203200
return nil, err
204201
}
205202

206-
url, err := appBinding.URL()
207-
if err != nil {
208-
return nil, err
209-
}
210-
session.cmd.Args = append(session.cmd.Args, []interface{}{
211-
fmt.Sprintf(`--input=%v`, url),
212-
fmt.Sprintf(`--output=%v`, opt.interimDataDir),
213-
}...)
203+
// backup cluster resources yaml into opt.backupDir
204+
mgr := backup.NewBackupManager(opt.context, opt.config, opt.sanitize)
214205

215-
err = session.setTLSParameters(appBinding, opt.setupOptions.ScratchDir)
206+
_, err = mgr.BackupToDir(opt.interimDataDir)
216207
if err != nil {
217208
return nil, err
218209
}
219210

220-
err = opt.waitForDBReady(appBinding)
221-
if err != nil {
222-
return nil, err
223-
}
224-
225-
session.sh.ShowCMD = false
226-
session.setUserArgs(opt.esArgs)
227-
session.sh.Command(session.cmd.Name, session.cmd.Args...) // xref: multielasticdump: https://github.com/taskrabbit/elasticsearch-dump#multielasticdump
228-
229-
if err := session.sh.Run(); err != nil {
230-
return nil, err
231-
}
232-
233211
// dumped data has been stored in the interim data dir. Now, we will backup this directory using Stash.
234212
opt.backupOptions.BackupPaths = []string{opt.interimDataDir}
235213

pkg/restore.go

Lines changed: 0 additions & 220 deletions
This file was deleted.

pkg/root.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ func NewRootCmd() *cobra.Command {
4242

4343
rootCmd.AddCommand(v.NewCmdVersion())
4444
rootCmd.AddCommand(NewCmdBackup())
45-
rootCmd.AddCommand(NewCmdRestore())
4645

4746
return rootCmd
4847
}

pkg/utils.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"context"
2121
"fmt"
2222
"io/ioutil"
23+
"k8s.io/client-go/rest"
2324
"os"
2425
"os/exec"
2526
"path/filepath"
@@ -62,6 +63,10 @@ type esOptions struct {
6263
storageSecret kmapi.ObjectReference
6364
waitTimeout int32
6465

66+
sanitize bool
67+
config *rest.Config
68+
context string
69+
6570
setupOptions restic.SetupOptions
6671
backupOptions restic.BackupOptions
6772
restoreOptions restic.RestoreOptions
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package arrays
2+
3+
import (
4+
"errors"
5+
"reflect"
6+
)
7+
8+
func InterfaceToSlice(slice interface{}) ([]interface{}, error) {
9+
s := reflect.ValueOf(slice)
10+
if s.Kind() != reflect.Slice {
11+
return nil, errors.New("slice of interface not found")
12+
}
13+
14+
ret := make([]interface{}, s.Len())
15+
16+
for i := 0; i < s.Len(); i++ {
17+
ret[i] = s.Index(i).Interface()
18+
}
19+
20+
return ret, nil
21+
}

0 commit comments

Comments
 (0)