Skip to content

Commit

Permalink
Fix plugins incompatible issue in upgrade test
Browse files Browse the repository at this point in the history
In upgrade test, both original and to-be-upgrading velero installation should use the compatible plugins,
but currently, plugin value is determined by provider.

Signed-off-by: danfengl <[email protected]>
  • Loading branch information
danfengliu committed Sep 14, 2021
1 parent b9eb6fd commit 185f23e
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 25 deletions.
2 changes: 2 additions & 0 deletions test/e2e/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ GINKGO_FOCUS ?=
VELERO_CLI ?=$$(pwd)/../../_output/bin/$(GOOS)/$(GOARCH)/velero
VELERO_IMAGE ?= velero/velero:main
VELERO_VERSION ?= $(VERSION)
VELERO_PLUGINS ?=
RESTIC_HELPER_IMAGE ?=
#Released version only
UPGRADE_FROM_VELERO_CLI ?=
Expand Down Expand Up @@ -86,6 +87,7 @@ run: ginkgo
(echo "Cloud provider for target cloud/plug-in provider is required, please rerun with CLOUD_PROVIDER=<aws,azure,kind,vsphere>"; exit 1)
@$(GINKGO) -v -focus="$(GINKGO_FOCUS)" . -- -velerocli=$(VELERO_CLI) \
-velero-image=$(VELERO_IMAGE) \
-velero-plugins=$(VELERO_PLUGINS) \
-velero-version=$(VELERO_VERSION) \
-restic-helper-image=$(RESTIC_HELPER_IMAGE) \
-upgrade-from-velero-cli=$(UPGRADE_FROM_VELERO_CLI) \
Expand Down
3 changes: 2 additions & 1 deletion test/e2e/e2e_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
var (
veleroCLI, veleroImage, veleroVersion, cloudCredentialsFile, bslConfig, bslBucket, bslPrefix, vslConfig, cloudProvider, objectStoreProvider, veleroNamespace, crdsVersion string
additionalBSLProvider, additionalBSLBucket, additionalBSLPrefix, additionalBSLConfig, additionalBSLCredentials, registryCredentialFile, resticHelperImage string
upgradeFromVeleroVersion, upgradeFromVeleroCLI string
upgradeFromVeleroVersion, upgradeFromVeleroCLI, veleroPlugins string
installVelero bool
)

Expand All @@ -39,6 +39,7 @@ func init() {
flag.StringVar(&cloudCredentialsFile, "credentials-file", "", "file containing credentials for backup and volume provider. Required.")
flag.StringVar(&veleroCLI, "velerocli", "velero", "path to the velero application to use.")
flag.StringVar(&veleroImage, "velero-image", "velero/velero:main", "image for the velero server to be tested.")
flag.StringVar(&veleroPlugins, "velero-plugins", "", "image for the velero server to be tested.")
flag.StringVar(&veleroVersion, "velero-version", "main", "image for the velero server to be tested.")
flag.StringVar(&resticHelperImage, "restic-helper-image", "", "image for the velero restic restore helper to be tested.")
flag.StringVar(&upgradeFromVeleroCLI, "upgrade-from-velero-cli", "", "path to the pre-upgrade velero application to use.")
Expand Down
9 changes: 6 additions & 3 deletions test/e2e/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,12 @@ func veleroInstall(ctx context.Context, cli, veleroImage string, resticHelperIma
return errors.New("No object store provider specified - must be specified when using kind as the cloud provider") // Gotta have an object store provider
}
}

version, err := getVeleroVersion(ctx, cli, true)
if err != nil {
return errors.WithMessage(err, "Failed to get velero version")
}
// Fetch the plugins for the provider before checking for the object store provider below.
providerPlugins := getProviderPlugins(objectStoreProvider)
providerPlugins := getProviderPlugins(version, objectStoreProvider)

