mirror of
https://github.com/vmware-tanzu/velero.git
synced 2026-09-20 23:14:17 +00:00
fix-ctx-issue
1. Fix issue of kubectl client and server mismatch version in GitAction E2E job, refer to https://github.com/elastic/cloud-on-k8s/issues/4737; 2. Adapt to the changing of keyword for involing Kpoia as fs backupper, new installtion breaked upgrade and migration tests; 3. Accept multi-labels of Ginkgo focus as input of E2E make command; 4. Distinguish workload namespace from each tests; 5. Fix issues of not using Velero util to perform Velero commands; 6. Add snapshot test case for NamespaceMapping E2E test; 7. Collect debug bundle after catching error of Velero backup or restore command; Signed-off-by: danfengl <danfengl@vmware.com>
This commit is contained in:
@@ -120,12 +120,11 @@ func RunKibishiiTests(client TestClient, veleroCfg VerleroConfig, backupName, re
|
||||
if err := DeleteNamespace(oneHourTimeout, client, kibishiiNamespace, true); err != nil {
|
||||
return errors.Wrapf(err, "failed to delete namespace %s", kibishiiNamespace)
|
||||
}
|
||||
time.Sleep(5 * time.Minute)
|
||||
|
||||
// the snapshots of AWS may be still in pending status when do the restore, wait for a while
|
||||
// to avoid this https://github.com/vmware-tanzu/velero/issues/1799
|
||||
// TODO remove this after https://github.com/vmware-tanzu/velero/issues/3533 is fixed
|
||||
if providerName == "aws" && useVolumeSnapshots {
|
||||
if useVolumeSnapshots {
|
||||
fmt.Println("Waiting 5 minutes to make sure the snapshots are ready...")
|
||||
time.Sleep(5 * time.Minute)
|
||||
}
|
||||
@@ -138,7 +137,6 @@ func RunKibishiiTests(client TestClient, veleroCfg VerleroConfig, backupName, re
|
||||
if err := KibishiiVerifyAfterRestore(client, kibishiiNamespace, oneHourTimeout, DefaultKibishiiData); err != nil {
|
||||
return errors.Wrapf(err, "Error verifying kibishii after restore")
|
||||
}
|
||||
|
||||
fmt.Printf("kibishii test completed successfully\n")
|
||||
return nil
|
||||
}
|
||||
@@ -151,8 +149,7 @@ func installKibishii(ctx context.Context, namespace string, cloudPlatform, veler
|
||||
}
|
||||
// We use kustomize to generate YAML for Kibishii from the checked-in yaml directories
|
||||
kibishiiInstallCmd := exec.CommandContext(ctx, "kubectl", "apply", "-n", namespace, "-k",
|
||||
kibishiiDirectory+cloudPlatform)
|
||||
|
||||
kibishiiDirectory+cloudPlatform, "--timeout=90s")
|
||||
_, stderr, err := veleroexec.RunCommand(kibishiiInstallCmd)
|
||||
fmt.Printf("Install Kibishii cmd: %s\n", kibishiiInstallCmd)
|
||||
if err != nil {
|
||||
|
||||
@@ -364,10 +364,10 @@ func (s AzureStorage) IsSnapshotExisted(cloudCredentialsFile, bslConfig, backupN
|
||||
snapshotCountFound := 0
|
||||
backupNameInSnapshot := ""
|
||||
if err != nil {
|
||||
errors.Wrap(err, fmt.Sprintf("Fail to list snapshots %s\n", envVars[resourceGroupEnvVar]))
|
||||
return errors.Wrap(err, fmt.Sprintf("Fail to list snapshots %s\n", envVars[resourceGroupEnvVar]))
|
||||
}
|
||||
if result.Value == nil {
|
||||
errors.New(fmt.Sprintf("No snapshots in Azure resource group %s\n", envVars[resourceGroupEnvVar]))
|
||||
return errors.New(fmt.Sprintf("No snapshots in Azure resource group %s\n", envVars[resourceGroupEnvVar]))
|
||||
}
|
||||
for _, v := range *result.Value {
|
||||
if snapshotCheck.EnableCSI {
|
||||
|
||||
@@ -46,7 +46,7 @@ func ObjectsShouldBeInBucket(cloudProvider, cloudCredentialsFile, bslBucket, bsl
|
||||
func ObjectsShouldNotBeInBucket(cloudProvider, cloudCredentialsFile, bslBucket, bslPrefix, bslConfig, backupName, subPrefix string, retryTimes int) error {
|
||||
var err error
|
||||
var exist bool
|
||||
fmt.Printf("|| VERIFICATION || - %s %s should not exist in storage %s\n", subPrefix, backupName, bslPrefix)
|
||||
fmt.Printf("|| VERIFICATION || - %s %s should not exist in object store %s\n", subPrefix, backupName, bslPrefix)
|
||||
for i := 0; i < retryTimes; i++ {
|
||||
exist, err = IsObjectsInBucket(cloudProvider, cloudCredentialsFile, bslBucket, bslPrefix, bslConfig, backupName, subPrefix)
|
||||
if err != nil {
|
||||
@@ -114,9 +114,9 @@ func SnapshotsShouldNotExistInCloud(cloudProvider, cloudCredentialsFile, bslBuck
|
||||
snapshotCheckPoint.ExpectCount = 0
|
||||
err := IsSnapshotExisted(cloudProvider, cloudCredentialsFile, bslBucket, bslConfig, backupName, snapshotCheckPoint)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, fmt.Sprintf("|| UNEXPECTED ||Snapshots %s is existed in cloud after backup as expected", backupName))
|
||||
return errors.Wrapf(err, fmt.Sprintf("|| UNEXPECTED ||Snapshots %s exist in cloud after backup as expected", backupName))
|
||||
}
|
||||
fmt.Printf("|| EXPECTED || - Snapshots are not existed in cloud, backup %s\n", backupName)
|
||||
fmt.Printf("|| EXPECTED || - Snapshots do not exist in cloud, backup %s\n", backupName)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -124,9 +124,9 @@ func SnapshotsShouldBeCreatedInCloud(cloudProvider, cloudCredentialsFile, bslBuc
|
||||
fmt.Printf("|| VERIFICATION || - Snapshots should exist in cloud, backup %s\n", backupName)
|
||||
err := IsSnapshotExisted(cloudProvider, cloudCredentialsFile, bslBucket, bslConfig, backupName, snapshotCheckPoint)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, fmt.Sprintf("|| UNEXPECTED ||Snapshots %s are not existed in cloud after backup as expected", backupName))
|
||||
return errors.Wrapf(err, fmt.Sprintf("|| UNEXPECTED ||Snapshots %s do not exist in cloud after backup as expected", backupName))
|
||||
}
|
||||
fmt.Printf("|| EXPECTED || - Snapshots are existed in cloud, backup %s\n", backupName)
|
||||
fmt.Printf("|| EXPECTED || - Snapshots exist in cloud, backup %s\n", backupName)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -87,7 +87,10 @@ func VeleroInstall(ctx context.Context, veleroCfg *VerleroConfig, useVolumeSnaps
|
||||
return errors.WithMessagef(err, "Failed to get Velero InstallOptions for plugin provider %s", veleroCfg.ObjectStoreProvider)
|
||||
}
|
||||
veleroInstallOptions.UseVolumeSnapshots = useVolumeSnapshots
|
||||
veleroInstallOptions.UseNodeAgent = !useVolumeSnapshots
|
||||
if !veleroCfg.UseRestic {
|
||||
veleroInstallOptions.UseNodeAgent = !useVolumeSnapshots
|
||||
}
|
||||
veleroInstallOptions.UseRestic = veleroCfg.UseRestic
|
||||
veleroInstallOptions.Image = veleroCfg.VeleroImage
|
||||
veleroInstallOptions.Namespace = veleroCfg.VeleroNamespace
|
||||
veleroInstallOptions.UploaderType = veleroCfg.UploaderType
|
||||
@@ -175,6 +178,9 @@ func installVeleroServer(ctx context.Context, cli string, options *installOption
|
||||
if options.UseNodeAgent {
|
||||
args = append(args, "--use-node-agent")
|
||||
}
|
||||
if options.UseRestic {
|
||||
args = append(args, "--use-restic")
|
||||
}
|
||||
if options.UseVolumeSnapshots {
|
||||
args = append(args, "--use-volume-snapshots")
|
||||
}
|
||||
@@ -285,7 +291,7 @@ func createVelereResources(ctx context.Context, cli, namespace string, args []st
|
||||
cmd.Stderr = os.Stderr
|
||||
fmt.Printf("Running cmd %q \n", cmd.String())
|
||||
if err = cmd.Run(); err != nil {
|
||||
return errors.Wrapf(err, "failed to apply velere resources")
|
||||
return errors.Wrapf(err, "failed to apply Velero resources")
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@@ -323,7 +323,7 @@ func VeleroBackupNamespace(ctx context.Context, veleroCLI, veleroNamespace strin
|
||||
if backupCfg.UseVolumeSnapshots {
|
||||
args = append(args, "--snapshot-volumes")
|
||||
} else {
|
||||
if backupCfg.UseRestic {
|
||||
if backupCfg.UseResticIfFSBackup {
|
||||
args = append(args, "--default-volumes-to-restic")
|
||||
} else {
|
||||
args = append(args, "--default-volumes-to-fs-backup")
|
||||
@@ -399,6 +399,7 @@ func VeleroRestoreExec(ctx context.Context, veleroCLI, veleroNamespace, restoreN
|
||||
if err := VeleroCmdExec(ctx, veleroCLI, args); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return checkRestorePhase(ctx, veleroCLI, veleroNamespace, restoreName, velerov1api.RestorePhaseCompleted)
|
||||
}
|
||||
|
||||
@@ -436,19 +437,14 @@ func VeleroScheduleCreate(ctx context.Context, veleroCLI string, veleroNamespace
|
||||
|
||||
func VeleroCmdExec(ctx context.Context, veleroCLI string, args []string) error {
|
||||
cmd := exec.CommandContext(ctx, veleroCLI, args...)
|
||||
var errBuf, outBuf bytes.Buffer
|
||||
cmd.Stderr = io.MultiWriter(os.Stderr, &errBuf)
|
||||
cmd.Stdout = io.MultiWriter(os.Stdout, &outBuf)
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
fmt.Printf("velero cmd =%v\n", cmd)
|
||||
err := cmd.Run()
|
||||
retAll := outBuf.String() + " " + errBuf.String()
|
||||
if strings.Contains(strings.ToLower(retAll), "failed") {
|
||||
return errors.Wrap(err, fmt.Sprintf("velero cmd =%v return with failure\n", cmd))
|
||||
if strings.Contains(fmt.Sprint(cmd.Stdout), "Failed") {
|
||||
return errors.New(fmt.Sprintf("velero cmd =%v return with failure\n", cmd))
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
return err
|
||||
}
|
||||
|
||||
func VeleroBackupLogs(ctx context.Context, veleroCLI string, veleroNamespace string, backupName string) error {
|
||||
@@ -511,6 +507,16 @@ func VeleroCreateBackupLocation(ctx context.Context,
|
||||
return VeleroCmdExec(ctx, veleroCLI, args)
|
||||
}
|
||||
|
||||
func VeleroVersion(ctx context.Context, veleroCLI, veleroNamespace string) error {
|
||||
args := []string{
|
||||
"version", "--namespace", veleroNamespace,
|
||||
}
|
||||
if err := VeleroCmdExec(ctx, veleroCLI, args); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func getProviderPlugins(ctx context.Context, veleroCLI, objectStoreProvider, providerPlugins, feature string) ([]string, error) {
|
||||
// Fetch the plugins for the provider before checking for the object store provider below.
|
||||
var plugins []string
|
||||
@@ -788,12 +794,11 @@ func GetBackup(ctx context.Context, veleroCLI string, backupName string) (string
|
||||
func IsBackupExist(ctx context.Context, veleroCLI string, backupName string) (bool, error) {
|
||||
out, outerr, err := GetBackup(ctx, veleroCLI, backupName)
|
||||
if err != nil {
|
||||
if err != nil {
|
||||
if strings.Contains(outerr, "not found") {
|
||||
return false, nil
|
||||
}
|
||||
return false, err
|
||||
if strings.Contains(outerr, "not found") {
|
||||
fmt.Printf("Backup CR %s was not found\n", backupName)
|
||||
return false, nil
|
||||
}
|
||||
return false, err
|
||||
}
|
||||
fmt.Printf("Backup <%s> exist locally according to output \n[%s]\n", backupName, out)
|
||||
return true, nil
|
||||
@@ -807,6 +812,7 @@ func WaitBackupDeleted(ctx context.Context, veleroCLI string, backupName string,
|
||||
if exist {
|
||||
return false, nil
|
||||
} else {
|
||||
fmt.Printf("Backup %s does not exist\n", backupName)
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user