From 70287f00f9c35dfa5c1a8acd366801e076841e65 Mon Sep 17 00:00:00 2001 From: Bridget McErlean Date: Mon, 15 Mar 2021 02:23:41 -0400 Subject: [PATCH] Install plugins for additional BSL in E2E test (#3582) The test for multiple credentials assumed that the plugin for the additional BSL provider was already installed. This will not be the case when performing a clean install of Velero between tests. This adds a new utility function to add the plugins that are necessary for the additional BSL provider. It doesn't check which plugins are already installed, it will just attempt to install and if the stderr contains the message that it is a duplicate plugin, we ignore the error and continue. This could be improved by instpecting the output from `velero plugin get` but I opted for a quicker solution given the upcoming release. Signed-off-by: Bridget McErlean --- test/e2e/backup_test.go | 7 +++++-- test/e2e/velero_utils.go | 30 ++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) 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 +}