Skip to content

Commit

Permalink
allow dissociating all workloads in node (#106)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyang0 committed Jan 2, 2024
1 parent 2c7e005 commit 1afc026
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
6 changes: 6 additions & 0 deletions cmd/workload/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,12 @@ func Command() *cli.Command {
Usage: "dissociate workload(s) from eru, return it resource but not remove it",
ArgsUsage: workloadArgsUsage,
Action: utils.ExitCoder(cmdWorkloadDissociate),
Flags: []cli.Flag{
&cli.StringSliceFlag{
Name: "node",
Usage: "dissociate all workload(s) on node(s)",
},
},
},
{
Name: "realloc",
Expand Down
22 changes: 19 additions & 3 deletions cmd/workload/dissociate.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,24 @@ import (
type dissociateWorkloadsOptions struct {
client corepb.CoreRPCClient
ids []string
nodes []string
}

func (o *dissociateWorkloadsOptions) run(ctx context.Context) error {
opts := &corepb.DissociateWorkloadOptions{IDs: o.ids}
ids := o.ids
for _, node := range o.nodes {
wrks, err := o.client.ListNodeWorkloads(ctx, &corepb.GetNodeOptions{Nodename: node})
if err != nil {
return err
}
for _, wrk := range wrks.Workloads {
ids = append(ids, wrk.Id)
}
}
if len(ids) == 0 {
return fmt.Errorf("no workloads found")
}
opts := &corepb.DissociateWorkloadOptions{IDs: ids}
resp, err := o.client.DissociateWorkload(ctx, opts)
if err != nil {
return err
Expand Down Expand Up @@ -48,14 +62,16 @@ func cmdWorkloadDissociate(c *cli.Context) error {
return err
}

nodes := c.StringSlice("node")
ids := c.Args().Slice()
if len(ids) == 0 {
return fmt.Errorf("Workload ID(s) should not be empty")
if len(ids) == 0 && len(nodes) == 0 {
return fmt.Errorf("Workload ID(s) and Node(s) should not be empty")
}

o := &dissociateWorkloadsOptions{
client: client,
ids: ids,
nodes: nodes,
}
return o.run(c.Context)
}

0 comments on commit 1afc026

Please sign in to comment.