Skip to content

Commit

Permalink
Merge pull request #107 from openebs/platform-csi-provisioner
Browse files Browse the repository at this point in the history
chore: add config for platform csi provisioner
  • Loading branch information
rohan2794 authored Dec 20, 2024
2 parents 9913de7 + 0416e6a commit 24a8e78
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 18 deletions.
2 changes: 2 additions & 0 deletions common/e2e_config/e2e_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ type E2EConfig struct {
FilteredMayastorPodCheck int `yaml:"filteredMayastorPodCheck" env-default:"0"`
// data plane interface
IOEngineTargetNvmfIface string `yaml:"ioengineTargetNvmfIface" env-default:"" env:"e2e_ioengine_target_nvmf_iface"`
// CSI provisioner , HZ: csi.hetzner.cloud
CsiProvisioner string `yaml:"csiProvisioner" env-default:"csi.hetzner.cloud"`
} `yaml:"platform"`
Product ProductSpec `yaml:"product"`

Expand Down
53 changes: 35 additions & 18 deletions common/k8stest/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,24 +380,6 @@ func DeploymentReady(deploymentName, namespace string) bool {
return false
}

func DaemonSetReady(daemonName string, namespace string) bool {
daemon, err := gTestEnv.KubeInt.AppsV1().DaemonSets(namespace).Get(
context.TODO(),
daemonName,
metaV1.GetOptions{},
)
if err != nil {
logf.Log.Info("Failed to get daemonset", "error", err)
return false
}

status := daemon.Status
logf.Log.Info("DaemonSet "+daemonName, "status", status)
return status.DesiredNumberScheduled == status.CurrentNumberScheduled &&
status.DesiredNumberScheduled == status.NumberReady &&
status.DesiredNumberScheduled == status.NumberAvailable
}

func ControlPlaneReady(sleepTime int, duration int) bool {
ready := false
count := (duration + sleepTime - 1) / sleepTime
Expand Down Expand Up @@ -1886,3 +1868,38 @@ func WaitForDeploymentToMatchExpectedState(deployName string, namespace string,
}
return false, err
}

// SizeToBytes return size in bytes, input can be string like 10 GiB , 512 MiB
func SizeToBytes(capacity string) (uint64, error) {
// Map for unit multipliers
unitMultipliers := map[string]float64{
"KiB": 1024,
"MiB": math.Pow(1024, 2),
"GiB": math.Pow(1024, 3),
"TiB": math.Pow(1024, 4),
"PiB": math.Pow(1024, 5),
}

// Split capacity into value and unit
parts := strings.Fields(capacity)
if len(parts) != 2 {
return 0, fmt.Errorf("invalid size string format")
}

// Parse the numeric value
value, err := strconv.ParseFloat(parts[0], 64)
if err != nil {
return 0, fmt.Errorf("invalid numeric value in size: %v", err)
}

// Get the multiplier for the unit
unit := parts[1]
multiplier, exists := unitMultipliers[unit]
if !exists {
return 0, fmt.Errorf("invalid or unsupported unit: %s", unit)
}

// Calculate bytes
bytes := value * multiplier
return uint64(bytes), nil
}
54 changes: 54 additions & 0 deletions common/k8stest/util_daemonset.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ package k8stest
import (
"context"
"fmt"
"time"

appsV1 "k8s.io/api/apps/v1"
v1 "k8s.io/api/apps/v1"
coreV1 "k8s.io/api/core/v1"
metaV1 "k8s.io/apimachinery/pkg/apis/meta/v1"
logf "sigs.k8s.io/controller-runtime/pkg/log"
)

func ListDaemonSet(namespace string) (v1.DaemonSetList, error) {
Expand Down Expand Up @@ -109,3 +111,55 @@ func UpdateDemonsetContainerAllEnv(daemonsetName string, containerName string, n
}
return nil
}

func WaitForDaemonsetReady(dsName string, namespace string, sleepTime int, duration int) bool {
ready := false
count := (duration + sleepTime - 1) / sleepTime

logf.Log.Info("DaemonsetReadyCheck", "Daemonet", dsName, "namespace", namespace)
for ix := 0; ix < count && !ready; ix++ {
time.Sleep(time.Duration(sleepTime) * time.Second)

ready = DaemonSetReady(dsName, namespace)
logf.Log.Info("DaemonSetReady: ", "daemonset", dsName, "ready", ready)
}

if !ready {
logf.Log.Info("Daemonset not ready", "Daemonset", dsName, "namespace", namespace)
return false
}

dsPodList, err := ListPodsByPrefix(namespace, dsName)
if err != nil {
logf.Log.Info("Failed to list pods with daemonset prefix", "daemonset", dsName, "error", err)
return false
}
for _, pod := range dsPodList {
// verify pod running
err := WaitForPodRunning(pod.Name, namespace, duration)
if err != nil {
logf.Log.Info("Pod not ready", "Pod name", pod.Name, "namespace", namespace)
return false
}

}
return ready
}

func DaemonSetReady(daemonName string, namespace string) bool {
daemon, err := gTestEnv.KubeInt.AppsV1().DaemonSets(namespace).Get(
context.TODO(),
daemonName,
metaV1.GetOptions{},
)
if err != nil {
logf.Log.Info("Failed to get daemonset", "error", err)
return false
}

status := daemon.Status
logf.Log.Info("DaemonSet "+daemonName, "status", status)
return status.DesiredNumberScheduled == status.CurrentNumberScheduled &&
status.DesiredNumberScheduled == status.NumberReady &&
status.DesiredNumberScheduled == status.NumberAvailable
}
1 change: 1 addition & 0 deletions configurations/hcloudci_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ deferredAssert: true
beforeEachCheckAndRestart: true
ioEngineNvmeTimeout: 110
networkInterface: eth0
csiProvisioner: csi.hetzner.cloud

0 comments on commit 24a8e78

Please sign in to comment.