Skip to content

Commit

Permalink
fix node Add/Set with extra resources
Browse files Browse the repository at this point in the history
  • Loading branch information
CMGS committed May 15, 2023
1 parent 1987591 commit 701f6f7
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
11 changes: 5 additions & 6 deletions cmd/node/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,20 +172,19 @@ func generateAddNodeOptions(c *cli.Context) (*corepb.AddNodeOptions, error) {
"cpumem": cb,
"storage": sb,
}
extraResources := c.String("extra-resources")
if extraResources != "" {
extraResourcesMap := make(map[string]any)
if err := json.Unmarshal([]byte(extraResources), &extraResourcesMap); err != nil {
return nil, fmt.Errorf("Invalid value for extra-resources: %v", err)
}

if extraResourcesMap, err := utils.ParseExtraResources(c); err != nil {
for k, v := range extraResourcesMap {
if _, ok := resources[k]; ok {
continue
}
eb, _ := json.Marshal(v)
resources[k] = eb
}
} else {
return nil, fmt.Errorf("[generateAddNodeOptions] get extra resources failed %v", err)
}

labels := utils.SplitEquality(c.StringSlice("label"))
return &corepb.AddNodeOptions{
Nodename: nodename,
Expand Down
10 changes: 10 additions & 0 deletions cmd/node/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,11 @@ func Command() *cli.Command {
Usage: "key file, like /etc/docker/tls/client.key",
Value: "",
},
&cli.StringFlag{
Name: "extra-resources",
Usage: "add extra resource requests",
Value: "",
},
},
},
{
Expand Down Expand Up @@ -261,6 +266,11 @@ func Command() *cli.Command {
Name: "test",
Usage: "mark node for testing, maybe no health check and status report",
},
&cli.StringFlag{
Name: "extra-resources",
Usage: "add extra resource requests",
Value: "",
},
},
},
},
Expand Down
13 changes: 13 additions & 0 deletions cmd/node/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package node
import (
"context"
"encoding/json"
"fmt"

"github.com/juju/errors"
"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -98,6 +99,18 @@ func generateSetNodeOptions(c *cli.Context, _ corepb.CoreRPCClient) (*corepb.Set
"storage": sb,
}

if extraResourcesMap, err := utils.ParseExtraResources(c); err != nil {
for k, v := range extraResourcesMap {
if _, ok := resources[k]; ok {
continue
}
eb, _ := json.Marshal(v)
resources[k] = eb
}
} else {
return nil, fmt.Errorf("[generateSetNodeOptions] get extra resources failed %v", err)
}

return &corepb.SetNodeOptions{
Nodename: name,
Resources: resources,
Expand Down

0 comments on commit 701f6f7

Please sign in to comment.