diff --git a/test/e2e/backup_test.go b/test/e2e/backup_test.go index c3775a6ba..1b058d977 100644 --- a/test/e2e/backup_test.go +++ b/test/e2e/backup_test.go @@ -34,8 +34,9 @@ var _ = Describe("[Restic] Velero tests on cluster using the plugin provider for uuidgen, err = uuid.NewRandom() Expect(err).To(Succeed()) if installVelero { - VeleroInstall(context.Background(), veleroImage, veleroNamespace, cloudProvider, objectStoreProvider, useVolumeSnapshots, - cloudCredentialsFile, bslBucket, bslPrefix, bslConfig, vslConfig, "") + Expect(VeleroInstall(context.Background(), veleroImage, veleroNamespace, cloudProvider, objectStoreProvider, useVolumeSnapshots, + cloudCredentialsFile, bslBucket, bslPrefix, bslConfig, vslConfig, "")).To(Succeed()) + } client, extensionsClient, err = kube.GetClusterClient() Expect(err).To(Succeed(), "Failed to instantiate cluster client") @@ -73,6 +74,8 @@ var _ = Describe("[Restic] Velero tests on cluster using the plugin provider for Skip("no additional BSL credentials given, not running multiple BackupStorageLocation with unique credentials tests") } + Expect(VeleroAddPluginsForProvider(context.TODO(), veleroCLI, veleroNamespace, additionalBSLProvider)).To(Succeed()) + // Create Secret for additional BSL secretName := fmt.Sprintf("bsl-credentials-%s", uuidgen) secretKey := fmt.Sprintf("creds-%s", additionalBSLProvider) diff --git a/test/e2e/velero_utils.go b/test/e2e/velero_utils.go index 6f93524a9..d3eb7deaa 100644 --- a/test/e2e/velero_utils.go +++ b/test/e2e/velero_utils.go @@ -1,6 +1,7 @@ package e2e import ( + "bytes" "context" "encoding/json" "fmt" @@ -8,6 +9,7 @@ import ( "os" "os/exec" "path/filepath" + "strings" "github.com/pkg/errors" "k8s.io/client-go/kubernetes" @@ -360,3 +362,31 @@ func VeleroCreateBackupLocation(ctx context.Context, return bslCreateCmd.Run() } + +// VeleroAddPluginsForProvider determines which plugins need to be installed for a provider and +// installs them in the current Velero installation, skipping over those that are already installed. +func VeleroAddPluginsForProvider(ctx context.Context, veleroCLI string, veleroNamespace string, provider string) error { + for _, plugin := range getProviderPlugins(provider) { + stdoutBuf := new(bytes.Buffer) + stderrBuf := new(bytes.Buffer) + + installPluginCmd := exec.CommandContext(ctx, veleroCLI, "--namespace", veleroNamespace, "plugin", "add", plugin) + installPluginCmd.Stdout = stdoutBuf + installPluginCmd.Stderr = stdoutBuf + + err := installPluginCmd.Run() + + fmt.Fprint(os.Stdout, stdoutBuf) + fmt.Fprint(os.Stderr, stderrBuf) + + if err != nil { + // If the plugin failed to install as it was already installed, ignore the error and continue + // TODO: Check which plugins are already installed by inspecting `velero plugin get` + if !strings.Contains(stderrBuf.String(), "Duplicate value") { + return errors.WithMessagef(err, "error installing plugin %s", plugin) + } + } + } + + return nil +}