Skip to content
This repository is currently being migrated. It's locked while the migration is in progress.

Commit

Permalink
Check a node is either cordoned or compute-only when moving (#224)
Browse files Browse the repository at this point in the history
Add a few extra checks so we don't let users move volumes into either
cordoned or compute-only nodes.
  • Loading branch information
Ricardo-Osorio committed Feb 7, 2023
1 parent 8d420b8 commit ec80b8d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
28 changes: 26 additions & 2 deletions cmd/update/volume_move.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"io"
"strconv"
"time"

"github.com/spf13/cobra"
Expand Down Expand Up @@ -49,6 +50,10 @@ func (c *volumeMoveCommand) runWithCtx(ctx context.Context, cmd *cobra.Command,

nsID := id.Namespace(c.namespace)

// look into the node config and its labels so we know whether we are
// attempting to move to a node that is marked as compute-only, etc
var toNodeCfg *model.Node

if !useIDs {
ns, err := c.client.GetNamespaceByName(ctx, c.namespace)
if err != nil {
Expand All @@ -62,11 +67,29 @@ func (c *volumeMoveCommand) runWithCtx(ctx context.Context, cmd *cobra.Command,
}
c.fromNode = fromNode.ID.String()

toNode, err := c.client.GetNodeByName(ctx, c.toNode)
toNodeCfg, err = c.client.GetNodeByName(ctx, c.toNode)
if err != nil {
return err
}
c.toNode = toNodeCfg.ID.String()
} else {
toNodeCfg, err = c.client.GetNode(ctx, id.Node(c.toNode))
if err != nil {
return err
}
c.toNode = toNode.ID.String()
}

if toNodeCfg.Cordoned {
return fmt.Errorf("cannot move volume into cordoned node")
}
if val, ok := toNodeCfg.Labels[model.LabelComputeOnly]; ok {
isComputeOnly, err := strconv.ParseBool(val)
if err != nil {
return fmt.Errorf("failed to parse compute-only label")
}
if isComputeOnly {
return fmt.Errorf("cannot move volume into compute-only node")
}
}

vol, err := c.getVolume(ctx, nsID)
Expand Down Expand Up @@ -184,6 +207,7 @@ A default timeout of 30min is in place but it should be adjusted with the global
err = c.client.SetReplicas(ctx, nsID, vol.ID, uint64(originalReplicaCount), setReplicasParam)
if err != nil {
c.display.TextMessage(ctx, c.writer, fmt.Sprintf("Failed to restore original replica count: %s. Can be addressed manually or wait for it to be re-synced with PVC.", err.Error()))
return
}

c.display.TextMessage(ctx, c.writer, "Restored volume original replica count.")
Expand Down
3 changes: 2 additions & 1 deletion model/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ const (
LabelReplicas = "storageos.com/replicas"
// LabelThrottle is a StorageOS volume label which when enabled deprioritises
// the volume's traffic by reducing disk I/O rate.
LabelThrottle = "storageos.com/throttle"
LabelThrottle = "storageos.com/throttle"
LabelComputeOnly = "storageos.com/computeonly"
)

// FsType indicates the kind of filesystem which a volume has been given.
Expand Down

0 comments on commit ec80b8d

Please sign in to comment.