Skip to content

Commit

Permalink
chore: add support for the openebs plugin
Browse files Browse the repository at this point in the history
the openebs plugin supercedes the mayastor
plugin.
However it is not a dropin replacement.
It is functional for all openebs IO engines,
and stem commands needs to further qualify
which IO engine the command is for.

At present invocations of the plugin in the
code base only exist for mayastor.

Refactor by adding functions
 -  GetMayastorPluginCmd returns and exec cmds with the
    correct argument list
 - GetMayastorPluginCmdString - needed for invocation of
   support shell scripts using the plugin
For the argument list is determined by name.
The assumption is that if the plugin name is
not kubectl-mayastor then it is the new plugin.

Refactor to replace most uses of GetPluginPath,
the exceptions being
  - upgrade
  - plugin version check commands

Also add support to create a config map for mayastor
diskpools.

Compatibilty with kubectl-mayastor is maintained

Signed-off-by: Blaise Dias <[email protected]>
  • Loading branch information
blaisedias committed Nov 13, 2024
1 parent ea271bc commit e225ec8
Show file tree
Hide file tree
Showing 11 changed files with 188 additions and 73 deletions.
10 changes: 3 additions & 7 deletions common/controlplane/v1/cordon.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"encoding/json"
"fmt"
"os/exec"
"strings"

