mirror of
https://github.com/vmware-tanzu/velero.git
synced 2026-08-15 11:46:06 +00:00
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 <bmcerlean@vmware.com>
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user