mirror of
https://github.com/vmware-tanzu/velero.git
synced 2026-09-29 03:05:54 +00:00
Modify the StorageClass install and delete code.
* Only install and uninstall SC and VSC once for default cluster. * Install and uninstall SC and VSC for standby cluster on migration case. * Refactor the StorageClass and VolumeSnapshotClass YAMLs. * Prettify the e2e_suite_test.go Signed-off-by: Xun Jiang <xun.jiang@broadcom.com>
This commit is contained in:
@@ -71,7 +71,7 @@ func GetConfigmap(c clientset.Interface, ns, secretName string) (*v1.ConfigMap,
|
||||
return c.CoreV1().ConfigMaps(ns).Get(context.TODO(), secretName, metav1.GetOptions{})
|
||||
}
|
||||
|
||||
func DeleteConfigmap(c clientset.Interface, ns, name string) error {
|
||||
func DeleteConfigMap(c clientset.Interface, ns, name string) error {
|
||||
if err := c.CoreV1().ConfigMaps(ns).Delete(context.TODO(), name, metav1.DeleteOptions{}); err != nil {
|
||||
return errors.Wrap(err, fmt.Sprintf("failed to delete configmap in namespace %q", ns))
|
||||
}
|
||||
@@ -79,7 +79,7 @@ func DeleteConfigmap(c clientset.Interface, ns, name string) error {
|
||||
}
|
||||
|
||||
func WaitForConfigmapDelete(c clientset.Interface, ns, name string) error {
|
||||
if err := DeleteConfigmap(c, ns, name); err != nil {
|
||||
if err := DeleteConfigMap(c, ns, name); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
+25
-24
@@ -23,7 +23,6 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
@@ -129,7 +128,7 @@ func VeleroInstall(ctx context.Context, veleroCfg *test.VeleroConfig, isStandbyC
|
||||
_, err = k8s.GetNamespace(ctx, *veleroCfg.ClientToInstallVelero, veleroCfg.VeleroNamespace)
|
||||
// We should uninstall Velero for a new service account creation.
|
||||
if !apierrors.IsNotFound(err) {
|
||||
if err := VeleroUninstall(context.Background(), veleroCfg.VeleroCLI, veleroCfg.VeleroNamespace); err != nil {
|
||||
if err := VeleroUninstall(context.Background(), *veleroCfg); err != nil {
|
||||
return errors.Wrapf(err, "Failed to uninstall velero %s", veleroCfg.VeleroNamespace)
|
||||
}
|
||||
}
|
||||
@@ -150,15 +149,19 @@ func VeleroInstall(ctx context.Context, veleroCfg *test.VeleroConfig, isStandbyC
|
||||
return errors.Wrapf(err, "Failed to create service account %s to %s namespace", veleroInstallOptions.ServiceAccountName, veleroCfg.VeleroNamespace)
|
||||
}
|
||||
}
|
||||
err = installVeleroServer(ctx, veleroCfg.VeleroCLI, veleroCfg.CloudProvider, &installOptions{
|
||||
Options: veleroInstallOptions,
|
||||
RegistryCredentialFile: veleroCfg.RegistryCredentialFile,
|
||||
RestoreHelperImage: veleroCfg.RestoreHelperImage,
|
||||
VeleroServerDebugMode: veleroCfg.VeleroServerDebugMode,
|
||||
WithoutDisableInformerCacheParam: veleroCfg.WithoutDisableInformerCacheParam,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
if err := installVeleroServer(
|
||||
ctx,
|
||||
veleroCfg.VeleroCLI,
|
||||
veleroCfg.CloudProvider,
|
||||
&installOptions{
|
||||
Options: veleroInstallOptions,
|
||||
RegistryCredentialFile: veleroCfg.RegistryCredentialFile,
|
||||
RestoreHelperImage: veleroCfg.RestoreHelperImage,
|
||||
VeleroServerDebugMode: veleroCfg.VeleroServerDebugMode,
|
||||
WithoutDisableInformerCacheParam: veleroCfg.WithoutDisableInformerCacheParam,
|
||||
},
|
||||
); err != nil {
|
||||
time.Sleep(9 * time.Hour)
|
||||
RunDebug(context.Background(), veleroCfg.VeleroCLI, veleroCfg.VeleroNamespace, "", "")
|
||||
return errors.WithMessagef(err, "Failed to install Velero in the cluster")
|
||||
@@ -320,14 +323,6 @@ func installVeleroServer(ctx context.Context, cli, cloudProvider string, options
|
||||
|
||||
if len(options.Features) > 0 {
|
||||
args = append(args, "--features", options.Features)
|
||||
if strings.EqualFold(options.Features, test.FeatureCSI) && options.UseVolumeSnapshots {
|
||||
// https://github.com/openebs/zfs-localpv/blob/develop/docs/snapshot.md
|
||||
fmt.Printf("Start to install %s VolumeSnapshotClass ... \n", cloudProvider)
|
||||
if err := k8s.KubectlApplyByFile(ctx, fmt.Sprintf("../testdata/volume-snapshot-class/%s.yaml", cloudProvider)); err != nil {
|
||||
fmt.Println("Fail to install VolumeSnapshotClass when CSI feature is enabled: ", err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if options.GarbageCollectionFrequency > 0 {
|
||||
@@ -374,14 +369,14 @@ func installVeleroServer(ctx context.Context, cli, cloudProvider string, options
|
||||
args = append(args, fmt.Sprintf("--uploader-type=%v", options.UploaderType))
|
||||
}
|
||||
|
||||
if err := createVelereResources(ctx, cli, namespace, args, options); err != nil {
|
||||
if err := createVeleroResources(ctx, cli, namespace, args, options); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return waitVeleroReady(ctx, namespace, options.UseNodeAgent)
|
||||
}
|
||||
|
||||
func createVelereResources(ctx context.Context, cli, namespace string, args []string, options *installOptions) error {
|
||||
func createVeleroResources(ctx context.Context, cli, namespace string, args []string, options *installOptions) error {
|
||||
args = append(args, "--dry-run", "--output", "json", "--crds-only")
|
||||
|
||||
// get the CRD definitions
|
||||
@@ -670,7 +665,7 @@ func PrepareVelero(ctx context.Context, caseName string, veleroCfg test.VeleroCo
|
||||
fmt.Printf("error in checking velero status with %v", err)
|
||||
ctx, ctxCancel := context.WithTimeout(context.Background(), time.Minute*5)
|
||||
defer ctxCancel()
|
||||
VeleroUninstall(ctx, veleroCfg.VeleroCLI, veleroCfg.VeleroNamespace)
|
||||
VeleroUninstall(ctx, veleroCfg)
|
||||
ready = false
|
||||
}
|
||||
if ready {
|
||||
@@ -681,9 +676,15 @@ func PrepareVelero(ctx context.Context, caseName string, veleroCfg test.VeleroCo
|
||||
return VeleroInstall(context.Background(), &veleroCfg, false)
|
||||
}
|
||||
|
||||
func VeleroUninstall(ctx context.Context, cli, namespace string) error {
|
||||
stdout, stderr, err := velerexec.RunCommand(exec.CommandContext(ctx, cli, "uninstall", "--force", "-n", namespace))
|
||||
if err != nil {
|
||||
func VeleroUninstall(ctx context.Context, veleroCfg test.VeleroConfig) error {
|
||||
if stdout, stderr, err := velerexec.RunCommand(exec.CommandContext(
|
||||
ctx,
|
||||
veleroCfg.VeleroCLI,
|
||||
"uninstall",
|
||||
"--force",
|
||||
"-n",
|
||||
veleroCfg.VeleroNamespace,
|
||||
)); err != nil {
|
||||
return errors.Wrapf(err, "failed to uninstall velero, stdout=%s, stderr=%s", stdout, stderr)
|
||||
}
|
||||
fmt.Println("Velero uninstalled ⛵")
|
||||
|
||||
@@ -616,9 +616,7 @@ func RunDebug(ctx context.Context, veleroCLI, veleroNamespace, backup, restore s
|
||||
if len(backup) > 0 {
|
||||
args = append(args, "--backup", backup)
|
||||
}
|
||||
if len(restore) > 0 {
|
||||
//args = append(args, "--restore", restore)
|
||||
}
|
||||
|
||||
fmt.Printf("Generating the debug tarball at %s\n", output)
|
||||
if err := VeleroCmdExec(ctx, veleroCLI, args); err != nil {
|
||||
fmt.Println(errors.Wrapf(err, "failed to run the debug command"))
|
||||
@@ -1228,6 +1226,7 @@ func GetBackupsCreationTime(ctx context.Context, veleroCLI, bslName string) ([]s
|
||||
func GetAllBackups(ctx context.Context, veleroCLI string) ([]string, error) {
|
||||
return GetBackupsFromBsl(ctx, veleroCLI, "")
|
||||
}
|
||||
|
||||
func DeleteBslResource(ctx context.Context, veleroCLI string, bslName string) error {
|
||||
args := []string{"backup-location", "delete", bslName, "--confirm"}
|
||||
|
||||
@@ -1431,6 +1430,7 @@ func VeleroUpgrade(ctx context.Context, veleroCfg VeleroConfig) error {
|
||||
}
|
||||
return waitVeleroReady(ctx, veleroCfg.VeleroNamespace, veleroCfg.UseNodeAgent)
|
||||
}
|
||||
|
||||
func ApplyCRDs(ctx context.Context, veleroCLI string) ([]string, error) {
|
||||
cmds := []*common.OsCommandLine{}
|
||||
|
||||
@@ -1629,20 +1629,32 @@ func GetVeleroPodName(ctx context.Context) ([]string, error) {
|
||||
return common.GetListByCmdPipes(ctx, cmds)
|
||||
}
|
||||
|
||||
func InstallTestStorageClasses(path string) error {
|
||||
// InstallStorageClasses create the "e2e-storage-class" and "e2e-storage-class-2"
|
||||
// StorageClasses for E2E tests.
|
||||
//
|
||||
// e2e-storage-class is the default StorageClass for E2E.
|
||||
// e2e-storage-class-2 is used for the StorageClass mapping test case.
|
||||
// Kibishii StorageClass is not covered here.
|
||||
func InstallStorageClasses(provider string) error {
|
||||
ctx, ctxCancel := context.WithTimeout(context.Background(), time.Minute*5)
|
||||
defer ctxCancel()
|
||||
err := InstallStorageClass(ctx, path)
|
||||
if err != nil {
|
||||
|
||||
storageClassFilePath := fmt.Sprintf("../testdata/storage-class/%s.yaml", provider)
|
||||
|
||||
if err := InstallStorageClass(ctx, storageClassFilePath); err != nil {
|
||||
return err
|
||||
}
|
||||
content, err := os.ReadFile(path)
|
||||
content, err := os.ReadFile(storageClassFilePath)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to get %s when install storage class", path)
|
||||
return errors.Wrapf(err, "failed to get %s when install storage class", storageClassFilePath)
|
||||
}
|
||||
|
||||
// replace sc to new value
|
||||
newContent := strings.ReplaceAll(string(content), fmt.Sprintf("name: %s", StorageClassName), fmt.Sprintf("name: %s", StorageClassName2))
|
||||
// Replace the name to e2e-storage-class-2
|
||||
newContent := strings.ReplaceAll(
|
||||
string(content),
|
||||
fmt.Sprintf("name: %s", StorageClassName),
|
||||
fmt.Sprintf("name: %s", StorageClassName2),
|
||||
)
|
||||
|
||||
tmpFile, err := os.CreateTemp("", "sc-file")
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user