Skip to content

Commit

Permalink
Merge pull request vmware-tanzu#5425 from danfengliu/fix-ctx-issue
Browse files Browse the repository at this point in the history
Fix E2E test and Git action CI issues
  • Loading branch information
blackpiglet authored Oct 17, 2022
2 parents c0430b8 + cf32cab commit 7a535ea
Show file tree
Hide file tree
Showing 18 changed files with 164 additions and 106 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/e2e-test-kind.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,17 @@ jobs:
aws_access_key_id=minio
aws_secret_access_key=minio123
EOF
# Match kubectl version to k8s server version
curl -LO https://dl.k8s.io/release/v${{ matrix.k8s }}/bin/linux/amd64/kubectl
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
GOPATH=~/go CLOUD_PROVIDER=kind \
OBJECT_STORE_PROVIDER=aws BSL_CONFIG=region=minio,s3ForcePathStyle="true",s3Url=http://$(hostname -i):9000 \
CREDS_FILE=/tmp/credential BSL_BUCKET=bucket \
ADDITIONAL_OBJECT_STORE_PROVIDER=aws ADDITIONAL_BSL_CONFIG=region=minio,s3ForcePathStyle="true",s3Url=http://$(hostname -i):9000 \
ADDITIONAL_CREDS_FILE=/tmp/credential ADDITIONAL_BSL_BUCKET=additional-bucket \
GINKGO_FOCUS='Basic\].+\[ClusterResource' VELERO_IMAGE=velero:pr-test \
GINKGO_FOCUS='Basic\]\[ClusterResource' VELERO_IMAGE=velero:pr-test \
make -C test/e2e run
timeout-minutes: 30
- name: Upload debug bundle
Expand Down
48 changes: 25 additions & 23 deletions pkg/cmd/cli/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,29 +43,31 @@ import (

// InstallOptions collects all the options for installing Velero into a Kubernetes cluster.
type InstallOptions struct {
Namespace string
Image string
BucketName string
Prefix string
ProviderName string
PodAnnotations flag.Map
PodLabels flag.Map
ServiceAccountAnnotations flag.Map
VeleroPodCPURequest string
VeleroPodMemRequest string
VeleroPodCPULimit string
VeleroPodMemLimit string
NodeAgentPodCPURequest string
NodeAgentPodMemRequest string
NodeAgentPodCPULimit string
NodeAgentPodMemLimit string
RestoreOnly bool
SecretFile string
NoSecret bool
DryRun bool
BackupStorageConfig flag.Map
VolumeSnapshotConfig flag.Map
UseNodeAgent bool
Namespace string
Image string
BucketName string
Prefix string
ProviderName string
PodAnnotations flag.Map
PodLabels flag.Map
ServiceAccountAnnotations flag.Map
VeleroPodCPURequest string
VeleroPodMemRequest string
VeleroPodCPULimit string
VeleroPodMemLimit string
NodeAgentPodCPURequest string
NodeAgentPodMemRequest string
NodeAgentPodCPULimit string
NodeAgentPodMemLimit string
RestoreOnly bool
SecretFile string
NoSecret bool
DryRun bool
BackupStorageConfig flag.Map
VolumeSnapshotConfig flag.Map
UseNodeAgent bool
//TODO remove UseRestic when migration test out of using it
UseRestic bool
Wait bool
UseVolumeSnapshots bool
DefaultRepoMaintenanceFrequency time.Duration
Expand Down
3 changes: 2 additions & 1 deletion test/e2e/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ OUTPUT_DIR := _output/$(GOOS)/$(GOARCH)/bin
GINKGO_FOCUS ?=
GINKGO_SKIP ?=
SKIP_STR := $(foreach var, $(subst ., ,$(GINKGO_SKIP)),-skip "$(var)")
FOCUS_STR := $(foreach var, $(subst ., ,$(GINKGO_FOCUS)),-focus "$(var)")
VELERO_CLI ?=$$(pwd)/../../_output/bin/$(GOOS)/$(GOARCH)/velero
VELERO_IMAGE ?= velero/velero:main
VELERO_VERSION ?= $(VERSION)
Expand Down Expand Up @@ -110,7 +111,7 @@ run: ginkgo
(echo "Bucket to store the backups from E2E tests is required, please re-run with BSL_BUCKET=<BucketName>"; exit 1 )
@[ "${CLOUD_PROVIDER}" ] && echo "Using cloud provider ${CLOUD_PROVIDER}" || \
(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)" $(SKIP_STR) . -- -velerocli=$(VELERO_CLI) \
@$(GINKGO) -v $(FOCUS_STR) $(SKIP_STR) . -- -velerocli=$(VELERO_CLI) \
-velero-image=$(VELERO_IMAGE) \
-plugins=$(PLUGINS) \
-velero-version=$(VELERO_VERSION) \
Expand Down
8 changes: 5 additions & 3 deletions test/e2e/backups/schedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type ScheduleBackup struct {
verifyTimes int
}

var ScheduleBackupTest func() = TestFunc(&ScheduleBackup{TestCase: TestCase{NSBaseName: "ns", NSIncluded: &[]string{"ns1"}}})
var ScheduleBackupTest func() = TestFunc(&ScheduleBackup{TestCase: TestCase{NSBaseName: "schedule-test-ns", NSIncluded: &[]string{"ns1"}}})

func (n *ScheduleBackup) Init() error {
n.Client = TestClientInstance
Expand All @@ -45,7 +45,6 @@ func (n *ScheduleBackup) StartRun() error {
n.RestoreName = n.RestoreName + "restore-ns-mapping-" + UUIDgen.String()

n.ScheduleArgs = []string{
"schedule", "create", "--namespace", VeleroCfg.VeleroNamespace, n.ScheduleName,
"--include-namespaces", strings.Join(*n.NSIncluded, ","),
"--schedule=*/" + fmt.Sprintf("%v", n.Period) + " * * * *",
}
Expand Down Expand Up @@ -78,7 +77,10 @@ func (n *ScheduleBackup) Backup() error {
now := time.Now().Minute()
triggerNow := now % n.Period
if triggerNow == 0 {
Expect(VeleroCmdExec(n.Ctx, VeleroCfg.VeleroCLI, n.ScheduleArgs)).To(Succeed())
Expect(VeleroScheduleCreate(n.Ctx, VeleroCfg.VeleroCLI, VeleroCfg.VeleroNamespace, n.ScheduleName, n.ScheduleArgs)).To(Succeed(), func() string {
RunDebug(context.Background(), VeleroCfg.VeleroCLI, VeleroCfg.VeleroNamespace, "", "")
return "Fail to restore workload"
})
break
}
}
Expand Down
32 changes: 22 additions & 10 deletions test/e2e/basic/namespace-mapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,24 @@ type NamespaceMapping struct {
kibishiiData *KibishiiData
}

var OneNamespaceMappingTest func() = TestFunc(&NamespaceMapping{TestCase: TestCase{NSBaseName: "ns", NSIncluded: &[]string{"ns1"}}})
var MultiNamespacesMappingTest func() = TestFunc(&NamespaceMapping{TestCase: TestCase{NSBaseName: "ns", NSIncluded: &[]string{"ns1", "ns2"}}})
const NamespaceBaseName string = "ns-mp-"

var OneNamespaceMappingResticTest func() = TestFunc(&NamespaceMapping{TestCase: TestCase{NSBaseName: NamespaceBaseName, NSIncluded: &[]string{NamespaceBaseName + "1"}, UseVolumeSnapshots: false}})
var MultiNamespacesMappingResticTest func() = TestFunc(&NamespaceMapping{TestCase: TestCase{NSBaseName: NamespaceBaseName, NSIncluded: &[]string{NamespaceBaseName + "1", NamespaceBaseName + "2"}, UseVolumeSnapshots: false}})
var OneNamespaceMappingSnapshotTest func() = TestFunc(&NamespaceMapping{TestCase: TestCase{NSBaseName: NamespaceBaseName, NSIncluded: &[]string{NamespaceBaseName + "1"}, UseVolumeSnapshots: true}})
var MultiNamespacesMappingSnapshotTest func() = TestFunc(&NamespaceMapping{TestCase: TestCase{NSBaseName: NamespaceBaseName, NSIncluded: &[]string{NamespaceBaseName + "1", NamespaceBaseName + "2"}, UseVolumeSnapshots: true}})

func (n *NamespaceMapping) Init() error {
n.Client = TestClientInstance
n.kibishiiData = &KibishiiData{2, 10, 10, 1024, 1024, 0, 2}

backupType := "restic"
if n.UseVolumeSnapshots {
backupType = "snapshot"
}
n.TestMsg = &TestMSG{
Desc: "Backup resources with include namespace test",
FailedMSG: "Failed to backup with namespace include",
Text: fmt.Sprintf("should backup namespaces %s", *n.NSIncluded),
Desc: fmt.Sprintf("Restore namespace %s with namespace mapping by %s test", *n.NSIncluded, backupType),
FailedMSG: "Failed to restore with namespace mapping",
Text: fmt.Sprintf("should restore namespace %s with namespace mapping by %s", *n.NSIncluded, backupType),
}
return nil
}
Expand All @@ -49,15 +56,20 @@ func (n *NamespaceMapping) StartRun() error {
n.BackupName = n.BackupName + ns
n.RestoreName = n.RestoreName + ns
}
n.BackupName = n.BackupName + "backup-ns-mapping-" + UUIDgen.String()
n.RestoreName = n.RestoreName + "restore-ns-mapping-" + UUIDgen.String()
n.BackupName = n.BackupName + UUIDgen.String()
n.RestoreName = n.RestoreName + UUIDgen.String()

n.MappedNamespaceList = mappedNSList
fmt.Println(mappedNSList)
n.BackupArgs = []string{
"create", "--namespace", VeleroCfg.VeleroNamespace, "backup", n.BackupName,
"--include-namespaces", strings.Join(*n.NSIncluded, ","),
"--default-volumes-to-fs-backup", "--wait",
"--include-namespaces", strings.Join(*n.NSIncluded, ","), "--wait",
}
if n.UseVolumeSnapshots {
n.BackupArgs = append(n.BackupArgs, "--snapshot-volumes")
} else {
n.BackupArgs = append(n.BackupArgs, "--snapshot-volumes=false")
n.BackupArgs = append(n.BackupArgs, "--default-volumes-to-fs-backup")
}
n.RestoreArgs = []string{
"create", "--namespace", VeleroCfg.VeleroNamespace, "restore", n.RestoreName,
Expand Down
1 change: 1 addition & 0 deletions test/e2e/basic/resources-check/namespaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ func (m *MultiNSBackup) Verify() error {
}

func (m *MultiNSBackup) Destroy() error {
m.Ctx, _ = context.WithTimeout(context.Background(), 60*time.Minute)
err := CleanupNamespaces(m.Ctx, m.Client, m.NSBaseName)
if err != nil {
return errors.Wrap(err, "Could cleanup retrieve namespaces")
Expand Down
7 changes: 5 additions & 2 deletions test/e2e/e2e_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
. "github.com/vmware-tanzu/velero/test/e2e/privilegesmgmt"
. "github.com/vmware-tanzu/velero/test/e2e/pv-backup"
. "github.com/vmware-tanzu/velero/test/e2e/resource-filtering"

. "github.com/vmware-tanzu/velero/test/e2e/scale"
. "github.com/vmware-tanzu/velero/test/e2e/upgrade"

Expand Down Expand Up @@ -126,8 +127,10 @@ var _ = Describe("[Migration][Snapshot]", MigrationWithSnapshots)

var _ = Describe("[Schedule][OrederedResources] Backup resources should follow the specific order in schedule", ScheduleOrderedResources)

var _ = Describe("[NamespaceMapping][Single] Backup resources should follow the specific order in schedule", OneNamespaceMappingTest)
var _ = Describe("[NamespaceMapping][Multiple] Backup resources should follow the specific order in schedule", MultiNamespacesMappingTest)
var _ = Describe("[NamespaceMapping][Single][Restic] Backup resources should follow the specific order in schedule", OneNamespaceMappingResticTest)
var _ = Describe("[NamespaceMapping][Multiple][Restic] Backup resources should follow the specific order in schedule", MultiNamespacesMappingResticTest)
var _ = Describe("[NamespaceMapping][Single][Snapshot] Backup resources should follow the specific order in schedule", OneNamespaceMappingSnapshotTest)
var _ = Describe("[NamespaceMapping][Multiple][Snapshot] Backup resources should follow the specific order in schedule", MultiNamespacesMappingSnapshotTest)

var _ = Describe("[pv-backup][Opt-In] Backup resources should follow the specific order in schedule", OptInPVBackupTest)
var _ = Describe("[pv-backup][Opt-Out] Backup resources should follow the specific order in schedule", OptOutPVBackupTest)
Expand Down
12 changes: 8 additions & 4 deletions test/e2e/migration/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ func MigrationTest(useVolumeSnapshots bool, veleroCLI2Version VeleroCLI2Version)
OriginVeleroCfg.Plugins = ""
//TODO: Remove this once origin Velero version is 1.10 and upper
OriginVeleroCfg.UploaderType = ""
OriginVeleroCfg.UseNodeAgent = false
OriginVeleroCfg.UseRestic = !useVolumeSnapshots
}
fmt.Println(OriginVeleroCfg)
Expect(VeleroInstall(context.Background(), &OriginVeleroCfg, useVolumeSnapshots)).To(Succeed())
Expand Down Expand Up @@ -157,9 +159,9 @@ func MigrationTest(useVolumeSnapshots bool, veleroCLI2Version VeleroCLI2Version)
BackupStorageClassCfg.IncludeResources = "StorageClass"
BackupStorageClassCfg.IncludeClusterResources = true
//TODO Remove UseRestic parameter once minor version is 1.10 or upper
BackupStorageClassCfg.UseRestic = true
BackupStorageClassCfg.UseResticIfFSBackup = true
if veleroCLI2Version.VeleroVersion == "self" {
BackupStorageClassCfg.UseRestic = false
BackupStorageClassCfg.UseResticIfFSBackup = false
}

Expect(VeleroBackupNamespace(context.Background(), OriginVeleroCfg.VeleroCLI,
Expand All @@ -175,9 +177,9 @@ func MigrationTest(useVolumeSnapshots bool, veleroCLI2Version VeleroCLI2Version)
BackupCfg.BackupLocation = ""
BackupCfg.Selector = ""
//TODO Remove UseRestic parameter once minor version is 1.10 or upper
BackupCfg.UseRestic = true
BackupCfg.UseResticIfFSBackup = true
if veleroCLI2Version.VeleroVersion == "self" {
BackupCfg.UseRestic = false
BackupCfg.UseResticIfFSBackup = false
}
Expect(VeleroBackupNamespace(context.Background(), OriginVeleroCfg.VeleroCLI,
OriginVeleroCfg.VeleroNamespace, BackupCfg)).To(Succeed(), func() string {
Expand Down Expand Up @@ -235,6 +237,8 @@ func MigrationTest(useVolumeSnapshots bool, veleroCLI2Version VeleroCLI2Version)

VeleroCfg.ObjectStoreProvider = ""
VeleroCfg.ClientToInstallVelero = VeleroCfg.StandbyClient
VeleroCfg.UseNodeAgent = !useVolumeSnapshots
VeleroCfg.UseRestic = false
Expect(VeleroInstall(context.Background(), &VeleroCfg, useVolumeSnapshots)).To(Succeed())
})

Expand Down
18 changes: 8 additions & 10 deletions test/e2e/privilegesmgmt/ssr.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,14 @@ func SSRTest() {
Expect(CreateNamespace(ctx, *VeleroCfg.ClientToInstallVelero, testNS)).To(Succeed(),
fmt.Sprintf("Failed to create %s namespace", testNS))

By(fmt.Sprintf("Get version in %s namespace", testNS))
cmd := []string{"version", "-n", testNS}
Expect(VeleroCmdExec(context.Background(), VeleroCfg.VeleroCLI, cmd)).To(Succeed(),
fmt.Sprintf("Failed to create an ssr object in the %s namespace", testNS))

By(fmt.Sprintf("Get version in %s namespace", VeleroCfg.VeleroNamespace))
cmd = []string{"version", "-n", VeleroCfg.VeleroNamespace}
Expect(VeleroCmdExec(context.Background(), VeleroCfg.VeleroCLI, cmd)).To(Succeed(),
fmt.Sprintf("Failed to create an ssr object in %s namespace", VeleroCfg.VeleroNamespace))

By(fmt.Sprintf("Get version in %s namespace", testNS), func() {
Expect(VeleroVersion(context.Background(), VeleroCfg.VeleroCLI, testNS)).To(Succeed(),
fmt.Sprintf("Failed to create an ssr object in the %s namespace", testNS))
})
By(fmt.Sprintf("Get version in %s namespace", VeleroCfg.VeleroNamespace), func() {
Expect(VeleroVersion(context.Background(), VeleroCfg.VeleroCLI, VeleroCfg.VeleroNamespace)).To(Succeed(),
fmt.Sprintf("Failed to create an ssr object in %s namespace", VeleroCfg.VeleroNamespace))
})
ssrListResp := new(v1.ServerStatusRequestList)
By(fmt.Sprintf("Check ssr object in %s namespace", VeleroCfg.VeleroNamespace))
err = waitutil.PollImmediate(5*time.Second, time.Minute,
Expand Down
6 changes: 3 additions & 3 deletions test/e2e/pv-backup/pv-backup-filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ func (p *PVBackupFiltering) StartRun() error {
if err != nil {
return err
}
p.BackupName = p.BackupName + "backup-opt-in-" + UUIDgen.String()
p.RestoreName = p.RestoreName + "restore-opt-in-" + UUIDgen.String()
p.BackupName = p.BackupName + "backup-" + p.id + "-" + UUIDgen.String()
p.RestoreName = p.RestoreName + "restore-" + p.id + "-" + UUIDgen.String()
p.BackupArgs = []string{
"create", "--namespace", VeleroCfg.VeleroNamespace, "backup", p.BackupName,
"--include-namespaces", strings.Join(*p.NSIncluded, ","),
Expand Down Expand Up @@ -84,7 +84,7 @@ func (p *PVBackupFiltering) CreateResources() error {
for j := 0; j <= VOLUME_COUNT_PER_POD-1; j++ {
volume := fmt.Sprintf("volume-%s-%d-%d", p.id, i, j)
volumes = append(volumes, volume)
//Volumes cherry pick policy for opt-in/out annotation to pods
//Volumes cherry-pick policy for opt-in/out annotation to apply
if j%2 == 0 {
volumeToAnnotationList = append(volumeToAnnotationList, volume)
}
Expand Down
Loading

0 comments on commit 7a535ea

Please sign in to comment.