This repository is currently being migrated. It's locked while the migration is in progress.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds set failover grace period and maintenance mode commands (#228)
- Loading branch information
1 parent
e122d67
commit 4e189d7
Showing
24 changed files
with
571 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
package update | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"fmt" | ||
"io" | ||
"strconv" | ||
"time" | ||
|
||
"code.storageos.net/storageos/c2-cli/apiclient" | ||
"code.storageos.net/storageos/c2-cli/cmd/argwrappers" | ||
"code.storageos.net/storageos/c2-cli/cmd/interfaces" | ||
"code.storageos.net/storageos/c2-cli/cmd/runwrappers" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
type maintenanceModeCommand struct { | ||
config interfaces.ConfigProvider | ||
client interfaces.Client | ||
w io.Writer | ||
} | ||
|
||
// NewMaintenanceModeCmd defines config for the "maintenance-mode" command | ||
func NewMaintenanceModeCmd(w io.Writer, client interfaces.Client, config interfaces.ConfigProvider) *cobra.Command { | ||
c := &maintenanceModeCommand{ | ||
config: config, | ||
client: client, | ||
w: w, | ||
} | ||
|
||
cmd := &cobra.Command{ | ||
Use: "maintenance-mode <true|false>", | ||
Short: "Sets maintenance mode for the entire cluster", | ||
Long: `Sets maintenance mode for the entire cluster | ||
When maintenance mode is enabled failovers will not occur`, | ||
Example: " storageos maintenance-mode true", | ||
Args: argwrappers.WrapInvalidArgsError(func(_ *cobra.Command, args []string) error { | ||
if len(args) != 1 { | ||
return errors.New("must specify true or false") | ||
} | ||
return nil | ||
}), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
run := runwrappers.Chain( | ||
runwrappers.RunWithTimeout(config), | ||
runwrappers.AuthenticateClient(config, client), | ||
)(c.run) | ||
|
||
return run(context.Background(), cmd, args) | ||
}, | ||
} | ||
|
||
return cmd | ||
} | ||
|
||
func (c *maintenanceModeCommand) run(ctx context.Context, _ *cobra.Command, args []string) error { | ||
useIDs, err := c.config.UseIDs() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
enabled, err := strconv.ParseBool(args[0]) | ||
if err != nil { | ||
return fmt.Errorf("failed to parse boolean from arguments: %w", err) | ||
} | ||
|
||
nodes, err := c.client.ListNodes(ctx) | ||
if err != nil { | ||
return fmt.Errorf("failed to list nodes: %w", err) | ||
} | ||
|
||
var gracePeriod uint64 | ||
if enabled { | ||
// Set the failover period to a 100 years, which should be a long enough maintenance window | ||
gracePeriod = uint64(time.Hour.Milliseconds() * 24 * 365 * 100) | ||
} | ||
|
||
for _, node := range nodes { | ||
|
||
err = c.client.SetFailoverGracePeriod(ctx, node.ID, &apiclient.SetFailoverGracePeriodParams{ | ||
GracePeriod: gracePeriod, | ||
}) | ||
if err != nil { | ||
n := node.Name | ||
if useIDs { | ||
n = string(node.ID) | ||
} | ||
|
||
return fmt.Errorf("failed to set maintenance mode for node %v: %w", n, err) | ||
} | ||
|
||
nodeOutput := node.Name | ||
if useIDs { | ||
nodeOutput = string(node.ID) | ||
} | ||
fmt.Fprintf(c.w, "set maintenance mode to %v for node/%s\n", enabled, nodeOutput) | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package update | ||
|
||
import ( | ||
"os" | ||
|
||
"code.storageos.net/storageos/c2-cli/cmd/interfaces" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// newNodeUpdate configures the set of commands which are grouped by the | ||
// "node" noun. | ||
func newNodeUpdate(client interfaces.Client, config interfaces.ConfigProvider) *cobra.Command { | ||
command := &cobra.Command{ | ||
Use: "node", | ||
Short: "Make changes to a node", | ||
} | ||
|
||
command.AddCommand(NewFailoverGracePeriodCmd(os.Stdout, client, config)) | ||
command.AddCommand(NewMaintenanceModeCmd(os.Stdout, client, config)) | ||
|
||
return command | ||
} |
Oops, something went wrong.