mirror of
https://github.com/vmware-tanzu/velero.git
synced 2026-08-15 11:46:06 +00:00
Self contain context in each high level function rather than passing around in structs
Signed-off-by: Tiger Kaovilai <tkaovila@redhat.com>
This commit is contained in:
Executable
+17
@@ -0,0 +1,17 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Copyright 2023 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.
|
||||
|
||||
go vet -mod=mod ./... || (echo "go vet is not happy, fix the errors above" && exit 1)
|
||||
@@ -39,8 +39,6 @@ import (
|
||||
type SyncBackups struct {
|
||||
testNS string
|
||||
backupName string
|
||||
ctx context.Context
|
||||
ctxCancel context.CancelFunc
|
||||
}
|
||||
|
||||
func (b *SyncBackups) Init() {
|
||||
@@ -48,11 +46,12 @@ func (b *SyncBackups) Init() {
|
||||
UUIDgen, _ = uuid.NewRandom()
|
||||
b.testNS = "sync-bsl-test-" + UUIDgen.String()
|
||||
b.backupName = "sync-bsl-test-" + UUIDgen.String()
|
||||
b.ctx, b.ctxCancel = context.WithTimeout(context.Background(), time.Minute*10)
|
||||
}
|
||||
|
||||
func BackupsSyncTest() {
|
||||
test := new(SyncBackups)
|
||||
ctx, ctxCancel := context.WithCancel(context.Background())
|
||||
defer ctxCancel()
|
||||
var (
|
||||
err error
|
||||
)
|
||||
@@ -80,13 +79,13 @@ func BackupsSyncTest() {
|
||||
|
||||
It("Backups in object storage should be synced to a new Velero successfully", func() {
|
||||
test.Init()
|
||||
defer test.ctxCancel()
|
||||
|
||||
By(fmt.Sprintf("Prepare workload as target to backup by creating namespace %s namespace", test.testNS))
|
||||
Expect(CreateNamespace(test.ctx, *VeleroCfg.ClientToInstallVelero, test.testNS)).To(Succeed(),
|
||||
Expect(CreateNamespace(ctx, *VeleroCfg.ClientToInstallVelero, test.testNS)).To(Succeed(),
|
||||
fmt.Sprintf("Failed to create %s namespace", test.testNS))
|
||||
if !VeleroCfg.Debug {
|
||||
defer func() {
|
||||
Expect(DeleteNamespace(test.ctx, *VeleroCfg.ClientToInstallVelero, test.testNS, false)).To(Succeed(), fmt.Sprintf("Failed to delete the namespace %s", test.testNS))
|
||||
Expect(DeleteNamespace(ctx, *VeleroCfg.ClientToInstallVelero, test.testNS, false)).To(Succeed(), fmt.Sprintf("Failed to delete the namespace %s", test.testNS))
|
||||
}()
|
||||
}
|
||||
|
||||
@@ -97,7 +96,7 @@ func BackupsSyncTest() {
|
||||
BackupCfg.UseVolumeSnapshots = false
|
||||
BackupCfg.Selector = ""
|
||||
By(fmt.Sprintf("Backup the workload in %s namespace", test.testNS), func() {
|
||||
Expect(VeleroBackupNamespace(test.ctx, VeleroCfg.VeleroCLI,
|
||||
Expect(VeleroBackupNamespace(ctx, VeleroCfg.VeleroCLI,
|
||||
VeleroCfg.VeleroNamespace, BackupCfg)).To(Succeed(), func() string {
|
||||
RunDebug(context.Background(), VeleroCfg.VeleroCLI, VeleroCfg.VeleroNamespace, test.backupName, "")
|
||||
return "Fail to backup workload"
|
||||
@@ -105,13 +104,13 @@ func BackupsSyncTest() {
|
||||
})
|
||||
|
||||
By("Uninstall velero", func() {
|
||||
Expect(VeleroUninstall(test.ctx, VeleroCfg.VeleroCLI, VeleroCfg.VeleroNamespace)).To(Succeed())
|
||||
Expect(VeleroUninstall(ctx, VeleroCfg.VeleroCLI, VeleroCfg.VeleroNamespace)).To(Succeed())
|
||||
})
|
||||
|
||||
By("Install velero", func() {
|
||||
veleroCfg := VeleroCfg
|
||||
veleroCfg.UseVolumeSnapshots = false
|
||||
Expect(VeleroInstall(test.ctx, &VeleroCfg)).To(Succeed())
|
||||
Expect(VeleroInstall(ctx, &VeleroCfg)).To(Succeed())
|
||||
})
|
||||
|
||||
By("Check all backups in object storage are synced to Velero", func() {
|
||||
@@ -121,14 +120,14 @@ func BackupsSyncTest() {
|
||||
|
||||
It("Deleted backups in object storage are synced to be deleted in Velero", func() {
|
||||
test.Init()
|
||||
defer test.ctxCancel()
|
||||
defer ctxCancel()
|
||||
By(fmt.Sprintf("Prepare workload as target to backup by creating namespace in %s namespace", test.testNS), func() {
|
||||
Expect(CreateNamespace(test.ctx, *VeleroCfg.ClientToInstallVelero, test.testNS)).To(Succeed(),
|
||||
Expect(CreateNamespace(ctx, *VeleroCfg.ClientToInstallVelero, test.testNS)).To(Succeed(),
|
||||
fmt.Sprintf("Failed to create %s namespace", test.testNS))
|
||||
})
|
||||
if !VeleroCfg.Debug {
|
||||
defer func() {
|
||||
Expect(DeleteNamespace(test.ctx, *VeleroCfg.ClientToInstallVelero, test.testNS, false)).To(Succeed(),
|
||||
Expect(DeleteNamespace(ctx, *VeleroCfg.ClientToInstallVelero, test.testNS, false)).To(Succeed(),
|
||||
fmt.Sprintf("Failed to delete the namespace %s", test.testNS))
|
||||
}()
|
||||
}
|
||||
@@ -139,7 +138,7 @@ func BackupsSyncTest() {
|
||||
BackupCfg.UseVolumeSnapshots = false
|
||||
BackupCfg.Selector = ""
|
||||
By(fmt.Sprintf("Backup the workload in %s namespace", test.testNS), func() {
|
||||
Expect(VeleroBackupNamespace(test.ctx, VeleroCfg.VeleroCLI,
|
||||
Expect(VeleroBackupNamespace(ctx, VeleroCfg.VeleroCLI,
|
||||
VeleroCfg.VeleroNamespace, BackupCfg)).To(Succeed(), func() string {
|
||||
RunDebug(context.Background(), VeleroCfg.VeleroCLI, VeleroCfg.VeleroNamespace, test.backupName, "")
|
||||
return "Fail to backup workload"
|
||||
@@ -159,11 +158,13 @@ func BackupsSyncTest() {
|
||||
})
|
||||
|
||||
By("Check if backups are deleted as a result of sync from BSL", func() {
|
||||
Expect(WaitBackupDeleted(test.ctx, VeleroCfg.VeleroCLI, test.backupName, time.Minute*10)).To(Succeed(), fmt.Sprintf("Failed to check backup %s deleted", test.backupName))
|
||||
Expect(WaitBackupDeleted(ctx, VeleroCfg.VeleroCLI, test.backupName, time.Minute*10)).To(Succeed(), fmt.Sprintf("Failed to check backup %s deleted", test.backupName))
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func (b *SyncBackups) IsBackupsSynced() error {
|
||||
return WaitForBackupToBeCreated(b.ctx, VeleroCfg.VeleroCLI, b.backupName, 10*time.Minute)
|
||||
ctx, ctxCancel := context.WithTimeout(context.Background(), 10*time.Minute)
|
||||
defer ctxCancel()
|
||||
return WaitForBackupToBeCreated(ctx, VeleroCfg.VeleroCLI, b.backupName, 10*time.Minute)
|
||||
}
|
||||
|
||||
+12
-14
@@ -42,8 +42,6 @@ type TTL struct {
|
||||
testNS string
|
||||
backupName string
|
||||
restoreName string
|
||||
ctx context.Context
|
||||
ctxCancel context.CancelFunc
|
||||
ttl time.Duration
|
||||
}
|
||||
|
||||
@@ -53,12 +51,13 @@ func (b *TTL) Init() {
|
||||
b.testNS = "backup-ttl-test-" + UUIDgen.String()
|
||||
b.backupName = "backup-ttl-test-" + UUIDgen.String()
|
||||
b.restoreName = "restore-ttl-test-" + UUIDgen.String()
|
||||
b.ctx, b.ctxCancel = context.WithTimeout(context.Background(), 2*time.Hour)
|
||||
b.ttl = 20 * time.Minute
|
||||
|
||||
}
|
||||
|
||||
func TTLTest() {
|
||||
ctx, contextCancel := context.WithCancel(context.Background())
|
||||
defer contextCancel()
|
||||
var err error
|
||||
var veleroCfg VeleroConfig
|
||||
useVolumeSnapshots := true
|
||||
@@ -88,20 +87,19 @@ func TTLTest() {
|
||||
if veleroCfg.InstallVelero {
|
||||
Expect(VeleroUninstall(context.Background(), veleroCfg.VeleroCLI, veleroCfg.VeleroNamespace)).To(Succeed())
|
||||
}
|
||||
Expect(DeleteNamespace(test.ctx, client, test.testNS, false)).To(Succeed(), fmt.Sprintf("Failed to delete the namespace %s", test.testNS))
|
||||
Expect(DeleteNamespace(ctx, client, test.testNS, false)).To(Succeed(), fmt.Sprintf("Failed to delete the namespace %s", test.testNS))
|
||||
}
|
||||
})
|
||||
|
||||
It("Backups in object storage should be synced to a new Velero successfully", func() {
|
||||
test.Init()
|
||||
defer test.ctxCancel()
|
||||
By(fmt.Sprintf("Prepare workload as target to backup by creating namespace %s namespace", test.testNS), func() {
|
||||
Expect(CreateNamespace(test.ctx, client, test.testNS)).To(Succeed(),
|
||||
Expect(CreateNamespace(ctx, client, test.testNS)).To(Succeed(),
|
||||
fmt.Sprintf("Failed to create %s namespace", test.testNS))
|
||||
})
|
||||
|
||||
By("Deploy sample workload of Kibishii", func() {
|
||||
Expect(KibishiiPrepareBeforeBackup(test.ctx, client, veleroCfg.CloudProvider,
|
||||
Expect(KibishiiPrepareBeforeBackup(ctx, client, veleroCfg.CloudProvider,
|
||||
test.testNS, veleroCfg.RegistryCredentialFile, veleroCfg.Features,
|
||||
veleroCfg.KibishiiDirectory, useVolumeSnapshots, DefaultKibishiiData)).To(Succeed())
|
||||
})
|
||||
@@ -115,7 +113,7 @@ func TTLTest() {
|
||||
BackupCfg.TTL = test.ttl
|
||||
|
||||
By(fmt.Sprintf("Backup the workload in %s namespace", test.testNS), func() {
|
||||
Expect(VeleroBackupNamespace(test.ctx, veleroCfg.VeleroCLI, veleroCfg.VeleroNamespace, BackupCfg)).To(Succeed(), func() string {
|
||||
Expect(VeleroBackupNamespace(ctx, veleroCfg.VeleroCLI, veleroCfg.VeleroNamespace, BackupCfg)).To(Succeed(), func() string {
|
||||
RunDebug(context.Background(), veleroCfg.VeleroCLI, veleroCfg.VeleroNamespace, test.backupName, "")
|
||||
return "Fail to backup workload"
|
||||
})
|
||||
@@ -126,7 +124,7 @@ func TTLTest() {
|
||||
if veleroCfg.CloudProvider == "vsphere" {
|
||||
// TODO - remove after upload progress monitoring is implemented
|
||||
By("Waiting for vSphere uploads to complete", func() {
|
||||
Expect(WaitForVSphereUploadCompletion(test.ctx, time.Hour,
|
||||
Expect(WaitForVSphereUploadCompletion(ctx, time.Hour,
|
||||
test.testNS, 2)).To(Succeed())
|
||||
})
|
||||
}
|
||||
@@ -139,7 +137,7 @@ func TTLTest() {
|
||||
}
|
||||
|
||||
By(fmt.Sprintf("Simulating a disaster by removing namespace %s\n", BackupCfg.BackupName), func() {
|
||||
Expect(DeleteNamespace(test.ctx, client, BackupCfg.BackupName, true)).To(Succeed(),
|
||||
Expect(DeleteNamespace(ctx, client, BackupCfg.BackupName, true)).To(Succeed(),
|
||||
fmt.Sprintf("Failed to delete namespace %s", BackupCfg.BackupName))
|
||||
})
|
||||
|
||||
@@ -149,9 +147,9 @@ func TTLTest() {
|
||||
}
|
||||
|
||||
By(fmt.Sprintf("Restore %s", test.testNS), func() {
|
||||
Expect(VeleroRestore(test.ctx, veleroCfg.VeleroCLI,
|
||||
Expect(VeleroRestore(ctx, veleroCfg.VeleroCLI,
|
||||
veleroCfg.VeleroNamespace, test.restoreName, test.backupName, "")).To(Succeed(), func() string {
|
||||
RunDebug(test.ctx, veleroCfg.VeleroCLI,
|
||||
RunDebug(ctx, veleroCfg.VeleroCLI,
|
||||
veleroCfg.VeleroNamespace, "", test.restoreName)
|
||||
return "Fail to restore workload"
|
||||
})
|
||||
@@ -166,7 +164,7 @@ func TTLTest() {
|
||||
})
|
||||
|
||||
By("Check TTL was set correctly", func() {
|
||||
ttl, err := GetBackupTTL(test.ctx, veleroCfg.VeleroNamespace, test.backupName)
|
||||
ttl, err := GetBackupTTL(ctx, veleroCfg.VeleroNamespace, test.backupName)
|
||||
Expect(err).NotTo(HaveOccurred(), "Fail to get Azure CSI snapshot checkpoint")
|
||||
t, _ := time.ParseDuration(strings.ReplaceAll(ttl, "'", ""))
|
||||
fmt.Println(t.Round(time.Minute).String())
|
||||
@@ -178,7 +176,7 @@ func TTLTest() {
|
||||
})
|
||||
|
||||
By("Check if backups are deleted by GC", func() {
|
||||
Expect(WaitBackupDeleted(test.ctx, veleroCfg.VeleroCLI, test.backupName, time.Minute*10)).To(Succeed(), fmt.Sprintf("Backup %s was not deleted by GC", test.backupName))
|
||||
Expect(WaitBackupDeleted(ctx, veleroCfg.VeleroCLI, test.backupName, time.Minute*10)).To(Succeed(), fmt.Sprintf("Backup %s was not deleted by GC", test.backupName))
|
||||
})
|
||||
|
||||
By("Backup file from cloud object storage should be deleted", func() {
|
||||
|
||||
@@ -82,15 +82,15 @@ func (n *NamespaceMapping) StartRun() error {
|
||||
return nil
|
||||
}
|
||||
func (n *NamespaceMapping) CreateResources() error {
|
||||
n.Ctx, _ = context.WithTimeout(context.Background(), 60*time.Minute)
|
||||
|
||||
ctx, ctxCancel := context.WithTimeout(context.Background(), 60*time.Minute)
|
||||
defer ctxCancel()
|
||||
for index, ns := range *n.NSIncluded {
|
||||
n.kibishiiData.Levels = len(*n.NSIncluded) + index
|
||||
By(fmt.Sprintf("Creating namespaces ...%s\n", ns), func() {
|
||||
Expect(CreateNamespace(n.Ctx, n.Client, ns)).To(Succeed(), fmt.Sprintf("Failed to create namespace %s", ns))
|
||||
Expect(CreateNamespace(ctx, n.Client, ns)).To(Succeed(), fmt.Sprintf("Failed to create namespace %s", ns))
|
||||
})
|
||||
By("Deploy sample workload of Kibishii", func() {
|
||||
Expect(KibishiiPrepareBeforeBackup(n.Ctx, n.Client, VeleroCfg.CloudProvider,
|
||||
Expect(KibishiiPrepareBeforeBackup(ctx, n.Client, VeleroCfg.CloudProvider,
|
||||
ns, VeleroCfg.RegistryCredentialFile, VeleroCfg.Features,
|
||||
VeleroCfg.KibishiiDirectory, false, n.kibishiiData)).To(Succeed())
|
||||
})
|
||||
@@ -99,17 +99,18 @@ func (n *NamespaceMapping) CreateResources() error {
|
||||
}
|
||||
|
||||
func (n *NamespaceMapping) Verify() error {
|
||||
n.Ctx, _ = context.WithTimeout(context.Background(), 60*time.Minute)
|
||||
ctx, ctxCancel := context.WithTimeout(context.Background(), 60*time.Minute)
|
||||
defer ctxCancel()
|
||||
for index, ns := range n.MappedNamespaceList {
|
||||
n.kibishiiData.Levels = len(*n.NSIncluded) + index
|
||||
By(fmt.Sprintf("Verify workload %s after restore ", ns), func() {
|
||||
Expect(KibishiiVerifyAfterRestore(n.Client, ns,
|
||||
n.Ctx, n.kibishiiData)).To(Succeed(), "Fail to verify workload after restore")
|
||||
ctx, n.kibishiiData)).To(Succeed(), "Fail to verify workload after restore")
|
||||
})
|
||||
}
|
||||
for _, ns := range *n.NSIncluded {
|
||||
By(fmt.Sprintf("Verify namespace %s for backup is no longer exist after restore with namespace mapping", ns), func() {
|
||||
Expect(NamespaceShouldNotExist(n.Ctx, n.Client, ns)).To(Succeed())
|
||||
Expect(NamespaceShouldNotExist(ctx, n.Client, ns)).To(Succeed())
|
||||
})
|
||||
}
|
||||
return nil
|
||||
|
||||
+22
-17
@@ -63,35 +63,38 @@ func (n *NodePort) StartRun() error {
|
||||
return nil
|
||||
}
|
||||
func (n *NodePort) CreateResources() error {
|
||||
n.Ctx, _ = context.WithTimeout(context.Background(), 60*time.Minute)
|
||||
ctx, ctxCancel := context.WithTimeout(context.Background(), 60*time.Minute)
|
||||
defer ctxCancel()
|
||||
|
||||
By(fmt.Sprintf("Creating service %s in namespaces %s ......\n", n.serviceName, n.namespace), func() {
|
||||
Expect(CreateNamespace(n.Ctx, n.Client, n.namespace)).To(Succeed(), fmt.Sprintf("Failed to create namespace %s", n.namespace))
|
||||
Expect(createServiceWithNodeport(n.Ctx, n.Client, n.namespace, n.serviceName, n.labels, 0)).To(Succeed(), fmt.Sprintf("Failed to create service %s", n.serviceName))
|
||||
service, err := GetService(n.Ctx, n.Client, n.namespace, n.serviceName)
|
||||
Expect(CreateNamespace(ctx, n.Client, n.namespace)).To(Succeed(), fmt.Sprintf("Failed to create namespace %s", n.namespace))
|
||||
Expect(createServiceWithNodeport(ctx, n.Client, n.namespace, n.serviceName, n.labels, 0)).To(Succeed(), fmt.Sprintf("Failed to create service %s", n.serviceName))
|
||||
service, err := GetService(ctx, n.Client, n.namespace, n.serviceName)
|
||||
Expect(err).To(Succeed())
|
||||
Expect(len(service.Spec.Ports)).To(Equal(1))
|
||||
n.nodePort = service.Spec.Ports[0].NodePort
|
||||
_, err = GetAllService(n.Ctx)
|
||||
_, err = GetAllService(ctx)
|
||||
Expect(err).To(Succeed(), "fail to get service")
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
func (n *NodePort) Destroy() error {
|
||||
ctx, ctxCancel := context.WithTimeout(context.Background(), 60*time.Minute)
|
||||
defer ctxCancel()
|
||||
By(fmt.Sprintf("Start to destroy namespace %s......", n.NSBaseName), func() {
|
||||
Expect(CleanupNamespacesWithPoll(n.Ctx, n.Client, NodeportBaseName)).To(Succeed(),
|
||||
Expect(CleanupNamespacesWithPoll(ctx, n.Client, NodeportBaseName)).To(Succeed(),
|
||||
fmt.Sprintf("Failed to delete namespace %s", n.NSBaseName))
|
||||
Expect(WaitForServiceDelete(n.Client, n.namespace, n.serviceName, false)).To(Succeed(), "fail to delete service")
|
||||
_, err := GetAllService(n.Ctx)
|
||||
_, err := GetAllService(ctx)
|
||||
Expect(err).To(Succeed(), "fail to get service")
|
||||
})
|
||||
|
||||
n.namespaceToCollision = NodeportBaseName + "tmp"
|
||||
By(fmt.Sprintf("Creating a new service which has the same nodeport as backed up service has in a new namespaces for nodeport collision ...%s\n", n.namespaceToCollision), func() {
|
||||
Expect(CreateNamespace(n.Ctx, n.Client, n.namespaceToCollision)).To(Succeed(), fmt.Sprintf("Failed to create namespace %s", n.namespaceToCollision))
|
||||
Expect(createServiceWithNodeport(n.Ctx, n.Client, n.namespaceToCollision, n.serviceName, n.labels, n.nodePort)).To(Succeed(), fmt.Sprintf("Failed to create service %s", n.serviceName))
|
||||
_, err := GetAllService(n.Ctx)
|
||||
Expect(CreateNamespace(ctx, n.Client, n.namespaceToCollision)).To(Succeed(), fmt.Sprintf("Failed to create namespace %s", n.namespaceToCollision))
|
||||
Expect(createServiceWithNodeport(ctx, n.Client, n.namespaceToCollision, n.serviceName, n.labels, n.nodePort)).To(Succeed(), fmt.Sprintf("Failed to create service %s", n.serviceName))
|
||||
_, err := GetAllService(ctx)
|
||||
Expect(err).To(Succeed(), "fail to get service")
|
||||
})
|
||||
|
||||
@@ -99,6 +102,8 @@ func (n *NodePort) Destroy() error {
|
||||
}
|
||||
|
||||
func (n *NodePort) Restore() error {
|
||||
ctx, ctxCancel := context.WithTimeout(context.Background(), 60*time.Minute)
|
||||
defer ctxCancel()
|
||||
index := 4
|
||||
restoreName1 := n.RestoreName + "-1"
|
||||
restoreName2 := restoreName1 + "-1"
|
||||
@@ -107,7 +112,7 @@ func (n *NodePort) Restore() error {
|
||||
args = append(args[:index], append([]string{n.RestoreName}, args[index:]...)...)
|
||||
args = append(args, "--preserve-nodeports=true")
|
||||
By(fmt.Sprintf("Start to restore %s with nodeports preservation when port %d is already occupied by other service", n.RestoreName, n.nodePort), func() {
|
||||
Expect(VeleroRestoreExec(n.Ctx, n.VeleroCfg.VeleroCLI,
|
||||
Expect(VeleroRestoreExec(ctx, n.VeleroCfg.VeleroCLI,
|
||||
n.VeleroCfg.VeleroNamespace, n.RestoreName,
|
||||
args, velerov1api.RestorePhasePartiallyFailed)).To(
|
||||
Succeed(),
|
||||
@@ -122,7 +127,7 @@ func (n *NodePort) Restore() error {
|
||||
args = append(args[:index], append([]string{restoreName1}, args[index:]...)...)
|
||||
args = append(args, "--preserve-nodeports=false")
|
||||
By(fmt.Sprintf("Start to restore %s without nodeports preservation ......", restoreName1), func() {
|
||||
Expect(VeleroRestoreExec(n.Ctx, n.VeleroCfg.VeleroCLI, n.VeleroCfg.VeleroNamespace,
|
||||
Expect(VeleroRestoreExec(ctx, n.VeleroCfg.VeleroCLI, n.VeleroCfg.VeleroNamespace,
|
||||
restoreName1, args, velerov1api.RestorePhaseCompleted)).To(Succeed(), func() string {
|
||||
RunDebug(context.Background(), n.VeleroCfg.VeleroCLI, n.VeleroCfg.VeleroNamespace, "", restoreName1)
|
||||
return "Fail to restore workload"
|
||||
@@ -130,16 +135,16 @@ func (n *NodePort) Restore() error {
|
||||
})
|
||||
|
||||
By(fmt.Sprintf("Delete service %s by deleting namespace %s", n.serviceName, n.namespace), func() {
|
||||
service, err := GetService(n.Ctx, n.Client, n.namespace, n.serviceName)
|
||||
service, err := GetService(ctx, n.Client, n.namespace, n.serviceName)
|
||||
Expect(err).To(Succeed())
|
||||
Expect(len(service.Spec.Ports)).To(Equal(1))
|
||||
fmt.Println(service.Spec.Ports)
|
||||
Expect(DeleteNamespace(n.Ctx, n.Client, n.namespace, true)).To(Succeed())
|
||||
Expect(DeleteNamespace(ctx, n.Client, n.namespace, true)).To(Succeed())
|
||||
})
|
||||
|
||||
By(fmt.Sprintf("Start to delete service %s in namespace %s ......", n.serviceName, n.namespaceToCollision), func() {
|
||||
Expect(WaitForServiceDelete(n.Client, n.namespaceToCollision, n.serviceName, true)).To(Succeed(), "fail to delete service")
|
||||
_, err := GetAllService(n.Ctx)
|
||||
_, err := GetAllService(ctx)
|
||||
Expect(err).To(Succeed(), "fail to get service")
|
||||
})
|
||||
|
||||
@@ -147,7 +152,7 @@ func (n *NodePort) Restore() error {
|
||||
args = append(args[:index], append([]string{restoreName2}, args[index:]...)...)
|
||||
args = append(args, "--preserve-nodeports=true")
|
||||
By(fmt.Sprintf("Start to restore %s with nodeports preservation ......", restoreName2), func() {
|
||||
Expect(VeleroRestoreExec(n.Ctx, n.VeleroCfg.VeleroCLI, n.VeleroCfg.VeleroNamespace,
|
||||
Expect(VeleroRestoreExec(ctx, n.VeleroCfg.VeleroCLI, n.VeleroCfg.VeleroNamespace,
|
||||
restoreName2, args, velerov1api.RestorePhaseCompleted)).To(Succeed(), func() string {
|
||||
RunDebug(context.Background(), n.VeleroCfg.VeleroCLI, n.VeleroCfg.VeleroNamespace, "", restoreName2)
|
||||
return "Fail to restore workload"
|
||||
@@ -155,7 +160,7 @@ func (n *NodePort) Restore() error {
|
||||
})
|
||||
|
||||
By(fmt.Sprintf("Verify service %s was restore successfully with the origin nodeport.", n.namespace), func() {
|
||||
service, err := GetService(n.Ctx, n.Client, n.namespace, n.serviceName)
|
||||
service, err := GetService(ctx, n.Client, n.namespace, n.serviceName)
|
||||
Expect(err).To(Succeed())
|
||||
Expect(len(service.Spec.Ports)).To(Equal(1))
|
||||
Expect(service.Spec.Ports[0].NodePort).To(Equal(n.nodePort))
|
||||
|
||||
@@ -74,7 +74,6 @@ func (p *PVCSelectedNodeChanging) StartRun() error {
|
||||
return nil
|
||||
}
|
||||
func (p *PVCSelectedNodeChanging) CreateResources() error {
|
||||
p.Ctx, _ = context.WithTimeout(context.Background(), 60*time.Minute)
|
||||
By(fmt.Sprintf("Create namespace %s", p.namespace), func() {
|
||||
Expect(CreateNamespace(context.Background(), p.Client, p.namespace)).To(Succeed(),
|
||||
fmt.Sprintf("Failed to create namespace %s", p.namespace))
|
||||
@@ -125,8 +124,10 @@ func (p *PVCSelectedNodeChanging) Destroy() error {
|
||||
}
|
||||
|
||||
func (p *PVCSelectedNodeChanging) Restore() error {
|
||||
ctx, ctxCancel := context.WithTimeout(context.Background(), 60*time.Minute)
|
||||
defer ctxCancel()
|
||||
By(fmt.Sprintf("Start to restore %s .....", p.RestoreName), func() {
|
||||
Expect(VeleroRestoreExec(context.Background(), p.VeleroCfg.VeleroCLI,
|
||||
Expect(VeleroRestoreExec(ctx, p.VeleroCfg.VeleroCLI,
|
||||
p.VeleroCfg.VeleroNamespace, p.RestoreName,
|
||||
p.RestoreArgs, velerov1api.RestorePhaseCompleted)).To(
|
||||
Succeed(),
|
||||
@@ -135,7 +136,7 @@ func (p *PVCSelectedNodeChanging) Restore() error {
|
||||
p.VeleroCfg.VeleroNamespace, "", p.RestoreName)
|
||||
return "Fail to restore workload"
|
||||
})
|
||||
err := WaitForPods(p.Ctx, p.Client, p.mappedNS, []string{p.podName})
|
||||
err := WaitForPods(ctx, p.Client, p.mappedNS, []string{p.podName})
|
||||
Expect(err).To(Succeed())
|
||||
})
|
||||
return nil
|
||||
|
||||
@@ -93,14 +93,15 @@ func (m *MultiNSBackup) StartRun() error {
|
||||
}
|
||||
|
||||
func (m *MultiNSBackup) CreateResources() error {
|
||||
m.Ctx, _ = context.WithTimeout(context.Background(), m.TimeoutDuration)
|
||||
ctx, ctxCancel := context.WithTimeout(context.Background(), 60*time.Minute)
|
||||
defer ctxCancel()
|
||||
fmt.Printf("Creating namespaces ...\n")
|
||||
labels := map[string]string{
|
||||
"ns-test": "true",
|
||||
}
|
||||
for nsNum := 0; nsNum < m.NamespacesTotal; nsNum++ {
|
||||
createNSName := fmt.Sprintf("%s-%00000d", m.NSBaseName, nsNum)
|
||||
if err := CreateNamespaceWithLabel(m.Ctx, m.Client, createNSName, labels); err != nil {
|
||||
if err := CreateNamespaceWithLabel(ctx, m.Client, createNSName, labels); err != nil {
|
||||
return errors.Wrapf(err, "Failed to create namespace %s", createNSName)
|
||||
}
|
||||
}
|
||||
@@ -108,10 +109,12 @@ func (m *MultiNSBackup) CreateResources() error {
|
||||
}
|
||||
|
||||
func (m *MultiNSBackup) Verify() error {
|
||||
ctx, ctxCancel := context.WithTimeout(context.Background(), m.TimeoutDuration)
|
||||
defer ctxCancel()
|
||||
// Verify that we got back all of the namespaces we created
|
||||
for nsNum := 0; nsNum < m.NamespacesTotal; nsNum++ {
|
||||
checkNSName := fmt.Sprintf("%s-%00000d", m.NSBaseName, nsNum)
|
||||
checkNS, err := GetNamespace(m.Ctx, m.Client, checkNSName)
|
||||
checkNS, err := GetNamespace(ctx, m.Client, checkNSName)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "Could not retrieve test namespace %s", checkNSName)
|
||||
} else if checkNS.Name != checkNSName {
|
||||
@@ -122,10 +125,11 @@ 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)
|
||||
ctx, ctxCancel := context.WithTimeout(context.Background(), 60*time.Minute)
|
||||
defer ctxCancel()
|
||||
err := CleanupNamespaces(ctx, m.Client, m.NSBaseName)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "Could cleanup retrieve namespaces")
|
||||
}
|
||||
return WaitAllSelectedNSDeleted(m.Ctx, m.Client, "ns-test=true")
|
||||
return WaitAllSelectedNSDeleted(ctx, m.Client, "ns-test=true")
|
||||
}
|
||||
|
||||
@@ -68,11 +68,12 @@ func (n *NSAnnotationCase) Init() error {
|
||||
}
|
||||
|
||||
func (n *NSAnnotationCase) CreateResources() error {
|
||||
n.Ctx, _ = context.WithTimeout(context.Background(), 10*time.Minute)
|
||||
ctx, ctxCancel := context.WithTimeout(context.Background(), 60*time.Minute)
|
||||
defer ctxCancel()
|
||||
for nsNum := 0; nsNum < n.NamespacesTotal; nsNum++ {
|
||||
createNSName := fmt.Sprintf("%s-%00000d", n.NSBaseName, nsNum)
|
||||
createAnnotationName := fmt.Sprintf("annotation-%s-%00000d", n.NSBaseName, nsNum)
|
||||
if err := CreateNamespaceWithAnnotation(n.Ctx, n.Client, createNSName, map[string]string{"testAnnotation": createAnnotationName}); err != nil {
|
||||
if err := CreateNamespaceWithAnnotation(ctx, n.Client, createNSName, map[string]string{"testAnnotation": createAnnotationName}); err != nil {
|
||||
return errors.Wrapf(err, "Failed to create namespace %s", createNSName)
|
||||
}
|
||||
}
|
||||
@@ -80,10 +81,12 @@ func (n *NSAnnotationCase) CreateResources() error {
|
||||
}
|
||||
|
||||
func (n *NSAnnotationCase) Verify() error {
|
||||
ctx, ctxCancel := context.WithTimeout(context.Background(), 60*time.Minute)
|
||||
defer ctxCancel()
|
||||
for nsNum := 0; nsNum < n.NamespacesTotal; nsNum++ {
|
||||
checkNSName := fmt.Sprintf("%s-%00000d", n.NSBaseName, nsNum)
|
||||
checkAnnoName := fmt.Sprintf("annotation-%s-%00000d", n.NSBaseName, nsNum)
|
||||
checkNS, err := GetNamespace(n.Ctx, n.Client, checkNSName)
|
||||
checkNS, err := GetNamespace(ctx, n.Client, checkNSName)
|
||||
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "Could not retrieve test namespace %s", checkNSName)
|
||||
|
||||
@@ -84,21 +84,22 @@ func (r *RBACCase) Init() error {
|
||||
}
|
||||
|
||||
func (r *RBACCase) CreateResources() error {
|
||||
r.Ctx, _ = context.WithTimeout(context.Background(), 10*time.Minute)
|
||||
ctx, ctxCancel := context.WithTimeout(context.Background(), 10*time.Minute)
|
||||
defer ctxCancel()
|
||||
for nsNum := 0; nsNum < r.NamespacesTotal; nsNum++ {
|
||||
createNSName := fmt.Sprintf("%s-%00000d", r.NSBaseName, nsNum)
|
||||
fmt.Printf("Creating namespaces ...%s\n", createNSName)
|
||||
if err := CreateNamespace(r.Ctx, r.Client, createNSName); err != nil {
|
||||
if err := CreateNamespace(ctx, r.Client, createNSName); err != nil {
|
||||
return errors.Wrapf(err, "Failed to create namespace %s", createNSName)
|
||||
}
|
||||
serviceAccountName := fmt.Sprintf("service-account-%s-%00000d", r.NSBaseName, nsNum)
|
||||
fmt.Printf("Creating service account ...%s\n", createNSName)
|
||||
if err := CreateServiceAccount(r.Ctx, r.Client, createNSName, serviceAccountName); err != nil {
|
||||
if err := CreateServiceAccount(ctx, r.Client, createNSName, serviceAccountName); err != nil {
|
||||
return errors.Wrapf(err, "Failed to create service account %s", serviceAccountName)
|
||||
}
|
||||
clusterRoleName := fmt.Sprintf("clusterrole-%s-%00000d", r.NSBaseName, nsNum)
|
||||
clusterRoleBindingName := fmt.Sprintf("clusterrolebinding-%s-%00000d", r.NSBaseName, nsNum)
|
||||
if err := CreateRBACWithBindingSA(r.Ctx, r.Client, createNSName, serviceAccountName, clusterRoleName, clusterRoleBindingName); err != nil {
|
||||
if err := CreateRBACWithBindingSA(ctx, r.Client, createNSName, serviceAccountName, clusterRoleName, clusterRoleBindingName); err != nil {
|
||||
return errors.Wrapf(err, "Failed to create cluster role %s with role binding %s", clusterRoleName, clusterRoleBindingName)
|
||||
}
|
||||
}
|
||||
@@ -106,13 +107,14 @@ func (r *RBACCase) CreateResources() error {
|
||||
}
|
||||
|
||||
func (r *RBACCase) Verify() error {
|
||||
ctx, ctxCancel := context.WithTimeout(context.Background(), 10*time.Minute)
|
||||
defer ctxCancel()
|
||||
for nsNum := 0; nsNum < r.NamespacesTotal; nsNum++ {
|
||||
checkNSName := fmt.Sprintf("%s-%00000d", r.NSBaseName, nsNum)
|
||||
checkServiceAccountName := fmt.Sprintf("service-account-%s-%00000d", r.NSBaseName, nsNum)
|
||||
checkClusterRoleName := fmt.Sprintf("clusterrole-%s-%00000d", r.NSBaseName, nsNum)
|
||||
checkClusterRoleBindingName := fmt.Sprintf("clusterrolebinding-%s-%00000d", r.NSBaseName, nsNum)
|
||||
|
||||
checkNS, err := GetNamespace(r.Ctx, r.Client, checkNSName)
|
||||
checkNS, err := GetNamespace(ctx, r.Client, checkNSName)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "Could not retrieve test namespace %s", checkNSName)
|
||||
}
|
||||
@@ -121,7 +123,7 @@ func (r *RBACCase) Verify() error {
|
||||
}
|
||||
|
||||
//getting service account from the restore
|
||||
checkSA, err := GetServiceAccount(r.Ctx, r.Client, checkNSName, checkServiceAccountName)
|
||||
checkSA, err := GetServiceAccount(ctx, r.Client, checkNSName, checkServiceAccountName)
|
||||
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "Could not retrieve test service account %s", checkSA)
|
||||
@@ -132,7 +134,7 @@ func (r *RBACCase) Verify() error {
|
||||
}
|
||||
|
||||
//getting cluster role from the restore
|
||||
checkClusterRole, err := GetClusterRole(r.Ctx, r.Client, checkClusterRoleName)
|
||||
checkClusterRole, err := GetClusterRole(ctx, r.Client, checkClusterRoleName)
|
||||
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "Could not retrieve test cluster role %s", checkClusterRole)
|
||||
@@ -143,7 +145,7 @@ func (r *RBACCase) Verify() error {
|
||||
}
|
||||
|
||||
//getting cluster role binding from the restore
|
||||
checkClusterRoleBinding, err := GetClusterRoleBinding(r.Ctx, r.Client, checkClusterRoleBindingName)
|
||||
checkClusterRoleBinding, err := GetClusterRoleBinding(ctx, r.Client, checkClusterRoleBindingName)
|
||||
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "Could not retrieve test cluster role binding %s", checkClusterRoleBinding)
|
||||
@@ -164,19 +166,21 @@ func (r *RBACCase) Verify() error {
|
||||
}
|
||||
|
||||
func (r *RBACCase) Destroy() error {
|
||||
ctx, ctxCancel := context.WithTimeout(context.Background(), 10*time.Minute)
|
||||
defer ctxCancel()
|
||||
//cleanup clusterrole
|
||||
err := CleanupClusterRole(r.Ctx, r.Client, r.NSBaseName)
|
||||
err := CleanupClusterRole(ctx, r.Client, r.NSBaseName)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "Could not cleanup clusterroles")
|
||||
}
|
||||
|
||||
//cleanup cluster rolebinding
|
||||
err = CleanupClusterRoleBinding(r.Ctx, r.Client, r.NSBaseName)
|
||||
err = CleanupClusterRoleBinding(ctx, r.Client, r.NSBaseName)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "Could not cleanup clusterrolebindings")
|
||||
}
|
||||
|
||||
err = CleanupNamespacesWithPoll(r.Ctx, r.Client, r.NSBaseName)
|
||||
err = CleanupNamespacesWithPoll(ctx, r.Client, r.NSBaseName)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "Could cleanup retrieve namespaces")
|
||||
}
|
||||
|
||||
@@ -74,13 +74,14 @@ func (s *StorageClasssChanging) StartRun() error {
|
||||
return nil
|
||||
}
|
||||
func (s *StorageClasssChanging) CreateResources() error {
|
||||
s.Ctx, _ = context.WithTimeout(context.Background(), 60*time.Minute)
|
||||
ctx, ctxCancel := context.WithTimeout(context.Background(), 10*time.Minute)
|
||||
defer ctxCancel()
|
||||
By(fmt.Sprintf("Create a storage class %s", s.desStorageClass), func() {
|
||||
Expect(InstallStorageClass(context.Background(), fmt.Sprintf("testdata/storage-class/%s.yaml",
|
||||
s.VeleroCfg.CloudProvider))).To(Succeed())
|
||||
})
|
||||
By(fmt.Sprintf("Create namespace %s", s.namespace), func() {
|
||||
Expect(CreateNamespace(s.Ctx, s.Client, s.namespace)).To(Succeed(),
|
||||
Expect(CreateNamespace(ctx, s.Client, s.namespace)).To(Succeed(),
|
||||
fmt.Sprintf("Failed to create namespace %s", s.namespace))
|
||||
})
|
||||
|
||||
@@ -96,10 +97,12 @@ func (s *StorageClasssChanging) CreateResources() error {
|
||||
}
|
||||
|
||||
func (s *StorageClasssChanging) Destroy() error {
|
||||
ctx, ctxCancel := context.WithTimeout(context.Background(), 10*time.Minute)
|
||||
defer ctxCancel()
|
||||
By(fmt.Sprintf("Expect storage class of PV %s to be %s ", s.volume, s.srcStorageClass), func() {
|
||||
pvName, err := GetPVByPodName(s.Client, s.namespace, s.volume)
|
||||
Expect(err).To(Succeed(), fmt.Sprintf("Failed to get PV name by pod name %s", s.podName))
|
||||
pv, err := GetPersistentVolume(s.Ctx, s.Client, s.namespace, pvName)
|
||||
pv, err := GetPersistentVolume(ctx, s.Client, s.namespace, pvName)
|
||||
Expect(err).To(Succeed(), fmt.Sprintf("Failed to get PV by pod name %s", s.podName))
|
||||
fmt.Println(pv)
|
||||
Expect(pv.Spec.StorageClassName).To(Equal(s.srcStorageClass),
|
||||
@@ -107,15 +110,17 @@ func (s *StorageClasssChanging) Destroy() error {
|
||||
})
|
||||
|
||||
By(fmt.Sprintf("Start to destroy namespace %s......", s.NSBaseName), func() {
|
||||
Expect(CleanupNamespacesWithPoll(s.Ctx, s.Client, s.NSBaseName)).To(Succeed(),
|
||||
Expect(CleanupNamespacesWithPoll(ctx, s.Client, s.NSBaseName)).To(Succeed(),
|
||||
fmt.Sprintf("Failed to delete namespace %s", s.NSBaseName))
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *StorageClasssChanging) Restore() error {
|
||||
ctx, ctxCancel := context.WithTimeout(context.Background(), 10*time.Minute)
|
||||
defer ctxCancel()
|
||||
By(fmt.Sprintf("Start to restore %s .....", s.RestoreName), func() {
|
||||
Expect(VeleroRestoreExec(s.Ctx, s.VeleroCfg.VeleroCLI,
|
||||
Expect(VeleroRestoreExec(ctx, s.VeleroCfg.VeleroCLI,
|
||||
s.VeleroCfg.VeleroNamespace, s.RestoreName,
|
||||
s.RestoreArgs, velerov1api.RestorePhaseCompleted)).To(
|
||||
Succeed(),
|
||||
@@ -128,11 +133,13 @@ func (s *StorageClasssChanging) Restore() error {
|
||||
return nil
|
||||
}
|
||||
func (s *StorageClasssChanging) Verify() error {
|
||||
ctx, ctxCancel := context.WithTimeout(context.Background(), 10*time.Minute)
|
||||
defer ctxCancel()
|
||||
By(fmt.Sprintf("Expect storage class of PV %s to be %s ", s.volume, s.desStorageClass), func() {
|
||||
time.Sleep(1 * time.Minute)
|
||||
pvName, err := GetPVByPodName(s.Client, s.mappedNS, s.volume)
|
||||
Expect(err).To(Succeed(), fmt.Sprintf("Failed to get PV name by pod name %s", s.podName))
|
||||
pv, err := GetPersistentVolume(s.Ctx, s.Client, s.mappedNS, pvName)
|
||||
pv, err := GetPersistentVolume(ctx, s.Client, s.mappedNS, pvName)
|
||||
Expect(err).To(Succeed(), fmt.Sprintf("Failed to get PV by pod name %s", s.podName))
|
||||
fmt.Println(pv)
|
||||
Expect(pv.Spec.StorageClassName).To(Equal(s.desStorageClass),
|
||||
|
||||
@@ -96,6 +96,8 @@ func BslDeletionTest(useVolumeSnapshots bool) {
|
||||
|
||||
When("kibishii is the sample workload", func() {
|
||||
It("Local backups and restic repos (if Velero was installed with Restic) will be deleted once the corresponding backup storage location is deleted", func() {
|
||||
oneHourTimeout, ctxCancel := context.WithTimeout(context.Background(), time.Minute*60)
|
||||
defer ctxCancel()
|
||||
if veleroCfg.AdditionalBSLProvider == "" {
|
||||
Skip("no additional BSL provider given, not running multiple BackupStorageLocation with unique credentials tests")
|
||||
}
|
||||
@@ -141,8 +143,6 @@ func BslDeletionTest(useVolumeSnapshots bool) {
|
||||
|
||||
backupName_1 := "backup1-" + UUIDgen.String()
|
||||
backupName_2 := "backup2-" + UUIDgen.String()
|
||||
oneHourTimeout, _ := context.WithTimeout(context.Background(), time.Minute*60)
|
||||
|
||||
backupLocation_1 := "default"
|
||||
backupLocation_2 := additionalBsl
|
||||
podName_1 := "kibishii-deployment-0"
|
||||
|
||||
@@ -97,13 +97,13 @@ func MigrationTest(useVolumeSnapshots bool, veleroCLI2Version VeleroCLI2Version)
|
||||
})
|
||||
When("kibishii is the sample workload", func() {
|
||||
It("should be successfully backed up and restored to the default BackupStorageLocation", func() {
|
||||
oneHourTimeout, ctxCancel := context.WithTimeout(context.Background(), time.Minute*60)
|
||||
defer ctxCancel()
|
||||
flag.Parse()
|
||||
UUIDgen, err = uuid.NewRandom()
|
||||
Expect(err).To(Succeed())
|
||||
supportUploaderType, err := IsSupportUploaderType(veleroCLI2Version.VeleroVersion)
|
||||
Expect(err).To(Succeed())
|
||||
oneHourTimeout, _ := context.WithTimeout(context.Background(), time.Minute*60)
|
||||
|
||||
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
|
||||
|
||||
@@ -57,8 +57,9 @@ func SSRTest() {
|
||||
})
|
||||
|
||||
It(fmt.Sprintf("Should create an ssr object in the %s namespace and later removed by controller", veleroCfg.VeleroNamespace), func() {
|
||||
ctx, ctxCancel := context.WithTimeout(context.Background(), time.Duration(time.Minute*10))
|
||||
defer ctxCancel()
|
||||
defer DeleteNamespace(context.TODO(), *veleroCfg.ClientToInstallVelero, testNS, false)
|
||||
ctx, _ := context.WithTimeout(context.Background(), time.Duration(time.Minute*10))
|
||||
By(fmt.Sprintf("Create %s namespace", testNS))
|
||||
Expect(CreateNamespace(ctx, *veleroCfg.ClientToInstallVelero, testNS)).To(Succeed(),
|
||||
fmt.Sprintf("Failed to create %s namespace", testNS))
|
||||
|
||||
@@ -31,7 +31,6 @@ var OptInPVBackupTest func() = TestFunc(&PVBackupFiltering{annotation: OPT_IN_AN
|
||||
var OptOutPVBackupTest func() = TestFunc(&PVBackupFiltering{annotation: OPT_OUT_ANN, id: "opt-out"})
|
||||
|
||||
func (p *PVBackupFiltering) Init() error {
|
||||
p.Ctx, _ = context.WithTimeout(context.Background(), 60*time.Minute)
|
||||
p.VeleroCfg = VeleroCfg
|
||||
p.Client = *p.VeleroCfg.ClientToInstallVelero
|
||||
p.VeleroCfg.UseVolumeSnapshots = false
|
||||
@@ -48,7 +47,9 @@ func (p *PVBackupFiltering) Init() error {
|
||||
}
|
||||
|
||||
func (p *PVBackupFiltering) StartRun() error {
|
||||
err := InstallStorageClass(p.Ctx, fmt.Sprintf("testdata/storage-class/%s.yaml", VeleroCfg.CloudProvider))
|
||||
ctx, ctxCancel := context.WithTimeout(context.Background(), 10*time.Minute)
|
||||
defer ctxCancel()
|
||||
err := InstallStorageClass(ctx, fmt.Sprintf("testdata/storage-class/%s.yaml", VeleroCfg.CloudProvider))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -72,9 +73,11 @@ func (p *PVBackupFiltering) StartRun() error {
|
||||
return nil
|
||||
}
|
||||
func (p *PVBackupFiltering) CreateResources() error {
|
||||
ctx, ctxCancel := context.WithTimeout(context.Background(), 10*time.Minute)
|
||||
defer ctxCancel()
|
||||
for _, ns := range *p.NSIncluded {
|
||||
By(fmt.Sprintf("Create namespaces %s for workload\n", ns), func() {
|
||||
Expect(CreateNamespace(p.Ctx, p.Client, ns)).To(Succeed(), fmt.Sprintf("Failed to create namespace %s", ns))
|
||||
Expect(CreateNamespace(ctx, p.Client, ns)).To(Succeed(), fmt.Sprintf("Failed to create namespace %s", ns))
|
||||
})
|
||||
var pods []string
|
||||
By(fmt.Sprintf("Deploy a few pods with several PVs in namespace %s", ns), func() {
|
||||
@@ -102,7 +105,7 @@ func (p *PVBackupFiltering) CreateResources() error {
|
||||
p.annotation: volumesToAnnotation,
|
||||
}
|
||||
By(fmt.Sprintf("Add annotation to pod %s of namespace %s", pod.Name, ns), func() {
|
||||
_, err := AddAnnotationToPod(p.Ctx, p.Client, ns, pod.Name, ann)
|
||||
_, err := AddAnnotationToPod(ctx, p.Client, ns, pod.Name, ann)
|
||||
Expect(err).To(Succeed())
|
||||
})
|
||||
})
|
||||
@@ -113,17 +116,17 @@ func (p *PVBackupFiltering) CreateResources() error {
|
||||
By(fmt.Sprintf("Waiting for all pods to start %s\n", p.podsList), func() {
|
||||
for index, ns := range *p.NSIncluded {
|
||||
By(fmt.Sprintf("Waiting for all pods to start %d in namespace %s", index, ns), func() {
|
||||
WaitForPods(p.Ctx, p.Client, ns, p.podsList[index])
|
||||
WaitForPods(ctx, p.Client, ns, p.podsList[index])
|
||||
})
|
||||
}
|
||||
})
|
||||
By(fmt.Sprintf("Populate all pods %s with file %s", p.podsList, FILE_NAME), func() {
|
||||
for index, ns := range *p.NSIncluded {
|
||||
By(fmt.Sprintf("Creating file in all pods to start %d in namespace %s", index, ns), func() {
|
||||
WaitForPods(p.Ctx, p.Client, ns, p.podsList[index])
|
||||
WaitForPods(ctx, p.Client, ns, p.podsList[index])
|
||||
for i, pod := range p.podsList[index] {
|
||||
for j := range p.volumesList[i] {
|
||||
Expect(CreateFileToPod(p.Ctx, ns, pod, pod, p.volumesList[i][j],
|
||||
Expect(CreateFileToPod(ctx, ns, pod, pod, p.volumesList[i][j],
|
||||
FILE_NAME, fileContent(ns, pod, p.volumesList[i][j]))).To(Succeed())
|
||||
}
|
||||
}
|
||||
@@ -134,10 +137,12 @@ func (p *PVBackupFiltering) CreateResources() error {
|
||||
}
|
||||
|
||||
func (p *PVBackupFiltering) Verify() error {
|
||||
ctx, ctxCancel := context.WithTimeout(context.Background(), time.Minute*60)
|
||||
defer ctxCancel()
|
||||
By(fmt.Sprintf("Waiting for all pods to start %s", p.podsList), func() {
|
||||
for index, ns := range *p.NSIncluded {
|
||||
By(fmt.Sprintf("Waiting for all pods to start %d in namespace %s", index, ns), func() {
|
||||
WaitForPods(p.Ctx, p.Client, ns, p.podsList[index])
|
||||
WaitForPods(ctx, p.Client, ns, p.podsList[index])
|
||||
})
|
||||
}
|
||||
})
|
||||
@@ -150,21 +155,21 @@ func (p *PVBackupFiltering) Verify() error {
|
||||
if j%2 == 0 {
|
||||
if p.annotation == OPT_IN_ANN {
|
||||
By(fmt.Sprintf("File should exists in PV %s of pod %s under namespace %s\n", p.volumesList[i][j], p.podsList[k][i], ns), func() {
|
||||
Expect(fileExist(p.Ctx, ns, p.podsList[k][i], p.volumesList[i][j])).To(Succeed(), "File not exist as expect")
|
||||
Expect(fileExist(ctx, ns, p.podsList[k][i], p.volumesList[i][j])).To(Succeed(), "File not exist as expect")
|
||||
})
|
||||
} else {
|
||||
By(fmt.Sprintf("File should not exist in PV %s of pod %s under namespace %s\n", p.volumesList[i][j], p.podsList[k][i], ns), func() {
|
||||
Expect(fileNotExist(p.Ctx, ns, p.podsList[k][i], p.volumesList[i][j])).To(Succeed(), "File exists, not as expect")
|
||||
Expect(fileNotExist(ctx, ns, p.podsList[k][i], p.volumesList[i][j])).To(Succeed(), "File exists, not as expect")
|
||||
})
|
||||
}
|
||||
} else {
|
||||
if p.annotation == OPT_OUT_ANN {
|
||||
By(fmt.Sprintf("File should exists in PV %s of pod %s under namespace %s\n", p.volumesList[i][j], p.podsList[k][i], ns), func() {
|
||||
Expect(fileExist(p.Ctx, ns, p.podsList[k][i], p.volumesList[i][j])).To(Succeed(), "File not exist as expect")
|
||||
Expect(fileExist(ctx, ns, p.podsList[k][i], p.volumesList[i][j])).To(Succeed(), "File not exist as expect")
|
||||
})
|
||||
} else {
|
||||
By(fmt.Sprintf("File should not exist in PV %s of pod %s under namespace %s\n", p.volumesList[i][j], p.podsList[k][i], ns), func() {
|
||||
Expect(fileNotExist(p.Ctx, ns, p.podsList[k][i], p.volumesList[i][j])).To(Succeed(), "File exists, not as expect")
|
||||
Expect(fileNotExist(ctx, ns, p.podsList[k][i], p.volumesList[i][j])).To(Succeed(), "File exists, not as expect")
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,20 +66,21 @@ func (f *FilteringCase) Init() error {
|
||||
}
|
||||
|
||||
func (f *FilteringCase) CreateResources() error {
|
||||
f.Ctx, _ = context.WithTimeout(context.Background(), 60*time.Minute)
|
||||
ctx, ctxCancel := context.WithTimeout(context.Background(), 10*time.Minute)
|
||||
defer ctxCancel()
|
||||
for nsNum := 0; nsNum < f.NamespacesTotal; nsNum++ {
|
||||
namespace := fmt.Sprintf("%s-%00000d", f.NSBaseName, nsNum)
|
||||
fmt.Printf("Creating resources in namespace ...%s\n", namespace)
|
||||
if err := CreateNamespace(f.Ctx, f.Client, namespace); err != nil {
|
||||
if err := CreateNamespace(ctx, f.Client, namespace); err != nil {
|
||||
return errors.Wrapf(err, "Failed to create namespace %s", namespace)
|
||||
}
|
||||
serviceAccountName := "default"
|
||||
// wait until the service account is created before patch the image pull secret
|
||||
if err := WaitUntilServiceAccountCreated(f.Ctx, f.Client, namespace, serviceAccountName, 10*time.Minute); err != nil {
|
||||
if err := WaitUntilServiceAccountCreated(ctx, f.Client, namespace, serviceAccountName, 10*time.Minute); err != nil {
|
||||
return errors.Wrapf(err, "failed to wait the service account %q created under the namespace %q", serviceAccountName, namespace)
|
||||
}
|
||||
// add the image pull secret to avoid the image pull limit issue of Docker Hub
|
||||
if err := PatchServiceAccountWithImagePullSecret(f.Ctx, f.Client, namespace, serviceAccountName, VeleroCfg.RegistryCredentialFile); err != nil {
|
||||
if err := PatchServiceAccountWithImagePullSecret(ctx, f.Client, namespace, serviceAccountName, VeleroCfg.RegistryCredentialFile); err != nil {
|
||||
return errors.Wrapf(err, "failed to patch the service account %q under the namespace %q", serviceAccountName, namespace)
|
||||
}
|
||||
//Create deployment
|
||||
@@ -120,11 +121,13 @@ func (f *FilteringCase) CreateResources() error {
|
||||
}
|
||||
|
||||
func (f *FilteringCase) Verify() error {
|
||||
ctx, ctxCancel := context.WithTimeout(context.Background(), 10*time.Minute)
|
||||
defer ctxCancel()
|
||||
for nsNum := 0; nsNum < f.NamespacesTotal; nsNum++ {
|
||||
namespace := fmt.Sprintf("%s-%00000d", f.NSBaseName, nsNum)
|
||||
fmt.Printf("Checking resources in namespaces ...%s\n", namespace)
|
||||
//Check namespace
|
||||
checkNS, err := GetNamespace(f.Ctx, f.Client, namespace)
|
||||
checkNS, err := GetNamespace(ctx, f.Client, namespace)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "Could not retrieve test namespace %s", namespace)
|
||||
}
|
||||
|
||||
@@ -76,7 +76,8 @@ func (e *ExcludeFromBackup) Init() error {
|
||||
}
|
||||
|
||||
func (e *ExcludeFromBackup) CreateResources() error {
|
||||
e.Ctx, _ = context.WithTimeout(context.Background(), 60*time.Minute)
|
||||
ctx, ctxCancel := context.WithTimeout(context.Background(), 10*time.Minute)
|
||||
defer ctxCancel()
|
||||
namespace := e.NSBaseName
|
||||
// These 2 labels for resources to be included
|
||||
label1 := map[string]string{
|
||||
@@ -86,16 +87,16 @@ func (e *ExcludeFromBackup) CreateResources() error {
|
||||
"velero.io/exclude-from-backup": "false",
|
||||
}
|
||||
fmt.Printf("Creating resources in namespace ...%s\n", namespace)
|
||||
if err := CreateNamespace(e.Ctx, e.Client, namespace); err != nil {
|
||||
if err := CreateNamespace(ctx, e.Client, namespace); err != nil {
|
||||
return errors.Wrapf(err, "Failed to create namespace %s", namespace)
|
||||
}
|
||||
serviceAccountName := "default"
|
||||
// wait until the service account is created before patch the image pull secret
|
||||
if err := WaitUntilServiceAccountCreated(e.Ctx, e.Client, namespace, serviceAccountName, 10*time.Minute); err != nil {
|
||||
if err := WaitUntilServiceAccountCreated(ctx, e.Client, namespace, serviceAccountName, 10*time.Minute); err != nil {
|
||||
return errors.Wrapf(err, "failed to wait the service account %q created under the namespace %q", serviceAccountName, namespace)
|
||||
}
|
||||
// add the image pull secret to avoid the image pull limit issue of Docker Hub
|
||||
if err := PatchServiceAccountWithImagePullSecret(e.Ctx, e.Client, namespace, serviceAccountName, VeleroCfg.RegistryCredentialFile); err != nil {
|
||||
if err := PatchServiceAccountWithImagePullSecret(ctx, e.Client, namespace, serviceAccountName, VeleroCfg.RegistryCredentialFile); err != nil {
|
||||
return errors.Wrapf(err, "failed to patch the service account %q under the namespace %q", serviceAccountName, namespace)
|
||||
}
|
||||
//Create deployment: to be included
|
||||
@@ -139,10 +140,12 @@ func (e *ExcludeFromBackup) CreateResources() error {
|
||||
}
|
||||
|
||||
func (e *ExcludeFromBackup) Verify() error {
|
||||
ctx, ctxCancel := context.WithTimeout(context.Background(), 10*time.Minute)
|
||||
defer ctxCancel()
|
||||
namespace := e.NSBaseName
|
||||
By(fmt.Sprintf("Checking resources in namespaces ...%s\n", namespace), func() {
|
||||
//Check namespace
|
||||
checkNS, err := GetNamespace(e.Ctx, e.Client, namespace)
|
||||
checkNS, err := GetNamespace(ctx, e.Client, namespace)
|
||||
Expect(err).ShouldNot(HaveOccurred(), fmt.Sprintf("Could not retrieve test namespace %s", namespace))
|
||||
Expect(checkNS.Name == namespace).To(Equal(true), fmt.Sprintf("Retrieved namespace for %s has name %s instead", namespace, checkNS.Name))
|
||||
|
||||
|
||||
@@ -109,11 +109,12 @@ func (e *ExcludeNamespaces) Init() error {
|
||||
}
|
||||
|
||||
func (e *ExcludeNamespaces) CreateResources() error {
|
||||
e.Ctx, _ = context.WithTimeout(context.Background(), 60*time.Minute)
|
||||
ctx, ctxCancel := context.WithTimeout(context.Background(), 10*time.Minute)
|
||||
defer ctxCancel()
|
||||
for nsNum := 0; nsNum < e.NamespacesTotal; nsNum++ {
|
||||
createNSName := fmt.Sprintf("%s-%00000d", e.NSBaseName, nsNum)
|
||||
fmt.Printf("Creating namespaces ...%s\n", createNSName)
|
||||
if err := CreateNamespace(e.Ctx, e.Client, createNSName); err != nil {
|
||||
if err := CreateNamespace(ctx, e.Client, createNSName); err != nil {
|
||||
return errors.Wrapf(err, "Failed to create namespace %s", createNSName)
|
||||
}
|
||||
}
|
||||
@@ -121,10 +122,12 @@ func (e *ExcludeNamespaces) CreateResources() error {
|
||||
}
|
||||
|
||||
func (e *ExcludeNamespaces) Verify() error {
|
||||
ctx, ctxCancel := context.WithTimeout(context.Background(), 10*time.Minute)
|
||||
defer ctxCancel()
|
||||
// Verify that we got back all of the namespaces we created
|
||||
for nsNum := 0; nsNum < e.namespacesExcluded; nsNum++ {
|
||||
excludeNSName := fmt.Sprintf("%s-%00000d", e.NSBaseName, nsNum)
|
||||
_, err := GetNamespace(e.Ctx, e.Client, excludeNSName)
|
||||
_, err := GetNamespace(ctx, e.Client, excludeNSName)
|
||||
if err == nil {
|
||||
return errors.Wrapf(err, "Resource filtering with exclude namespace but exclude namespace %s exist", excludeNSName)
|
||||
}
|
||||
@@ -136,7 +139,7 @@ func (e *ExcludeNamespaces) Verify() error {
|
||||
|
||||
for nsNum := e.namespacesExcluded; nsNum < e.NamespacesTotal; nsNum++ {
|
||||
checkNSName := fmt.Sprintf("%s-%00000d", e.NSBaseName, nsNum)
|
||||
checkNS, err := GetNamespace(e.Ctx, e.Client, checkNSName)
|
||||
checkNS, err := GetNamespace(ctx, e.Client, checkNSName)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "Could not retrieve test namespace %s", checkNSName)
|
||||
}
|
||||
|
||||
@@ -105,11 +105,12 @@ func (i *IncludeNamespaces) Init() error {
|
||||
}
|
||||
|
||||
func (i *IncludeNamespaces) CreateResources() error {
|
||||
i.Ctx, _ = context.WithTimeout(context.Background(), 60*time.Minute)
|
||||
ctx, ctxCancel := context.WithTimeout(context.Background(), 10*time.Minute)
|
||||
defer ctxCancel()
|
||||
for nsNum := 0; nsNum < i.NamespacesTotal; nsNum++ {
|
||||
createNSName := fmt.Sprintf("%s-%00000d", i.NSBaseName, nsNum)
|
||||
fmt.Printf("Creating namespaces ...%s\n", createNSName)
|
||||
if err := CreateNamespace(i.Ctx, i.Client, createNSName); err != nil {
|
||||
if err := CreateNamespace(ctx, i.Client, createNSName); err != nil {
|
||||
return errors.Wrapf(err, "Failed to create namespace %s", createNSName)
|
||||
}
|
||||
}
|
||||
@@ -117,10 +118,12 @@ func (i *IncludeNamespaces) CreateResources() error {
|
||||
}
|
||||
|
||||
func (i *IncludeNamespaces) Verify() error {
|
||||
ctx, ctxCancel := context.WithTimeout(context.Background(), 10*time.Minute)
|
||||
defer ctxCancel()
|
||||
// Verify that we got back all of the namespaces we created
|
||||
for nsNum := 0; nsNum < i.namespacesIncluded; nsNum++ {
|
||||
checkNSName := fmt.Sprintf("%s-%00000d", i.NSBaseName, nsNum)
|
||||
checkNS, err := GetNamespace(i.Ctx, i.Client, checkNSName)
|
||||
checkNS, err := GetNamespace(ctx, i.Client, checkNSName)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "Could not retrieve test namespace %s", checkNSName)
|
||||
}
|
||||
@@ -131,7 +134,7 @@ func (i *IncludeNamespaces) Verify() error {
|
||||
|
||||
for nsNum := i.namespacesIncluded; nsNum < i.NamespacesTotal; nsNum++ {
|
||||
excludeNSName := fmt.Sprintf("%s-%00000d", i.NSBaseName, nsNum)
|
||||
_, err := GetNamespace(i.Ctx, i.Client, excludeNSName)
|
||||
_, err := GetNamespace(ctx, i.Client, excludeNSName)
|
||||
if err == nil {
|
||||
return errors.Wrapf(err, "Resource filtering with include namespace but exclude namespace %s exist", excludeNSName)
|
||||
}
|
||||
|
||||
@@ -75,7 +75,8 @@ func (l *LabelSelector) Init() error {
|
||||
}
|
||||
|
||||
func (l *LabelSelector) CreateResources() error {
|
||||
l.Ctx, _ = context.WithTimeout(context.Background(), 60*time.Minute)
|
||||
ctx, ctxCancel := context.WithTimeout(context.Background(), 10*time.Minute)
|
||||
defer ctxCancel()
|
||||
for nsNum := 0; nsNum < l.NamespacesTotal; nsNum++ {
|
||||
namespace := fmt.Sprintf("%s-%00000d", l.NSBaseName, nsNum)
|
||||
fmt.Printf("Creating resources in namespace ...%s\n", namespace)
|
||||
@@ -85,17 +86,17 @@ func (l *LabelSelector) CreateResources() error {
|
||||
"resourcefiltering": "false",
|
||||
}
|
||||
}
|
||||
if err := CreateNamespaceWithLabel(l.Ctx, l.Client, namespace, labels); err != nil {
|
||||
if err := CreateNamespaceWithLabel(ctx, l.Client, namespace, labels); err != nil {
|
||||
return errors.Wrapf(err, "Failed to create namespace %s", namespace)
|
||||
}
|
||||
|
||||
serviceAccountName := "default"
|
||||
// wait until the service account is created before patch the image pull secret
|
||||
if err := WaitUntilServiceAccountCreated(l.Ctx, l.Client, namespace, serviceAccountName, 10*time.Minute); err != nil {
|
||||
if err := WaitUntilServiceAccountCreated(ctx, l.Client, namespace, serviceAccountName, 10*time.Minute); err != nil {
|
||||
return errors.Wrapf(err, "failed to wait the service account %q created under the namespace %q", serviceAccountName, namespace)
|
||||
}
|
||||
// add the image pull secret to avoid the image pull limit issue of Docker Hub
|
||||
if err := PatchServiceAccountWithImagePullSecret(l.Ctx, l.Client, namespace, serviceAccountName, VeleroCfg.RegistryCredentialFile); err != nil {
|
||||
if err := PatchServiceAccountWithImagePullSecret(ctx, l.Client, namespace, serviceAccountName, VeleroCfg.RegistryCredentialFile); err != nil {
|
||||
return errors.Wrapf(err, "failed to patch the service account %q under the namespace %q", serviceAccountName, namespace)
|
||||
}
|
||||
//Create deployment
|
||||
|
||||
@@ -102,8 +102,8 @@ func (r *ResourcePoliciesCase) Init() error {
|
||||
}
|
||||
|
||||
func (r *ResourcePoliciesCase) CreateResources() error {
|
||||
r.Ctx, _ = context.WithTimeout(context.Background(), 60*time.Minute)
|
||||
|
||||
ctx, ctxCancel := context.WithTimeout(context.Background(), 10*time.Minute)
|
||||
defer ctxCancel()
|
||||
By(("Installing storage class..."), func() {
|
||||
Expect(r.installTestStorageClasses(fmt.Sprintf("testdata/storage-class/%s.yaml", VeleroCfg.CloudProvider))).To(Succeed(), "Failed to install storage class")
|
||||
})
|
||||
@@ -119,7 +119,7 @@ func (r *ResourcePoliciesCase) CreateResources() error {
|
||||
for nsNum := 0; nsNum < r.NamespacesTotal; nsNum++ {
|
||||
namespace := fmt.Sprintf("%s-%00000d", r.NSBaseName, nsNum)
|
||||
By(fmt.Sprintf("Create namespaces %s for workload\n", namespace), func() {
|
||||
Expect(CreateNamespace(r.Ctx, r.Client, namespace)).To(Succeed(), fmt.Sprintf("Failed to create namespace %s", namespace))
|
||||
Expect(CreateNamespace(ctx, r.Client, namespace)).To(Succeed(), fmt.Sprintf("Failed to create namespace %s", namespace))
|
||||
})
|
||||
|
||||
volName := fmt.Sprintf("vol-%s-%00000d", r.NSBaseName, nsNum)
|
||||
@@ -145,12 +145,14 @@ func (r *ResourcePoliciesCase) CreateResources() error {
|
||||
}
|
||||
|
||||
func (r *ResourcePoliciesCase) Verify() error {
|
||||
ctx, ctxCancel := context.WithTimeout(context.Background(), 10*time.Minute)
|
||||
defer ctxCancel()
|
||||
for i, ns := range *r.NSIncluded {
|
||||
By(fmt.Sprintf("Verify pod data in namespace %s", ns), func() {
|
||||
By(fmt.Sprintf("Waiting for deployment %s in namespace %s ready", r.NSBaseName, ns), func() {
|
||||
Expect(WaitForReadyDeployment(r.Client.ClientGo, ns, r.NSBaseName)).To(Succeed(), fmt.Sprintf("Failed to waiting for deployment %s in namespace %s ready", r.NSBaseName, ns))
|
||||
})
|
||||
podList, err := ListPods(r.Ctx, r.Client, ns)
|
||||
podList, err := ListPods(ctx, r.Client, ns)
|
||||
Expect(err).To(Succeed(), fmt.Sprintf("failed to list pods in namespace: %q with error %v", ns, err))
|
||||
|
||||
volName := fmt.Sprintf("vol-%s-%00000d", r.NSBaseName, i)
|
||||
@@ -159,7 +161,7 @@ func (r *ResourcePoliciesCase) Verify() error {
|
||||
if vol.Name != volName {
|
||||
continue
|
||||
}
|
||||
content, err := ReadFileFromPodVolume(r.Ctx, ns, pod.Name, "container-busybox", vol.Name, FileName)
|
||||
content, err := ReadFileFromPodVolume(ctx, ns, pod.Name, "container-busybox", vol.Name, FileName)
|
||||
if i%2 == 0 {
|
||||
Expect(err).To(HaveOccurred(), "Expected file not found") // File should not exist
|
||||
} else {
|
||||
@@ -228,7 +230,9 @@ func (r *ResourcePoliciesCase) createDeploymentWithVolume(namespace string, volL
|
||||
}
|
||||
|
||||
func (r *ResourcePoliciesCase) writeDataIntoPods(namespace, volName string) error {
|
||||
podList, err := ListPods(r.Ctx, r.Client, namespace)
|
||||
ctx, ctxCancel := context.WithTimeout(context.Background(), 10*time.Minute)
|
||||
defer ctxCancel()
|
||||
podList, err := ListPods(ctx, r.Client, namespace)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, fmt.Sprintf("failed to list pods in namespace: %q with error %v", namespace, err))
|
||||
}
|
||||
@@ -237,7 +241,7 @@ func (r *ResourcePoliciesCase) writeDataIntoPods(namespace, volName string) erro
|
||||
if vol.Name != volName {
|
||||
continue
|
||||
}
|
||||
err := CreateFileToPod(r.Ctx, namespace, pod.Name, "container-busybox", vol.Name, FileName, fmt.Sprintf("ns-%s pod-%s volume-%s", namespace, pod.Name, vol.Name))
|
||||
err := CreateFileToPod(ctx, namespace, pod.Name, "container-busybox", vol.Name, FileName, fmt.Sprintf("ns-%s pod-%s volume-%s", namespace, pod.Name, vol.Name))
|
||||
if err != nil {
|
||||
return errors.Wrap(err, fmt.Sprintf("failed to create file into pod %s in namespace: %q", pod.Name, namespace))
|
||||
}
|
||||
@@ -247,8 +251,10 @@ func (r *ResourcePoliciesCase) writeDataIntoPods(namespace, volName string) erro
|
||||
}
|
||||
|
||||
func (r *ResourcePoliciesCase) deleteTestStorageClassList(scList []string) error {
|
||||
ctx, ctxCancel := context.WithTimeout(context.Background(), 10*time.Minute)
|
||||
defer ctxCancel()
|
||||
for _, v := range scList {
|
||||
if err := DeleteStorageClass(r.Ctx, r.Client, v); err != nil {
|
||||
if err := DeleteStorageClass(ctx, r.Client, v); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -256,7 +262,9 @@ func (r *ResourcePoliciesCase) deleteTestStorageClassList(scList []string) error
|
||||
}
|
||||
|
||||
func (r *ResourcePoliciesCase) installTestStorageClasses(path string) error {
|
||||
err := InstallStorageClass(r.Ctx, path)
|
||||
ctx, ctxCancel := context.WithTimeout(context.Background(), 10*time.Minute)
|
||||
defer ctxCancel()
|
||||
err := InstallStorageClass(ctx, path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -277,5 +285,5 @@ func (r *ResourcePoliciesCase) installTestStorageClasses(path string) error {
|
||||
if _, err := tmpFile.WriteString(newContent); err != nil {
|
||||
return errors.Wrapf(err, "failed to write content into temp file %s when install storage class", tmpFile.Name())
|
||||
}
|
||||
return InstallStorageClass(r.Ctx, tmpFile.Name())
|
||||
return InstallStorageClass(ctx, tmpFile.Name())
|
||||
}
|
||||
|
||||
@@ -64,13 +64,15 @@ func ScheduleOrderedResources() {
|
||||
})
|
||||
|
||||
It("Create a schedule to backup resources in a specific order should be successful", func() {
|
||||
ctx, ctxCancel := context.WithTimeout(context.Background(), 10*time.Minute)
|
||||
defer ctxCancel()
|
||||
test := &OrderedResources{}
|
||||
test.VeleroCfg = VeleroCfg
|
||||
err := test.Init()
|
||||
Expect(err).To(Succeed(), err)
|
||||
defer func() {
|
||||
Expect(DeleteNamespace(test.Ctx, test.Client, test.Namespace, false)).To(Succeed(), fmt.Sprintf("Failed to delete the namespace %s", test.Namespace))
|
||||
err = VeleroScheduleDelete(test.Ctx, veleroCfg.VeleroCLI, veleroCfg.VeleroNamespace, test.ScheduleName)
|
||||
Expect(DeleteNamespace(ctx, test.Client, test.Namespace, false)).To(Succeed(), fmt.Sprintf("Failed to delete the namespace %s", test.Namespace))
|
||||
err = VeleroScheduleDelete(ctx, veleroCfg.VeleroCLI, veleroCfg.VeleroNamespace, test.ScheduleName)
|
||||
Expect(err).To(Succeed(), fmt.Sprintf("Failed to delete schedule with err %v", err))
|
||||
err = test.DeleteBackups()
|
||||
Expect(err).To(Succeed(), fmt.Sprintf("Failed to delete backups with err %v", err))
|
||||
@@ -82,24 +84,24 @@ func ScheduleOrderedResources() {
|
||||
})
|
||||
|
||||
By(fmt.Sprintf("Create schedule the workload in %s namespace", test.Namespace), func() {
|
||||
err = VeleroScheduleCreate(test.Ctx, veleroCfg.VeleroCLI, veleroCfg.VeleroNamespace, test.ScheduleName, test.ScheduleArgs)
|
||||
err = VeleroScheduleCreate(ctx, veleroCfg.VeleroCLI, veleroCfg.VeleroNamespace, test.ScheduleName, test.ScheduleArgs)
|
||||
Expect(err).To(Succeed(), fmt.Sprintf("Failed to create schedule %s with err %v", test.ScheduleName, err))
|
||||
})
|
||||
|
||||
By(fmt.Sprintf("Checking resource order in %s schedule cr", test.ScheduleName), func() {
|
||||
err = CheckScheduleWithResourceOrder(test.Ctx, veleroCfg.VeleroCLI, veleroCfg.VeleroNamespace, test.ScheduleName, test.OrderMap)
|
||||
err = CheckScheduleWithResourceOrder(ctx, veleroCfg.VeleroCLI, veleroCfg.VeleroNamespace, test.ScheduleName, test.OrderMap)
|
||||
Expect(err).To(Succeed(), fmt.Sprintf("Failed to check schedule %s with err %v", test.ScheduleName, err))
|
||||
})
|
||||
|
||||
By("Checking resource order in backup cr", func() {
|
||||
backupList := new(velerov1api.BackupList)
|
||||
err = waitutil.PollImmediate(10*time.Second, time.Minute*5, func() (bool, error) {
|
||||
if err = test.Client.Kubebuilder.List(test.Ctx, backupList, &kbclient.ListOptions{Namespace: veleroCfg.VeleroNamespace}); err != nil {
|
||||
if err = test.Client.Kubebuilder.List(ctx, backupList, &kbclient.ListOptions{Namespace: veleroCfg.VeleroNamespace}); err != nil {
|
||||
return false, fmt.Errorf("failed to list backup object in %s namespace with err %v", veleroCfg.VeleroNamespace, err)
|
||||
}
|
||||
|
||||
for _, backup := range backupList.Items {
|
||||
if err = CheckBackupWithResourceOrder(test.Ctx, veleroCfg.VeleroCLI, veleroCfg.VeleroNamespace, backup.Name, test.OrderMap); err == nil {
|
||||
if err = CheckBackupWithResourceOrder(ctx, veleroCfg.VeleroCLI, veleroCfg.VeleroNamespace, backup.Name, test.OrderMap); err == nil {
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
@@ -139,21 +141,22 @@ func (o *OrderedResources) Init() error {
|
||||
|
||||
func (o *OrderedResources) CreateResources() error {
|
||||
veleroCfg := o.VeleroCfg
|
||||
o.Ctx, _ = context.WithTimeout(context.Background(), 5*time.Minute)
|
||||
ctx, ctxCancel := context.WithTimeout(context.Background(), 10*time.Minute)
|
||||
defer ctxCancel()
|
||||
label := map[string]string{
|
||||
"orderedresources": "true",
|
||||
}
|
||||
fmt.Printf("Creating resources in %s namespace ...\n", o.Namespace)
|
||||
if err := CreateNamespace(o.Ctx, o.Client, o.Namespace); err != nil {
|
||||
if err := CreateNamespace(ctx, o.Client, o.Namespace); err != nil {
|
||||
return errors.Wrapf(err, "failed to create namespace %s", o.Namespace)
|
||||
}
|
||||
serviceAccountName := "default"
|
||||
// wait until the service account is created before patch the image pull secret
|
||||
if err := WaitUntilServiceAccountCreated(o.Ctx, o.Client, o.Namespace, serviceAccountName, 10*time.Minute); err != nil {
|
||||
if err := WaitUntilServiceAccountCreated(ctx, o.Client, o.Namespace, serviceAccountName, 10*time.Minute); err != nil {
|
||||
return errors.Wrapf(err, "failed to wait the service account %q created under the namespace %q", serviceAccountName, o.Namespace)
|
||||
}
|
||||
// add the image pull secret to avoid the image pull limit issue of Docker Hub
|
||||
if err := PatchServiceAccountWithImagePullSecret(o.Ctx, o.Client, o.Namespace, serviceAccountName, veleroCfg.RegistryCredentialFile); err != nil {
|
||||
if err := PatchServiceAccountWithImagePullSecret(ctx, o.Client, o.Namespace, serviceAccountName, veleroCfg.RegistryCredentialFile); err != nil {
|
||||
return errors.Wrapf(err, "failed to patch the service account %q under the namespace %q", serviceAccountName, o.Namespace)
|
||||
}
|
||||
//Create deployment
|
||||
@@ -194,13 +197,15 @@ func (o *OrderedResources) CreateResources() error {
|
||||
}
|
||||
|
||||
func (o *OrderedResources) DeleteBackups() error {
|
||||
ctx, ctxCancel := context.WithTimeout(context.Background(), 10*time.Minute)
|
||||
defer ctxCancel()
|
||||
veleroCfg := o.VeleroCfg
|
||||
backupList := new(velerov1api.BackupList)
|
||||
if err := o.Client.Kubebuilder.List(o.Ctx, backupList, &kbclient.ListOptions{Namespace: veleroCfg.VeleroNamespace}); err != nil {
|
||||
if err := o.Client.Kubebuilder.List(ctx, backupList, &kbclient.ListOptions{Namespace: veleroCfg.VeleroNamespace}); err != nil {
|
||||
return fmt.Errorf("failed to list backup object in %s namespace with err %v", veleroCfg.VeleroNamespace, err)
|
||||
}
|
||||
for _, backup := range backupList.Items {
|
||||
if err := VeleroBackupDelete(o.Ctx, veleroCfg.VeleroCLI, veleroCfg.VeleroNamespace, backup.Name); err != nil {
|
||||
if err := VeleroBackupDelete(ctx, veleroCfg.VeleroCLI, veleroCfg.VeleroNamespace, backup.Name); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,7 +69,6 @@ func (n *ScheduleBackupCreation) StartRun() error {
|
||||
return nil
|
||||
}
|
||||
func (p *ScheduleBackupCreation) CreateResources() error {
|
||||
p.Ctx, _ = context.WithTimeout(context.Background(), 60*time.Minute)
|
||||
By(fmt.Sprintf("Create namespace %s", p.namespace), func() {
|
||||
Expect(CreateNamespace(context.Background(), p.Client, p.namespace)).To(Succeed(),
|
||||
fmt.Sprintf("Failed to create namespace %s", p.namespace))
|
||||
@@ -85,6 +84,8 @@ func (p *ScheduleBackupCreation) CreateResources() error {
|
||||
}
|
||||
|
||||
func (n *ScheduleBackupCreation) Backup() error {
|
||||
ctx, ctxCancel := context.WithTimeout(context.Background(), 10*time.Minute)
|
||||
defer ctxCancel()
|
||||
// Wait until the beginning of the given period to create schedule, it will give us
|
||||
// a predictable period to wait for the first scheduled backup, and verify no immediate
|
||||
// scheduled backup was created between schedule creation and first scheduled backup.
|
||||
@@ -94,7 +95,7 @@ func (n *ScheduleBackupCreation) Backup() error {
|
||||
now := time.Now().Minute()
|
||||
triggerNow := now % n.Period
|
||||
if triggerNow == 0 {
|
||||
Expect(VeleroScheduleCreate(n.Ctx, VeleroCfg.VeleroCLI, VeleroCfg.VeleroNamespace, n.ScheduleName, n.ScheduleArgs)).To(Succeed(), func() string {
|
||||
Expect(VeleroScheduleCreate(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"
|
||||
})
|
||||
|
||||
@@ -53,10 +53,11 @@ func (n *ScheduleBackup) StartRun() error {
|
||||
return nil
|
||||
}
|
||||
func (n *ScheduleBackup) CreateResources() error {
|
||||
n.Ctx, _ = context.WithTimeout(context.Background(), 60*time.Minute)
|
||||
ctx, ctxCanel := context.WithTimeout(context.Background(), 60*time.Minute)
|
||||
defer ctxCanel()
|
||||
for _, ns := range *n.NSIncluded {
|
||||
By(fmt.Sprintf("Creating namespaces %s ......\n", ns), func() {
|
||||
Expect(CreateNamespace(n.Ctx, n.Client, ns)).To(Succeed(), fmt.Sprintf("Failed to create namespace %s", ns))
|
||||
Expect(CreateNamespace(ctx, n.Client, ns)).To(Succeed(), fmt.Sprintf("Failed to create namespace %s", ns))
|
||||
})
|
||||
configmaptName := n.NSBaseName
|
||||
fmt.Printf("Creating configmap %s in namespaces ...%s\n", configmaptName, ns)
|
||||
@@ -69,6 +70,8 @@ func (n *ScheduleBackup) CreateResources() error {
|
||||
}
|
||||
|
||||
func (n *ScheduleBackup) Backup() error {
|
||||
ctx, ctxCancel := context.WithTimeout(context.Background(), 10*time.Minute)
|
||||
defer ctxCancel()
|
||||
// Wait until the beginning of the given period to create schedule, it will give us
|
||||
// a predictable period to wait for the first scheduled backup, and verify no immediate
|
||||
// scheduled backup was created between schedule creation and first scheduled backup.
|
||||
@@ -78,7 +81,7 @@ func (n *ScheduleBackup) Backup() error {
|
||||
now := time.Now().Minute()
|
||||
triggerNow := now % n.Period
|
||||
if triggerNow == 0 {
|
||||
Expect(VeleroScheduleCreate(n.Ctx, VeleroCfg.VeleroCLI, VeleroCfg.VeleroNamespace, n.ScheduleName, n.ScheduleArgs)).To(Succeed(), func() string {
|
||||
Expect(VeleroScheduleCreate(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"
|
||||
})
|
||||
@@ -89,6 +92,8 @@ func (n *ScheduleBackup) Backup() error {
|
||||
return nil
|
||||
}
|
||||
func (n *ScheduleBackup) Destroy() error {
|
||||
ctx, ctxCancel := context.WithTimeout(context.Background(), 10*time.Minute)
|
||||
defer ctxCancel()
|
||||
By(fmt.Sprintf("Schedule %s is created without any delay\n", n.ScheduleName), func() {
|
||||
creationTimestamp, err := GetSchedule(context.Background(), VeleroCfg.VeleroNamespace, n.ScheduleName)
|
||||
Expect(err).To(Succeed())
|
||||
@@ -144,7 +149,7 @@ func (n *ScheduleBackup) Destroy() error {
|
||||
n.BackupName = strings.Replace(n.randBackupName, " ", "", -1)
|
||||
|
||||
By("Delete all namespaces", func() {
|
||||
Expect(CleanupNamespacesWithPoll(n.Ctx, n.Client, n.NSBaseName)).To(Succeed(), "Could cleanup retrieve namespaces")
|
||||
Expect(CleanupNamespacesWithPoll(ctx, n.Client, n.NSBaseName)).To(Succeed(), "Could cleanup retrieve namespaces")
|
||||
})
|
||||
|
||||
n.RestoreArgs = []string{
|
||||
@@ -159,7 +164,7 @@ func (n *ScheduleBackup) Destroy() error {
|
||||
backupCount := len(backupsInfo)
|
||||
|
||||
By(fmt.Sprintf("Pause schedule %s ......\n", n.ScheduleName), func() {
|
||||
Expect(VeleroSchedulePause(n.Ctx, VeleroCfg.VeleroCLI, VeleroCfg.VeleroNamespace, n.ScheduleName)).To(Succeed(), func() string {
|
||||
Expect(VeleroSchedulePause(ctx, VeleroCfg.VeleroCLI, VeleroCfg.VeleroNamespace, n.ScheduleName)).To(Succeed(), func() string {
|
||||
RunDebug(context.Background(), VeleroCfg.VeleroCLI, VeleroCfg.VeleroNamespace, "", "")
|
||||
return "Fail to restore workload"
|
||||
})
|
||||
@@ -182,7 +187,7 @@ func (n *ScheduleBackup) Destroy() error {
|
||||
})
|
||||
|
||||
By(fmt.Sprintf("Unpause schedule %s ......\n", n.ScheduleName), func() {
|
||||
Expect(VeleroScheduleUnpause(n.Ctx, VeleroCfg.VeleroCLI, VeleroCfg.VeleroNamespace, n.ScheduleName)).To(Succeed(), func() string {
|
||||
Expect(VeleroScheduleUnpause(ctx, VeleroCfg.VeleroCLI, VeleroCfg.VeleroNamespace, n.ScheduleName)).To(Succeed(), func() string {
|
||||
RunDebug(context.Background(), VeleroCfg.VeleroCLI, VeleroCfg.VeleroNamespace, "", "")
|
||||
return "Fail to unpause schedule"
|
||||
})
|
||||
|
||||
+13
-7
@@ -68,7 +68,6 @@ type TestCase struct {
|
||||
NamespacesTotal int
|
||||
TestMsg *TestMSG
|
||||
Client TestClient
|
||||
Ctx context.Context
|
||||
NSIncluded *[]string
|
||||
UseVolumeSnapshots bool
|
||||
VeleroCfg VeleroConfig
|
||||
@@ -159,8 +158,10 @@ func (t *TestCase) StartRun() error {
|
||||
}
|
||||
|
||||
func (t *TestCase) Backup() error {
|
||||
ctx, ctxCancel := context.WithTimeout(context.Background(), 10*time.Minute)
|
||||
defer ctxCancel()
|
||||
veleroCfg := t.GetTestCase().VeleroCfg
|
||||
if err := VeleroBackupExec(t.Ctx, veleroCfg.VeleroCLI, veleroCfg.VeleroNamespace, t.BackupName, t.BackupArgs); err != nil {
|
||||
if err := VeleroBackupExec(ctx, veleroCfg.VeleroCLI, veleroCfg.VeleroNamespace, t.BackupName, t.BackupArgs); err != nil {
|
||||
RunDebug(context.Background(), veleroCfg.VeleroCLI, veleroCfg.VeleroNamespace, t.BackupName, "")
|
||||
return errors.Wrapf(err, "Failed to backup resources")
|
||||
}
|
||||
@@ -168,13 +169,17 @@ func (t *TestCase) Backup() error {
|
||||
}
|
||||
|
||||
func (t *TestCase) Destroy() error {
|
||||
ctx, ctxCancel := context.WithTimeout(context.Background(), 10*time.Minute)
|
||||
defer ctxCancel()
|
||||
By(fmt.Sprintf("Start to destroy namespace %s......", t.NSBaseName), func() {
|
||||
Expect(CleanupNamespacesWithPoll(t.Ctx, t.Client, t.NSBaseName)).To(Succeed(), "Could cleanup retrieve namespaces")
|
||||
Expect(CleanupNamespacesWithPoll(ctx, t.Client, t.NSBaseName)).To(Succeed(), "Could cleanup retrieve namespaces")
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *TestCase) Restore() error {
|
||||
ctx, ctxCancel := context.WithTimeout(context.Background(), 10*time.Minute)
|
||||
defer ctxCancel()
|
||||
veleroCfg := t.GetTestCase().VeleroCfg
|
||||
// the snapshots of AWS may be still in pending status when do the restore, wait for a while
|
||||
// to avoid this https://github.com/vmware-tanzu/velero/issues/1799
|
||||
@@ -188,7 +193,7 @@ func (t *TestCase) Restore() error {
|
||||
if t.RestorePhaseExpect == "" {
|
||||
t.RestorePhaseExpect = velerov1api.RestorePhaseCompleted
|
||||
}
|
||||
Expect(VeleroRestoreExec(t.Ctx, veleroCfg.VeleroCLI, veleroCfg.VeleroNamespace, t.RestoreName, t.RestoreArgs, t.RestorePhaseExpect)).To(Succeed(), func() string {
|
||||
Expect(VeleroRestoreExec(ctx, veleroCfg.VeleroCLI, veleroCfg.VeleroNamespace, t.RestoreName, t.RestoreArgs, t.RestorePhaseExpect)).To(Succeed(), func() string {
|
||||
RunDebug(context.Background(), veleroCfg.VeleroCLI, veleroCfg.VeleroNamespace, "", t.RestoreName)
|
||||
return "Fail to restore workload"
|
||||
})
|
||||
@@ -201,13 +206,15 @@ func (t *TestCase) Verify() error {
|
||||
}
|
||||
|
||||
func (t *TestCase) Clean() error {
|
||||
ctx, ctxCancel := context.WithTimeout(context.Background(), 10*time.Minute)
|
||||
defer ctxCancel()
|
||||
veleroCfg := t.GetTestCase().VeleroCfg
|
||||
if !veleroCfg.Debug {
|
||||
By(fmt.Sprintf("Clean namespace with prefix %s after test", t.NSBaseName), func() {
|
||||
CleanupNamespaces(t.Ctx, t.Client, t.NSBaseName)
|
||||
CleanupNamespaces(ctx, t.Client, t.NSBaseName)
|
||||
})
|
||||
By("Clean backups after test", func() {
|
||||
DeleteBackups(t.Ctx, t.Client)
|
||||
DeleteBackups(ctx, t.Client)
|
||||
})
|
||||
}
|
||||
return nil
|
||||
@@ -225,7 +232,6 @@ func RunTestCase(test VeleroBackupRestoreTest) error {
|
||||
if test == nil {
|
||||
return errors.New("No case should be tested")
|
||||
}
|
||||
|
||||
defer test.Clean()
|
||||
err := test.StartRun()
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user