diff --git a/test/e2e/backup/backup.go b/test/e2e/backup/backup.go index 2f252171b1..2ac8458513 100644 --- a/test/e2e/backup/backup.go +++ b/test/e2e/backup/backup.go @@ -120,7 +120,7 @@ func BackupRestoreTest(backupRestoreTestConfig BackupRestoreTestConfig) { It("should be successfully backed up and restored to the default BackupStorageLocation", func() { if InstallVelero { if useVolumeSnapshots { - //Install node agent also + // Install node agent also veleroCfg.UseNodeAgent = useVolumeSnapshots // DefaultVolumesToFsBackup should be mutually exclusive with useVolumeSnapshots in installation CLI, // otherwise DefaultVolumesToFsBackup need to be set to false in backup CLI when taking volume snapshot @@ -162,7 +162,7 @@ func BackupRestoreTest(backupRestoreTestConfig BackupRestoreTestConfig) { if InstallVelero { if useVolumeSnapshots { veleroCfg.DefaultVolumesToFsBackup = !useVolumeSnapshots - } else { //FS volume backup + } else { // FS volume backup // Install VolumeSnapshots also veleroCfg.UseVolumeSnapshots = !useVolumeSnapshots // DefaultVolumesToFsBackup is false in installation CLI here, diff --git a/test/e2e/backups/deletion.go b/test/e2e/backups/deletion.go index e4bf69702d..fd4b1c67ed 100644 --- a/test/e2e/backups/deletion.go +++ b/test/e2e/backups/deletion.go @@ -43,6 +43,7 @@ func BackupDeletionWithSnapshots() { func BackupDeletionWithRestic() { backup_deletion_test(false) } + func backup_deletion_test(useVolumeSnapshots bool) { veleroCfg := VeleroCfg veleroCfg.UseVolumeSnapshots = useVolumeSnapshots @@ -81,7 +82,8 @@ func backup_deletion_test(useVolumeSnapshots bool) { // runUpgradeTests runs upgrade test on the provider by kibishii. func runBackupDeletionTests(client TestClient, veleroCfg VeleroConfig, backupLocation string, - useVolumeSnapshots bool, kibishiiDirectory string) error { + useVolumeSnapshots bool, kibishiiDirectory string, +) error { var err error var snapshotCheckPoint SnapshotCheckPoint backupName := "backup-" + UUIDgen.String() diff --git a/test/e2e/backups/sync_backups.go b/test/e2e/backups/sync_backups.go index 447fc735b9..5ba90aded5 100644 --- a/test/e2e/backups/sync_backups.go +++ b/test/e2e/backups/sync_backups.go @@ -50,9 +50,7 @@ func (b *SyncBackups) Init() { func BackupsSyncTest() { test := new(SyncBackups) - var ( - err error - ) + var err error veleroCfg := VeleroCfg BeforeEach(func() { flag.Parse() diff --git a/test/e2e/basic/api-group/enable_api_group_extentions.go b/test/e2e/basic/api-group/enable_api_group_extentions.go index 546d2f7212..8378d58133 100644 --- a/test/e2e/basic/api-group/enable_api_group_extentions.go +++ b/test/e2e/basic/api-group/enable_api_group_extentions.go @@ -30,9 +30,7 @@ import ( ) func APIExtensionsVersionsTest() { - var ( - backupName, restoreName string - ) + var backupName, restoreName string resourceName := "apiextensions.k8s.io" crdName := "rocknrollbands.music.example.io" diff --git a/test/e2e/basic/backup-volume-info/base.go b/test/e2e/basic/backup-volume-info/base.go index 15e92699e6..098dba3426 100644 --- a/test/e2e/basic/backup-volume-info/base.go +++ b/test/e2e/basic/backup-volume-info/base.go @@ -96,6 +96,7 @@ func (v *BackupVolumeInfo) Start() error { v.TestCase.Start() return nil } + func (v *BackupVolumeInfo) CreateResources() error { labels := map[string]string{ "volume-info": "true", diff --git a/test/e2e/basic/namespace-mapping.go b/test/e2e/basic/namespace-mapping.go index a2ebc24c8b..fd5975c320 100644 --- a/test/e2e/basic/namespace-mapping.go +++ b/test/e2e/basic/namespace-mapping.go @@ -21,10 +21,12 @@ type NamespaceMapping struct { const NamespaceBaseName string = "ns-mp-" -var OneNamespaceMappingResticTest func() = TestFunc(&NamespaceMapping{TestCase: TestCase{NamespacesTotal: 1, UseVolumeSnapshots: false}}) -var MultiNamespacesMappingResticTest func() = TestFunc(&NamespaceMapping{TestCase: TestCase{NamespacesTotal: 2, UseVolumeSnapshots: false}}) -var OneNamespaceMappingSnapshotTest func() = TestFunc(&NamespaceMapping{TestCase: TestCase{NamespacesTotal: 1, UseVolumeSnapshots: true}}) -var MultiNamespacesMappingSnapshotTest func() = TestFunc(&NamespaceMapping{TestCase: TestCase{NamespacesTotal: 2, UseVolumeSnapshots: true}}) +var ( + OneNamespaceMappingResticTest func() = TestFunc(&NamespaceMapping{TestCase: TestCase{NamespacesTotal: 1, UseVolumeSnapshots: false}}) + MultiNamespacesMappingResticTest func() = TestFunc(&NamespaceMapping{TestCase: TestCase{NamespacesTotal: 2, UseVolumeSnapshots: false}}) + OneNamespaceMappingSnapshotTest func() = TestFunc(&NamespaceMapping{TestCase: TestCase{NamespacesTotal: 1, UseVolumeSnapshots: true}}) + MultiNamespacesMappingSnapshotTest func() = TestFunc(&NamespaceMapping{TestCase: TestCase{NamespacesTotal: 2, UseVolumeSnapshots: true}}) +) func (n *NamespaceMapping) Init() error { n.TestCase.Init() diff --git a/test/e2e/basic/nodeport.go b/test/e2e/basic/nodeport.go index 7cee801a08..f28fcb9cd2 100644 --- a/test/e2e/basic/nodeport.go +++ b/test/e2e/basic/nodeport.go @@ -166,7 +166,8 @@ func (n *NodePort) Restore() error { } func createServiceWithNodeport(ctx context.Context, client TestClient, namespace string, - service string, labels map[string]string, nodePort int32) error { + service string, labels map[string]string, nodePort int32, +) error { serviceSpec := &v1.ServiceSpec{ Ports: []v1.ServicePort{ { diff --git a/test/e2e/basic/pvc-selected-node-changing.go b/test/e2e/basic/pvc-selected-node-changing.go index e200929c11..85383bca8c 100644 --- a/test/e2e/basic/pvc-selected-node-changing.go +++ b/test/e2e/basic/pvc-selected-node-changing.go @@ -43,8 +43,10 @@ func (p *PVCSelectedNodeChanging) Init() error { } p.BackupName = "backup-" + p.CaseBaseName p.RestoreName = "restore-" + p.CaseBaseName - p.labels = map[string]string{"velero.io/plugin-config": "", - "velero.io/change-pvc-node-selector": "RestoreItemAction"} + p.labels = map[string]string{ + "velero.io/plugin-config": "", + "velero.io/change-pvc-node-selector": "RestoreItemAction", + } p.configmaptName = "change-pvc-node-selector-config" p.volume = "volume-1" p.podName = "pod-1" @@ -128,6 +130,7 @@ func (p *PVCSelectedNodeChanging) Restore() error { }) return nil } + func (p *PVCSelectedNodeChanging) Verify() error { By(fmt.Sprintf("PVC selected node should be %s", p.newNodeName), func() { pvcNameList, err := GetPvcByPVCName(p.Ctx, p.mappedNS, p.pvcName) diff --git a/test/e2e/basic/resources-check/namespaces_annotation.go b/test/e2e/basic/resources-check/namespaces_annotation.go index e698d48185..55ae45aeec 100644 --- a/test/e2e/basic/resources-check/namespaces_annotation.go +++ b/test/e2e/basic/resources-check/namespaces_annotation.go @@ -76,7 +76,6 @@ func (n *NSAnnotationCase) Verify() error { checkNSName := fmt.Sprintf("%s-%00000d", n.CaseBaseName, nsNum) checkAnnoName := fmt.Sprintf("annotation-%s-%00000d", n.CaseBaseName, nsNum) checkNS, err := GetNamespace(n.Ctx, n.Client, checkNSName) - if err != nil { return errors.Wrapf(err, "Could not retrieve test namespace %s", checkNSName) } diff --git a/test/e2e/basic/resources-check/rbac.go b/test/e2e/basic/resources-check/rbac.go index b79c3615f4..8820a800a6 100644 --- a/test/e2e/basic/resources-check/rbac.go +++ b/test/e2e/basic/resources-check/rbac.go @@ -112,9 +112,8 @@ func (r *RBACCase) Verify() error { return errors.Errorf("Retrieved namespace for %s has name %s instead", checkNSName, checkNS.Name) } - //getting service account from the restore + // getting service account from the restore checkSA, err := GetServiceAccount(r.Ctx, r.Client, checkNSName, checkServiceAccountName) - if err != nil { return errors.Wrapf(err, "Could not retrieve test service account %s", checkSA) } @@ -123,9 +122,8 @@ func (r *RBACCase) Verify() error { return errors.Errorf("Retrieved service account for %s has name %s instead", checkServiceAccountName, checkSA.Name) } - //getting cluster role from the restore + // getting cluster role from the restore checkClusterRole, err := GetClusterRole(r.Ctx, r.Client, checkClusterRoleName) - if err != nil { return errors.Wrapf(err, "Could not retrieve test cluster role %s", checkClusterRole) } @@ -134,9 +132,8 @@ func (r *RBACCase) Verify() error { return errors.Errorf("Retrieved cluster role for %s has name %s instead", checkClusterRoleName, checkClusterRole.Name) } - //getting cluster role binding from the restore + // getting cluster role binding from the restore checkClusterRoleBinding, err := GetClusterRoleBinding(r.Ctx, r.Client, checkClusterRoleBindingName) - if err != nil { return errors.Wrapf(err, "Could not retrieve test cluster role binding %s", checkClusterRoleBinding) } @@ -145,7 +142,7 @@ func (r *RBACCase) Verify() error { return errors.Errorf("Retrieved cluster role binding for %s has name %s instead", checkClusterRoleBindingName, checkClusterRoleBinding.Name) } - //check if the role binding maps to service account + // check if the role binding maps to service account checkSubjects := checkClusterRoleBinding.Subjects[0].Name if checkSubjects != checkServiceAccountName { @@ -156,13 +153,13 @@ func (r *RBACCase) Verify() error { } func (r *RBACCase) Destroy() error { - //cleanup clusterrole + // cleanup clusterrole err := CleanupClusterRole(r.Ctx, r.Client, r.CaseBaseName) if err != nil { return errors.Wrap(err, "Could not cleanup clusterroles") } - //cleanup cluster rolebinding + // cleanup cluster rolebinding err = CleanupClusterRoleBinding(r.Ctx, r.Client, r.CaseBaseName) if err != nil { return errors.Wrap(err, "Could not cleanup clusterrolebindings") diff --git a/test/e2e/basic/storage-class-changing.go b/test/e2e/basic/storage-class-changing.go index e2e5a02967..0ff8520ae8 100644 --- a/test/e2e/basic/storage-class-changing.go +++ b/test/e2e/basic/storage-class-changing.go @@ -48,8 +48,10 @@ func (s *StorageClasssChanging) Init() error { } s.srcStorageClass = StorageClassName s.desStorageClass = StorageClassName2 - s.labels = map[string]string{"velero.io/change-storage-class": "RestoreItemAction", - "velero.io/plugin-config": ""} + s.labels = map[string]string{ + "velero.io/change-storage-class": "RestoreItemAction", + "velero.io/plugin-config": "", + } s.data = map[string]string{s.srcStorageClass: s.desStorageClass} s.cmName = "change-storage-class-config" s.volume = "volume-1" @@ -124,6 +126,7 @@ func (s *StorageClasssChanging) Restore() error { }) return nil } + func (s *StorageClasssChanging) Verify() error { By(fmt.Sprintf("Expect storage class of PV %s to be %s ", s.volume, s.desStorageClass), func() { Expect(WaitForReadyDeployment(s.Client.ClientGo, s.mappedNS, s.deploymentName)).To(Succeed()) diff --git a/test/e2e/bsl-mgmt/deletion.go b/test/e2e/bsl-mgmt/deletion.go index 51584d85ba..c41fd3d0d3 100644 --- a/test/e2e/bsl-mgmt/deletion.go +++ b/test/e2e/bsl-mgmt/deletion.go @@ -50,6 +50,7 @@ func BslDeletionWithSnapshots() { func BslDeletionWithRestic() { BslDeletionTest(false) } + func BslDeletionTest(useVolumeSnapshots bool) { var ( err error @@ -143,7 +144,7 @@ func BslDeletionTest(useVolumeSnapshots bool) { label1 := "for=1" // TODO remove when issue https://github.com/vmware-tanzu/velero/issues/4724 is fixed - //label2 := "for!=1" + // label2 := "for!=1" label2 := "for=2" By("Create namespace for sample workload", func() { Expect(CreateNamespace(oneHourTimeout, *veleroCfg.ClientToInstallVelero, bslDeletionTestNs)).To(Succeed()) diff --git a/test/e2e/e2e_suite_test.go b/test/e2e/e2e_suite_test.go index 68de2ecc46..fb771dc48c 100644 --- a/test/e2e/e2e_suite_test.go +++ b/test/e2e/e2e_suite_test.go @@ -357,6 +357,7 @@ var _ = Describe( Label("APIGroup", "APIVersion", "SKIP_KIND", "LongTime"), APIGroupVersionsTest, ) + var _ = Describe( "CRD of apiextentions v1beta1 should be B/R successfully from cluster(k8s version < 1.22) to cluster(k8s version >= 1.22)", Label("APIGroup", "APIExtensions", "SKIP_KIND"), @@ -424,6 +425,7 @@ var _ = Describe( Label("Upgrade", "Restic"), BackupUpgradeRestoreWithRestic, ) + var _ = Describe( "Velero upgrade tests on cluster using the plugin provider for object storage and snapshots for volume backups", Label("Upgrade", "Snapshot", "SkipVanillaZfs"), @@ -436,51 +438,61 @@ var _ = Describe( Label("ResourceFiltering", "ExcludeFromBackup"), ExcludeFromBackupTest, ) + var _ = Describe( "Velero test on exclude namespace from the cluster backup", Label("ResourceFiltering", "ExcludeNamespaces", "Backup"), BackupWithExcludeNamespaces, ) + var _ = Describe( "Velero test on exclude namespace from the cluster restore", Label("ResourceFiltering", "ExcludeNamespaces", "Restore"), RestoreWithExcludeNamespaces, ) + var _ = Describe( "Velero test on exclude resources from the cluster backup", Label("ResourceFiltering", "ExcludeResources", "Backup"), BackupWithExcludeResources, ) + var _ = Describe( "Velero test on exclude resources from the cluster restore", Label("ResourceFiltering", "ExcludeResources", "Restore"), RestoreWithExcludeResources, ) + var _ = Describe( "Velero test on include namespace from the cluster backup", Label("ResourceFiltering", "IncludeNamespaces", "Backup"), BackupWithIncludeNamespaces, ) + var _ = Describe( "Velero test on include namespace from the cluster restore", Label("ResourceFiltering", "IncludeNamespaces", "Restore"), RestoreWithIncludeNamespaces, ) + var _ = Describe( "Velero test on include resources from the cluster backup", Label("ResourceFiltering", "IncludeResources", "Backup"), BackupWithIncludeResources, ) + var _ = Describe( "Velero test on include resources from the cluster restore", Label("ResourceFiltering", "IncludeResources", "Restore"), RestoreWithIncludeResources, ) + var _ = Describe( "Velero test on backup include resources matching the label selector", Label("ResourceFiltering", "LabelSelector"), BackupWithLabelSelector, ) + var _ = Describe( "Velero test on skip backup of volume by resource policies", Label("ResourceFiltering", "ResourcePolicies", "Restic"), @@ -493,21 +505,25 @@ var _ = Describe( Label("BackupVolumeInfo", "SkippedVolume"), SkippedVolumeInfoTest, ) + var _ = Describe( "", Label("BackupVolumeInfo", "FilesystemUpload"), FilesystemUploadVolumeInfoTest, ) + var _ = Describe( "", Label("BackupVolumeInfo", "CSIDataMover"), CSIDataMoverVolumeInfoTest, ) + var _ = Describe( "", Label("BackupVolumeInfo", "CSISnapshot"), CSISnapshotVolumeInfoTest, ) + var _ = Describe( "", Label("BackupVolumeInfo", "NativeSnapshot"), @@ -525,16 +541,19 @@ var _ = Describe( Label("Backups", "Deletion", "Restic"), BackupDeletionWithRestic, ) + var _ = Describe( "Velero tests of snapshot backup deletion", Label("Backups", "Deletion", "Snapshot", "SkipVanillaZfs"), BackupDeletionWithSnapshots, ) + var _ = Describe( "Local backups and Restic repos will be deleted once the corresponding backup storage location is deleted", Label("Backups", "TTL", "LongTime", "Snapshot", "SkipVanillaZfs"), TTLTest, ) + var _ = Describe( "Backups in object storage are synced to a new Velero and deleted backups in object storage are synced to be deleted in Velero", Label("Backups", "BackupsSync"), @@ -546,11 +565,13 @@ var _ = Describe( Label("Schedule", "Periodical", "Pause", "LongTime"), SchedulePeriodicalTest, ) + var _ = Describe( "Backup resources should follow the specific order in schedule", Label("Schedule", "OrderedResources"), ScheduleOrderedResources, ) + var _ = Describe( "Schedule controller wouldn't create a new backup when it still has pending or InProgress backup", Label("Schedule", "InProgress", "SKIP_KIND", "LongTime"), @@ -568,6 +589,7 @@ var _ = Describe( Label("BSL", "Deletion", "Snapshot", "SkipVanillaZfs"), BslDeletionWithSnapshots, ) + var _ = Describe( "Local backups and Restic repos will be deleted once the corresponding backup storage location is deleted", Label("BSL", "Deletion", "Restic"), @@ -579,6 +601,7 @@ var _ = Describe( Label("Migration", "FSB"), MigrationWithFS, ) + var _ = Describe( "Migrate resources between clusters by snapshot", Label("Migration", "Snapshot", "SkipVanillaZfs"), @@ -590,16 +613,19 @@ var _ = Describe( Label("NamespaceMapping", "Single", "Restic"), OneNamespaceMappingResticTest, ) + var _ = Describe( "Backup resources should follow the specific order in schedule", Label("NamespaceMapping", "Multiple", "Restic"), MultiNamespacesMappingResticTest, ) + var _ = Describe( "Backup resources should follow the specific order in schedule", Label("NamespaceMapping", "Single", "Snapshot", "SkipVanillaZfs"), OneNamespaceMappingSnapshotTest, ) + var _ = Describe( "Backup resources should follow the specific order in schedule", Label("NamespaceMapping", "Multiple", "Snapshot", "SkipVanillaZfs"), @@ -611,6 +637,7 @@ var _ = Describe( Label("PVBackup", "OptIn"), OptInPVBackupTest, ) + var _ = Describe( "Backup resources should follow the specific order in schedule", Label("PVBackup", "OptOut"), @@ -622,6 +649,7 @@ var _ = Describe( Label("UploaderConfig", "ParallelFilesUpload"), ParallelFilesUploadTest, ) + var _ = Describe( "Velero test on parallel files download", Label("UploaderConfig", "ParallelFilesDownload"), diff --git a/test/e2e/migration/migration.go b/test/e2e/migration/migration.go index 7eb57daaec..7755a4155a 100644 --- a/test/e2e/migration/migration.go +++ b/test/e2e/migration/migration.go @@ -120,8 +120,8 @@ func (m *migrationE2E) Backup() error { var err error if m.veleroCLI2Version.VeleroCLI == "" { - //Assume tag of velero server image is identical to velero CLI version - //Download velero CLI if it's empty according to velero CLI version + // Assume tag of velero server image is identical to velero CLI version + // Download velero CLI if it's empty according to velero CLI version By( fmt.Sprintf("Install the expected version Velero CLI %s", m.veleroCLI2Version.VeleroVersion), @@ -256,7 +256,7 @@ func (m *migrationE2E) Backup() error { snapshotCheckPoint.NamespaceBackedUp = m.CaseBaseName if OriginVeleroCfg.SnapshotMoveData { - //VolumeSnapshotContent should be deleted after data movement + // VolumeSnapshotContent should be deleted after data movement _, err := util.CheckVolumeSnapshotCR( *m.VeleroCfg.DefaultClient, map[string]string{"namespace": m.CaseBaseName}, @@ -358,8 +358,10 @@ func (m *migrationE2E) Restore() error { By(fmt.Sprintf("Restore %s", m.CaseBaseName), func() { if m.VeleroCfg.SnapshotMoveData { cmName := "datamover-storage-class-config" - labels := map[string]string{"velero.io/change-storage-class": "RestoreItemAction", - "velero.io/plugin-config": ""} + labels := map[string]string{ + "velero.io/change-storage-class": "RestoreItemAction", + "velero.io/plugin-config": "", + } data := map[string]string{kibishii.KibishiiStorageClassName: test.StorageClassName} By(fmt.Sprintf("Create ConfigMap %s in namespace %s", diff --git a/test/e2e/privilegesmgmt/ssr.go b/test/e2e/privilegesmgmt/ssr.go index 9b0e99a0f8..b96a098b6d 100644 --- a/test/e2e/privilegesmgmt/ssr.go +++ b/test/e2e/privilegesmgmt/ssr.go @@ -37,9 +37,7 @@ import ( func SSRTest() { testNS := "ssr-test" - var ( - err error - ) + var err error veleroCfg := VeleroCfg BeforeEach(func() { flag.Parse() diff --git a/test/e2e/pv-backup/pv-backup-filter.go b/test/e2e/pv-backup/pv-backup-filter.go index b58cb8a55b..98d339544b 100644 --- a/test/e2e/pv-backup/pv-backup-filter.go +++ b/test/e2e/pv-backup/pv-backup-filter.go @@ -23,12 +23,16 @@ type PVBackupFiltering struct { id string } -const POD_COUNT, VOLUME_COUNT_PER_POD = 2, 3 -const OPT_IN_ANN, OPT_OUT_ANN = "backup.velero.io/backup-volumes", "backup.velero.io/backup-volumes-excludes" -const FILE_NAME = "test-data.txt" +const ( + POD_COUNT, VOLUME_COUNT_PER_POD = 2, 3 + OPT_IN_ANN, OPT_OUT_ANN = "backup.velero.io/backup-volumes", "backup.velero.io/backup-volumes-excludes" + FILE_NAME = "test-data.txt" +) -var OptInPVBackupTest func() = TestFunc(&PVBackupFiltering{annotation: OPT_IN_ANN, id: "opt-in"}) -var OptOutPVBackupTest func() = TestFunc(&PVBackupFiltering{annotation: OPT_OUT_ANN, id: "opt-out"}) +var ( + OptInPVBackupTest func() = TestFunc(&PVBackupFiltering{annotation: OPT_IN_ANN, id: "opt-in"}) + OptOutPVBackupTest func() = TestFunc(&PVBackupFiltering{annotation: OPT_OUT_ANN, id: "opt-out"}) +) func (p *PVBackupFiltering) Init() error { p.TestCase.Init() @@ -70,14 +74,14 @@ func (p *PVBackupFiltering) CreateResources() error { var pods []string By(fmt.Sprintf("Deploy a few pods with several PVs in namespace %s", ns), func() { var volumesToAnnotation string - //Make sure PVC name is unique from other tests to avoid PVC creation error + // Make sure PVC name is unique from other tests to avoid PVC creation error for i := 0; i <= POD_COUNT-1; i++ { var volumeToAnnotationList []string var volumes []string 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 apply + // Volumes cherry-pick policy for opt-in/out annotation to apply if j%2 == 0 { volumeToAnnotationList = append(volumeToAnnotationList, volume) } @@ -182,6 +186,7 @@ func fileExist(ctx context.Context, namespace, podName, volume string) error { FILE_NAME, volume, podName, namespace)) } } + func fileNotExist(ctx context.Context, namespace, podName, volume string) error { _, _, err := ReadFileFromPodVolume(ctx, namespace, podName, podName, volume, FILE_NAME) if err != nil { diff --git a/test/e2e/resource-filtering/base.go b/test/e2e/resource-filtering/base.go index 8cfce438d5..bf30972675 100644 --- a/test/e2e/resource-filtering/base.go +++ b/test/e2e/resource-filtering/base.go @@ -35,8 +35,10 @@ type FilteringCase struct { labelSelector string } -var testInBackup = FilteringCase{IsTestInBackup: true} -var testInRestore = FilteringCase{IsTestInBackup: false} +var ( + testInBackup = FilteringCase{IsTestInBackup: true} + testInRestore = FilteringCase{IsTestInBackup: false} +) func (f *FilteringCase) Init() error { f.TestCase.Init() @@ -66,7 +68,7 @@ func (f *FilteringCase) CreateResources() error { if err := CreateNamespace(f.Ctx, f.Client, namespace); err != nil { return errors.Wrapf(err, "Failed to create namespace %s", namespace) } - //Create deployment + // Create deployment fmt.Printf("Creating deployment in namespaces ...%s\n", namespace) deployment := NewDeployment(f.CaseBaseName, namespace, f.replica, f.labels, nil).Result() deployment, err := CreateDeployment(f.Client.ClientGo, namespace, deployment) @@ -77,7 +79,7 @@ func (f *FilteringCase) CreateResources() error { if err != nil { return errors.Wrap(err, fmt.Sprintf("failed to ensure job completion in namespace: %q", namespace)) } - //Create Secret + // Create Secret secretName := f.CaseBaseName fmt.Printf("Creating secret %s in namespaces ...%s\n", secretName, namespace) _, err = CreateSecret(f.Client.ClientGo, namespace, secretName, f.labels) @@ -88,7 +90,7 @@ func (f *FilteringCase) CreateResources() error { if err != nil { return errors.Wrap(err, fmt.Sprintf("failed to ensure secret completion in namespace: %q", namespace)) } - //Create Configmap + // Create Configmap configmaptName := f.CaseBaseName fmt.Printf("Creating configmap %s in namespaces ...%s\n", configmaptName, namespace) _, err = CreateConfigMap(f.Client.ClientGo, namespace, configmaptName, f.labels, nil) @@ -107,7 +109,7 @@ func (f *FilteringCase) Verify() error { for nsNum := 0; nsNum < f.NamespacesTotal; nsNum++ { namespace := fmt.Sprintf("%s-%00000d", f.CaseBaseName, nsNum) fmt.Printf("Checking resources in namespaces ...%s\n", namespace) - //Check namespace + // Check namespace checkNS, err := GetNamespace(f.Ctx, f.Client, namespace) if err != nil { return errors.Wrapf(err, "Could not retrieve test namespace %s", namespace) @@ -115,24 +117,26 @@ func (f *FilteringCase) Verify() error { if checkNS.Name != namespace { return errors.Errorf("Retrieved namespace for %s has name %s instead", namespace, checkNS.Name) } - //Check deployment + // Check deployment _, err = GetDeployment(f.Client.ClientGo, namespace, f.CaseBaseName) if err != nil { return errors.Wrap(err, fmt.Sprintf("failed to list deployment in namespace: %q", namespace)) } - //Check secrets + // Check secrets secretsList, err := f.Client.ClientGo.CoreV1().Secrets(namespace).List(context.TODO(), metav1.ListOptions{ - LabelSelector: f.labelSelector}) + LabelSelector: f.labelSelector, + }) if err != nil { return errors.Wrap(err, fmt.Sprintf("failed to list secrets in namespace: %q", namespace)) } else if len(secretsList.Items) == 0 { return errors.Wrap(err, fmt.Sprintf("no secrets found in namespace: %q", namespace)) } - //Check configmap + // Check configmap configmapList, err := f.Client.ClientGo.CoreV1().ConfigMaps(namespace).List(context.TODO(), metav1.ListOptions{ - LabelSelector: f.labelSelector}) + LabelSelector: f.labelSelector, + }) if err != nil { return errors.Wrap(err, fmt.Sprintf("failed to list configmap in namespace: %q", namespace)) } else if len(configmapList.Items) == 0 { diff --git a/test/e2e/resource-filtering/exclude_label.go b/test/e2e/resource-filtering/exclude_label.go index b90d63dd87..c6cada9d30 100644 --- a/test/e2e/resource-filtering/exclude_label.go +++ b/test/e2e/resource-filtering/exclude_label.go @@ -86,7 +86,7 @@ func (e *ExcludeFromBackup) CreateResources() error { if err := CreateNamespace(e.Ctx, e.Client, namespace); err != nil { return errors.Wrapf(err, "Failed to create namespace %s", namespace) } - //Create deployment: to be included + // Create deployment: to be included fmt.Printf("Creating deployment in namespaces ...%s\n", namespace) deployment := NewDeployment(e.CaseBaseName, namespace, e.replica, label2, nil).Result() deployment, err := CreateDeployment(e.Client.ClientGo, namespace, deployment) @@ -97,7 +97,7 @@ func (e *ExcludeFromBackup) CreateResources() error { if err != nil { return errors.Wrap(err, fmt.Sprintf("failed to ensure job completion in namespace: %q", namespace)) } - //Create Secret + // Create Secret secretName := e.CaseBaseName fmt.Printf("Creating secret %s in namespaces ...%s\n", secretName, namespace) _, err = CreateSecret(e.Client.ClientGo, namespace, secretName, e.labels) @@ -112,7 +112,7 @@ func (e *ExcludeFromBackup) CreateResources() error { _, err = GetSecret(e.Client.ClientGo, namespace, e.CaseBaseName) Expect(err).ShouldNot(HaveOccurred(), fmt.Sprintf("failed to list deployment in namespace: %q", namespace)) }) - //Create Configmap: to be included + // Create Configmap: to be included configmaptName := e.CaseBaseName fmt.Printf("Creating configmap %s in namespaces ...%s\n", configmaptName, namespace) _, err = CreateConfigMap(e.Client.ClientGo, namespace, configmaptName, label1, nil) @@ -129,21 +129,21 @@ func (e *ExcludeFromBackup) CreateResources() error { func (e *ExcludeFromBackup) Verify() error { namespace := e.CaseBaseName By(fmt.Sprintf("Checking resources in namespaces ...%s\n", namespace), func() { - //Check namespace + // Check namespace checkNS, err := GetNamespace(e.Ctx, e.Client, namespace) Expect(err).ShouldNot(HaveOccurred(), fmt.Sprintf("Could not retrieve test namespace %s", namespace)) Expect(checkNS.Name).To(Equal(namespace), fmt.Sprintf("Retrieved namespace for %s has name %s instead", namespace, checkNS.Name)) - //Check deployment: should be included + // Check deployment: should be included _, err = GetDeployment(e.Client.ClientGo, namespace, e.CaseBaseName) Expect(err).ShouldNot(HaveOccurred(), fmt.Sprintf("failed to list deployment in namespace: %q", namespace)) - //Check secrets: secrets should not be included + // Check secrets: secrets should not be included _, err = GetSecret(e.Client.ClientGo, namespace, e.CaseBaseName) Expect(err).Should(HaveOccurred(), fmt.Sprintf("failed to list deployment in namespace: %q", namespace)) Expect(apierrors.IsNotFound(err)).To(BeTrue()) - //Check configmap: should be included + // Check configmap: should be included _, err = GetConfigMap(e.Client.ClientGo, namespace, e.CaseBaseName) Expect(err).ShouldNot(HaveOccurred(), fmt.Sprintf("failed to list configmap in namespace: %q", namespace)) }) diff --git a/test/e2e/resource-filtering/exclude_namespaces.go b/test/e2e/resource-filtering/exclude_namespaces.go index 1b8e5da550..e2265a0621 100644 --- a/test/e2e/resource-filtering/exclude_namespaces.go +++ b/test/e2e/resource-filtering/exclude_namespaces.go @@ -42,8 +42,10 @@ type ExcludeNamespaces struct { namespacesExcluded int } -var BackupWithExcludeNamespaces func() = TestFunc(&ExcludeNamespaces{FilteringCase: testInBackup}) -var RestoreWithExcludeNamespaces func() = TestFunc(&ExcludeNamespaces{FilteringCase: testInRestore}) +var ( + BackupWithExcludeNamespaces func() = TestFunc(&ExcludeNamespaces{FilteringCase: testInBackup}) + RestoreWithExcludeNamespaces func() = TestFunc(&ExcludeNamespaces{FilteringCase: testInRestore}) +) func (e *ExcludeNamespaces) Init() error { e.FilteringCase.Init() diff --git a/test/e2e/resource-filtering/exclude_resources.go b/test/e2e/resource-filtering/exclude_resources.go index 5c2f37e737..fe42955197 100644 --- a/test/e2e/resource-filtering/exclude_resources.go +++ b/test/e2e/resource-filtering/exclude_resources.go @@ -43,8 +43,10 @@ type ExcludeResources struct { FilteringCase } -var BackupWithExcludeResources func() = TestFunc(&ExcludeResources{testInBackup}) -var RestoreWithExcludeResources func() = TestFunc(&ExcludeResources{testInRestore}) +var ( + BackupWithExcludeResources func() = TestFunc(&ExcludeResources{testInBackup}) + RestoreWithExcludeResources func() = TestFunc(&ExcludeResources{testInRestore}) +) func (e *ExcludeResources) Init() error { e.FilteringCase.Init() @@ -98,15 +100,15 @@ func (e *ExcludeResources) Verify() error { for nsNum := 0; nsNum < e.NamespacesTotal; nsNum++ { namespace := fmt.Sprintf("%s-%00000d", e.CaseBaseName, nsNum) fmt.Printf("Checking resources in namespaces ...%s\n", namespace) - //Check deployment + // Check deployment _, err := GetDeployment(e.Client.ClientGo, namespace, e.CaseBaseName) if err != nil { return errors.Wrap(err, fmt.Sprintf("failed to list deployment in namespace: %q", namespace)) } - //Check secrets + // Check secrets secretsList, err := e.Client.ClientGo.CoreV1().Secrets(namespace).List(e.Ctx, metav1.ListOptions{LabelSelector: e.labelSelector}) if err != nil { - if apierrors.IsNotFound(err) { //resource should be excluded + if apierrors.IsNotFound(err) { // resource should be excluded return nil } return errors.Wrap(err, fmt.Sprintf("failed to list secrets in namespace: %q", namespace)) @@ -114,7 +116,7 @@ func (e *ExcludeResources) Verify() error { return errors.Errorf(fmt.Sprintf("Should no secrets found %s in namespace: %q", secretsList.Items[0].Name, namespace)) } - //Check configmap + // Check configmap configmapList, err := e.Client.ClientGo.CoreV1().ConfigMaps(namespace).List(e.Ctx, metav1.ListOptions{LabelSelector: e.labelSelector}) if err != nil { return errors.Wrap(err, fmt.Sprintf("failed to list configmap in namespace: %q", namespace)) diff --git a/test/e2e/resource-filtering/include_namespaces.go b/test/e2e/resource-filtering/include_namespaces.go index d511de2123..c8e2407fb5 100644 --- a/test/e2e/resource-filtering/include_namespaces.go +++ b/test/e2e/resource-filtering/include_namespaces.go @@ -43,8 +43,10 @@ type IncludeNamespaces struct { FilteringCase } -var BackupWithIncludeNamespaces func() = TestFunc(&IncludeNamespaces{FilteringCase: testInBackup}) -var RestoreWithIncludeNamespaces func() = TestFunc(&IncludeNamespaces{FilteringCase: testInRestore}) +var ( + BackupWithIncludeNamespaces func() = TestFunc(&IncludeNamespaces{FilteringCase: testInBackup}) + RestoreWithIncludeNamespaces func() = TestFunc(&IncludeNamespaces{FilteringCase: testInRestore}) +) func (i *IncludeNamespaces) Init() error { i.FilteringCase.Init() diff --git a/test/e2e/resource-filtering/include_resources.go b/test/e2e/resource-filtering/include_resources.go index 23199d2de2..903e50cc02 100644 --- a/test/e2e/resource-filtering/include_resources.go +++ b/test/e2e/resource-filtering/include_resources.go @@ -40,8 +40,10 @@ type IncludeResources struct { FilteringCase } -var BackupWithIncludeResources func() = TestFunc(&IncludeResources{testInBackup}) -var RestoreWithIncludeResources func() = TestFunc(&IncludeResources{testInRestore}) +var ( + BackupWithIncludeResources func() = TestFunc(&IncludeResources{testInBackup}) + RestoreWithIncludeResources func() = TestFunc(&IncludeResources{testInRestore}) +) func (i *IncludeResources) Init() error { i.FilteringCase.Init() @@ -94,15 +96,15 @@ func (i *IncludeResources) Verify() error { for nsNum := 0; nsNum < i.NamespacesTotal; nsNum++ { namespace := fmt.Sprintf("%s-%00000d", i.CaseBaseName, nsNum) fmt.Printf("Checking resources in namespaces ...%s\n", namespace) - //Check deployment + // Check deployment _, err := GetDeployment(i.Client.ClientGo, namespace, i.CaseBaseName) if err != nil { return errors.Wrap(err, fmt.Sprintf("failed to list deployment in namespace: %q", namespace)) } - //Check secrets + // Check secrets secretsList, err := i.Client.ClientGo.CoreV1().Secrets(namespace).List(i.Ctx, metav1.ListOptions{LabelSelector: i.labelSelector}) if err != nil { - if apierrors.IsNotFound(err) { //resource should be excluded + if apierrors.IsNotFound(err) { // resource should be excluded return nil } return errors.Wrap(err, fmt.Sprintf("failed to list secrets in namespace: %q", namespace)) @@ -110,7 +112,7 @@ func (i *IncludeResources) Verify() error { return errors.Errorf(fmt.Sprintf("Should no secrets found %s in namespace: %q", secretsList.Items[0].Name, namespace)) } - //Check configmap + // Check configmap configmapList, err := i.Client.ClientGo.CoreV1().ConfigMaps(namespace).List(i.Ctx, metav1.ListOptions{LabelSelector: i.labelSelector}) if err != nil { return errors.Wrap(err, fmt.Sprintf("failed to list configmap in namespace: %q", namespace)) diff --git a/test/e2e/resource-filtering/label_selector.go b/test/e2e/resource-filtering/label_selector.go index 1d566b5853..6b05da0acf 100644 --- a/test/e2e/resource-filtering/label_selector.go +++ b/test/e2e/resource-filtering/label_selector.go @@ -85,7 +85,7 @@ func (l *LabelSelector) CreateResources() error { if err := CreateNamespaceWithLabel(l.Ctx, l.Client, namespace, labels); err != nil { return errors.Wrapf(err, "Failed to create namespace %s", namespace) } - //Create deployment + // Create deployment fmt.Printf("Creating deployment in namespaces ...%s\n", namespace) deployment := NewDeployment(l.CaseBaseName, namespace, l.replica, labels, nil).Result() @@ -97,7 +97,7 @@ func (l *LabelSelector) CreateResources() error { if err != nil { return errors.Wrap(err, fmt.Sprintf("failed to ensure job completion in namespace: %q", namespace)) } - //Create Secret + // Create Secret secretName := l.CaseBaseName fmt.Printf("Creating secret %s in namespaces ...%s\n", secretName, namespace) _, err = CreateSecret(l.Client.ClientGo, namespace, secretName, l.labels) @@ -116,39 +116,39 @@ func (l *LabelSelector) Verify() error { for nsNum := 0; nsNum < l.NamespacesTotal; nsNum++ { namespace := fmt.Sprintf("%s-%00000d", l.CaseBaseName, nsNum) fmt.Printf("Checking resources in namespaces ...%s\n", namespace) - //Check deployment + // Check deployment _, err := GetDeployment(l.Client.ClientGo, namespace, l.CaseBaseName) - if nsNum%2 == 1 { //include + if nsNum%2 == 1 { // include if err != nil { return errors.Wrap(err, fmt.Sprintf("failed to list deployment in namespace: %q", namespace)) } - } else { //exclude + } else { // exclude if err == nil { return fmt.Errorf("failed to exclude deployment in namespaces %q", namespace) } else { - if apierrors.IsNotFound(err) { //resource should be excluded + if apierrors.IsNotFound(err) { // resource should be excluded return nil } return errors.Wrap(err, fmt.Sprintf("failed to list deployment in namespace: %q", namespace)) } } - //Check secrets + // Check secrets secretsList, err := l.Client.ClientGo.CoreV1().Secrets(namespace).List(l.Ctx, metav1.ListOptions{ LabelSelector: l.labelSelector, }) - if nsNum%2 == 0 { //include + if nsNum%2 == 0 { // include if err != nil { return errors.Wrap(err, fmt.Sprintf("failed to list secrets in namespace: %q", namespace)) } else if len(secretsList.Items) == 0 { return errors.Errorf(fmt.Sprintf("no secrets found in namespace: %q", namespace)) } - } else { //exclude + } else { // exclude if err == nil { return fmt.Errorf("failed to exclude secrets in namespaces %q", namespace) } else { - if apierrors.IsNotFound(err) { //resource should be excluded + if apierrors.IsNotFound(err) { // resource should be excluded return nil } return errors.Wrap(err, fmt.Sprintf("failed to list secrets in namespace: %q", namespace)) diff --git a/test/e2e/resourcepolicies/resource_policies.go b/test/e2e/resourcepolicies/resource_policies.go index 94e238eda3..3beae0941c 100644 --- a/test/e2e/resourcepolicies/resource_policies.go +++ b/test/e2e/resourcepolicies/resource_policies.go @@ -127,7 +127,7 @@ func (r *ResourcePoliciesCase) CreateResources() error { Expect(r.createDeploymentWithVolume(namespace, volList)).To(Succeed(), fmt.Sprintf("Failed to create deployment namespace %s", namespace)) }) - //Write data into pods + // Write data into pods By(fmt.Sprintf("Writing data into pod in namespaces ...%s\n", namespace), func() { Expect(r.writeDataIntoPods(namespace, volName)).To(Succeed(), fmt.Sprintf("Failed to write data into pod in namespace %s", namespace)) }) diff --git a/test/e2e/schedule/ordered_resources.go b/test/e2e/schedule/ordered_resources.go index 238a014c75..d965ca581e 100644 --- a/test/e2e/schedule/ordered_resources.go +++ b/test/e2e/schedule/ordered_resources.go @@ -16,7 +16,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -//the ordered resources test related to https://github.com/vmware-tanzu/velero/issues/4561 +// the ordered resources test related to https://github.com/vmware-tanzu/velero/issues/4561 import ( "context" "fmt" @@ -96,7 +96,7 @@ func (o *OrderedResources) CreateResources() error { return errors.Wrapf(err, "failed to create namespace %s", o.Namespace) } - //Create deployment + // Create deployment deploymentName := fmt.Sprintf("deploy-%s", o.CaseBaseName) fmt.Printf("Creating deployment %s in %s namespaces ...\n", deploymentName, o.Namespace) deployment := k8sutil.NewDeployment(deploymentName, o.Namespace, 1, label, nil).Result() @@ -109,7 +109,7 @@ func (o *OrderedResources) CreateResources() error { return errors.Wrap(err, fmt.Sprintf("failed to ensure job completion in namespace: %q", o.Namespace)) } - //Create Secret + // Create Secret secretName := fmt.Sprintf("secret-%s", o.CaseBaseName) fmt.Printf("Creating secret %s in %s namespaces ...\n", secretName, o.Namespace) _, err = k8sutil.CreateSecret(o.Client.ClientGo, o.Namespace, secretName, label) @@ -117,7 +117,7 @@ func (o *OrderedResources) CreateResources() error { return errors.Wrap(err, fmt.Sprintf("failed to create secret in the namespace %q", o.Namespace)) } - //Create ConfigMap + // Create ConfigMap cmName := fmt.Sprintf("configmap-%s", o.CaseBaseName) fmt.Printf("Creating ConfigMap %s in %s namespaces ...\n", cmName, o.Namespace) if _, err := k8sutil.CreateConfigMap( diff --git a/test/e2e/test/test.go b/test/e2e/test/test.go index 78704a4bba..6ce84a0441 100644 --- a/test/e2e/test/test.go +++ b/test/e2e/test/test.go @@ -98,6 +98,7 @@ func TestIt(test VeleroBackupRestoreTest) error { }) return nil } + func (t *TestCase) Init() error { t.UUIDgen = t.GenerateUUID() t.VeleroCfg = VeleroCfg diff --git a/test/e2e/upgrade/upgrade.go b/test/e2e/upgrade/upgrade.go index 4757fbbe90..1efd53a539 100644 --- a/test/e2e/upgrade/upgrade.go +++ b/test/e2e/upgrade/upgrade.go @@ -33,8 +33,10 @@ import ( . "github.com/vmware-tanzu/velero/test/util/velero" ) -var upgradeNamespace string -var veleroCfg VeleroConfig +var ( + upgradeNamespace string + veleroCfg VeleroConfig +) func BackupUpgradeRestoreWithSnapshots() { veleroCfg = VeleroCfg @@ -111,8 +113,8 @@ func BackupUpgradeRestoreTest(useVolumeSnapshots bool, veleroCLI2Version VeleroC supportUploaderType, err := IsSupportUploaderType(veleroCLI2Version.VeleroVersion) Expect(err).To(Succeed()) if veleroCLI2Version.VeleroCLI == "" { - //Assume tag of velero server image is identical to velero CLI version - //Download velero CLI if it's empty according to velero CLI version + // Assume tag of velero server image is identical to velero CLI version + // Download velero CLI if it's empty according to velero CLI version By(fmt.Sprintf("Install the expected old version Velero CLI (%s) for installing Velero", veleroCLI2Version.VeleroVersion), func() { veleroCLI2Version.VeleroCLI, err = InstallVeleroCLI(veleroCLI2Version.VeleroVersion) @@ -170,7 +172,7 @@ func BackupUpgradeRestoreTest(useVolumeSnapshots bool, veleroCLI2Version VeleroC BackupCfg.UseVolumeSnapshots = useVolumeSnapshots BackupCfg.DefaultVolumesToFsBackup = !useVolumeSnapshots BackupCfg.Selector = "" - //TODO: pay attention to this param, remove it when restic is not the default backup tool any more. + // TODO: pay attention to this param, remove it when restic is not the default backup tool any more. BackupCfg.UseResticIfFSBackup = !supportUploaderType Expect(VeleroBackupNamespace(oneHourTimeout, tmpCfg.UpgradeFromVeleroCLI, tmpCfg.VeleroNamespace, BackupCfg)).To(Succeed(), func() string { diff --git a/test/perf/e2e_suite_test.go b/test/perf/e2e_suite_test.go index cb4522d699..3d97b005b9 100644 --- a/test/perf/e2e_suite_test.go +++ b/test/perf/e2e_suite_test.go @@ -66,7 +66,7 @@ func init() { flag.StringVar(&VeleroCfg.VeleroPodCPURequest, "velero-pod-cpu-request", "2", "CPU request for velero pod. Optional.") flag.StringVar(&VeleroCfg.VeleroPodMemRequest, "velero-pod-mem-request", "2Gi", "Memory request for velero pod. Optional.") flag.DurationVar(&VeleroCfg.PodVolumeOperationTimeout, "pod-volume-operation-timeout", 360*time.Minute, "Timeout for pod volume operations. Optional.") - //vmware-tanzu-experiments + // vmware-tanzu-experiments flag.StringVar(&VeleroCfg.Features, "features", "", "Comma-separated list of features to enable for this Velero process.") flag.StringVar(&VeleroCfg.DefaultClusterContext, "default-cluster-context", "", "Default cluster context for migration test.") flag.StringVar(&VeleroCfg.UploaderType, "uploader-type", "kopia", "Identify persistent volume backup uploader.") diff --git a/test/perf/metrics/pod.go b/test/perf/metrics/pod.go index 56572f6728..167f989018 100644 --- a/test/perf/metrics/pod.go +++ b/test/perf/metrics/pod.go @@ -29,8 +29,10 @@ import ( "github.com/vmware-tanzu/velero/test/util/metrics" ) -const PodResourceDesc = "Resource consumption" -const PodMetricsTimeout = 5 * time.Minute +const ( + PodResourceDesc = "Resource consumption" + PodMetricsTimeout = 5 * time.Minute +) type PodMetrics struct { Client *metricsclientset.Clientset diff --git a/test/perf/restore/restore.go b/test/perf/restore/restore.go index 6adbff5f4e..70a2949674 100644 --- a/test/perf/restore/restore.go +++ b/test/perf/restore/restore.go @@ -88,6 +88,7 @@ func (r *RestoreTest) Restore() error { return r.TestCase.Restore() } + func (r *RestoreTest) Destroy() error { return nil } diff --git a/test/perf/test/test.go b/test/perf/test/test.go index 1bc8a3fc06..221950b737 100644 --- a/test/perf/test/test.go +++ b/test/perf/test/test.go @@ -265,7 +265,8 @@ func (t *TestCase) MonitorMetircs(ctx context.Context, collectors *metrics.Metri BslPrefix: VeleroCfg.BSLPrefix, BslConfig: VeleroCfg.BSLConfig, Metrics: make(map[string]string), - BslBucket: VeleroCfg.BSLBucket} + BslBucket: VeleroCfg.BSLBucket, + } collectors.RegisterOneTimeMetric(minioMetrics) timeMetrics := &metrics.TimeMetrics{ diff --git a/test/pkg/client/config.go b/test/pkg/client/config.go index 7546a0ac4c..224fa26430 100644 --- a/test/pkg/client/config.go +++ b/test/pkg/client/config.go @@ -72,11 +72,11 @@ func SaveConfig(config VeleroConfig) error { // Try to make the directory in case it doesn't exist dir := filepath.Dir(fileName) - if err := os.MkdirAll(dir, 0700); err != nil { + if err := os.MkdirAll(dir, 0o700); err != nil { return errors.WithStack(err) } - configFile, err := os.OpenFile(fileName, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0600) + configFile, err := os.OpenFile(fileName, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0o600) if err != nil { return errors.WithStack(err) } diff --git a/test/pkg/client/dynamic.go b/test/pkg/client/dynamic.go index 8fcfab107b..5c5db46aca 100644 --- a/test/pkg/client/dynamic.go +++ b/test/pkg/client/dynamic.go @@ -77,14 +77,14 @@ type Getter interface { // Patcher patches an object. type Patcher interface { - //Patch patches the named object using the provided patch bytes, which are expected to be in JSON merge patch format. The patched object is returned. + // Patch patches the named object using the provided patch bytes, which are expected to be in JSON merge patch format. The patched object is returned. Patch(name string, data []byte) (*unstructured.Unstructured, error) } // Deletor deletes an object. type Deletor interface { - //Patch patches the named object using the provided patch bytes, which are expected to be in JSON merge patch format. The patched object is returned. + // Patch patches the named object using the provided patch bytes, which are expected to be in JSON merge patch format. The patched object is returned. Delete(name string, opts metav1.DeleteOptions) error } diff --git a/test/pkg/client/factory.go b/test/pkg/client/factory.go index 340cba587f..e9fd78eca9 100644 --- a/test/pkg/client/factory.go +++ b/test/pkg/client/factory.go @@ -98,7 +98,7 @@ func NewFactory(baseName, kubecontext string, config VeleroConfig) Factory { f.flags.StringVar(&f.kubeconfig, "kubeconfig", "", "Path to the kubeconfig file to use to talk to the Kubernetes apiserver. If unset, try the environment variable KUBECONFIG, as well as in-cluster configuration") f.flags.StringVarP(&f.namespace, "namespace", "n", f.namespace, "The namespace in which Velero should operate") - //f.flags.StringVar(&f.kubecontext, "kubecontext", "", "The context to use to talk to the Kubernetes apiserver. If unset defaults to whatever your current-context is (kubectl config current-context)") + // f.flags.StringVar(&f.kubecontext, "kubecontext", "", "The context to use to talk to the Kubernetes apiserver. If unset defaults to whatever your current-context is (kubectl config current-context)") return f } @@ -149,7 +149,6 @@ func (f *factory) KubebuilderClient() (kbclient.Client, error) { kubebuilderClient, err := kbclient.New(clientConfig, kbclient.Options{ Scheme: scheme, }) - if err != nil { return nil, err } diff --git a/test/types.go b/test/types.go index 35a1502c2d..6bf3ae9ec6 100644 --- a/test/types.go +++ b/test/types.go @@ -31,18 +31,20 @@ const StorageClassName = "e2e-storage-class" // e2e-storage-class-2 is used for the StorageClass mapping test case. const StorageClassName2 = "e2e-storage-class-2" -const FeatureCSI = "EnableCSI" -const VanillaZFS = "vanilla-zfs" -const Kind = "kind" -const Azure = "azure" -const AzureCSI = "azure-csi" -const AwsCSI = "aws-csi" -const AWS = "aws" -const GCP = "gcp" -const Vsphere = "vsphere" -const CSI = "csi" -const Velero = "velero" -const VeleroRestoreHelper = "velero-restore-helper" +const ( + FeatureCSI = "EnableCSI" + VanillaZFS = "vanilla-zfs" + Kind = "kind" + Azure = "azure" + AzureCSI = "azure-csi" + AwsCSI = "aws-csi" + AWS = "aws" + GCP = "gcp" + Vsphere = "vsphere" + CSI = "csi" + Velero = "velero" + VeleroRestoreHelper = "velero-restore-helper" +) const UploaderTypeRestic = "restic" @@ -53,12 +55,16 @@ const ( VeleroVSphereConfigMapName = "velero-vsphere-plugin-config" ) -var PublicCloudProviders = []string{AWS, Azure, GCP, Vsphere} -var LocalCloudProviders = []string{Kind, VanillaZFS} -var CloudProviders = append(PublicCloudProviders, LocalCloudProviders...) +var ( + PublicCloudProviders = []string{AWS, Azure, GCP, Vsphere} + LocalCloudProviders = []string{Kind, VanillaZFS} + CloudProviders = append(PublicCloudProviders, LocalCloudProviders...) +) -var InstallVelero bool -var UUIDgen uuid.UUID +var ( + InstallVelero bool + UUIDgen uuid.UUID +) var VeleroCfg VeleroConfig diff --git a/test/util/common/common.go b/test/util/common/common.go index 3b130f209a..5e3acccf90 100644 --- a/test/util/common/common.go +++ b/test/util/common/common.go @@ -90,7 +90,7 @@ func CMDExecWithOutput(checkCMD *exec.Cmd) (*[]byte, error) { } func WriteToFile(content, fileName string) error { - file, err := os.OpenFile(fileName, os.O_WRONLY|os.O_CREATE, 0666) + file, err := os.OpenFile(fileName, os.O_WRONLY|os.O_CREATE, 0o666) if err != nil { fmt.Println("fail to open file", err) return err @@ -110,6 +110,7 @@ func WriteToFile(content, fileName string) error { } return nil } + func CreateFileContent(namespace, podName, volume string) string { return fmt.Sprintf("ns-%s pod-%s volume-%s", namespace, podName, volume) } diff --git a/test/util/eks/eks.go b/test/util/eks/eks.go index ff3df3c317..c400e4c662 100644 --- a/test/util/eks/eks.go +++ b/test/util/eks/eks.go @@ -29,8 +29,10 @@ import ( ) func KubectlDeleteIAMServiceAcount(ctx context.Context, name, namespace, cluster string) error { - args := []string{"delete", "iamserviceaccount", name, - "--namespace", namespace, "--cluster", cluster, "--wait"} + args := []string{ + "delete", "iamserviceaccount", name, + "--namespace", namespace, "--cluster", cluster, "--wait", + } fmt.Println(args) cmd := exec.CommandContext(ctx, "eksctl", args...) @@ -44,9 +46,11 @@ func KubectlDeleteIAMServiceAcount(ctx context.Context, name, namespace, cluster } func EksctlCreateIAMServiceAcount(ctx context.Context, name, namespace, policyARN, cluster string) error { - args := []string{"create", "iamserviceaccount", name, + args := []string{ + "create", "iamserviceaccount", name, "--namespace", namespace, "--cluster", cluster, "--attach-policy-arn", policyARN, - "--approve", "--override-existing-serviceaccounts"} + "--approve", "--override-existing-serviceaccounts", + } PollInterval := 1 * time.Minute PollTimeout := 10 * time.Minute diff --git a/test/util/k8s/client.go b/test/util/k8s/client.go index 1018e3bdf1..048e5d24f6 100644 --- a/test/util/k8s/client.go +++ b/test/util/k8s/client.go @@ -48,9 +48,7 @@ type TestClient struct { MetricsClient *metricsclientset.Clientset } -var ( - err error -) +var err error // NewTestClient returns a set of ready-to-use API clients. func NewTestClient(kubecontext string) (TestClient, error) { @@ -66,7 +64,6 @@ func InitTestClient(kubecontext string) (TestClient, error) { f := client.NewFactory("e2e", kubecontext, config) clientGo, err := f.KubeClient() - if err != nil { return TestClient{}, err } diff --git a/test/util/k8s/common.go b/test/util/k8s/common.go index 95f6858115..7ed7cb0812 100644 --- a/test/util/k8s/common.go +++ b/test/util/k8s/common.go @@ -63,7 +63,7 @@ func WaitForPods(ctx context.Context, client TestClient, namespace string, pods for _, podName := range pods { checkPod, err := client.ClientGo.CoreV1().Pods(namespace).Get(context.TODO(), podName, metav1.GetOptions{}) if err != nil { - //Should ignore "etcdserver: request timed out" kind of errors, try to get pod status again before timeout. + // Should ignore "etcdserver: request timed out" kind of errors, try to get pod status again before timeout. fmt.Println(errors.Wrap(err, fmt.Sprintf("Failed to verify pod %s/%s is %s, try again...\n", namespace, podName, corev1.PodRunning))) return false, nil } @@ -300,8 +300,10 @@ func PrepareVolumeList(volumeNameList []string) (vols []*corev1.Volume) { } func CalFileHashInPod(ctx context.Context, namespace, podName, containerName, filePath string) (string, error) { - arg := []string{"exec", "-n", namespace, "-c", containerName, podName, - "--", "/bin/sh", "-c", fmt.Sprintf("sha256sum %s | awk '{ print $1 }'", filePath)} + arg := []string{ + "exec", "-n", namespace, "-c", containerName, podName, + "--", "/bin/sh", "-c", fmt.Sprintf("sha256sum %s | awk '{ print $1 }'", filePath), + } cmd := exec.CommandContext(ctx, "kubectl", arg...) output, err := cmd.Output() if err != nil { @@ -315,16 +317,20 @@ func CalFileHashInPod(ctx context.Context, namespace, podName, containerName, fi } func WriteRandomDataToFileInPod(ctx context.Context, namespace, podName, containerName, volume, filename string, fileSize int64) error { - arg := []string{"exec", "-n", namespace, "-c", containerName, podName, - "--", "/bin/sh", "-c", fmt.Sprintf("dd if=/dev/urandom of=/%s/%s bs=%d count=1", volume, filename, fileSize)} + arg := []string{ + "exec", "-n", namespace, "-c", containerName, podName, + "--", "/bin/sh", "-c", fmt.Sprintf("dd if=/dev/urandom of=/%s/%s bs=%d count=1", volume, filename, fileSize), + } cmd := exec.CommandContext(ctx, "kubectl", arg...) fmt.Printf("Kubectl exec cmd =%v\n", cmd) return cmd.Run() } func CreateFileToPod(ctx context.Context, namespace, podName, containerName, volume, filename, content string) error { - arg := []string{"exec", "-n", namespace, "-c", containerName, podName, - "--", "/bin/sh", "-c", fmt.Sprintf("echo ns-%s pod-%s volume-%s > /%s/%s", namespace, podName, volume, volume, filename)} + arg := []string{ + "exec", "-n", namespace, "-c", containerName, podName, + "--", "/bin/sh", "-c", fmt.Sprintf("echo ns-%s pod-%s volume-%s > /%s/%s", namespace, podName, volume, volume, filename), + } cmd := exec.CommandContext(ctx, "kubectl", arg...) fmt.Printf("Kubectl exec cmd =%v\n", cmd) return cmd.Run() @@ -345,9 +351,12 @@ func FileExistInPV(ctx context.Context, namespace, podName, containerName, volum } } } + func ReadFileFromPodVolume(ctx context.Context, namespace, podName, containerName, volume, filename string) (string, string, error) { - arg := []string{"exec", "-n", namespace, "-c", containerName, podName, - "--", "cat", fmt.Sprintf("/%s/%s", volume, filename)} + arg := []string{ + "exec", "-n", namespace, "-c", containerName, podName, + "--", "cat", fmt.Sprintf("/%s/%s", volume, filename), + } cmd := exec.CommandContext(ctx, "kubectl", arg...) fmt.Printf("Kubectl exec cmd =%v\n", cmd) stdout, stderr, err := veleroexec.RunCommand(cmd) diff --git a/test/util/k8s/deployment.go b/test/util/k8s/deployment.go index 3158f8c023..7f16e9f5a7 100644 --- a/test/util/k8s/deployment.go +++ b/test/util/k8s/deployment.go @@ -125,6 +125,7 @@ func CreateDeploy(c clientset.Interface, ns string, deployment *apps.Deployment) _, err := c.AppsV1().Deployments(ns).Create(context.TODO(), deployment, metav1.CreateOptions{}) return err } + func CreateDeployment(c clientset.Interface, ns string, deployment *apps.Deployment) (*apps.Deployment, error) { return c.AppsV1().Deployments(ns).Create(context.TODO(), deployment, metav1.CreateOptions{}) } diff --git a/test/util/k8s/namespace.go b/test/util/k8s/namespace.go index b2a5cae0e6..569f4dfc46 100644 --- a/test/util/k8s/namespace.go +++ b/test/util/k8s/namespace.go @@ -128,7 +128,6 @@ func DeleteNamespace(ctx context.Context, client TestClient, namespace string, w func CleanupNamespacesWithPoll(ctx context.Context, client TestClient, CaseBaseName string) error { namespaces, err := client.ClientGo.CoreV1().Namespaces().List(ctx, metav1.ListOptions{}) - if err != nil { return errors.Wrap(err, "Could not retrieve namespaces") } @@ -146,7 +145,6 @@ func CleanupNamespacesWithPoll(ctx context.Context, client TestClient, CaseBaseN func CleanupNamespacesFiterdByExcludes(ctx context.Context, client TestClient, excludeNS []string) error { namespaces, err := client.ClientGo.CoreV1().Namespaces().List(ctx, metav1.ListOptions{}) - if err != nil { return errors.Wrap(err, "Could not retrieve namespaces") } diff --git a/test/util/k8s/rbac.go b/test/util/k8s/rbac.go index 634fdf84f1..4fd6911f85 100644 --- a/test/util/k8s/rbac.go +++ b/test/util/k8s/rbac.go @@ -40,7 +40,7 @@ func CreateRBACWithBindingSA(ctx context.Context, client TestClient, namespace s return err } - //creating role binding and binding it to the test service account + // creating role binding and binding it to the test service account rolebinding := &v1.ClusterRoleBinding{ ObjectMeta: metav1.ObjectMeta{ Name: clusterrolebinding, diff --git a/test/util/k8s/service.go b/test/util/k8s/service.go index 873adfbb3d..5bee3e53bb 100644 --- a/test/util/k8s/service.go +++ b/test/util/k8s/service.go @@ -30,7 +30,8 @@ import ( ) func CreateService(ctx context.Context, client TestClient, namespace string, - service string, labels map[string]string, serviceSpec *corev1.ServiceSpec) error { + service string, labels map[string]string, serviceSpec *corev1.ServiceSpec, +) error { se := &corev1.Service{ TypeMeta: metav1.TypeMeta{ Kind: "Service", diff --git a/test/util/kibishii/kibishii_utils.go b/test/util/kibishii/kibishii_utils.go index be503ff0b1..9b9eba0d32 100644 --- a/test/util/kibishii/kibishii_utils.go +++ b/test/util/kibishii/kibishii_utils.go @@ -49,12 +49,16 @@ type KibishiiData struct { ExpectedNodes int } -var DefaultKibishiiWorkerCounts = 2 -var DefaultKibishiiData = &KibishiiData{2, 10, 10, 1024, 1024, 0, DefaultKibishiiWorkerCounts} +var ( + DefaultKibishiiWorkerCounts = 2 + DefaultKibishiiData = &KibishiiData{2, 10, 10, 1024, 1024, 0, DefaultKibishiiWorkerCounts} +) -var KibishiiPodNameList = []string{"kibishii-deployment-0", "kibishii-deployment-1"} -var KibishiiPVCNameList = []string{"kibishii-data-kibishii-deployment-0", "kibishii-data-kibishii-deployment-1"} -var KibishiiStorageClassName = "kibishii-storage-class" +var ( + KibishiiPodNameList = []string{"kibishii-deployment-0", "kibishii-deployment-1"} + KibishiiPVCNameList = []string{"kibishii-data-kibishii-deployment-0", "kibishii-data-kibishii-deployment-1"} + KibishiiStorageClassName = "kibishii-storage-class" +) func GetKibishiiPVCNameList(workerCount int) []string { var kibishiiPVCNameList []string @@ -264,7 +268,8 @@ func RunKibishiiTests( } func installKibishii(ctx context.Context, namespace string, cloudPlatform, veleroFeatures, - kibishiiDirectory string, useVolumeSnapshots bool, workerReplicas int) error { + kibishiiDirectory string, useVolumeSnapshots bool, workerReplicas int, +) error { if strings.EqualFold(cloudPlatform, Azure) && strings.EqualFold(veleroFeatures, FeatureCSI) { cloudPlatform = AzureCSI @@ -331,7 +336,6 @@ func generateData(ctx context.Context, namespace string, kibishiiData *KibishiiD } return true, nil }) - if err != nil { return errors.Wrapf(err, fmt.Sprintf("Failed to wait generate data in namespace %s", namespace)) } @@ -361,7 +365,6 @@ func verifyData(ctx context.Context, namespace string, kibishiiData *KibishiiDat } return true, nil }) - if err != nil { return errors.Wrapf(err, fmt.Sprintf("Failed to verify kibishii data in namespace %s\n", namespace)) } @@ -384,7 +387,8 @@ func KibishiiGenerateData(oneHourTimeout context.Context, kibishiiNamespace stri func KibishiiPrepareBeforeBackup(oneHourTimeout context.Context, client TestClient, providerName, kibishiiNamespace, registryCredentialFile, veleroFeatures, - kibishiiDirectory string, useVolumeSnapshots bool, kibishiiData *KibishiiData) error { + kibishiiDirectory string, useVolumeSnapshots bool, kibishiiData *KibishiiData, +) error { fmt.Printf("installKibishii %s\n", time.Now().Format("2006-01-02 15:04:05")) serviceAccountName := "default" @@ -416,7 +420,8 @@ func KibishiiPrepareBeforeBackup(oneHourTimeout context.Context, client TestClie } func KibishiiVerifyAfterRestore(client TestClient, kibishiiNamespace string, oneHourTimeout context.Context, - kibishiiData *KibishiiData, incrementalFileName string) error { + kibishiiData *KibishiiData, incrementalFileName string, +) error { if kibishiiData == nil { kibishiiData = DefaultKibishiiData } @@ -448,8 +453,10 @@ func KibishiiVerifyAfterRestore(client TestClient, kibishiiNamespace string, one } func ClearKibishiiData(ctx context.Context, namespace, podName, containerName, dir string) error { - arg := []string{"exec", "-n", namespace, "-c", containerName, podName, - "--", "/bin/sh", "-c", "rm -rf /" + dir + "/*"} + arg := []string{ + "exec", "-n", namespace, "-c", containerName, podName, + "--", "/bin/sh", "-c", "rm -rf /" + dir + "/*", + } cmd := exec.CommandContext(ctx, "kubectl", arg...) fmt.Printf("Kubectl exec cmd =%v\n", cmd) return cmd.Run() diff --git a/test/util/providers/azure_utils.go b/test/util/providers/azure_utils.go index 86c439fb60..a4bf26f797 100644 --- a/test/util/providers/azure_utils.go +++ b/test/util/providers/azure_utils.go @@ -102,6 +102,7 @@ func loadCredentialsIntoEnv(credentialsFile string) error { } return nil } + func parseCloudConfiguration(cloudName string) (cloud.Configuration, error) { if cloudName == "" { fmt.Println("cloudName is empty") @@ -111,6 +112,7 @@ func parseCloudConfiguration(cloudName string) (cloud.Configuration, error) { cloudConfiguration, err := cloudConfigurationFromName(cloudName) return cloudConfiguration, errors.WithStack(err) } + func getStorageAccountKey(credentialsFile, accountName, subscriptionID, resourceGroupCfg string) (string, error) { if err := loadCredentialsIntoEnv(credentialsFile); err != nil { return "", err @@ -187,6 +189,7 @@ func getStorageAccountKey(credentialsFile, accountName, subscriptionID, resource return storageKey, nil } + func handleErrors(err error) { if err != nil { if bloberror.HasCode(err, bloberror.ContainerAlreadyExists) { @@ -219,6 +222,7 @@ func deleteBlob(client *azblob.Client, containerName, blobName string) error { _, err := client.DeleteBlob(context.Background(), containerName, blobName, nil) return err } + func (s AzureStorage) IsObjectsInBucket(cloudCredentialsFile, bslBucket, bslPrefix, bslConfig, backupName string) (bool, error) { ctx := context.Background() accountName, accountKey, err := getStorageCredential(cloudCredentialsFile, bslConfig) diff --git a/test/util/providers/common.go b/test/util/providers/common.go index a7c68dc37e..73856d02ee 100644 --- a/test/util/providers/common.go +++ b/test/util/providers/common.go @@ -48,6 +48,7 @@ func ObjectsShouldBeInBucket(objectStoreProvider, cloudCredentialsFile, bslBucke fmt.Printf("|| EXPECTED || - Backup %s exist in object storage bucket %s\n", backupName, bslBucket) return nil } + func ObjectsShouldNotBeInBucket(objectStoreProvider, cloudCredentialsFile, bslBucket, bslPrefix, bslConfig, backupName, subPrefix string, retryTimes int) error { var err error var exist bool @@ -89,15 +90,17 @@ func getProvider(cloudProvider string) (ObjectsInStorage, error) { } return s, nil } + func getFullPrefix(bslPrefix, subPrefix string) string { if bslPrefix == "" { bslPrefix = subPrefix + "/" } else { - //subPrefix must have surfix "/", so that objects under it can be listed + // subPrefix must have surfix "/", so that objects under it can be listed bslPrefix = strings.Trim(bslPrefix, "/") + "/" + strings.Trim(subPrefix, "/") + "/" } return bslPrefix } + func IsObjectsInBucket(objectStoreProvider, cloudCredentialsFile, bslBucket, bslPrefix, bslConfig, backupName, subPrefix string) (bool, error) { bslPrefix = getFullPrefix(bslPrefix, subPrefix) s, err := getProvider(objectStoreProvider) diff --git a/test/util/providers/gcloud_utils.go b/test/util/providers/gcloud_utils.go index f653aa02af..ded29fc080 100644 --- a/test/util/providers/gcloud_utils.go +++ b/test/util/providers/gcloud_utils.go @@ -50,7 +50,7 @@ func (s GCSStorage) IsObjectsInBucket(cloudCredentialsFile, bslBucket, bslPrefix for { obj, err := iter.Next() if err == iterator.Done { - //return false, errors.Wrapf(err, fmt.Sprintf("Backup %s was not found under prefix %s \n", backupObject, bslPrefix)) + // return false, errors.Wrapf(err, fmt.Sprintf("Backup %s was not found under prefix %s \n", backupObject, bslPrefix)) return false, nil } if err != nil { diff --git a/test/util/report/report.go b/test/util/report/report.go index 91ec876b17..0cef50ecfa 100644 --- a/test/util/report/report.go +++ b/test/util/report/report.go @@ -33,7 +33,7 @@ func GenerateYamlReport() error { // Open the file in append mode. If the file does not exist, it will be created. filePath := "perf-report.yaml" - file, err := os.OpenFile(filePath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644) + file, err := os.OpenFile(filePath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0o644) if err != nil { return errors.Wrap(err, "error opening file") } diff --git a/test/util/velero/install.go b/test/util/velero/install.go index 027ca43048..76c565e1a8 100644 --- a/test/util/velero/install.go +++ b/test/util/velero/install.go @@ -240,9 +240,9 @@ func generateVSpherePlugin(veleroCfg *test.VeleroConfig) error { } func cleanVSpherePluginConfig(c clientset.Interface, ns, secretName, configMapName string) error { - //clear secret + // clear secret _, err := k8s.GetSecret(c, ns, secretName) - if err == nil { //exist + if err == nil { // exist if err := k8s.WaitForSecretDelete(c, ns, secretName); err != nil { return errors.WithMessagef(err, "Failed to clear up vsphere plugin secret in %s namespace", ns) } @@ -250,7 +250,7 @@ func cleanVSpherePluginConfig(c clientset.Interface, ns, secretName, configMapNa return errors.WithMessagef(err, "Failed to retrieve vsphere plugin secret in %s namespace", ns) } - //clear configmap + // clear configmap _, err = k8s.GetConfigMap(c, ns, configMapName) if err == nil { if err := k8s.WaitForConfigmapDelete(c, ns, configMapName); err != nil { @@ -293,7 +293,7 @@ func installVeleroServer(ctx context.Context, cli, cloudProvider string, options if len(options.Prefix) > 0 { args = append(args, "--prefix", options.Prefix) } - //Treat ServiceAccountName priority higher than SecretFile + // Treat ServiceAccountName priority higher than SecretFile if len(options.ServiceAccountName) > 0 { args = append(args, "--service-account-name", options.ServiceAccountName) } else { diff --git a/test/util/velero/velero_utils.go b/test/util/velero/velero_utils.go index d799df9f7f..706a38bac3 100644 --- a/test/util/velero/velero_utils.go +++ b/test/util/velero/velero_utils.go @@ -52,9 +52,11 @@ import ( . "github.com/vmware-tanzu/velero/test/util/k8s" ) -const BackupObjectsPrefix = "backups" -const RestoreObjectsPrefix = "restores" -const PluginsObjectsPrefix = "plugins" +const ( + BackupObjectsPrefix = "backups" + RestoreObjectsPrefix = "restores" + PluginsObjectsPrefix = "plugins" +) var ImagesMatrix = map[string]map[string][]string{ "v1.10": { @@ -211,7 +213,8 @@ func getPluginsByVersion(version string, cloudProvider string, needDataMoverPlug // getProviderVeleroInstallOptions returns Velero InstallOptions for the provider. func getProviderVeleroInstallOptions(veleroCfg *VeleroConfig, - plugins []string) (*cliinstall.Options, error) { + plugins []string, +) (*cliinstall.Options, error) { if veleroCfg.CloudCredentialsFile == "" && veleroCfg.ServiceAccountNameToInstall == "" { return nil, errors.Errorf("No credentials were supplied to use for E2E tests") } @@ -277,7 +280,8 @@ func getProviderVeleroInstallOptions(veleroCfg *VeleroConfig, // checkBackupPhase uses VeleroCLI to inspect the phase of a Velero backup. func checkBackupPhase(ctx context.Context, veleroCLI string, veleroNamespace string, backupName string, - expectedPhase velerov1api.BackupPhase) error { + expectedPhase velerov1api.BackupPhase, +) error { checkCMD := exec.CommandContext(ctx, veleroCLI, "--namespace", veleroNamespace, "backup", "get", "-o", "json", backupName) @@ -305,7 +309,8 @@ func checkBackupPhase(ctx context.Context, veleroCLI string, veleroNamespace str // checkRestorePhase uses VeleroCLI to inspect the phase of a Velero restore. func checkRestorePhase(ctx context.Context, veleroCLI string, veleroNamespace string, restoreName string, - expectedPhase velerov1api.RestorePhase) error { + expectedPhase velerov1api.RestorePhase, +) error { checkCMD := exec.CommandContext(ctx, veleroCLI, "--namespace", veleroNamespace, "restore", "get", "-o", "json", restoreName) @@ -369,6 +374,7 @@ func checkSchedulePause(ctx context.Context, veleroCLI, veleroNamespace, schedul } return nil } + func CheckScheduleWithResourceOrder(ctx context.Context, veleroCLI, veleroNamespace, scheduleName string, order map[string]string) error { checkCMD := exec.CommandContext(ctx, veleroCLI, "--namespace", veleroNamespace, "schedule", "get", scheduleName, "-o", "json") jsonBuf, err := common.CMDExecWithOutput(checkCMD) @@ -1069,7 +1075,8 @@ func WaitBackupDeleted(ctx context.Context, backupName string, timeout time.Dura } func WaitForExpectedStateOfBackup(ctx context.Context, backupName string, - timeout time.Duration, existing bool, veleroCfg *VeleroConfig) error { + timeout time.Duration, existing bool, veleroCfg *VeleroConfig, +) error { return wait.PollImmediate(10*time.Second, timeout, func() (bool, error) { if exist, err := IsBackupExist(ctx, backupName, veleroCfg); err != nil { return false, err @@ -1334,6 +1341,7 @@ func GetVersionList(veleroCli, veleroVersion string) []VeleroCLI2Version { } return veleroCLI2VersionList } + func DeleteAllBackups(ctx context.Context, veleroCfg *VeleroConfig) error { client := veleroCfg.ClientToInstallVelero backupList := new(velerov1api.BackupList) @@ -1668,6 +1676,7 @@ func GetPvName(ctx context.Context, client TestClient, pvcName, namespace string return pvList[0], nil } + func DeletePVs(ctx context.Context, client TestClient, pvList []string) error { for _, pv := range pvList { args := []string{"delete", "pv", pv, "--timeout=0s"} @@ -1767,6 +1776,7 @@ func KubectlGetDeleteBackupRequestDetails(ctx context.Context, deleteBackupReque } return stdout, err } + func KubectlGetDeleteBackupRequestStatus(ctx context.Context, deleteBackupRequest, veleroNamespace string) (string, error) { args1 := []string{"get", "deletebackuprequests", "-n", veleroNamespace, deleteBackupRequest, "-o", "json"}