Skip to content

Commit

Permalink
feat: switch context.TODO() to context.Background()
Browse files Browse the repository at this point in the history
Signed-off-by: Karel Simon <[email protected]>
  • Loading branch information
ksimon1 committed Sep 27, 2023
1 parent fcd5427 commit b39a3f4
Show file tree
Hide file tree
Showing 18 changed files with 113 additions and 112 deletions.
20 changes: 10 additions & 10 deletions modules/tests/test/copy_template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var _ = Describe("Copy template task", func() {
f.TestSetup(config)

if template := config.TaskData.Template; template != nil {
t, err := f.TemplateClient.Templates(template.Namespace).Create(context.TODO(), template, v1.CreateOptions{})
t, err := f.TemplateClient.Templates(template.Namespace).Create(context.Background(), template, v1.CreateOptions{})
Expect(err).ShouldNot(HaveOccurred())
f.ManageTemplates(t)
}
Expand Down Expand Up @@ -73,7 +73,7 @@ var _ = Describe("Copy template task", func() {
f.TestSetup(config)

if template := config.TaskData.Template; template != nil {
t, err := f.TemplateClient.Templates(template.Namespace).Create(context.TODO(), template, v1.CreateOptions{})
t, err := f.TemplateClient.Templates(template.Namespace).Create(context.Background(), template, v1.CreateOptions{})
Expect(err).ShouldNot(HaveOccurred())
f.ManageTemplates(t)
}
Expand All @@ -87,7 +87,7 @@ var _ = Describe("Copy template task", func() {
resultTemplateName := results["name"]
resultTemplateNamespace := results["namespace"]

newTemplate, err := f.TemplateClient.Templates(resultTemplateNamespace).Get(context.TODO(), resultTemplateName, v1.GetOptions{})
newTemplate, err := f.TemplateClient.Templates(resultTemplateNamespace).Get(context.Background(), resultTemplateName, v1.GetOptions{})
Expect(err).ShouldNot(HaveOccurred())
Expect(newTemplate).ToNot(BeNil(), "new template should exists")

Expand Down Expand Up @@ -174,7 +174,7 @@ var _ = Describe("Copy template task", func() {
}
f.TestSetup(config)

t, err := f.TemplateClient.Templates(config.TaskData.SourceNamespace).Create(context.TODO(), config.TaskData.Template, v1.CreateOptions{})
t, err := f.TemplateClient.Templates(config.TaskData.SourceNamespace).Create(context.Background(), config.TaskData.Template, v1.CreateOptions{})
Expect(err).ShouldNot(HaveOccurred())
f.ManageTemplates(t)

Expand All @@ -187,7 +187,7 @@ var _ = Describe("Copy template task", func() {
resultTemplateName := results["name"]
resultTemplateNamespace := results["namespace"]

newTemplate, err := f.TemplateClient.Templates(resultTemplateNamespace).Get(context.TODO(), resultTemplateName, v1.GetOptions{})
newTemplate, err := f.TemplateClient.Templates(resultTemplateNamespace).Get(context.Background(), resultTemplateName, v1.GetOptions{})
Expect(err).ShouldNot(HaveOccurred())
Expect(newTemplate).ToNot(BeNil(), " template should exists")
f.ManageTemplates(newTemplate)
Expand Down Expand Up @@ -222,13 +222,13 @@ var _ = Describe("Copy template task", func() {
}
f.TestSetup(config)

t, err := f.TemplateClient.Templates(config.TaskData.SourceNamespace).Create(context.TODO(), config.TaskData.Template, v1.CreateOptions{})
t, err := f.TemplateClient.Templates(config.TaskData.SourceNamespace).Create(context.Background(), config.TaskData.Template, v1.CreateOptions{})
Expect(err).ShouldNot(HaveOccurred())
f.ManageTemplates(t)

//create template which has the same name as template which will be created
config.TaskData.Template.Name = NewTemplateName
t, err = f.TemplateClient.Templates(string(config.TaskData.SourceNamespace)).Create(context.TODO(), config.TaskData.Template, v1.CreateOptions{})
t, err = f.TemplateClient.Templates(string(config.TaskData.SourceNamespace)).Create(context.Background(), config.TaskData.Template, v1.CreateOptions{})
Expect(err).ShouldNot(HaveOccurred())
f.ManageTemplates(t)

Expand All @@ -254,14 +254,14 @@ var _ = Describe("Copy template task", func() {
}
f.TestSetup(config)

t, err := f.TemplateClient.Templates(config.TaskData.SourceNamespace).Create(context.TODO(), config.TaskData.Template, v1.CreateOptions{})
t, err := f.TemplateClient.Templates(config.TaskData.SourceNamespace).Create(context.Background(), config.TaskData.Template, v1.CreateOptions{})
Expect(err).ShouldNot(HaveOccurred())
f.ManageTemplates(t)

//create template which has the same name as template which will be created
config.TaskData.Template.Name = NewTemplateName
config.TaskData.Template.Objects = []runtime.RawExtension{}
t, err = f.TemplateClient.Templates(string(config.TaskData.SourceNamespace)).Create(context.TODO(), config.TaskData.Template, v1.CreateOptions{})
t, err = f.TemplateClient.Templates(string(config.TaskData.SourceNamespace)).Create(context.Background(), config.TaskData.Template, v1.CreateOptions{})

Expect(err).ShouldNot(HaveOccurred())
f.ManageTemplates(t)
Expand All @@ -275,7 +275,7 @@ var _ = Describe("Copy template task", func() {
resultTemplateName := results["name"]
resultTemplateNamespace := results["namespace"]

newTemplate, err := f.TemplateClient.Templates(resultTemplateNamespace).Get(context.TODO(), resultTemplateName, v1.GetOptions{})
newTemplate, err := f.TemplateClient.Templates(resultTemplateNamespace).Get(context.Background(), resultTemplateName, v1.GetOptions{})
Expect(err).ShouldNot(HaveOccurred())
Expect(newTemplate).ToNot(BeNil(), " template should exists")
Expect(newTemplate.Objects).To(HaveLen(1), "template should be updated")
Expand Down
2 changes: 1 addition & 1 deletion modules/tests/test/create_vm_from_manifest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ var _ = Describe("Create VM from manifest", func() {
CreateVMResults.Namespace: expectedVMStub.Namespace,
})

vm, err := f.KubevirtClient.VirtualMachine(expectedVMStub.Namespace).Get(context.TODO(), expectedVMStub.Name, &v1.GetOptions{})
vm, err := f.KubevirtClient.VirtualMachine(expectedVMStub.Namespace).Get(context.Background(), expectedVMStub.Name, &v1.GetOptions{})
Expect(err).ShouldNot(HaveOccurred())

Expect(*vm.Spec.RunStrategy).To(Equal(expectedRunStrategy), "vm should have correct run strategy")
Expand Down
12 changes: 6 additions & 6 deletions modules/tests/test/create_vm_from_template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var _ = Describe("Create VM from template", func() {
f.TestSetup(config)

if template := config.TaskData.Template; template != nil {
template, err := f.TemplateClient.Templates(template.Namespace).Create(context.TODO(), template, v1.CreateOptions{})
template, err := f.TemplateClient.Templates(template.Namespace).Create(context.Background(), template, v1.CreateOptions{})
Expect(err).ShouldNot(HaveOccurred())
f.ManageTemplates(template)
}
Expand Down Expand Up @@ -153,7 +153,7 @@ var _ = Describe("Create VM from template", func() {
DescribeTable("VM is created successfully", func(config *testconfigs.CreateVMTestConfig) {
f.TestSetup(config)
if template := config.TaskData.Template; template != nil {
template, err := f.TemplateClient.Templates(template.Namespace).Create(context.TODO(), template, v1.CreateOptions{})
template, err := f.TemplateClient.Templates(template.Namespace).Create(context.Background(), template, v1.CreateOptions{})
Expect(err).ShouldNot(HaveOccurred())
f.ManageTemplates(template)
}
Expand Down Expand Up @@ -310,7 +310,7 @@ var _ = Describe("Create VM from template", func() {
},
}
f.TestSetup(config)
template, err := f.TemplateClient.Templates(template.Namespace).Create(context.TODO(), template, v1.CreateOptions{})
template, err := f.TemplateClient.Templates(template.Namespace).Create(context.Background(), template, v1.CreateOptions{})
Expect(err).ShouldNot(HaveOccurred())
f.ManageTemplates(template)

Expand Down Expand Up @@ -356,7 +356,7 @@ var _ = Describe("Create VM from template", func() {
Context("with StartVM", func() {
DescribeTable("VM is created from template with StartVM attribute", func(config *testconfigs.CreateVMTestConfig, phase kubevirtv1.VirtualMachineInstancePhase, running bool) {
f.TestSetup(config)
template, err := f.TemplateClient.Templates(config.TaskData.Template.Namespace).Create(context.TODO(), config.TaskData.Template, v1.CreateOptions{})
template, err := f.TemplateClient.Templates(config.TaskData.Template.Namespace).Create(context.Background(), config.TaskData.Template, v1.CreateOptions{})
Expect(err).ShouldNot(HaveOccurred())
f.ManageTemplates(template)

Expand Down Expand Up @@ -423,7 +423,7 @@ var _ = Describe("Create VM from template", func() {
DescribeTable("VM is created from template with runStrategy attribute", func(config *testconfigs.CreateVMTestConfig, expectedRunStrategy kubevirtv1.VirtualMachineRunStrategy) {
f.TestSetup(config)

template, err := f.TemplateClient.Templates(config.TaskData.Template.Namespace).Create(context.TODO(), config.TaskData.Template, v1.CreateOptions{})
template, err := f.TemplateClient.Templates(config.TaskData.Template.Namespace).Create(context.Background(), config.TaskData.Template, v1.CreateOptions{})
Expect(err).ShouldNot(HaveOccurred())
f.ManageTemplates(template)

Expand All @@ -439,7 +439,7 @@ var _ = Describe("Create VM from template", func() {
CreateVMResults.Namespace: expectedVMStub.Namespace,
})

vm, err := f.KubevirtClient.VirtualMachine(expectedVMStub.Namespace).Get(context.TODO(), expectedVMStub.Name, &v1.GetOptions{})
vm, err := f.KubevirtClient.VirtualMachine(expectedVMStub.Namespace).Get(context.Background(), expectedVMStub.Name, &v1.GetOptions{})
Expect(err).ShouldNot(HaveOccurred())

Expect(*vm.Spec.RunStrategy).To(Equal(expectedRunStrategy), "vm should have correct run strategy")
Expand Down
6 changes: 3 additions & 3 deletions modules/tests/test/dataobject/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func WaitForSuccessfulDataVolume(kubevirtClient kubevirtcliv1.KubevirtClient, na

func WaitForSuccessfulDataSource(cdiClientSet cdicliv1beta1.CdiV1beta1Interface, namespace, name string, timeout time.Duration) error {
return wait.PollImmediate(constants.PollInterval, timeout, func() (bool, error) {
dataSource, err := cdiClientSet.DataSources(namespace).Get(context.TODO(), name, metav1.GetOptions{})
dataSource, err := cdiClientSet.DataSources(namespace).Get(context.Background(), name, metav1.GetOptions{})
if err != nil {
return true, err
}
Expand All @@ -31,9 +31,9 @@ func WaitForSuccessfulDataSource(cdiClientSet cdicliv1beta1.CdiV1beta1Interface,
}

func IsDataVolumeImportSuccessful(kubevirtClient kubevirtcliv1.KubevirtClient, namespace, name string) (bool, error) {
dataVolume, err := kubevirtClient.CdiClient().CdiV1beta1().DataVolumes(namespace).Get(context.TODO(), name, metav1.GetOptions{})
dataVolume, err := kubevirtClient.CdiClient().CdiV1beta1().DataVolumes(namespace).Get(context.Background(), name, metav1.GetOptions{})
if errors.IsNotFound(err) {
pvc, err := kubevirtClient.CoreV1().PersistentVolumeClaims(namespace).Get(context.TODO(), name, metav1.GetOptions{})
pvc, err := kubevirtClient.CoreV1().PersistentVolumeClaims(namespace).Get(context.Background(), name, metav1.GetOptions{})
if err != nil {
return false, err
}
Expand Down
4 changes: 2 additions & 2 deletions modules/tests/test/disk_virt_libguestfs_tasks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ var _ = Describe("Run disk virt-customize / virt-sysprep", func() {
f.TestSetup(config)

if dataVolume := config.TaskData.Datavolume; dataVolume != nil {
dataVolume, err := f.CdiClient.DataVolumes(dataVolume.Namespace).Create(context.TODO(), dataVolume, metav1.CreateOptions{})
dataVolume, err := f.CdiClient.DataVolumes(dataVolume.Namespace).Create(context.Background(), dataVolume, metav1.CreateOptions{})
Expect(err).ShouldNot(HaveOccurred())
f.ManageDataVolumes(dataVolume)
err = dataobject.WaitForSuccessfulDataVolume(f.KubevirtClient, dataVolume.Namespace, dataVolume.Name, constants.Timeouts.SmallDVCreation.Duration)
Expand Down Expand Up @@ -125,7 +125,7 @@ var _ = Describe("Run disk virt-customize / virt-sysprep", func() {

dataVolume := testConfig.TaskData.Datavolume
// prepare DataVolume
dataVolume, err := f.CdiClient.DataVolumes(dataVolume.Namespace).Create(context.TODO(), dataVolume, metav1.CreateOptions{})
dataVolume, err := f.CdiClient.DataVolumes(dataVolume.Namespace).Create(context.Background(), dataVolume, metav1.CreateOptions{})
Expect(err).ShouldNot(HaveOccurred())
f.ManageDataVolumes(dataVolume)
err = dataobject.WaitForSuccessfulDataVolume(f.KubevirtClient, dataVolume.Namespace, dataVolume.Name, constants.Timeouts.SmallDVCreation.Duration)
Expand Down
16 changes: 8 additions & 8 deletions modules/tests/test/execute_and_cleanup_vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ var _ = Describe("Execute in VM / Cleanup VM", func() {
f.TestSetup(config)

if secret := config.TaskData.Secret; secret != nil {
secret, err := f.K8sClient.CoreV1().Secrets(secret.Namespace).Create(context.TODO(), secret, v1.CreateOptions{})
secret, err := f.K8sClient.CoreV1().Secrets(secret.Namespace).Create(context.Background(), secret, v1.CreateOptions{})
Expect(err).ShouldNot(HaveOccurred())
f.ManageSecrets(secret)
}
Expand All @@ -78,7 +78,7 @@ var _ = Describe("Execute in VM / Cleanup VM", func() {
"userdata": volume.CloudInitNoCloud.UserData,
},
}
cloudInitSecret, err := f.K8sClient.CoreV1().Secrets(vm.Namespace).Create(context.TODO(), cloudInitSecret, v1.CreateOptions{})
cloudInitSecret, err := f.K8sClient.CoreV1().Secrets(vm.Namespace).Create(context.Background(), cloudInitSecret, v1.CreateOptions{})
Expect(err).ShouldNot(HaveOccurred())
f.ManageSecrets(cloudInitSecret)
volume.CloudInitNoCloud.UserData = ""
Expand All @@ -87,11 +87,11 @@ var _ = Describe("Execute in VM / Cleanup VM", func() {
}
}
}
vm, err := f.KubevirtClient.VirtualMachine(vm.Namespace).Create(context.TODO(), vm)
vm, err := f.KubevirtClient.VirtualMachine(vm.Namespace).Create(context.Background(), vm)
Expect(err).ShouldNot(HaveOccurred())
f.ManageVMs(vm)
if config.TaskData.ShouldStartVM {
err := f.KubevirtClient.VirtualMachine(vm.Namespace).Start(context.TODO(), vm.Name, &kubevirtv1.StartOptions{})
err := f.KubevirtClient.VirtualMachine(vm.Namespace).Start(context.Background(), vm.Name, &kubevirtv1.StartOptions{})
Expect(err).ShouldNot(HaveOccurred())
time.Sleep(Timeouts.WaitBeforeExecutingVM.Duration)
}
Expand Down Expand Up @@ -431,17 +431,17 @@ var _ = Describe("Execute in VM / Cleanup VM", func() {
f.TestSetup(config)

if secret := config.TaskData.Secret; secret != nil {
secret, err := f.K8sClient.CoreV1().Secrets(secret.Namespace).Create(context.TODO(), secret, v1.CreateOptions{})
secret, err := f.K8sClient.CoreV1().Secrets(secret.Namespace).Create(context.Background(), secret, v1.CreateOptions{})
Expect(err).ShouldNot(HaveOccurred())
f.ManageSecrets(secret)
}

if vm := config.TaskData.VM; vm != nil {
vm, err := f.KubevirtClient.VirtualMachine(vm.Namespace).Create(context.TODO(), vm)
vm, err := f.KubevirtClient.VirtualMachine(vm.Namespace).Create(context.Background(), vm)
Expect(err).ShouldNot(HaveOccurred())
f.ManageVMs(vm)
if config.TaskData.ShouldStartVM {
err := f.KubevirtClient.VirtualMachine(vm.Namespace).Start(context.TODO(), vm.Name, &kubevirtv1.StartOptions{})
err := f.KubevirtClient.VirtualMachine(vm.Namespace).Start(context.Background(), vm.Name, &kubevirtv1.StartOptions{})
Expect(err).ShouldNot(HaveOccurred())
time.Sleep(Timeouts.WaitBeforeExecutingVM.Duration)
}
Expand All @@ -454,7 +454,7 @@ var _ = Describe("Execute in VM / Cleanup VM", func() {
ExpectTermination(config.ExpectedTermination).
ExpectResults(nil)

vm, err := f.KubevirtClient.VirtualMachine(config.TaskData.VMNamespace).Get(context.TODO(), config.TaskData.VMName, &metav1.GetOptions{})
vm, err := f.KubevirtClient.VirtualMachine(config.TaskData.VMNamespace).Get(context.Background(), config.TaskData.VMName, &metav1.GetOptions{})

if config.TaskData.Delete {
Expect(err).Should(HaveOccurred())
Expand Down
20 changes: 10 additions & 10 deletions modules/tests/test/framework/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,10 @@ func (f *Framework) AfterEach() {
defer func() {
if !f.Debug {
for _, taskRun := range taskRuns {
defer f.TknClient.TaskRuns(taskRun.Namespace).Delete(context.TODO(), taskRun.Name, metav1.DeleteOptions{})
defer f.TknClient.TaskRuns(taskRun.Namespace).Delete(context.Background(), taskRun.Name, metav1.DeleteOptions{})
}
for _, pipelineRun := range pipelineRuns {
defer f.TknClient.PipelineRuns(pipelineRun.Namespace).Delete(context.TODO(), pipelineRun.Name, metav1.DeleteOptions{})
defer f.TknClient.PipelineRuns(pipelineRun.Namespace).Delete(context.Background(), pipelineRun.Name, metav1.DeleteOptions{})
}
}
for _, taskRun := range taskRuns {
Expand All @@ -121,29 +121,29 @@ func (f *Framework) AfterEach() {

if !failed { // failed has its own cleanup
for _, taskRun := range taskRuns {
defer f.TknClient.TaskRuns(taskRun.Namespace).Delete(context.TODO(), taskRun.Name, metav1.DeleteOptions{})
defer f.TknClient.TaskRuns(taskRun.Namespace).Delete(context.Background(), taskRun.Name, metav1.DeleteOptions{})
}
for _, pipelineRun := range pipelineRuns {
defer f.TknClient.PipelineRuns(pipelineRun.Namespace).Delete(context.TODO(), pipelineRun.Name, metav1.DeleteOptions{})
defer f.TknClient.PipelineRuns(pipelineRun.Namespace).Delete(context.Background(), pipelineRun.Name, metav1.DeleteOptions{})
}
}
for _, pipeline := range f.managedResources.pipelines {
defer f.TknClient.Pipelines(pipeline.Namespace).Delete(context.TODO(), pipeline.Name, metav1.DeleteOptions{})
defer f.TknClient.Pipelines(pipeline.Namespace).Delete(context.Background(), pipeline.Name, metav1.DeleteOptions{})
}
for _, dv := range f.managedResources.dataVolumes {
defer f.CdiClient.DataVolumes(dv.Namespace).Delete(context.TODO(), dv.Name, metav1.DeleteOptions{})
defer f.CdiClient.DataVolumes(dv.Namespace).Delete(context.Background(), dv.Name, metav1.DeleteOptions{})
}
for _, ds := range f.managedResources.dataSources {
defer f.CdiClient.DataSources(ds.Namespace).Delete(context.TODO(), ds.Name, metav1.DeleteOptions{})
defer f.CdiClient.DataSources(ds.Namespace).Delete(context.Background(), ds.Name, metav1.DeleteOptions{})
}
for _, vm := range f.managedResources.vms {
defer f.KubevirtClient.VirtualMachine(vm.Namespace).Delete(context.TODO(), vm.Name, &metav1.DeleteOptions{})
defer f.KubevirtClient.VirtualMachine(vm.Namespace).Delete(context.Background(), vm.Name, &metav1.DeleteOptions{})
}
for _, t := range f.managedResources.templates {
defer f.TemplateClient.Templates(t.Namespace).Delete(context.TODO(), t.Name, metav1.DeleteOptions{})
defer f.TemplateClient.Templates(t.Namespace).Delete(context.Background(), t.Name, metav1.DeleteOptions{})
}
for _, s := range f.managedResources.secrets {
defer f.KubevirtClient.CoreV1().Secrets(s.Namespace).Delete(context.TODO(), s.Name, metav1.DeleteOptions{})
defer f.KubevirtClient.CoreV1().Secrets(s.Namespace).Delete(context.Background(), s.Name, metav1.DeleteOptions{})
}
for _, clusterInstancetype := range f.managedResources.clusterInstancetypes {
defer f.KubevirtClient.VirtualMachineClusterInstancetype().Delete(context.Background(), clusterInstancetype.Name, metav1.DeleteOptions{})
Expand Down
Loading

0 comments on commit b39a3f4

Please sign in to comment.