Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 23 additions & 26 deletions cmd/node/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,33 +63,18 @@ func getLocalIP() string {
return ""
}

func generateAddNodeOptions(c *cli.Context) (*corepb.AddNodeOptions, error) {
podname := c.Args().First()
if podname == "" {
return nil, fmt.Errorf("podname must not be empty")
}

nodename := c.String("nodename")
if nodename == "" {
n, err := os.Hostname()
if err != nil {
return nil, err
}
nodename = n
}

func readTLSConfigs(c *cli.Context) (caContent, certContent, keyContent string, err error) {
ca := c.String("ca")
if ca == "" {
defaultPath := "/etc/docker/tls/ca.crt"
if _, err := os.Stat(defaultPath); err == nil {
ca = defaultPath
}
}
caContent := ""
if ca != "" {
f, err := ioutil.ReadFile(ca)
if err != nil {
return nil, fmt.Errorf("Error during reading %s: %v", ca, err)
return "", "", "", fmt.Errorf("Error during reading %s: %v", ca, err)
}
caContent = string(f)
}
Expand All @@ -101,11 +86,10 @@ func generateAddNodeOptions(c *cli.Context) (*corepb.AddNodeOptions, error) {
cert = defaultPath
}
}
certContent := ""
if cert != "" {
f, err := ioutil.ReadFile(cert)
if err != nil {
return nil, fmt.Errorf("Error during reading %s: %v", cert, err)
return "", "", "", fmt.Errorf("Error during reading %s: %v", cert, err)
}
certContent = string(f)
}
Expand All @@ -117,14 +101,28 @@ func generateAddNodeOptions(c *cli.Context) (*corepb.AddNodeOptions, error) {
key = defaultPath
}
}
keyContent := ""
if key != "" {
f, err := ioutil.ReadFile(key)
if err != nil {
return nil, fmt.Errorf("Error during reading %s: %v", key, err)
return "", "", "", fmt.Errorf("Error during reading %s: %v", key, err)
}
keyContent = string(f)
}
return caContent, certContent, keyContent, nil
}

func generateAddNodeOptions(c *cli.Context) (*corepb.AddNodeOptions, error) {
podname := c.Args().First()
if podname == "" {
return nil, fmt.Errorf("podname must not be empty")
}

nodename := c.String("nodename")

ca, cert, key, err := readTLSConfigs(c)
if err != nil {
return nil, err
}

endpoint := c.String("endpoint")
if endpoint == "" {
Expand All @@ -133,7 +131,7 @@ func generateAddNodeOptions(c *cli.Context) (*corepb.AddNodeOptions, error) {
return nil, fmt.Errorf("unable to get local ip")
}
port := 2376
if caContent == "" {
if ca == "" {
port = 2375
}
endpoint = fmt.Sprintf("tcp://%s:%d", ip, port)
Expand All @@ -145,7 +143,6 @@ func generateAddNodeOptions(c *cli.Context) (*corepb.AddNodeOptions, error) {
}

var (
err error
memory, storage int64
)
if memory, err = utils.ParseRAMInHuman(c.String("memory")); err != nil {
Expand Down Expand Up @@ -196,9 +193,9 @@ func generateAddNodeOptions(c *cli.Context) (*corepb.AddNodeOptions, error) {
Nodename: nodename,
Endpoint: endpoint,
Podname: podname,
Ca: caContent,
Cert: certContent,
Key: keyContent,
Ca: ca,
Cert: cert,
Key: key,
Cpu: int32(cpu),
Share: int32(share),
Memory: memory,
Expand Down
34 changes: 21 additions & 13 deletions cmd/node/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,6 @@ func Command() *cli.Command {
ArgsUsage: nodeArgsUsage,
Action: utils.ExitCoder(cmdNodeRemove),
},
{
Name: "update",
Usage: "update a node",
ArgsUsage: nodeArgsUsage,
Action: utils.ExitCoder(cmdNodeUpdate),
Flags: []cli.Flag{
&cli.StringFlag{
Name: "endpoint",
Usage: "update node endpoint",
},
},
},
{
Name: "workloads",
Usage: "list node workloads",
Expand Down Expand Up @@ -113,6 +101,7 @@ func Command() *cli.Command {
},
{
Name: "set",
Aliases: []string{"update"},
Usage: "set node resource",
ArgsUsage: nodeArgsUsage,
Action: utils.ExitCoder(cmdNodeSet),
Expand Down Expand Up @@ -164,6 +153,25 @@ func Command() *cli.Command {
Name: "delta",
Usage: "delta flag for settings, when set, all values will be relative to the current values, refer to each option for details",
},
&cli.StringFlag{
Name: "endpoint",
Usage: "update node endpoint",
},
&cli.StringFlag{
Name: "ca",
Usage: "ca file, like /etc/docker/tls/ca.crt",
Value: "",
},
&cli.StringFlag{
Name: "cert",
Usage: "cert file, like /etc/docker/tls/client.crt",
Value: "",
},
&cli.StringFlag{
Name: "key",
Usage: "key file, like /etc/docker/tls/client.key",
Value: "",
},
},
},
{
Expand All @@ -176,7 +184,7 @@ func Command() *cli.Command {
Name: "nodename",
Usage: "name of this node, use `hostname` as default",
EnvVars: []string{"HOSTNAME"},
Value: "",
Value: utils.GetHostname(),
},
&cli.StringFlag{
Name: "endpoint",
Expand Down
24 changes: 24 additions & 0 deletions cmd/node/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,14 @@ func generateSetNodeOptionsAbsolute(c *cli.Context, client corepb.CoreRPCClient)
}
}

var (
ca, cert, key string
)
ca, cert, key, err = readTLSConfigs(c)
if err != nil {
return nil, err
}

return &corepb.SetNodeOptions{
Nodename: name,
StatusOpt: corepb.TriOpt_KEEP,
Expand All @@ -158,6 +166,10 @@ func generateSetNodeOptionsAbsolute(c *cli.Context, client corepb.CoreRPCClient)
Numa: numa,
Labels: utils.SplitEquality(c.StringSlice("label")),
WorkloadsDown: c.Bool("mark-workloads-down"),
Endpoint: c.String("endpoint"),
Ca: ca,
Cert: cert,
Key: key,
}, nil
}

Expand Down Expand Up @@ -229,6 +241,14 @@ func generateSetNodeOptionsDelta(c *cli.Context, _ corepb.CoreRPCClient) (*corep
return nil, err
}

var (
ca, cert, key string
)
ca, cert, key, err = readTLSConfigs(c)
if err != nil {
return nil, err
}

return &corepb.SetNodeOptions{
Nodename: name,
StatusOpt: corepb.TriOpt_KEEP,
Expand All @@ -240,5 +260,9 @@ func generateSetNodeOptionsDelta(c *cli.Context, _ corepb.CoreRPCClient) (*corep
Numa: numa,
Labels: utils.SplitEquality(c.StringSlice("label")),
WorkloadsDown: c.Bool("mark-workloads-down"),
Endpoint: c.String("endpoint"),
Ca: ca,
Cert: cert,
Key: key,
}, nil
}
51 changes: 0 additions & 51 deletions cmd/node/update.go

This file was deleted.

6 changes: 6 additions & 0 deletions cmd/utils/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,9 @@ func ExitCoder(f func(*cli.Context) error) func(*cli.Context) error {
return nil
}
}

// GetHostname .
func GetHostname() string {
hostname, _ := os.Hostname()
return hostname
}
Loading