Skip to content

Commit

Permalink
Merge pull request #99 from openebs/support-new-plugins
Browse files Browse the repository at this point in the history
chore: add support for the openebs plugin
  • Loading branch information
blaisedias authored Nov 26, 2024
2 parents d861faf + a805ced commit 19cdec1
Show file tree
Hide file tree
Showing 11 changed files with 186 additions and 75 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
18 changes: 18 additions & 0 deletions common/controlplane/v1/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,19 @@ package v1
import (
"fmt"
"os/exec"
"path/filepath"
"strings"

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

func GetPluginPath() string {
// Use kubectl plugin path in preference
if e2e_config.GetConfig().KubectlPluginPath != "" {
return e2e_config.GetConfig().KubectlPluginPath
}
// path to kubectl plugin is not specified, fall back
// to using plugin directory and configured plugin file name
if e2e_config.GetConfig().KubectlPluginDir == "" {
panic("unspecified location of kubectl plugin")
}
Expand Down Expand Up @@ -60,3 +67,14 @@ 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" {
if filepath.Base(binPath) != "kubectl-mayastor" {
return exec.Command(binPath, append([]string{"mayastor"}, arg...)...)
}
return exec.Command(binPath, arg...)
}
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
3 changes: 2 additions & 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 Expand Up @@ -191,6 +191,7 @@ type E2EConfig struct {
OpenEbsE2eRootDir string `yaml:"openEbsE2eRootDir" env:"openebs_e2e_root_dir"`
SessionDir string `yaml:"sessionDir" env:"e2e_session_dir"`
MayastorVersion string `yaml:"mayastorVersion" env:"e2e_mayastor_version"`
KubectlPluginPath string `yaml:"kubectlPluginPath" env:"e2e_kubectl_plugin_path"`
KubectlPluginDir string `yaml:"kubectlPluginDir" env:"e2e_kubectl_plugin_dir"`
MaasOauthApiToken string `yaml:"maasOauthApiToken" env:"e2e_maas_api_token"`
MaasEndpoint string `yaml:"maasEndpoint" env:"e2e_maas_endpoint"`
Expand Down
Loading

0 comments on commit 19cdec1

Please sign in to comment.