// TODO - handle this better
if cloudProvider == "vsphere" {
Expand All @@ -70,7 +73,7 @@ func veleroInstall(ctx context.Context, cli, veleroImage string, resticHelperIma
// Snapshot location specified
objectStoreProvider = "aws"
}
err := ensureClusterExists(ctx)
err = ensureClusterExists(ctx)
if err != nil {
return errors.WithMessage(err, "Failed to ensure Kubernetes cluster exists")
}
Expand Down
87 changes: 66 additions & 21 deletions test/e2e/velero_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,49 @@ import (
veleroexec "github.com/vmware-tanzu/velero/pkg/util/exec"
)

func getProviderPlugins(providerName string) []string {
// TODO: make plugin images configurable
switch providerName {
case "aws":
return []string{"velero/velero-plugin-for-aws:v1.2.1"}
case "azure":
return []string{"velero/velero-plugin-for-microsoft-azure:v1.2.0"}
case "vsphere":
return []string{"velero/velero-plugin-for-aws:v1.2.1", "vsphereveleroplugin/velero-plugin-for-vsphere:v1.1.1"}
case "gcp":
return []string{"velero/velero-plugin-for-gcp:v1.2.1"}
default:
panic(fmt.Errorf("unknown provider name: %s", providerName))
var pluginsMatric = map[string]map[string][]string{
"v1.4": {
"aws": {"velero/velero-plugin-for-aws:v1.1.0"},
"azure": {"velero/velero-plugin-for-microsoft-azure:v1.1.2"},
"vsphere": {"velero/velero-plugin-for-aws:v1.1.0"},
"gcp": {"velero/velero-plugin-for-gcp:v1.1.0"},
},
"v1.5": {
"aws": {"velero/velero-plugin-for-aws:v1.1.0"},
"azure": {"velero/velero-plugin-for-microsoft-azure:v1.1.2"},
"vsphere": {"velero/velero-plugin-for-aws:v1.1.0", "vsphereveleroplugin/velero-plugin-for-vsphere:v1.1.1"},
"gcp": {"velero/velero-plugin-for-gcp:v1.1.0"},
},
"v1.6": {
"aws": {"velero/velero-plugin-for-aws:v1.2.1"},
"azure": {"velero/velero-plugin-for-microsoft-azure:v1.2.1"},
"vsphere": {"velero/velero-plugin-for-aws:v1.2.1", "vsphereveleroplugin/velero-plugin-for-vsphere:v1.1.1"},
"gcp": {"velero/velero-plugin-for-gcp:v1.2.1"},
},
"v1.7": {
"aws": {"velero/velero-plugin-for-aws:v1.3.0-rc.1"},
"azure": {"velero/velero-plugin-for-microsoft-azure:v1.3.0-rc.1"},
"vsphere": {"velero/velero-plugin-for-aws:v1.3.0-rc.1", "vsphereveleroplugin/velero-plugin-for-vsphere:v1.1.1"},
"gcp": {"velero/velero-plugin-for-gcp:v1.3.0-rc.1"},
},
}

func getProviderPlugins(version, providerName string) []string {

arr := strings.Split(version, ".")
if len(arr) < 3 {
panic(fmt.Errorf("invalid velero version: %s", version))
}
mainVersion := arr[0] + "." + arr[1]
cloudMap, ok := pluginsMatric[mainVersion]
if !ok {
panic(fmt.Errorf("fail to get plugins by version: %s", version))
}
plugins, ok := cloudMap[providerName]
if !ok {
panic(fmt.Errorf("fail to get plugins by version: %s and provider %s", version, providerName))
}
return plugins
}

// getProviderVeleroInstallOptions returns Velero InstallOptions for the provider.
Expand Down Expand Up @@ -327,7 +356,11 @@ func veleroCreateBackupLocation(ctx context.Context,
// 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) {
version, err := getVeleroVersion(ctx, veleroCLI, true)
if err != nil {
return errors.WithMessage(err, "Failed to get velero version")
}
for _, plugin := range getProviderPlugins(version, provider) {
stdoutBuf := new(bytes.Buffer)
stderrBuf := new(bytes.Buffer)

Expand Down Expand Up @@ -398,8 +431,12 @@ func waitForVSphereUploadCompletion(ctx context.Context, timeout time.Duration,
return err
}

func getVeleroVersion(ctx context.Context, veleroCLI string) (string, error) {
cmd := exec.CommandContext(ctx, veleroCLI, "version", "--timeout", "60s")
func getVeleroVersion(ctx context.Context, veleroCLI string, clientOnly bool) (string, error) {
args := []string{"version", "--timeout", "60s"}
if clientOnly {
args = append(args, "--client-only")
}
cmd := exec.CommandContext(ctx, veleroCLI, args...)
fmt.Println("Get Version Command:" + cmd.String())
stdout, stderr, err := veleroexec.RunCommand(cmd)
if err != nil {
Expand All @@ -408,20 +445,28 @@ func getVeleroVersion(ctx context.Context, veleroCLI string) (string, error) {

output := strings.Replace(stdout, "\n", " ", -1)
fmt.Println("Version:" + output)
regCompiler := regexp.MustCompile(`(?i)client\s*:\s*version\s*:\s*(\S+).+server\s*:\s*version\s*:\s*(\S+)`)
resultCount := 3
regexpRule := `(?i)client\s*:\s*version\s*:\s*(\S+).+server\s*:\s*version\s*:\s*(\S+)`
if clientOnly {
resultCount = 2
regexpRule = `(?i)client\s*:\s*version\s*:\s*(\S+)`
}
regCompiler := regexp.MustCompile(regexpRule)
versionMatches := regCompiler.FindStringSubmatch(output)
if len(versionMatches) < 3 {
if len(versionMatches) < resultCount {
return "", errors.New("Velero version command returned null version")
}
if versionMatches[1] != versionMatches[2] {
return "", errors.New("Velero server and client version are not matched")
if !clientOnly {
if versionMatches[1] != versionMatches[2] {
return "", errors.New("Velero server and client version are not matched")
}
}
return versionMatches[1], nil
}

func checkVeleroVersion(ctx context.Context, veleroCLI string, expectedVer string) error {
tag := expectedVer
tagInstalled, err := getVeleroVersion(ctx, veleroCLI)
tagInstalled, err := getVeleroVersion(ctx, veleroCLI, false)
if err != nil {
return errors.WithMessagef(err, "Failed to get Velero version")
}
Expand Down

0 comments on commit 185f23e

Please sign in to comment.