Add BSL status check for Velero Installation and BSL creation. (#9163)
Some checks failed
Run the E2E test on kind / build (push) Failing after 8s
Run the E2E test on kind / setup-test-matrix (push) Successful in 3s
Run the E2E test on kind / run-e2e-test (push) Has been skipped
Main CI / Build (push) Failing after 4s
Close stale issues and PRs / stale (push) Successful in 14s
Trivy Nightly Scan / Trivy nightly scan (velero, main) (push) Failing after 7s
Trivy Nightly Scan / Trivy nightly scan (velero-plugin-for-aws, main) (push) Failing after 4s
Trivy Nightly Scan / Trivy nightly scan (velero-plugin-for-gcp, main) (push) Failing after 3s
Trivy Nightly Scan / Trivy nightly scan (velero-plugin-for-microsoft-azure, main) (push) Failing after 3s

Signed-off-by: Xun Jiang <xun.jiang@broadcom.com>
This commit is contained in:
Xun Jiang/Bruce Jiang
2025-08-14 03:09:11 +08:00
committed by GitHub
parent 81e7330a64
commit d295314b33
2 changed files with 37 additions and 24 deletions

View File

@@ -187,10 +187,15 @@ func VeleroInstall(ctx context.Context, veleroCfg *test.VeleroConfig, isStandbyC
WorkerOS: veleroCfg.WorkerOS,
},
); err != nil {
time.Sleep(1 * time.Minute)
RunDebug(context.Background(), veleroCfg.VeleroCLI, veleroCfg.VeleroNamespace, "", "")
RunDebug(ctx, veleroCfg.VeleroCLI, veleroCfg.VeleroNamespace, "", "")
return errors.WithMessagef(err, "Failed to install Velero in the cluster")
}
if err := CheckBSL(ctx, veleroCfg.VeleroNamespace, common.DefaultBSLName); err != nil {
RunDebug(ctx, veleroCfg.VeleroCLI, veleroCfg.VeleroNamespace, "", "")
return fmt.Errorf("fail to wait BSL default till ready: %w", err)
}
fmt.Printf("Finish velero install %s\n", time.Now().Format("2006-01-02 15:04:05"))
return nil
}
@@ -754,32 +759,35 @@ func IsVeleroReady(ctx context.Context, veleroCfg *test.VeleroConfig) (bool, err
}
}
// Check BSL with poll
err = wait.PollUntilContextTimeout(ctx, k8s.PollInterval, time.Minute, true, func(ctx context.Context) (bool, error) {
return checkBSL(ctx, veleroCfg) == nil, nil
})
if err != nil {
return false, errors.Wrap(err, "failed to check the bsl")
if err := CheckBSL(ctx, namespace, common.DefaultBSLName); err != nil {
return false, err
}
return true, nil
}
func checkBSL(ctx context.Context, veleroCfg *test.VeleroConfig) error {
namespace := veleroCfg.VeleroNamespace
stdout, stderr, err := velerexec.RunCommand(exec.CommandContext(ctx, "kubectl", "get", "bsl", "default",
"-o", "json", "-n", namespace))
if err != nil {
return errors.Wrapf(err, "failed to get bsl %s stdout=%s, stderr=%s", veleroCfg.BSLBucket, stdout, stderr)
} else {
bsl := &velerov1api.BackupStorageLocation{}
if err = json.Unmarshal([]byte(stdout), bsl); err != nil {
return errors.Wrapf(err, "failed to unmarshal the velero bsl")
func CheckBSL(ctx context.Context, ns string, bslName string) error {
// Check BSL with poll
err := wait.PollUntilContextTimeout(ctx, k8s.PollInterval, time.Minute, true, func(ctx context.Context) (bool, error) {
stdout, stderr, err := velerexec.RunCommand(exec.CommandContext(ctx, "kubectl", "get", "bsl", bslName,
"-o", "json", "-n", ns))
if err != nil {
return false, errors.Wrapf(err, "failed to get bsl %s stdout=%s, stderr=%s", bslName, stdout, stderr)
} else {
bsl := &velerov1api.BackupStorageLocation{}
if err = json.Unmarshal([]byte(stdout), bsl); err != nil {
return false, errors.Wrapf(err, "failed to unmarshal the velero bsl")
}
if bsl.Status.Phase != velerov1api.BackupStorageLocationPhaseAvailable {
// BSL is not ready. Continue polling till timeout.
return false, nil
}
}
if bsl.Status.Phase != velerov1api.BackupStorageLocationPhaseAvailable {
return fmt.Errorf("current bsl %s is not available", veleroCfg.BSLBucket)
}
}
return nil
return true, nil
})
return err
}
func PrepareVelero(ctx context.Context, caseName string, veleroCfg test.VeleroConfig) error {

View File

@@ -653,7 +653,12 @@ func VeleroCreateBackupLocation(ctx context.Context,
if secretName != "" && secretKey != "" {
args = append(args, "--credential", fmt.Sprintf("%s=%s", secretName, secretKey))
}
return VeleroCmdExec(ctx, veleroCLI, args)
if err := VeleroCmdExec(ctx, veleroCLI, args); err != nil {
return err
}
return CheckBSL(ctx, veleroNamespace, name)
}
func VeleroVersion(ctx context.Context, veleroCLI, veleroNamespace string) error {