Fix missing default storageclass issue

Signed-off-by: danfengl <danfengl@vmware.com>
This commit is contained in:
danfengl
2023-08-30 10:55:57 +00:00
parent e6b510e32b
commit 80ccbd2b70
5 changed files with 50 additions and 8 deletions
+3
View File
@@ -10,6 +10,9 @@ import (
"os/exec"
)
const StorageClassName = "e2e-storage-class"
const StorageClassName2 = "e2e-storage-class-2"
type OsCommandLine struct {
Cmd string
Args []string
+31
View File
@@ -20,6 +20,7 @@ import (
"fmt"
"os"
"os/exec"
"strings"
"time"
"github.com/pkg/errors"
@@ -33,6 +34,9 @@ import (
"github.com/vmware-tanzu/velero/test/e2e/util/common"
)
const StorageClassName = "e2e-storage-class"
const StorageClassName2 = "e2e-storage-class-2"
// ensureClusterExists returns whether or not a Kubernetes cluster exists for tests to be run on.
func EnsureClusterExists(ctx context.Context) error {
return exec.CommandContext(ctx, "kubectl", "cluster-info").Run()
@@ -363,3 +367,30 @@ func GetAPIVersions(client *TestClient, name string) ([]string, error) {
}
return nil, errors.New("Server API groups is empty")
}
func InstallTestStorageClasses(path string) error {
ctx, ctxCancel := context.WithTimeout(context.Background(), time.Minute*5)
defer ctxCancel()
err := InstallStorageClass(ctx, path)
if err != nil {
return err
}
content, err := os.ReadFile(path)
if err != nil {
return errors.Wrapf(err, "failed to get %s when install storage class", path)
}
// replace sc to new value
newContent := strings.ReplaceAll(string(content), fmt.Sprintf("name: %s", StorageClassName), fmt.Sprintf("name: %s", StorageClassName2))
tmpFile, err := os.CreateTemp("", "sc-file")
if err != nil {
return errors.Wrapf(err, "failed to create temp file when install storage class")
}
defer os.Remove(tmpFile.Name())
if _, err := tmpFile.WriteString(newContent); err != nil {
return errors.Wrapf(err, "failed to write content into temp file %s when install storage class", tmpFile.Name())
}
return InstallStorageClass(ctx, tmpFile.Name())
}