-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: danfengl <[email protected]>
- Loading branch information
1 parent
7c75cd6
commit 6a8e716
Showing
7 changed files
with
365 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
Copyright the Velero contributors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package e2e | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"github.com/pkg/errors" | ||
"golang.org/x/net/context" | ||
) | ||
|
||
const ( | ||
kibishiiNamespace = "kibishii-workload" | ||
jumpPadPod = "jump-pad" | ||
) | ||
|
||
// runKibishiiTests runs kibishii tests on the provider. | ||
func runKibishiiTests(client testClient, providerName, veleroCLI, veleroNamespace, backupName, restoreName, backupLocation string, | ||
useVolumeSnapshots bool, registryCredentialFile string) error { | ||
oneHourTimeout, _ := context.WithTimeout(context.Background(), time.Minute*60) | ||
serviceAccountName := "default" | ||
|
||
if err := kibishiiPrepareBeforeBackup(client, providerName, oneHourTimeout, kibishiiNamespace, serviceAccountName, registryCredentialFile); err != nil { | ||
return errors.Wrapf(err, "Failed to install and prepare data for kibishii %s", kibishiiNamespace) | ||
} | ||
|
||
if err := veleroBackupNamespace(oneHourTimeout, veleroCLI, veleroNamespace, backupName, kibishiiNamespace, backupLocation, useVolumeSnapshots); err != nil { | ||
veleroBackupLogs(oneHourTimeout, veleroCLI, veleroNamespace, backupName) | ||
return errors.Wrapf(err, "Failed to backup kibishii namespace %s", kibishiiNamespace) | ||
} | ||
|
||
if providerName == "vsphere" && useVolumeSnapshots { | ||
// Wait for uploads started by the Velero Plug-in for vSphere to complete | ||
// TODO - remove after upload progress monitoring is implemented | ||
fmt.Println("Waiting for vSphere uploads to complete") | ||
if err := waitForVSphereUploadCompletion(oneHourTimeout, time.Hour, kibishiiNamespace); err != nil { | ||
return errors.Wrapf(err, "Error waiting for uploads to complete") | ||
} | ||
} | ||
fmt.Printf("Simulating a disaster by removing namespace %s\n", kibishiiNamespace) | ||
if err := deleteNamespace(oneHourTimeout, client, kibishiiNamespace, true); err != nil { | ||
return errors.Wrapf(err, "failed to delete namespace %s", kibishiiNamespace) | ||
} | ||
|
||
if err := veleroRestore(oneHourTimeout, veleroCLI, veleroNamespace, restoreName, backupName); err != nil { | ||
veleroRestoreLogs(oneHourTimeout, veleroCLI, veleroNamespace, restoreName) | ||
return errors.Wrapf(err, "Restore %s failed from backup %s", restoreName, backupName) | ||
} | ||
|
||
if err := kibishiiVerifyAfterRestore(client, kibishiiNamespace, oneHourTimeout); err != nil { | ||
return errors.Wrapf(err, "Error verifying kibishii after restore") | ||
} | ||
time.Sleep(time.Duration(1) * time.Hour) | ||
defer func() { | ||
if err := deleteNamespace(oneHourTimeout, client, kibishiiNamespace, true); err != nil { | ||
fmt.Println(errors.Wrapf(err, "failed to delete the namespace %q", kibishiiNamespace)) | ||
} | ||
}() | ||
|
||
fmt.Printf("kibishii test completed successfully\n") | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* | ||
Copyright the Velero contributors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
package e2e | ||
|
||
import ( | ||
"context" | ||
"flag" | ||
"time" | ||
|
||
"github.com/google/uuid" | ||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
// Test backup and restore of Kibishi using restic | ||
var _ = Describe("[Upgrade-Restic] Velero tests on cluster using the plugin provider for object storage and Restic for volume backups", backup_upgrade_restore_with_restic) | ||
|
||
var _ = Describe("[Upgrade-Snapshot] Velero tests on cluster using the plugin provider for object storage and snapshots for volume backups", backup_upgrade_restore_with_snapshots) | ||
|
||
func backup_upgrade_restore_with_snapshots() { | ||
backup_upgrade_restore_test(true) | ||
} | ||
|
||
func backup_upgrade_restore_with_restic() { | ||
backup_upgrade_restore_test(false) | ||
} | ||
|
||
func backup_upgrade_restore_test(useVolumeSnapshots bool) { | ||
var ( | ||
backupName, restoreName string | ||
veleroImageTemp string | ||
) | ||
veleroImageProfix := "velero/velero:" | ||
client, err := newTestClient() | ||
Expect(err).To(Succeed(), "Failed to instantiate cluster client for backup tests") | ||
|
||
BeforeEach(func() { | ||
if useVolumeSnapshots && cloudProvider == "kind" { | ||
Skip("Volume snapshots not supported on kind") | ||
} | ||
var err error | ||
flag.Parse() | ||
uuidgen, err = uuid.NewRandom() | ||
Expect(err).To(Succeed()) | ||
err = veleroUninstall(context.Background(), veleroCLI, veleroNamespace) | ||
Expect(err).To(Succeed()) | ||
|
||
veleroImageTemp = veleroImage | ||
veleroImage = veleroImageProfix + upgradeFromVersion | ||
cli, err := installVeleroCLI(upgradeFromVersion) | ||
Expect(err).To(Succeed()) | ||
Expect(veleroInstall(context.Background(), cli, veleroImage, veleroNamespace, cloudProvider, objectStoreProvider, useVolumeSnapshots, | ||
cloudCredentialsFile, bslBucket, bslPrefix, bslConfig, vslConfig, "", "", registryCredentialFile)).To(Succeed()) | ||
time.Sleep(10 * time.Second) | ||
Expect(checkVeleroVersion(context.Background(), cli, upgradeFromVersion)).To(Succeed()) | ||
|
||
}) | ||
|
||
AfterEach(func() { | ||
|
||
}) | ||
|
||
When("kibishii is the sample workload", func() { | ||
FIt("should be successfully backed up and restored to the default BackupStorageLocation", func() { | ||
backupName = "backup-" + uuidgen.String() | ||
restoreName = "restore-" + uuidgen.String() | ||
// Even though we are using Velero's CloudProvider plugin for object storage, the kubernetes cluster is running on | ||
// KinD. So use the kind installation for Kibishii. | ||
veleroImage = veleroImageTemp | ||
Expect(runUpgradeTests(client, veleroImage, cloudProvider, veleroCLI, veleroNamespace, backupName, restoreName, "", useVolumeSnapshots, registryCredentialFile)).To(Succeed(), | ||
"Failed to successfully backup and restore Kibishii namespace") | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/* | ||
Copyright the Velero contributors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package e2e | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
"time" | ||
|
||
"github.com/pkg/errors" | ||
"golang.org/x/net/context" | ||
) | ||
|
||
const ( | ||
upgradeNamespace = "upgrade-workload" | ||
) | ||
|
||
// runKibishiiTests runs kibishii tests on the provider. | ||
func runUpgradeTests(client testClient, toVeleroImage, providerName, veleroCLI, veleroNamespace, backupName, restoreName, backupLocation string, | ||
useVolumeSnapshots bool, registryCredentialFile string) error { | ||
oneHourTimeout, _ := context.WithTimeout(context.Background(), time.Minute*60) | ||
serviceAccountName := "default" | ||
if err := kibishiiPrepareBeforeBackup(client, providerName, oneHourTimeout, upgradeNamespace, serviceAccountName, registryCredentialFile); err != nil { | ||
return errors.Wrapf(err, "Failed to install and prepare data for kibishii %s", upgradeNamespace) | ||
} | ||
|
||
defer func() { | ||
if err := deleteNamespace(oneHourTimeout, client, upgradeNamespace, true); err != nil { | ||
fmt.Println(errors.Wrapf(err, "failed to delete the namespace %q", upgradeNamespace)) | ||
} | ||
}() | ||
|
||
if err := veleroBackupNamespace(oneHourTimeout, veleroCLI, veleroNamespace, backupName, upgradeNamespace, backupLocation, useVolumeSnapshots); err != nil { | ||
veleroBackupLogs(oneHourTimeout, veleroCLI, veleroNamespace, backupName) | ||
return errors.Wrapf(err, "Failed to backup kibishii namespace %s", upgradeNamespace) | ||
} | ||
|
||
if providerName == "vsphere" && useVolumeSnapshots { | ||
// Wait for uploads started by the Velero Plug-in for vSphere to complete | ||
// TODO - remove after upload progress monitoring is implemented | ||
fmt.Println("Waiting for vSphere uploads to complete") | ||
if err := waitForVSphereUploadCompletion(oneHourTimeout, time.Hour, upgradeNamespace); err != nil { | ||
return errors.Wrapf(err, "Error waiting for uploads to complete") | ||
} | ||
} | ||
fmt.Printf("Simulating a disaster by removing namespace %s\n", upgradeNamespace) | ||
if err := deleteNamespace(oneHourTimeout, client, upgradeNamespace, true); err != nil { | ||
return errors.Wrapf(err, "failed to delete namespace %s", upgradeNamespace) | ||
} | ||
var cli string | ||
var err error | ||
main_tag := "main" | ||
upgradeToVersion := veleroImage[strings.Index(toVeleroImage, ":")+1:] | ||
if upgradeToVersion == main_tag { | ||
cli = veleroCLI | ||
} else { | ||
cli, err = installVeleroCLI(upgradeToVersion) | ||
if err != nil { | ||
return errors.Wrapf(err, "Fail to install velero CLI.") | ||
} | ||
} | ||
if err := veleroInstall(context.Background(), cli, toVeleroImage, veleroNamespace, cloudProvider, objectStoreProvider, useVolumeSnapshots, | ||
cloudCredentialsFile, bslBucket, bslPrefix, bslConfig, vslConfig, crdsVersion, "", registryCredentialFile); err != nil { | ||
return errors.Wrapf(err, "Failed to install velero from image %s", toVeleroImage) | ||
} | ||
time.Sleep(10 * time.Second) | ||
if err := checkVeleroVersion(context.Background(), cli, upgradeToVersion); err != nil { | ||
return errors.Wrapf(err, "Velero install version mismatch.") | ||
} | ||
if err := veleroRestore(oneHourTimeout, cli, veleroNamespace, restoreName, backupName); err != nil { | ||
veleroRestoreLogs(oneHourTimeout, cli, veleroNamespace, restoreName) | ||
return errors.Wrapf(err, "Restore %s failed from backup %s", restoreName, backupName) | ||
} | ||
|
||
if err := kibishiiVerifyAfterRestore(client, upgradeNamespace, oneHourTimeout); err != nil { | ||
return errors.Wrapf(err, "Error verifying kibishii after restore") | ||
} | ||
|
||
fmt.Printf("kibishii test completed successfully\n") | ||
return nil | ||
} |
Oops, something went wrong.