"github.com/openebs/openebs-e2e/common"
Expand Down Expand Up @@ -49,8 +48,7 @@ type NodeCordonState struct {

func (cp CPv1) CordonNode(nodeName string, cordonLabel string) error {
logf.Log.Info("Executing cordon node command", "node", nodeName, "cordon label", cordonLabel)
kubectlPlugin := GetPluginPath()
cmd := exec.Command(kubectlPlugin, "-n", common.NSMayastor(), "cordon", "node", nodeName, cordonLabel)
cmd := GetMayastorPluginCmd("-n", common.NSMayastor(), "cordon", "node", nodeName, cordonLabel)
var out bytes.Buffer
cmd.Stdout = &out
err := cmd.Run()
Expand All @@ -64,8 +62,7 @@ func (cp CPv1) CordonNode(nodeName string, cordonLabel string) error {

func (cp CPv1) GetCordonNodeLabels(nodeName string) ([]string, error) {
logf.Log.Info("Executing command to get cordon node labels", "node", nodeName)
pluginPath := GetPluginPath()
cmd := exec.Command(pluginPath, "-n", common.NSMayastor(), "get", "node", nodeName, "-ojson")
cmd := GetMayastorPluginCmd("-n", common.NSMayastor(), "get", "node", nodeName, "-ojson")
var out bytes.Buffer
cmd.Stdout = &out
err := cmd.Run()
Expand Down Expand Up @@ -97,8 +94,7 @@ func (cp CPv1) GetCordonNodeLabels(nodeName string) ([]string, error) {

func (cp CPv1) UnCordonNode(nodeName string, cordonLabel string) error {
logf.Log.Info("Executing uncordon node command", "node", nodeName, "cordon label", cordonLabel)
kubectlPlugin := GetPluginPath()
cmd := exec.Command(kubectlPlugin, "-n", common.NSMayastor(), "uncordon", "node", nodeName, cordonLabel)
cmd := GetMayastorPluginCmd("-n", common.NSMayastor(), "uncordon", "node", nodeName, cordonLabel)
var out bytes.Buffer
cmd.Stdout = &out
err := cmd.Run()
Expand Down
11 changes: 4 additions & 7 deletions common/controlplane/v1/drain.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"encoding/json"
"fmt"
"os/exec"
"strings"

"github.com/openebs/openebs-e2e/common"
Expand All @@ -15,14 +14,13 @@ import (
// DrainNode drain the given node with label
func (cp CPv1) DrainNode(nodeName string, drainLabel string, drainTimeOut int) error {
logf.Log.Info("Executing drain node command", "node", nodeName, "drain label", drainLabel, "timeout", drainTimeOut)
kubectlPlugin := GetPluginPath()
// #FIXME remove drain timeout drain command is fuctional
cmd := exec.Command(kubectlPlugin, "-n", common.NSMayastor(), "drain", "node", nodeName, drainLabel, "--drain-timeout", fmt.Sprintf("%ds", drainTimeOut))
cmd := GetMayastorPluginCmd("-n", common.NSMayastor(), "drain", "node", nodeName, drainLabel, "--drain-timeout", fmt.Sprintf("%ds", drainTimeOut))
var out bytes.Buffer
cmd.Stdout = &out
err := cmd.Run()
if err != nil {
return fmt.Errorf("%s plugin failed to drain node %s with drain label %s , error %v", kubectlPlugin, nodeName, drainLabel, err)
return fmt.Errorf("%s plugin failed to drain node %s with drain label %s , error %v", GetPluginPath(), nodeName, drainLabel, err)
} else if strings.Contains(out.String(), ErrorResponse) {
return fmt.Errorf("REST api error, failed to drain node %s with label %s, error %v", nodeName, drainLabel, out.String())
}
Expand All @@ -32,13 +30,12 @@ func (cp CPv1) DrainNode(nodeName string, drainLabel string, drainTimeOut int) e
// GetDrainNodeLabels returns draining, drained labels and error
func (cp CPv1) GetDrainNodeLabels(nodeName string) ([]string, []string, error) {
logf.Log.Info("Executing command to get drain node labels", "node", nodeName)
pluginPath := GetPluginPath()
cmd := exec.Command(pluginPath, "-n", common.NSMayastor(), "get", "node", nodeName, "-ojson")
cmd := GetMayastorPluginCmd("-n", common.NSMayastor(), "get", "node", nodeName, "-ojson")
var out bytes.Buffer
cmd.Stdout = &out
err := cmd.Run()
if err != nil {
return nil, nil, fmt.Errorf("%s failed to get cordon labels for node %s, error %v", pluginPath, nodeName, err)
return nil, nil, fmt.Errorf("%s failed to get cordon labels for node %s, error %v", GetPluginPath(), nodeName, err)
}
outputString := out.String()
var cordonLabelsInfo NodeCordonLabelsInfo
Expand Down
12 changes: 3 additions & 9 deletions common/controlplane/v1/msn_cp.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package v1
import (
"encoding/json"
"fmt"
"os/exec"
"strings"

"github.com/openebs/openebs-e2e/common"
Expand All @@ -31,11 +30,9 @@ type msnState struct {
}

func GetMayastorCpNode(nodeName string) (*MayastorCpNode, error) {
pluginpath := GetPluginPath()

var jsonInput []byte
var err error
cmd := exec.Command(pluginpath, "-n", common.NSMayastor(), "-ojson", "get", "node", nodeName)
cmd := GetMayastorPluginCmd("-n", common.NSMayastor(), "-ojson", "get", "node", nodeName)
jsonInput, err = cmd.CombinedOutput()
err = CheckPluginError(jsonInput, err)
if err != nil {
Expand All @@ -54,11 +51,9 @@ func GetMayastorCpNode(nodeName string) (*MayastorCpNode, error) {
}

func ListMayastorCpNodes() ([]MayastorCpNode, error) {
pluginpath := GetPluginPath()

var jsonInput []byte
var err error
cmd := exec.Command(pluginpath, "-n", common.NSMayastor(), "-ojson", "get", "nodes")
cmd := GetMayastorPluginCmd("-n", common.NSMayastor(), "-ojson", "get", "nodes")
jsonInput, err = cmd.CombinedOutput()
err = CheckPluginError(jsonInput, err)
if err != nil {
Expand Down Expand Up @@ -137,7 +132,6 @@ func (cp CPv1) GetMsNodeStatus(nodeName string) (string, error) {

// UpdateNodeLabel adds or remove labels from nodes
func (cp CPv1) UpdateNodeLabel(nodeName string, labelKey, labelValue string) error {
pluginPath := GetPluginPath()
args := []string{"label", "node", nodeName}

// Check if a label value is provided
Expand All @@ -149,7 +143,7 @@ func (cp CPv1) UpdateNodeLabel(nodeName string, labelKey, labelValue string) err
args = append(args, fmt.Sprintf("%s-", labelKey))
}

cmd := exec.Command(pluginPath, args...)
cmd := GetMayastorPluginCmd(args...)

// Print the command that will be executed
logf.Log.Info("Executing", "command", strings.Join(cmd.Args, " "))
Expand Down
9 changes: 2 additions & 7 deletions common/controlplane/v1/msp_cp.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"encoding/json"
"fmt"
"os"
"os/exec"

"github.com/openebs/openebs-e2e/common"

Expand Down Expand Up @@ -41,11 +40,9 @@ func (cp CPv1) CreatePoolOnInstall() bool {
}

func GetMayastorCpPool(name string) (*MayastorCpPool, error) {
pluginpath := GetPluginPath()

var jsonInput []byte
var err error
cmd := exec.Command(pluginpath, "-n", common.NSMayastor(), "-ojson", "get", "pool", name)
cmd := GetMayastorPluginCmd("-n", common.NSMayastor(), "-ojson", "get", "pool", name)
jsonInput, err = cmd.CombinedOutput()
err = CheckPluginError(jsonInput, err)
if err != nil {
Expand All @@ -65,11 +62,9 @@ func GetMayastorCpPool(name string) (*MayastorCpPool, error) {
}

func ListMayastorCpPools() ([]MayastorCpPool, error) {
pluginpath := GetPluginPath()

var jsonInput []byte
var err error
cmd := exec.Command(pluginpath, "-n", common.NSMayastor(), "-ojson", "get", "pools")
cmd := GetMayastorPluginCmd("-n", common.NSMayastor(), "-ojson", "get", "pools")
jsonInput, err = cmd.CombinedOutput()
err = CheckPluginError(jsonInput, err)
if err != nil {
Expand Down
21 changes: 5 additions & 16 deletions common/controlplane/v1/msv_cp.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package v1
import (
"encoding/json"
"fmt"
"os/exec"
"regexp"
"strconv"
"strings"
Expand All @@ -23,11 +22,9 @@ func HasNotFoundRestJsonError(str string) bool {
}

func getMayastorCpVolume(uuid string) (*common.MayastorVolume, error) {
pluginpath := GetPluginPath()

var jsonInput []byte
var err error
cmd := exec.Command(pluginpath, "-n", common.NSMayastor(), "-ojson", "get", "volume", uuid)
cmd := GetMayastorPluginCmd("-n", common.NSMayastor(), "-ojson", "get", "volume", uuid)
jsonInput, err = cmd.CombinedOutput()
err = CheckPluginError(jsonInput, err)
if err != nil {
Expand All @@ -46,11 +43,9 @@ func getMayastorCpVolume(uuid string) (*common.MayastorVolume, error) {
}

func listMayastorCpVolumes() ([]common.MayastorVolume, error) {
pluginpath := GetPluginPath()

var jsonInput []byte
var err error
cmd := exec.Command(pluginpath, "-n", common.NSMayastor(), "-ojson", "get", "volumes")
cmd := GetMayastorPluginCmd("-n", common.NSMayastor(), "-ojson", "get", "volumes")
jsonInput, err = cmd.CombinedOutput()
err = CheckPluginError(jsonInput, err)
if err != nil {
Expand All @@ -67,11 +62,9 @@ func listMayastorCpVolumes() ([]common.MayastorVolume, error) {
}

func scaleMayastorVolume(uuid string, replicaCount int) error {
pluginpath := GetPluginPath()

var err error
var jsonInput []byte
cmd := exec.Command(pluginpath, "-n", common.NSMayastor(), "scale", "volume", uuid, strconv.Itoa(replicaCount))
cmd := GetMayastorPluginCmd("-n", common.NSMayastor(), "scale", "volume", uuid, strconv.Itoa(replicaCount))
jsonInput, err = cmd.CombinedOutput()
err = CheckPluginError(jsonInput, err)
if err != nil {
Expand Down Expand Up @@ -237,11 +230,9 @@ func (cp CPv1) ListMsvs() ([]common.MayastorVolume, error) {
}

func (cp CPv1) ListRestoredMsvs() ([]common.MayastorVolume, error) {
pluginpath := GetPluginPath()

var jsonInput []byte
var err error
cmd := exec.Command(pluginpath, "-n", common.NSMayastor(), "-ojson", "get", "volumes", "--source", "snapshot")
cmd := GetMayastorPluginCmd("-n", common.NSMayastor(), "-ojson", "get", "volumes", "--source", "snapshot")
jsonInput, err = cmd.CombinedOutput()
err = CheckPluginError(jsonInput, err)
if err != nil {
Expand Down Expand Up @@ -361,11 +352,9 @@ func (cp CPv1) GetMsvDeviceUri(volName string) (string, error) {
}

func (cp CPv1) SetVolumeMaxSnapshotCount(uuid string, maxSnapshotCount int32) error {
pluginpath := GetPluginPath()

var err error
var jsonInput []byte
cmd := exec.Command(pluginpath, "-n", common.NSMayastor(), "set", "volume", uuid, "max-snapshots", strconv.Itoa(int(maxSnapshotCount)))
cmd := GetMayastorPluginCmd("-n", common.NSMayastor(), "set", "volume", uuid, "max-snapshots", strconv.Itoa(int(maxSnapshotCount)))
jsonInput, err = cmd.CombinedOutput()
err = CheckPluginError(jsonInput, err)
if err != nil {
Expand Down
21 changes: 21 additions & 0 deletions common/controlplane/v1/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,24 @@ func CheckPluginError(jsonInput []byte, err error) error {
}
return err
}

// GetMayastorPluginCmd return an exec cmd object setup to invoke the plugin
// for the mayastor IOEngine
func GetMayastorPluginCmd(arg ...string) *exec.Cmd {
binPath := GetPluginPath()
if e2e_config.GetConfig().Product.KubectlPluginName != "kubectl-mayastor" {
return exec.Command(binPath, append([]string{"mayastor"}, arg...)...)
}
return exec.Command(binPath, arg...)
}

// GetMayastorPluginCmdString return a string which can be supplied to
// shell commands to invoke the plugin for the mayastor IOEngine
// deprecated: use GetMayastorPluginCmd in preference
func GetMayastorPluginCmdString() string {
binPath := GetPluginPath()
if e2e_config.GetConfig().Product.KubectlPluginName != "kubectl-mayastor" {
return binPath + " " + "mayastor "
}
return binPath
}
25 changes: 6 additions & 19 deletions common/controlplane/v1/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,14 @@ package v1
import (
"encoding/json"
"fmt"
"os/exec"

"github.com/openebs/openebs-e2e/common"
)

func (cp CPv1) GetSnapshots() ([]common.SnapshotSchema, error) {
pluginpath := GetPluginPath()

var jsonInput []byte
var err error
cmd := exec.Command(pluginpath, "-n", common.NSMayastor(), "-ojson", "get", "volume-snapshots")
cmd := GetMayastorPluginCmd("-n", common.NSMayastor(), "-ojson", "get", "volume-snapshots")
jsonInput, err = cmd.CombinedOutput()
err = CheckPluginError(jsonInput, err)
if err != nil {
Expand All @@ -30,12 +27,10 @@ func (cp CPv1) GetSnapshots() ([]common.SnapshotSchema, error) {
}

func (cp CPv1) GetSnapshot(snapshotId string) (common.SnapshotSchema, error) {
pluginpath := GetPluginPath()

var jsonInput []byte
var err error
var response []common.SnapshotSchema
cmd := exec.Command(pluginpath, "-n", common.NSMayastor(), "-ojson", "get", "volume-snapshots", "--snapshot", snapshotId)
cmd := GetMayastorPluginCmd("-n", common.NSMayastor(), "-ojson", "get", "volume-snapshots", "--snapshot", snapshotId)
jsonInput, err = cmd.CombinedOutput()
err = CheckPluginError(jsonInput, err)
if err != nil {
Expand All @@ -57,12 +52,10 @@ func (cp CPv1) GetSnapshot(snapshotId string) (common.SnapshotSchema, error) {
}

func (cp CPv1) GetVolumeSnapshot(volUuid string, snapshotId string) (common.SnapshotSchema, error) {
pluginpath := GetPluginPath()

var jsonInput []byte
var err error
var response []common.SnapshotSchema
cmd := exec.Command(pluginpath, "-n", common.NSMayastor(), "-ojson", "get", "volume-snapshots", "--volume", volUuid, "--snapshot", snapshotId)
cmd := GetMayastorPluginCmd("-n", common.NSMayastor(), "-ojson", "get", "volume-snapshots", "--volume", volUuid, "--snapshot", snapshotId)
jsonInput, err = cmd.CombinedOutput()
err = CheckPluginError(jsonInput, err)
if err != nil {
Expand All @@ -83,11 +76,9 @@ func (cp CPv1) GetVolumeSnapshot(volUuid string, snapshotId string) (common.Snap
}

func (cp CPv1) GetVolumeSnapshots(volUuid string) ([]common.SnapshotSchema, error) {
pluginpath := GetPluginPath()

var jsonInput []byte
var err error
cmd := exec.Command(pluginpath, "-n", common.NSMayastor(), "-ojson", "get", "volume-snapshots", "--volume", volUuid)
cmd := GetMayastorPluginCmd("-n", common.NSMayastor(), "-ojson", "get", "volume-snapshots", "--volume", volUuid)
jsonInput, err = cmd.CombinedOutput()
err = CheckPluginError(jsonInput, err)
if err != nil {
Expand All @@ -104,11 +95,9 @@ func (cp CPv1) GetVolumeSnapshots(volUuid string) ([]common.SnapshotSchema, erro
}

func (cp CPv1) GetVolumeSnapshotTopology() ([]common.SnapshotSchema, error) {
pluginpath := GetPluginPath()

var jsonInput []byte
var err error
cmd := exec.Command(pluginpath, "-n", common.NSMayastor(), "-ojson", "get", "volume-snapshot-topology")
cmd := GetMayastorPluginCmd("-n", common.NSMayastor(), "-ojson", "get", "volume-snapshot-topology")
jsonInput, err = cmd.CombinedOutput()
err = CheckPluginError(jsonInput, err)
if err != nil {
Expand All @@ -125,12 +114,10 @@ func (cp CPv1) GetVolumeSnapshotTopology() ([]common.SnapshotSchema, error) {
}

func (cp CPv1) GetPerSnapshotVolumeSnapshotTopology(snapshotId string) (common.SnapshotSchema, error) {
pluginpath := GetPluginPath()

var jsonInput []byte
var err error
var response []common.SnapshotSchema
cmd := exec.Command(pluginpath, "-n", common.NSMayastor(), "-ojson", "get", "volume-snapshot-topology", "--snapshot", snapshotId)
cmd := GetMayastorPluginCmd("-n", common.NSMayastor(), "-ojson", "get", "volume-snapshot-topology", "--snapshot", snapshotId)
jsonInput, err = cmd.CombinedOutput()
err = CheckPluginError(jsonInput, err)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion common/e2e_config/e2e_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ type ProductSpec struct {
IOEnginePodLabelValue string `yaml:"ioEnginePodLabelValue" env-default:"io-engine"`
IOEnginePodName string `yaml:"ioEnginePodName"`
JaegersCrdName string `yaml:"jaegersCrdName" env-default:"jaegers.jaegertracing.io"`
KubectlPluginName string `yaml:"kubectlPluginName" env-default:"kubectl-mayastor"`
KubectlPluginName string `yaml:"kubectlPluginName" env-default:"kubectl-mayastor" env:"e2e_kc_plugin"`
KubectlPluginPort int `yaml:"kubectlPluginPort" env-default:"30011"`
LogConfigResources []string `yaml:"logConfigResources"`
LogDumpCsiAttacherName string `yaml:"logDumpCsiAttacherName" env-default:"csi-attacher"`
Expand Down
6 changes: 3 additions & 3 deletions common/k8stest/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -1001,7 +1001,7 @@ func GenerateSupportBundle(testLogDir string) {
bashCmd := fmt.Sprintf("%s/e2e-cluster-dump.sh --destdir '%s' --plugin '%s'",
locations.GetE2EScriptsPath(),
testLogDir,
mcpV1.GetPluginPath(),
mcpV1.GetMayastorPluginCmdString(),
)
logf.Log.Info("About to execute", "command", bashCmd)
cmd := exec.Command("bash", "-c", bashCmd)
Expand All @@ -1013,7 +1013,7 @@ func GenerateSupportBundle(testLogDir string) {
logf.Log.Info(out.String())
}
bashCmd = fmt.Sprintf("%s -n %s get volume-replica-topologies -o json > %s/%s",
mcpV1.GetPluginPath(),
mcpV1.GetMayastorPluginCmdString(),
common.NSMayastor(),
testLogDir,
"replica-topologies.json")
Expand All @@ -1024,7 +1024,7 @@ func GenerateSupportBundle(testLogDir string) {
logf.Log.Info("command failed", "error", err)
logf.Log.Info(out.String())
}
cmd = exec.Command(mcpV1.GetPluginPath(), "dump", "system", "-n", common.NSMayastor(), "-d", testLogDir)
cmd = mcpV1.GetMayastorPluginCmd("dump", "system", "-n", common.NSMayastor(), "-d", testLogDir)
logf.Log.Info("About to execute", "command", cmd)
err = cmd.Run()
if err != nil {
Expand Down
Loading

0 comments on commit e225ec8

Please sign in to comment.