Skip to content

Commit

Permalink
upgrade to skbn 0.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
maorfr committed Dec 6, 2018
1 parent 30976b4 commit 631bb00
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
18 changes: 10 additions & 8 deletions cmd/kube-tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,14 @@ func NewRootCmd(args []string) *cobra.Command {
}

type simpleBackupCmd struct {
namespace string
selector string
container string
path string
dst string
parallel int
tag string
namespace string
selector string
container string
path string
dst string
parallel int
tag string
bufferSize float64

out io.Writer
}
Expand All @@ -55,7 +56,7 @@ func NewSimpleBackupCmd(out io.Writer) *cobra.Command {
Short: "backup files to S3",
Long: ``,
Run: func(cmd *cobra.Command, args []string) {
if _, err := kubetasks.SimpleBackup(b.namespace, b.selector, b.container, b.path, b.dst, b.parallel, b.tag); err != nil {
if _, err := kubetasks.SimpleBackup(b.namespace, b.selector, b.container, b.path, b.dst, b.parallel, b.tag, b.bufferSize); err != nil {
log.Fatal(err)
}
},
Expand All @@ -69,6 +70,7 @@ func NewSimpleBackupCmd(out io.Writer) *cobra.Command {
f.StringVar(&b.dst, "dst", "", "destination to backup to. Example: s3://bucket/backup")
f.IntVarP(&b.parallel, "parallel", "p", 1, "number of files to copy in parallel. set this flag to 0 for full parallelism")
f.StringVar(&b.tag, "tag", utils.GetTimeStamp(), "tag to backup to. Default is Now (yyMMddHHmmss)")
f.Float64VarP(&b.bufferSize, "buffer-size", "b", 6.75, "in-memory buffer size (in MB) to use for files copy (buffer per file_")

return cmd
}
Expand Down
10 changes: 6 additions & 4 deletions pkg/kubetasks/kubetasks.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package kubetasks

import (
"bytes"
"fmt"
"log"
"path/filepath"
Expand All @@ -12,7 +13,7 @@ import (
)

// SimpleBackup performs backup
func SimpleBackup(namespace, selector, container, path, dst string, parallel int, tag string) (string, error) {
func SimpleBackup(namespace, selector, container, path, dst string, parallel int, tag string, bufferSize float64) (string, error) {
log.Println("Backup started!")
dstPrefix, dstPath := utils.SplitInTwo(dst, "://")
dstPath = filepath.Join(dstPath, tag)
Expand Down Expand Up @@ -40,7 +41,7 @@ func SimpleBackup(namespace, selector, container, path, dst string, parallel int
}

log.Println("Starting files copy to tag: " + tag)
if err := skbn.PerformCopy(k8sClient, dstClient, "k8s", dstPrefix, fromToPathsAllPods, parallel); err != nil {
if err := skbn.PerformCopy(k8sClient, dstClient, "k8s", dstPrefix, fromToPathsAllPods, parallel, bufferSize); err != nil {
return "", err
}

Expand Down Expand Up @@ -88,15 +89,16 @@ func Execute(namespace, selector, container, command string) error {
}

commandArray := strings.Fields(command)
stdout, stderr, err := skbn.Exec(*k8sClient, namespace, pods[0], container, commandArray, nil)
stdout := new(bytes.Buffer)
stderr, err := skbn.Exec(*k8sClient, namespace, pods[0], container, commandArray, nil, stdout)
if len(stderr) != 0 {
return fmt.Errorf("STDERR: " + (string)(stderr))
}
if err != nil {
return err
}

printOutput((string)(stdout), pods[0])
printOutput(stdout.String(), pods[0])
return nil
}

Expand Down

0 comments on commit 631bb00

Please # to comment.