Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow dissociating all workloads in node #106

Merged
merged 1 commit into from
Jan 2, 2024
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
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)
}