-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
Feature/node cordon
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package node | ||
|
||
import ( | ||
"fmt" | ||
"github.com/dnephin/cobra" | ||
"github.com/storageos/go-api/types" | ||
"github.com/storageos/go-cli/cli" | ||
"github.com/storageos/go-cli/cli/command" | ||
"strings" | ||
) | ||
|
||
type cordonOptions struct { | ||
nodes []string | ||
} | ||
|
||
func newCordonCommand(storageosCli *command.StorageOSCli) *cobra.Command { | ||
var opt cordonOptions | ||
|
||
cmd := &cobra.Command{ | ||
Use: "cordon NODE [NODE...]", | ||
Short: "Put one or more nodes into an unschedulable state", | ||
Args: cli.RequiresMinArgs(1), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
opt.nodes = args | ||
return runCordon(storageosCli, opt) | ||
}, | ||
} | ||
|
||
return cmd | ||
} | ||
|
||
func runCordon(storageosCli *command.StorageOSCli, opt cordonOptions) error { | ||
client := storageosCli.Client() | ||
failed := make([]string, 0, len(opt.nodes)) | ||
|
||
for _, nodeID := range opt.nodes { | ||
n, err := client.Controller(nodeID) | ||
if err != nil { | ||
failed = append(failed, nodeID) | ||
continue | ||
} | ||
|
||
_, err = client.ControllerUpdate(types.ControllerUpdateOptions{ | ||
ID: n.ID, | ||
Name: n.Name, | ||
Description: n.Description, | ||
Labels: n.Labels, | ||
Cordon: true, | ||
}) | ||
if err != nil { | ||
failed = append(failed, nodeID) | ||
continue | ||
} | ||
|
||
fmt.Fprintln(storageosCli.Out(), nodeID) | ||
} | ||
|
||
if len(failed) > 0 { | ||
return fmt.Errorf("Failed to cordon: %s", strings.Join(failed, ", ")) | ||
} | ||
return nil | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package node | ||
|
||
import ( | ||
"fmt" | ||
"github.com/dnephin/cobra" | ||
"github.com/storageos/go-api/types" | ||
"github.com/storageos/go-cli/cli" | ||
"github.com/storageos/go-cli/cli/command" | ||
"strings" | ||
) | ||
|
||
type uncordonOptions struct { | ||
nodes []string | ||
} | ||
|
||
func newUncordonCommand(storageosCli *command.StorageOSCli) *cobra.Command { | ||
var opt uncordonOptions | ||
|
||
cmd := &cobra.Command{ | ||
Use: "uncordon NODE [NODE...]", | ||
Short: "Restore one or more nodes from an unschedulable state", | ||
Args: cli.RequiresMinArgs(1), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
opt.nodes = args | ||
return runUncordon(storageosCli, opt) | ||
}, | ||
} | ||
|
||
return cmd | ||
} | ||
|
||
func runUncordon(storageosCli *command.StorageOSCli, opt uncordonOptions) error { | ||
client := storageosCli.Client() | ||
failed := make([]string, 0, len(opt.nodes)) | ||
|
||
for _, nodeID := range opt.nodes { | ||
n, err := client.Controller(nodeID) | ||
if err != nil { | ||
failed = append(failed, nodeID) | ||
continue | ||
} | ||
|
||
_, err = client.ControllerUpdate(types.ControllerUpdateOptions{ | ||
ID: n.ID, | ||
Name: n.Name, | ||
Description: n.Description, | ||
Labels: n.Labels, | ||
Cordon: false, | ||
}) | ||
if err != nil { | ||
failed = append(failed, nodeID) | ||
continue | ||
} | ||
|
||
fmt.Fprintln(storageosCli.Out(), nodeID) | ||
} | ||
|
||
if len(failed) > 0 { | ||
return fmt.Errorf("Failed to uncordon: %s", strings.Join(failed, ", ")) | ||
} | ||
return nil | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package node | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"github.com/dnephin/cobra" | ||
"github.com/storageos/go-api/types" | ||
"github.com/storageos/go-cli/cli" | ||
"github.com/storageos/go-cli/cli/command" | ||
"strings" | ||
) | ||
|
||
const ( | ||
flagDescription = "description" | ||
flagLabelAdd = "label-add" | ||
flagLabelRemove = "label-rm" | ||
) | ||
|
||
type updateOptions struct { | ||
description string | ||
addLabel string | ||
rmLabel string | ||
} | ||
|
||
func newUpdateCommand(storageosCli *command.StorageOSCli) *cobra.Command { | ||
opt := updateOptions{} | ||
|
||
cmd := &cobra.Command{ | ||
Use: "update [OPTIONS] NODE", | ||
Short: "Update a node", | ||
Args: cli.ExactArgs(1), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
return runUpdate(storageosCli, opt, args[0]) | ||
}, | ||
} | ||
|
||
flags := cmd.Flags() | ||
flags.StringVarP(&opt.description, flagDescription, "d", "", `Node description`) | ||
flags.StringVar(&opt.addLabel, flagLabelAdd, "", "Add or update a node label (key=value)") | ||
flags.StringVar(&opt.rmLabel, flagLabelRemove, "", "Remove a node label if exists") | ||
return cmd | ||
} | ||
|
||
func runUpdate(storageosCli *command.StorageOSCli, opt updateOptions, nodeID string) error { | ||
client := storageosCli.Client() | ||
|
||
n, err := client.Controller(nodeID) | ||
if err != nil { | ||
return fmt.Errorf("Failed to find node (%s): %v", nodeID, err) | ||
} | ||
|
||
if opt.description != "" { | ||
n.Description = opt.description | ||
} | ||
|
||
if opt.rmLabel != "" { | ||
delete(n.Labels, opt.rmLabel) | ||
} | ||
|
||
if opt.addLabel != "" { | ||
arr := strings.Split(opt.addLabel, "=") | ||
|
||
if len(arr) != 2 || arr[0] == "" || arr[1] == "" { | ||
return errors.New("Bad label format: " + opt.addLabel) | ||
} | ||
|
||
n.Labels[arr[0]] = arr[1] | ||
} | ||
|
||
if _, err = client.ControllerUpdate(types.ControllerUpdateOptions{ | ||
ID: n.ID, | ||
Name: n.Name, | ||
Description: n.Description, | ||
Labels: n.Labels, | ||
Cordon: n.Cordon, | ||
}); err != nil { | ||
return fmt.Errorf("Failed to update node (%s): %v", nodeID, err) | ||
} | ||
|
||
fmt.Fprintln(storageosCli.Out(), nodeID) | ||
return nil | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.