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
8 changes: 1 addition & 7 deletions cmd/node/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package node

import (
"context"
"errors"
"fmt"
"strings"

Expand Down Expand Up @@ -48,11 +47,6 @@ func cmdNodeAdd(ctx context.Context, cmd *cli.Command) error {
}

func generateAddNodeOptions(cmd *cli.Command) (*corepb.AddNodeOptions, error) {
podname := cmd.Args().First()
if podname == "" {
return nil, errors.New("podname must not be empty")
}

nodename := cmd.String("nodename")

endpoint := cmd.String("endpoint")
Expand Down Expand Up @@ -80,7 +74,7 @@ func generateAddNodeOptions(cmd *cli.Command) (*corepb.AddNodeOptions, error) {
return &corepb.AddNodeOptions{
Nodename: nodename,
Endpoint: endpoint,
Podname: podname,
Podname: cmd.StringArgs(argPod)[0],
Labels: labels,
Resources: resources,
Test: cmd.Bool("test"),
Expand Down
10 changes: 4 additions & 6 deletions cmd/node/add_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,12 @@ func TestGenerateAddNodeOptionsRequiresEndpoint(t *testing.T) {

func TestGenerateAddNodeOptionsWithoutPod(t *testing.T) {
c := Command()
lookupSubcommand(t, c, "add").Action = func(_ context.Context, cmd *cli.Command) error {
if _, err := generateAddNodeOptions(cmd); err == nil {
t.Error("got nil, want an error for node add without a pod")
}
lookupSubcommand(t, c, "add").Action = func(context.Context, *cli.Command) error {
t.Error("the action ran without a pod argument")
return nil
}
if err := c.Run(t.Context(), []string{"node", "add"}); err != nil {
t.Fatalf("run: %v", err)
if err := c.Run(t.Context(), []string{"node", "add"}); err == nil {
t.Error("got nil, want an error for node add without a pod")
}
}

Expand Down
21 changes: 12 additions & 9 deletions cmd/node/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import (
)

const (
argNode = "node"
argPod = "pod"
nodeArgsUsage = "node name"
podArgsUsage = "pod name"

flagLabel = "label"
flagStorage = "storage"
Expand All @@ -22,13 +25,13 @@ func Command() *cli.Command {
{
Name: "get",
Usage: "get a node",
ArgsUsage: nodeArgsUsage,
Arguments: utils.Positional(argNode, nodeArgsUsage, 1),
Action: utils.ExitCoder(cmdNodeGet),
},
{
Name: "remove",
Usage: "remove a node",
ArgsUsage: nodeArgsUsage,
Arguments: utils.Positional(argNode, nodeArgsUsage, 1),
Action: utils.ExitCoder(cmdNodeRemove),
},
{
Expand All @@ -41,13 +44,13 @@ func Command() *cli.Command {
},
},
Aliases: []string{"containers"},
ArgsUsage: nodeArgsUsage,
Arguments: utils.Positional(argNode, nodeArgsUsage, 1),
Action: utils.ExitCoder(cmdNodeListWorkloads),
},
{
Name: "up",
Usage: "set node up",
ArgsUsage: nodeArgsUsage,
Arguments: utils.Positional(argNode, nodeArgsUsage, 1),
Action: utils.ExitCoder(cmdNodeSetUp),
},
{
Expand All @@ -64,7 +67,7 @@ func Command() *cli.Command {
Value: 20,
},
},
ArgsUsage: nodeArgsUsage,
Arguments: utils.Positional(argNode, nodeArgsUsage, 1),
Action: utils.ExitCoder(cmdNodeSetDown),
},
{
Expand All @@ -82,7 +85,7 @@ func Command() *cli.Command {
Value: 0,
},
},
ArgsUsage: nodeArgsUsage,
Arguments: utils.Positional(argNode, nodeArgsUsage, 1),
Action: utils.ExitCoder(cmdNodeSetStatus),
},
{
Expand All @@ -93,7 +96,7 @@ func Command() *cli.Command {
{
Name: "resource",
Usage: "check node resource",
ArgsUsage: nodeArgsUsage,
Arguments: utils.Positional(argNode, nodeArgsUsage, 1),
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "fix",
Expand All @@ -106,7 +109,7 @@ func Command() *cli.Command {
Name: "set",
Aliases: []string{"update"},
Usage: "set node resource",
ArgsUsage: nodeArgsUsage,
Arguments: utils.Positional(argNode, nodeArgsUsage, 1),
Action: utils.ExitCoder(cmdNodeSet),
Flags: []cli.Flag{
&cli.BoolFlag{
Expand Down Expand Up @@ -177,7 +180,7 @@ func Command() *cli.Command {
{
Name: "add",
Usage: "add node",
ArgsUsage: "pod name",
Arguments: utils.Positional(argPod, podArgsUsage, 1),
Action: utils.ExitCoder(cmdNodeAdd),
Flags: []cli.Flag{
&cli.StringFlag{
Expand Down
7 changes: 1 addition & 6 deletions cmd/node/down.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,9 @@ func cmdNodeSetDown(ctx context.Context, cmd *cli.Command) error {
return err
}

name := cmd.Args().First()
if name == "" {
return errors.New("node name must be given")
}

o := &setNodeDownOptions{
client: client,
name: name,
name: cmd.StringArgs(argNode)[0],
check: cmd.Bool("check"),
checkTimeout: cmd.Int("check-timeout"),
}
Expand Down
8 changes: 1 addition & 7 deletions cmd/node/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package node

import (
"context"
"errors"

corepb "github.com/projecteru2/core/rpc/gen"
"github.com/urfave/cli/v3"
Expand Down Expand Up @@ -34,14 +33,9 @@ func cmdNodeGet(ctx context.Context, cmd *cli.Command) error {
return err
}

name := cmd.Args().First()
if name == "" {
return errors.New("node name must be given")
}

o := &getNodeOptions{
client: client,
name: name,
name: cmd.StringArgs(argNode)[0],
}
return o.run(ctx)
}
8 changes: 1 addition & 7 deletions cmd/node/remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package node

import (
"context"
"errors"

"github.com/projecteru2/core/log"
corepb "github.com/projecteru2/core/rpc/gen"
Expand Down Expand Up @@ -33,14 +32,9 @@ func cmdNodeRemove(ctx context.Context, cmd *cli.Command) error {
return err
}

name := cmd.Args().First()
if name == "" {
return errors.New("node name must be given")
}

o := &removeNodeOptions{
client: client,
name: name,
name: cmd.StringArgs(argNode)[0],
}
return o.run(ctx)
}
8 changes: 1 addition & 7 deletions cmd/node/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package node

import (
"context"
"errors"

corepb "github.com/projecteru2/core/rpc/gen"
"github.com/urfave/cli/v3"
Expand Down Expand Up @@ -37,14 +36,9 @@ func cmdNodeResource(ctx context.Context, cmd *cli.Command) error {
return err
}

name := cmd.Args().First()
if name == "" {
return errors.New("node name must be given")
}

o := &nodeResourceOptions{
client: client,
name: name,
name: cmd.StringArgs(argNode)[0],
fix: cmd.Bool("fix"),
}
return o.run(ctx)
Expand Down
8 changes: 1 addition & 7 deletions cmd/node/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package node

import (
"context"
"errors"

"github.com/projecteru2/core/log"
resourcetypes "github.com/projecteru2/core/resource/types"
Expand Down Expand Up @@ -45,11 +44,6 @@ func cmdNodeSet(ctx context.Context, cmd *cli.Command) error {
}

func generateSetNodeOptions(cmd *cli.Command) (*corepb.SetNodeOptions, error) {
name := cmd.Args().First()
if name == "" {
return nil, errors.New("node name must be given")
}

cpumem, storage := collectResourceParams(cmd)
if cmd.IsSet("cpu") {
cpumem["cpu"] = cmd.String("cpu")
Expand All @@ -67,7 +61,7 @@ func generateSetNodeOptions(cmd *cli.Command) (*corepb.SetNodeOptions, error) {
}

return &corepb.SetNodeOptions{
Nodename: name,
Nodename: cmd.StringArgs(argNode)[0],
Resources: resources,
Labels: utils.SplitEquality(cmd.StringSlice(flagLabel)),
WorkloadsDown: cmd.Bool("mark-workloads-down"),
Expand Down
7 changes: 1 addition & 6 deletions cmd/node/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package node

import (
"context"
"errors"
"fmt"
"time"

Expand Down Expand Up @@ -55,17 +54,13 @@ func cmdNodeSetStatus(ctx context.Context, cmd *cli.Command) error {
return err
}

name := cmd.Args().First()
if name == "" {
return errors.New("node name must be given")
}
if cmd.Int("interval") < 0 {
return fmt.Errorf("--interval must not be negative, got %d", cmd.Int("interval"))
}

o := &setNodeStatusOptions{
client: client,
name: name,
name: cmd.StringArgs(argNode)[0],
ttl: cmd.Int("ttl"),
interval: cmd.Int("interval"),
}
Expand Down
8 changes: 1 addition & 7 deletions cmd/node/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package node

import (
"context"
"errors"

"github.com/projecteru2/core/log"
corepb "github.com/projecteru2/core/rpc/gen"
Expand Down Expand Up @@ -34,14 +33,9 @@ func cmdNodeSetUp(ctx context.Context, cmd *cli.Command) error {
return err
}

name := cmd.Args().First()
if name == "" {
return errors.New("node name must be given")
}

o := &setNodeUpOptions{
client: client,
name: name,
name: cmd.StringArgs(argNode)[0],
}
return o.run(ctx)
}
8 changes: 1 addition & 7 deletions cmd/node/workloads.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package node

import (
"context"
"errors"

corepb "github.com/projecteru2/core/rpc/gen"
"github.com/urfave/cli/v3"
Expand Down Expand Up @@ -36,14 +35,9 @@ func cmdNodeListWorkloads(ctx context.Context, cmd *cli.Command) error {
return err
}

name := cmd.Args().First()
if name == "" {
return errors.New("node name must be given")
}

o := &listNodeWorkloadsOptions{
client: client,
name: name,
name: cmd.StringArgs(argNode)[0],
labels: utils.SplitEquality(cmd.StringSlice(flagLabel)),
}
return o.run(ctx)
Expand Down
8 changes: 1 addition & 7 deletions cmd/pod/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package pod

import (
"context"
"errors"

corepb "github.com/projecteru2/core/rpc/gen"
"github.com/urfave/cli/v3"
Expand Down Expand Up @@ -36,14 +35,9 @@ func cmdPodAdd(ctx context.Context, cmd *cli.Command) error {
return err
}

name := cmd.Args().First()
if name == "" {
return errors.New("pod name must be given")
}

o := &addPodOptions{
client: client,
name: name,
name: cmd.StringArgs(argPod)[0],
desc: cmd.String("desc"),
}
return o.run(ctx)
Expand Down
8 changes: 1 addition & 7 deletions cmd/pod/capacity.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package pod
import (
"context"
"crypto/rand"
"errors"
"fmt"
"strings"

Expand Down Expand Up @@ -50,19 +49,14 @@ func cmdPodCapacity(ctx context.Context, cmd *cli.Command) error {
return err
}

name := cmd.Args().First()
if name == "" {
return errors.New("pod name must be given")
}

resources, err := capacityResources(cmd)
if err != nil {
return err
}

o := &capacityPodOptions{
client: client,
podname: name,
podname: cmd.StringArgs(argPod)[0],
nodenames: cmd.StringSlice("node"),
resources: resources,
}
Expand Down
Loading