diff --git a/cli.go b/cli.go index a060023..5f3ac0f 100644 --- a/cli.go +++ b/cli.go @@ -14,6 +14,7 @@ import ( "github.com/projecteru2/cli/cmd/workload" "github.com/projecteru2/cli/describe" "github.com/projecteru2/cli/version" + "github.com/sirupsen/logrus" "github.com/urfave/cli/v2" ) diff --git a/cmd/core/cmd.go b/cmd/core/cmd.go index a6185a1..ba2cb2c 100644 --- a/cmd/core/cmd.go +++ b/cmd/core/cmd.go @@ -2,6 +2,7 @@ package core import ( "github.com/projecteru2/cli/cmd/utils" + "github.com/urfave/cli/v2" ) diff --git a/cmd/core/info.go b/cmd/core/info.go index 1f2b0ee..237d3b1 100644 --- a/cmd/core/info.go +++ b/cmd/core/info.go @@ -6,6 +6,7 @@ import ( "github.com/projecteru2/cli/cmd/utils" "github.com/projecteru2/cli/describe" corepb "github.com/projecteru2/core/rpc/gen" + "github.com/urfave/cli/v2" ) diff --git a/cmd/image/build.go b/cmd/image/build.go index 7201e40..e6257b5 100644 --- a/cmd/image/build.go +++ b/cmd/image/build.go @@ -7,10 +7,11 @@ import ( "io/ioutil" "strings" - "github.com/juju/errors" "github.com/projecteru2/cli/cmd/utils" dockerengine "github.com/projecteru2/core/engine/docker" corepb "github.com/projecteru2/core/rpc/gen" + + "github.com/juju/errors" "github.com/sethgrid/curse" "github.com/sirupsen/logrus" "github.com/urfave/cli/v2" diff --git a/cmd/image/cache.go b/cmd/image/cache.go index a0f8e7a..65d6885 100644 --- a/cmd/image/cache.go +++ b/cmd/image/cache.go @@ -4,9 +4,10 @@ import ( "context" "io" - "github.com/juju/errors" "github.com/projecteru2/cli/cmd/utils" corepb "github.com/projecteru2/core/rpc/gen" + + "github.com/juju/errors" "github.com/sirupsen/logrus" "github.com/urfave/cli/v2" ) diff --git a/cmd/image/cmd.go b/cmd/image/cmd.go index 17761d6..44a91c0 100644 --- a/cmd/image/cmd.go +++ b/cmd/image/cmd.go @@ -2,6 +2,7 @@ package image import ( "github.com/projecteru2/cli/cmd/utils" + "github.com/urfave/cli/v2" ) diff --git a/cmd/image/remove.go b/cmd/image/remove.go index 6595570..d33380c 100644 --- a/cmd/image/remove.go +++ b/cmd/image/remove.go @@ -4,9 +4,10 @@ import ( "context" "io" - "github.com/juju/errors" "github.com/projecteru2/cli/cmd/utils" corepb "github.com/projecteru2/core/rpc/gen" + + "github.com/juju/errors" "github.com/sirupsen/logrus" "github.com/urfave/cli/v2" ) diff --git a/cmd/lambda/cmd.go b/cmd/lambda/cmd.go index 314f48b..aea0627 100644 --- a/cmd/lambda/cmd.go +++ b/cmd/lambda/cmd.go @@ -3,6 +3,7 @@ package lambda import ( "github.com/projecteru2/cli/cmd/utils" "github.com/projecteru2/core/strategy" + "github.com/urfave/cli/v2" ) diff --git a/cmd/lambda/run.go b/cmd/lambda/run.go index d15b85a..adba7f1 100644 --- a/cmd/lambda/run.go +++ b/cmd/lambda/run.go @@ -5,10 +5,11 @@ import ( "fmt" "strings" - "github.com/juju/errors" "github.com/projecteru2/cli/cmd/utils" "github.com/projecteru2/cli/interactive" corepb "github.com/projecteru2/core/rpc/gen" + + "github.com/juju/errors" "github.com/urfave/cli/v2" ) @@ -91,6 +92,8 @@ func generateLambdaOptions(c *cli.Context) (*corepb.RunAndWaitOptions, error) { return nil, fmt.Errorf("[Lambda] memory wrong %v", err) } + content, modes, owners := utils.GenerateFileOptions(c) + return &corepb.RunAndWaitOptions{ Async: c.Bool("async"), AsyncTimeout: int32(c.Int("async-timeout")), @@ -122,7 +125,9 @@ func generateLambdaOptions(c *cli.Context) (*corepb.RunAndWaitOptions, error) { Networks: utils.GetNetworks(network), OpenStdin: c.Bool("stdin"), DeployStrategy: corepb.DeployOptions_Strategy(corepb.DeployOptions_Strategy_value[strings.ToUpper(c.String("deploy-strategy"))]), - Data: utils.ReadAllFiles(c.StringSlice("file")), + Data: content, + Owners: owners, + Modes: modes, User: c.String("user"), }, }, nil diff --git a/cmd/network/cmd.go b/cmd/network/cmd.go index 4117f8e..743f037 100644 --- a/cmd/network/cmd.go +++ b/cmd/network/cmd.go @@ -2,6 +2,7 @@ package network import ( "github.com/projecteru2/cli/cmd/utils" + "github.com/urfave/cli/v2" ) diff --git a/cmd/network/connect.go b/cmd/network/connect.go index aa75886..11c1c77 100644 --- a/cmd/network/connect.go +++ b/cmd/network/connect.go @@ -3,9 +3,10 @@ package network import ( "context" - "github.com/juju/errors" "github.com/projecteru2/cli/cmd/utils" corepb "github.com/projecteru2/core/rpc/gen" + + "github.com/juju/errors" "github.com/sirupsen/logrus" "github.com/urfave/cli/v2" ) diff --git a/cmd/network/disconnect.go b/cmd/network/disconnect.go index 4c6d8bf..058ce84 100644 --- a/cmd/network/disconnect.go +++ b/cmd/network/disconnect.go @@ -3,9 +3,10 @@ package network import ( "context" - "github.com/juju/errors" "github.com/projecteru2/cli/cmd/utils" corepb "github.com/projecteru2/core/rpc/gen" + + "github.com/juju/errors" "github.com/sirupsen/logrus" "github.com/urfave/cli/v2" ) diff --git a/cmd/node/add.go b/cmd/node/add.go index d62801b..d62a01e 100644 --- a/cmd/node/add.go +++ b/cmd/node/add.go @@ -11,6 +11,7 @@ import ( "github.com/projecteru2/cli/cmd/utils" "github.com/projecteru2/cli/describe" corepb "github.com/projecteru2/core/rpc/gen" + "github.com/urfave/cli/v2" ) diff --git a/cmd/node/cmd.go b/cmd/node/cmd.go index 68ad841..f2da175 100644 --- a/cmd/node/cmd.go +++ b/cmd/node/cmd.go @@ -2,6 +2,7 @@ package node import ( "github.com/projecteru2/cli/cmd/utils" + "github.com/urfave/cli/v2" ) diff --git a/cmd/node/down.go b/cmd/node/down.go index 72ba449..0d79080 100644 --- a/cmd/node/down.go +++ b/cmd/node/down.go @@ -4,9 +4,10 @@ import ( "context" "time" - "github.com/juju/errors" "github.com/projecteru2/cli/cmd/utils" corepb "github.com/projecteru2/core/rpc/gen" + + "github.com/juju/errors" "github.com/sirupsen/logrus" "github.com/urfave/cli/v2" ) diff --git a/cmd/node/get.go b/cmd/node/get.go index 3d54c8f..127381b 100644 --- a/cmd/node/get.go +++ b/cmd/node/get.go @@ -3,10 +3,11 @@ package node import ( "context" - "github.com/juju/errors" "github.com/projecteru2/cli/cmd/utils" "github.com/projecteru2/cli/describe" corepb "github.com/projecteru2/core/rpc/gen" + + "github.com/juju/errors" "github.com/urfave/cli/v2" ) diff --git a/cmd/node/remove.go b/cmd/node/remove.go index 7e440ed..ca0861a 100644 --- a/cmd/node/remove.go +++ b/cmd/node/remove.go @@ -3,9 +3,10 @@ package node import ( "context" - "github.com/juju/errors" "github.com/projecteru2/cli/cmd/utils" corepb "github.com/projecteru2/core/rpc/gen" + + "github.com/juju/errors" "github.com/sirupsen/logrus" "github.com/urfave/cli/v2" ) diff --git a/cmd/node/resource.go b/cmd/node/resource.go index 60bcb66..f0bd10d 100644 --- a/cmd/node/resource.go +++ b/cmd/node/resource.go @@ -3,10 +3,11 @@ package node import ( "context" - "github.com/juju/errors" "github.com/projecteru2/cli/cmd/utils" "github.com/projecteru2/cli/describe" corepb "github.com/projecteru2/core/rpc/gen" + + "github.com/juju/errors" "github.com/urfave/cli/v2" ) diff --git a/cmd/node/set.go b/cmd/node/set.go index b7a1abe..3441ffb 100644 --- a/cmd/node/set.go +++ b/cmd/node/set.go @@ -6,9 +6,10 @@ import ( "strconv" "strings" - "github.com/juju/errors" "github.com/projecteru2/cli/cmd/utils" corepb "github.com/projecteru2/core/rpc/gen" + + "github.com/juju/errors" "github.com/sirupsen/logrus" "github.com/urfave/cli/v2" ) diff --git a/cmd/node/status.go b/cmd/node/status.go index ef31976..525fa9b 100644 --- a/cmd/node/status.go +++ b/cmd/node/status.go @@ -4,9 +4,10 @@ import ( "context" "time" - "github.com/juju/errors" "github.com/projecteru2/cli/cmd/utils" corepb "github.com/projecteru2/core/rpc/gen" + + "github.com/juju/errors" "github.com/urfave/cli/v2" ) diff --git a/cmd/node/up.go b/cmd/node/up.go index be3a537..5e44b0d 100644 --- a/cmd/node/up.go +++ b/cmd/node/up.go @@ -3,9 +3,10 @@ package node import ( "context" - "github.com/juju/errors" "github.com/projecteru2/cli/cmd/utils" corepb "github.com/projecteru2/core/rpc/gen" + + "github.com/juju/errors" "github.com/sirupsen/logrus" "github.com/urfave/cli/v2" ) diff --git a/cmd/node/update.go b/cmd/node/update.go index 590b525..d491ba1 100644 --- a/cmd/node/update.go +++ b/cmd/node/update.go @@ -3,9 +3,10 @@ package node import ( "context" - "github.com/juju/errors" "github.com/projecteru2/cli/cmd/utils" corepb "github.com/projecteru2/core/rpc/gen" + + "github.com/juju/errors" "github.com/sirupsen/logrus" "github.com/urfave/cli/v2" ) diff --git a/cmd/node/watch.go b/cmd/node/watch.go index 2af72dc..cd06f7a 100644 --- a/cmd/node/watch.go +++ b/cmd/node/watch.go @@ -7,6 +7,7 @@ import ( "github.com/projecteru2/cli/cmd/utils" "github.com/projecteru2/cli/describe" corepb "github.com/projecteru2/core/rpc/gen" + "github.com/urfave/cli/v2" ) diff --git a/cmd/node/workloads.go b/cmd/node/workloads.go index 9446067..1928382 100644 --- a/cmd/node/workloads.go +++ b/cmd/node/workloads.go @@ -3,10 +3,11 @@ package node import ( "context" - "github.com/juju/errors" "github.com/projecteru2/cli/cmd/utils" "github.com/projecteru2/cli/describe" corepb "github.com/projecteru2/core/rpc/gen" + + "github.com/juju/errors" "github.com/urfave/cli/v2" ) diff --git a/cmd/pod/add.go b/cmd/pod/add.go index 75afdaa..38cc956 100644 --- a/cmd/pod/add.go +++ b/cmd/pod/add.go @@ -3,10 +3,11 @@ package pod import ( "context" - "github.com/juju/errors" "github.com/projecteru2/cli/cmd/utils" "github.com/projecteru2/cli/describe" corepb "github.com/projecteru2/core/rpc/gen" + + "github.com/juju/errors" "github.com/urfave/cli/v2" ) diff --git a/cmd/pod/capacity.go b/cmd/pod/capacity.go index 357fc58..eb4bfba 100644 --- a/cmd/pod/capacity.go +++ b/cmd/pod/capacity.go @@ -4,11 +4,12 @@ import ( "context" "fmt" - "github.com/google/uuid" - "github.com/juju/errors" "github.com/projecteru2/cli/cmd/utils" "github.com/projecteru2/cli/describe" corepb "github.com/projecteru2/core/rpc/gen" + + "github.com/google/uuid" + "github.com/juju/errors" "github.com/urfave/cli/v2" ) diff --git a/cmd/pod/cmd.go b/cmd/pod/cmd.go index 56c16b4..6a1932f 100644 --- a/cmd/pod/cmd.go +++ b/cmd/pod/cmd.go @@ -2,6 +2,7 @@ package pod import ( "github.com/projecteru2/cli/cmd/utils" + "github.com/urfave/cli/v2" ) diff --git a/cmd/pod/list.go b/cmd/pod/list.go index 3e6129d..0456040 100644 --- a/cmd/pod/list.go +++ b/cmd/pod/list.go @@ -7,6 +7,7 @@ import ( "github.com/projecteru2/cli/cmd/utils" "github.com/projecteru2/cli/describe" corepb "github.com/projecteru2/core/rpc/gen" + "github.com/urfave/cli/v2" ) diff --git a/cmd/pod/networks.go b/cmd/pod/networks.go index e7d7e96..08ccbe7 100644 --- a/cmd/pod/networks.go +++ b/cmd/pod/networks.go @@ -3,10 +3,11 @@ package pod import ( "context" - "github.com/juju/errors" "github.com/projecteru2/cli/cmd/utils" "github.com/projecteru2/cli/describe" corepb "github.com/projecteru2/core/rpc/gen" + + "github.com/juju/errors" "github.com/urfave/cli/v2" ) diff --git a/cmd/pod/nodes.go b/cmd/pod/nodes.go index 608971c..7913750 100644 --- a/cmd/pod/nodes.go +++ b/cmd/pod/nodes.go @@ -4,10 +4,11 @@ import ( "context" "strings" - "github.com/juju/errors" "github.com/projecteru2/cli/cmd/utils" "github.com/projecteru2/cli/describe" corepb "github.com/projecteru2/core/rpc/gen" + + "github.com/juju/errors" "github.com/urfave/cli/v2" ) diff --git a/cmd/pod/remove.go b/cmd/pod/remove.go index 97a3c94..9e37798 100644 --- a/cmd/pod/remove.go +++ b/cmd/pod/remove.go @@ -3,9 +3,10 @@ package pod import ( "context" - "github.com/juju/errors" "github.com/projecteru2/cli/cmd/utils" corepb "github.com/projecteru2/core/rpc/gen" + + "github.com/juju/errors" "github.com/sirupsen/logrus" "github.com/urfave/cli/v2" ) diff --git a/cmd/pod/resource.go b/cmd/pod/resource.go index 69f4805..e66d162 100644 --- a/cmd/pod/resource.go +++ b/cmd/pod/resource.go @@ -6,10 +6,11 @@ import ( "strconv" "strings" - "github.com/juju/errors" "github.com/projecteru2/cli/cmd/utils" "github.com/projecteru2/cli/describe" corepb "github.com/projecteru2/core/rpc/gen" + + "github.com/juju/errors" "github.com/urfave/cli/v2" ) diff --git a/cmd/status/cmd.go b/cmd/status/cmd.go index b7e5ad6..46e1fcf 100644 --- a/cmd/status/cmd.go +++ b/cmd/status/cmd.go @@ -2,6 +2,7 @@ package status import ( "github.com/projecteru2/cli/cmd/utils" + "github.com/urfave/cli/v2" ) diff --git a/cmd/status/status.go b/cmd/status/status.go index 1cb7cbf..dbb45d0 100644 --- a/cmd/status/status.go +++ b/cmd/status/status.go @@ -8,6 +8,7 @@ import ( "github.com/projecteru2/cli/cmd/utils" corepb "github.com/projecteru2/core/rpc/gen" coreutils "github.com/projecteru2/core/utils" + "github.com/sethvargo/go-signalcontext" "github.com/sirupsen/logrus" "github.com/urfave/cli/v2" diff --git a/cmd/utils/client.go b/cmd/utils/client.go index 88d123f..528f047 100644 --- a/cmd/utils/client.go +++ b/cmd/utils/client.go @@ -4,6 +4,7 @@ import ( coreclient "github.com/projecteru2/core/client" corepb "github.com/projecteru2/core/rpc/gen" coretypes "github.com/projecteru2/core/types" + "github.com/urfave/cli/v2" ) diff --git a/cmd/utils/file.go b/cmd/utils/file.go index 9b8b1ce..eaa648d 100644 --- a/cmd/utils/file.go +++ b/cmd/utils/file.go @@ -3,30 +3,75 @@ package utils import ( "io/ioutil" "net/http" + "strconv" "strings" + + corepb "github.com/projecteru2/core/rpc/gen" + "github.com/projecteru2/core/types" + + "github.com/urfave/cli/v2" ) // ReadAllFiles open each pair in files -// and returns a map with key as dstfile, value as content of srcfile -// files: list of srcfile:dstfile -func ReadAllFiles(files []string) map[string][]byte { - m := map[string][]byte{} +// and returns a map with key as dstfile, value as linux file +// files: list of srcfile:dstfile:mode:uid:gid +func ReadAllFiles(files []string) map[string]*types.LinuxFile { + m := map[string]*types.LinuxFile{} for _, file := range files { ps := strings.Split(file, ":") - if len(ps) != 2 { - continue - } + f := &types.LinuxFile{} + var err error - content, err := ioutil.ReadFile(ps[0]) - if err != nil { - continue + switch { + case len(ps) >= 5: + // srcfile:dstfile:mode:uid:gid + var uid, gid int64 + uid, err = strconv.ParseInt(ps[3], 10, 0) + if err != nil { + break + } + gid, err = strconv.ParseInt(ps[3], 10, 0) + if err != nil { + break + } + f.UID = int(uid) + f.GID = int(gid) + fallthrough + case len(ps) >= 3: + // srcfile:dstfile:mode + f.Mode, err = strconv.ParseInt(ps[2], 8, 0) + if err != nil { + break + } + fallthrough + case len(ps) >= 2: + // srcfile:dstfile + f.Content, err = ioutil.ReadFile(ps[0]) + if err != nil { + break + } + m[ps[1]] = f } - - m[ps[1]] = content } return m } +// GenerateFileOptions returns file options +func GenerateFileOptions(c *cli.Context) (map[string][]byte, map[string]*corepb.FileMode, map[string]*corepb.FileOwner) { + data := map[string][]byte{} + modes := map[string]*corepb.FileMode{} + owners := map[string]*corepb.FileOwner{} + + m := ReadAllFiles(c.StringSlice("file")) + for dst, file := range m { + data[dst] = file.Content + modes[dst] = &corepb.FileMode{Mode: file.Mode} + owners[dst] = &corepb.FileOwner{Uid: int32(file.UID), Gid: int32(file.GID)} + } + + return data, modes, owners +} + // SplitFiles transfers a list of // src:dst to // {src: dst} diff --git a/cmd/workload/cmd.go b/cmd/workload/cmd.go index 0534529..c89bd85 100644 --- a/cmd/workload/cmd.go +++ b/cmd/workload/cmd.go @@ -3,6 +3,7 @@ package workload import ( "github.com/projecteru2/cli/cmd/utils" "github.com/projecteru2/core/strategy" + "github.com/urfave/cli/v2" ) @@ -211,7 +212,7 @@ func Command() *cli.Command { Flags: []cli.Flag{ &cli.StringSliceFlag{ Name: "file", - Usage: "copy local files to workload, can use multiple times. src_path:dst_path", + Usage: "copy local files to workload, can use multiple times. src_path:dst_path[:mode[:uid:gid]]", }, }, }, diff --git a/cmd/workload/control.go b/cmd/workload/control.go index 38af9a5..5b75101 100644 --- a/cmd/workload/control.go +++ b/cmd/workload/control.go @@ -9,6 +9,7 @@ import ( corecluster "github.com/projecteru2/core/cluster" corepb "github.com/projecteru2/core/rpc/gen" coreutils "github.com/projecteru2/core/utils" + "github.com/sirupsen/logrus" "github.com/urfave/cli/v2" ) diff --git a/cmd/workload/copy.go b/cmd/workload/copy.go index 56ace9c..ddae02a 100644 --- a/cmd/workload/copy.go +++ b/cmd/workload/copy.go @@ -12,13 +12,14 @@ import ( "github.com/projecteru2/cli/cmd/utils" corepb "github.com/projecteru2/core/rpc/gen" coreutils "github.com/projecteru2/core/utils" + "github.com/sirupsen/logrus" "github.com/urfave/cli/v2" ) type copyWorkloadsOptions struct { client corepb.CoreRPCClient - // where to store copied content + // where to store copied files dir string // map workloadID -> list of path of files sources map[string][]string diff --git a/cmd/workload/deploy.go b/cmd/workload/deploy.go index ecf8e58..511de9c 100644 --- a/cmd/workload/deploy.go +++ b/cmd/workload/deploy.go @@ -10,6 +10,7 @@ import ( "github.com/projecteru2/cli/cmd/utils" "github.com/projecteru2/cli/types" corepb "github.com/projecteru2/core/rpc/gen" + "github.com/sirupsen/logrus" "github.com/urfave/cli/v2" "gopkg.in/yaml.v2" @@ -199,6 +200,8 @@ func generateDeployOptions(c *cli.Context) (*corepb.DeployOptions, error) { rawArgsByte = []byte(rawArgs) } + content, modes, owners := utils.GenerateFileOptions(c) + return &corepb.DeployOptions{ Name: specs.Appname, Entrypoint: &corepb.EntrypointOptions{ @@ -237,7 +240,9 @@ func generateDeployOptions(c *cli.Context) (*corepb.DeployOptions, error) { Dns: specs.DNS, ExtraHosts: specs.ExtraHosts, DeployStrategy: corepb.DeployOptions_Strategy(corepb.DeployOptions_Strategy_value[strings.ToUpper(c.String("deploy-strategy"))]), - Data: utils.ReadAllFiles(c.StringSlice("file")), + Data: content, + Modes: modes, + Owners: owners, User: c.String("user"), Debug: c.Bool("debug"), NodesLimit: int32(c.Int("nodes-limit")), diff --git a/cmd/workload/dissociate.go b/cmd/workload/dissociate.go index 1d45795..8198f39 100644 --- a/cmd/workload/dissociate.go +++ b/cmd/workload/dissociate.go @@ -7,6 +7,7 @@ import ( "github.com/projecteru2/cli/cmd/utils" corepb "github.com/projecteru2/core/rpc/gen" + "github.com/sirupsen/logrus" "github.com/urfave/cli/v2" ) diff --git a/cmd/workload/exec.go b/cmd/workload/exec.go index ac3d7ca..105df1f 100644 --- a/cmd/workload/exec.go +++ b/cmd/workload/exec.go @@ -7,6 +7,7 @@ import ( "github.com/projecteru2/cli/cmd/utils" "github.com/projecteru2/cli/interactive" corepb "github.com/projecteru2/core/rpc/gen" + "github.com/urfave/cli/v2" ) diff --git a/cmd/workload/get.go b/cmd/workload/get.go index 121ec60..a5c81ff 100644 --- a/cmd/workload/get.go +++ b/cmd/workload/get.go @@ -7,6 +7,7 @@ import ( "github.com/projecteru2/cli/cmd/utils" "github.com/projecteru2/cli/describe" corepb "github.com/projecteru2/core/rpc/gen" + "github.com/urfave/cli/v2" ) diff --git a/cmd/workload/list.go b/cmd/workload/list.go index 2955488..5283303 100644 --- a/cmd/workload/list.go +++ b/cmd/workload/list.go @@ -8,6 +8,7 @@ import ( "github.com/projecteru2/cli/cmd/utils" "github.com/projecteru2/cli/describe" corepb "github.com/projecteru2/core/rpc/gen" + "github.com/urfave/cli/v2" ) diff --git a/cmd/workload/logs.go b/cmd/workload/logs.go index ea9301c..1792801 100644 --- a/cmd/workload/logs.go +++ b/cmd/workload/logs.go @@ -8,6 +8,7 @@ import ( "github.com/projecteru2/cli/cmd/utils" corepb "github.com/projecteru2/core/rpc/gen" coreutils "github.com/projecteru2/core/utils" + "github.com/sirupsen/logrus" "github.com/urfave/cli/v2" ) diff --git a/cmd/workload/realloc.go b/cmd/workload/realloc.go index b5c2263..3dceb85 100644 --- a/cmd/workload/realloc.go +++ b/cmd/workload/realloc.go @@ -4,9 +4,10 @@ import ( "context" "strings" - "github.com/juju/errors" "github.com/projecteru2/cli/cmd/utils" corepb "github.com/projecteru2/core/rpc/gen" + + "github.com/juju/errors" "github.com/sirupsen/logrus" "github.com/urfave/cli/v2" ) diff --git a/cmd/workload/remove.go b/cmd/workload/remove.go index 241eaa1..4adf650 100644 --- a/cmd/workload/remove.go +++ b/cmd/workload/remove.go @@ -7,6 +7,7 @@ import ( "github.com/projecteru2/cli/cmd/utils" corepb "github.com/projecteru2/core/rpc/gen" + "github.com/sirupsen/logrus" "github.com/urfave/cli/v2" ) diff --git a/cmd/workload/replace.go b/cmd/workload/replace.go index 59cce64..a03b781 100644 --- a/cmd/workload/replace.go +++ b/cmd/workload/replace.go @@ -10,6 +10,7 @@ import ( "github.com/projecteru2/cli/cmd/utils" "github.com/projecteru2/cli/types" corepb "github.com/projecteru2/core/rpc/gen" + "github.com/sirupsen/logrus" "github.com/urfave/cli/v2" "gopkg.in/yaml.v2" @@ -171,6 +172,8 @@ func generateReplaceOptions(c *cli.Context) (*corepb.DeployOptions, error) { } } + content, modes, owners := utils.GenerateFileOptions(c) + return &corepb.DeployOptions{ Name: specs.Appname, Entrypoint: &corepb.EntrypointOptions{ @@ -209,7 +212,9 @@ func generateReplaceOptions(c *cli.Context) (*corepb.DeployOptions, error) { Dns: specs.DNS, ExtraHosts: specs.ExtraHosts, DeployStrategy: corepb.DeployOptions_Strategy(corepb.DeployOptions_Strategy_value[""]), - Data: utils.ReadAllFiles(c.StringSlice("file")), + Data: content, + Modes: modes, + Owners: owners, User: c.String("user"), Debug: c.Bool("debug"), NodesLimit: 0, diff --git a/cmd/workload/send.go b/cmd/workload/send.go index 212e34c..487e01e 100644 --- a/cmd/workload/send.go +++ b/cmd/workload/send.go @@ -7,6 +7,7 @@ import ( "github.com/projecteru2/cli/cmd/utils" corepb "github.com/projecteru2/core/rpc/gen" + "github.com/sirupsen/logrus" "github.com/urfave/cli/v2" ) @@ -14,15 +15,18 @@ import ( type sendWorkloadsOptions struct { client corepb.CoreRPCClient // workload ids - ids []string - // map filename -> content of files - files map[string][]byte + ids []string + content map[string][]byte + modes map[string]*corepb.FileMode + owners map[string]*corepb.FileOwner } func (o *sendWorkloadsOptions) run(ctx context.Context) error { opts := &corepb.SendOptions{ - Ids: o.ids, - Data: o.files, + Ids: o.ids, + Data: o.content, + Modes: o.modes, + Owners: o.owners, } resp, err := o.client.Send(ctx, opts) if err != nil { @@ -53,8 +57,8 @@ func cmdWorkloadSend(c *cli.Context) error { return err } - files := utils.ReadAllFiles(c.StringSlice("file")) - if len(files) == 0 { + content, modes, owners := utils.GenerateFileOptions(c) + if len(content) == 0 { return fmt.Errorf("files should not be empty") } @@ -64,9 +68,11 @@ func cmdWorkloadSend(c *cli.Context) error { } o := &sendWorkloadsOptions{ - client: client, - ids: ids, - files: files, + client: client, + ids: ids, + content: content, + modes: modes, + owners: owners, } return o.run(c.Context) } diff --git a/cmd/workload/status.go b/cmd/workload/status.go index bb7ac0f..bf103cf 100644 --- a/cmd/workload/status.go +++ b/cmd/workload/status.go @@ -7,6 +7,7 @@ import ( "github.com/projecteru2/cli/cmd/utils" "github.com/projecteru2/cli/describe" corepb "github.com/projecteru2/core/rpc/gen" + "github.com/urfave/cli/v2" ) diff --git a/describe/core.go b/describe/core.go index 6077b2a..5168517 100644 --- a/describe/core.go +++ b/describe/core.go @@ -3,8 +3,9 @@ package describe import ( "os" - "github.com/jedib0t/go-pretty/v6/table" corepb "github.com/projecteru2/core/rpc/gen" + + "github.com/jedib0t/go-pretty/v6/table" ) // Core function will describe a coreinfo diff --git a/describe/network.go b/describe/network.go index ce01e5a..323fad0 100644 --- a/describe/network.go +++ b/describe/network.go @@ -4,8 +4,9 @@ import ( "os" "strings" - "github.com/jedib0t/go-pretty/v6/table" corepb "github.com/projecteru2/core/rpc/gen" + + "github.com/jedib0t/go-pretty/v6/table" ) // Networks describes a list of Network diff --git a/describe/node.go b/describe/node.go index c65e2ff..82b551b 100644 --- a/describe/node.go +++ b/describe/node.go @@ -6,8 +6,9 @@ import ( "os" "strings" - "github.com/jedib0t/go-pretty/v6/table" corepb "github.com/projecteru2/core/rpc/gen" + + "github.com/jedib0t/go-pretty/v6/table" "github.com/sirupsen/logrus" ) diff --git a/describe/pod.go b/describe/pod.go index 09c2179..90a09f8 100644 --- a/describe/pod.go +++ b/describe/pod.go @@ -6,8 +6,9 @@ import ( "sort" "strconv" - "github.com/jedib0t/go-pretty/v6/table" corepb "github.com/projecteru2/core/rpc/gen" + + "github.com/jedib0t/go-pretty/v6/table" ) type capacityOfNode struct { diff --git a/describe/workload.go b/describe/workload.go index 35ee6d2..7b1df2a 100644 --- a/describe/workload.go +++ b/describe/workload.go @@ -6,8 +6,9 @@ import ( "os" "strings" - "github.com/jedib0t/go-pretty/v6/table" corepb "github.com/projecteru2/core/rpc/gen" + + "github.com/jedib0t/go-pretty/v6/table" ) // Workloads describes a list of Workload diff --git a/go.mod b/go.mod index 0b50658..6b55df7 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,7 @@ require ( github.com/juju/testing v0.0.0-20201216035041-2be42bba85f3 // indirect github.com/kless/term v0.0.0-20161130133337-e551c64f56c0 // indirect github.com/pkg/term v1.1.0 - github.com/projecteru2/core v0.0.0-20210817035812-6d3c4ea93880 + github.com/projecteru2/core v0.0.0-20210923162924-912e9f1d49aa github.com/sethgrid/curse v0.0.0-20181231162520-d4ee583ebf0f github.com/sethvargo/go-signalcontext v0.1.0 github.com/sirupsen/logrus v1.7.0 diff --git a/go.sum b/go.sum index d46d7e5..3e5ef16 100644 --- a/go.sum +++ b/go.sum @@ -71,6 +71,7 @@ github.com/cilium/ebpf v0.5.0/go.mod h1:4tRaxcgiL706VnOzHOdBlY8IEAIdxINsQBcU4xJJ github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= +github.com/cncf/xds/go v0.0.0-20210312221358-fbca930ec8ed/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= github.com/cockroachdb/datadriven v0.0.0-20200714090401-bf6692d28da5/go.mod h1:h6jFvWxBdQXxjopDMZyH2UVceIRfR84bdzbkoKrsWNo= github.com/cockroachdb/errors v1.2.4/go.mod h1:rQD95gz6FARkaKkQXUksEje/d9a6wBJoCr5oaCLELYA= github.com/cockroachdb/logtags v0.0.0-20190617123548-eb05cc24525f/go.mod h1:i/u985jwjWRlyHXQbwatDASoW0RMlZ/3i9yJHE2xLkI= @@ -140,6 +141,7 @@ github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.m github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk= github.com/envoyproxy/go-control-plane v0.9.9-0.20210217033140-668b12f5399d/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk= +github.com/envoyproxy/go-control-plane v0.9.9-0.20210512163311-63b5d3c536b0/go.mod h1:hliV/p42l8fGbc6Y9bQ70uLwIvmJyVE5k4iMKlh8wCQ= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/etcd-io/bbolt v1.3.3/go.mod h1:ZF2nL25h33cCyBtcyWeZ2/I3HQOfTP+0PIEvHjkjCrw= github.com/etcd-io/gofail v0.0.0-20190801230047-ad7f989257ca/go.mod h1:49H/RkXP8pKaZy4h0d+NW16rSLhyVBt4o6VLJbmOqDE= @@ -460,7 +462,10 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI= github.com/projecteru2/core v0.0.0-20210817035812-6d3c4ea93880 h1:0OqLCDeFN2Yc1QwtwuifnCmANXPk37XZ8CCw/7WZa0g= github.com/projecteru2/core v0.0.0-20210817035812-6d3c4ea93880/go.mod h1:6InLQok5z99ql9sNb6mISwdO927u8vl3q4zSmH07SoA= +github.com/projecteru2/core v0.0.0-20210923162924-912e9f1d49aa h1:/wxjr8H+dpYBNwqPPUiwbIWZpMYYPCtQ6iU5WvgTEXk= +github.com/projecteru2/core v0.0.0-20210923162924-912e9f1d49aa/go.mod h1:/7fZaf8yXd353d1tDX9KwvXMkptauKGe4zhIpqNetj8= github.com/projecteru2/libyavirt v0.0.0-20210514093713-959b2e232319/go.mod h1:9/SNmdphwl12ubwihkRa9YtOozM6liYLDxsricra1mY= +github.com/projecteru2/libyavirt v0.0.0-20210920022816-abc7aa0cf6ae/go.mod h1:FOc+hWBMLsMrmx5p3/moizKeSomedZPNwB6LhS+kEnE= github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDft0ttaMvbicHlPoso= github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo= @@ -500,6 +505,7 @@ github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQD github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= github.com/ryanuber/columnize v2.1.0+incompatible/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= github.com/sanity-io/litter v1.3.0/go.mod h1:5Z71SvaYy5kcGtyglXOC9rrUi3c1E8CamFWjQsazTh0= +github.com/sanity-io/litter v1.5.1/go.mod h1:5Z71SvaYy5kcGtyglXOC9rrUi3c1E8CamFWjQsazTh0= github.com/schollz/closestmatch v2.1.0+incompatible/go.mod h1:RtP1ddjLong6gTkbtmuhtR2uUrrJOpYzYRvbcPAid+g= github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc= github.com/seccomp/libseccomp-golang v0.9.1/go.mod h1:GbW5+tmTXfcxTToHLXlScSlAvWlF4P2Ca7zGrPiEpWo= @@ -861,6 +867,8 @@ google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAG google.golang.org/grpc v1.37.0/go.mod h1:NREThFqKR1f3iQ6oBuvc5LadQuXVGo9rkm5ZGrQdJfM= google.golang.org/grpc v1.38.0 h1:/9BgsAsa5nWe26HqOlvlgJnqBuktYOLCgjCPqsa56W0= google.golang.org/grpc v1.38.0/go.mod h1:NREThFqKR1f3iQ6oBuvc5LadQuXVGo9rkm5ZGrQdJfM= +google.golang.org/grpc v1.40.0 h1:AGJ0Ih4mHjSeibYkFGh1dD9KJ/eOtZ93I6hoHhukQ5Q= +google.golang.org/grpc v1.40.0/go.mod h1:ogyxbiOoUXAkP+4+xa6PZSE9DZgIHtSpzjDTB9KAK34= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= @@ -873,6 +881,8 @@ google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlba google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.26.0 h1:bxAC2xTBsZGibn2RTntX0oH50xLsqy1OxA9tTL3p/lk= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +google.golang.org/protobuf v1.27.1 h1:SnqbnDw1V7RiZcXPx5MEeqPv2s79L9i7BJUlG/+RurQ= +google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= gopkg.in/airbrake/gobrake.v2 v2.0.9/go.mod h1:/h5ZAUhDkGaJfjzjKLSjv6zCL6O0LLBxU4K+aSYdM/U= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/interactive/stream.go b/interactive/stream.go index 311997e..7f0f30c 100644 --- a/interactive/stream.go +++ b/interactive/stream.go @@ -13,9 +13,10 @@ import ( "text/template" "unsafe" + corepb "github.com/projecteru2/core/rpc/gen" + "github.com/getlantern/deepcopy" "github.com/pkg/term/termios" - corepb "github.com/projecteru2/core/rpc/gen" "github.com/sirupsen/logrus" "golang.org/x/sys/unix" )