defer ctxCancel

Signed-off-by: Tiger Kaovilai <tkaovila@redhat.com>
This commit is contained in:
Tiger Kaovilai
2023-04-16 13:33:43 -04:00
parent 84daa36efe
commit 3f4b258dee
8 changed files with 24 additions and 10 deletions
+2 -1
View File
@@ -67,7 +67,8 @@ func GetNamespace(ctx context.Context, client TestClient, namespace string) (*co
}
func DeleteNamespace(ctx context.Context, client TestClient, namespace string, wait bool) error {
tenMinuteTimeout, _ := context.WithTimeout(context.Background(), time.Minute*10)
tenMinuteTimeout, ctxCancel := context.WithTimeout(context.Background(), time.Minute*10)
defer ctxCancel()
if err := client.ClientGo.CoreV1().Namespaces().Delete(context.TODO(), namespace, metav1.DeleteOptions{}); err != nil {
return errors.Wrap(err, fmt.Sprintf("failed to delete the namespace %q", namespace))
}
+6 -3
View File
@@ -55,7 +55,8 @@ var KibishiiPodNameList = []string{"kibishii-deployment-0", "kibishii-deployment
func RunKibishiiTests(veleroCfg VeleroConfig, backupName, restoreName, backupLocation, kibishiiNamespace string,
useVolumeSnapshots, defaultVolumesToFsBackup bool) error {
client := *veleroCfg.ClientToInstallVelero
oneHourTimeout, _ := context.WithTimeout(context.Background(), time.Minute*60)
oneHourTimeout, ctxCancel := context.WithTimeout(context.Background(), time.Minute*60)
defer ctxCancel()
veleroCLI := veleroCfg.VeleroCLI
providerName := veleroCfg.CloudProvider
veleroNamespace := veleroCfg.VeleroNamespace
@@ -221,7 +222,8 @@ func generateData(ctx context.Context, namespace string, kibishiiData *KibishiiD
timeout := 30 * time.Minute
interval := 1 * time.Second
err := wait.PollImmediate(interval, timeout, func() (bool, error) {
timeout, _ := context.WithTimeout(context.Background(), time.Minute*20)
timeout, ctxCancel := context.WithTimeout(context.Background(), time.Minute*20)
defer ctxCancel()
kibishiiGenerateCmd := exec.CommandContext(timeout, "kubectl", "exec", "-n", namespace, "jump-pad", "--",
"/usr/local/bin/generate.sh", strconv.Itoa(kibishiiData.Levels), strconv.Itoa(kibishiiData.DirsPerLevel),
strconv.Itoa(kibishiiData.FilesPerLevel), strconv.Itoa(kibishiiData.FileLength),
@@ -246,7 +248,8 @@ func verifyData(ctx context.Context, namespace string, kibishiiData *KibishiiDat
timeout := 10 * time.Minute
interval := 5 * time.Second
err := wait.PollImmediate(interval, timeout, func() (bool, error) {
timeout, _ := context.WithTimeout(context.Background(), time.Minute*20)
timeout, ctxCancel := context.WithTimeout(context.Background(), time.Minute*20)
defer ctxCancel()
kibishiiVerifyCmd := exec.CommandContext(timeout, "kubectl", "exec", "-n", namespace, "jump-pad", "--",
"/usr/local/bin/verify.sh", strconv.Itoa(kibishiiData.Levels), strconv.Itoa(kibishiiData.DirsPerLevel),
strconv.Itoa(kibishiiData.FilesPerLevel), strconv.Itoa(kibishiiData.FileLength),
+2 -1
View File
@@ -138,7 +138,8 @@ func IsSnapshotExisted(cloudProvider, cloudCredentialsFile, bslBucket, bslConfig
}
if cloudProvider == "vsphere" {
var retSnapshotIDs []string
ctx, _ := context.WithTimeout(context.Background(), time.Minute*2)
ctx, ctxCancel := context.WithTimeout(context.Background(), time.Minute*2)
defer ctxCancel()
retSnapshotIDs, err = velero.GetVsphereSnapshotIDs(ctx, time.Hour, snapshotCheck.NamespaceBackedUp, snapshotCheck.PodName)
if err != nil {
return errors.Wrapf(err, fmt.Sprintf("Fail to get snapshot CRs of backup%s", backupName))