Skip to content

Commit c253398

Browse files
authored
refactor: cleanup context passing in kubernetes runtime (#314)
1 parent c9c8b3c commit c253398

File tree

2 files changed

+12
-18
lines changed

2 files changed

+12
-18
lines changed

runtime/kubernetes/build.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,9 @@ func (c *client) SetupBuild(ctx context.Context, b *pipeline.Build) error {
4545

4646
if c.PipelinePodTemplate == nil {
4747
if len(c.config.PipelinePodsTemplateName) > 0 {
48-
// nolint: contextcheck // ignore non-inherited new context
49-
podsTemplateResponse, err := c.VelaKubernetes.VelaV1alpha1().PipelinePodsTemplates(c.config.Namespace).Get(
50-
context.Background(), c.config.PipelinePodsTemplateName, metav1.GetOptions{},
51-
)
48+
podsTemplateResponse, err := c.VelaKubernetes.VelaV1alpha1().
49+
PipelinePodsTemplates(c.config.Namespace).
50+
Get(ctx, c.config.PipelinePodsTemplateName, metav1.GetOptions{})
5251
if err != nil {
5352
return err
5453
}
@@ -192,10 +191,9 @@ func (c *client) AssembleBuild(ctx context.Context, b *pipeline.Build) error {
192191
// send API call to create the pod
193192
//
194193
// https://pkg.go.dev/k8s.io/client-go/kubernetes/typed/core/v1?tab=doc#PodInterface
195-
// nolint: contextcheck // ignore non-inherited new context
196194
_, err = c.Kubernetes.CoreV1().
197195
Pods(c.config.Namespace).
198-
Create(context.Background(), c.Pod, metav1.CreateOptions{})
196+
Create(ctx, c.Pod, metav1.CreateOptions{})
199197
if err != nil {
200198
return err
201199
}
@@ -233,10 +231,9 @@ func (c *client) RemoveBuild(ctx context.Context, b *pipeline.Build) error {
233231

234232
c.Logger.Infof("removing pod %s", c.Pod.ObjectMeta.Name)
235233
// send API call to delete the pod
236-
// nolint: contextcheck // ignore non-inherited new context
237234
err := c.Kubernetes.CoreV1().
238235
Pods(c.config.Namespace).
239-
Delete(context.Background(), c.Pod.ObjectMeta.Name, opts)
236+
Delete(ctx, c.Pod.ObjectMeta.Name, opts)
240237
if err != nil {
241238
return err
242239
}

runtime/kubernetes/container.go

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,9 @@ func (c *client) InspectContainer(ctx context.Context, ctn *pipeline.Container)
3434
// send API call to capture the container
3535
//
3636
// https://pkg.go.dev/k8s.io/client-go/kubernetes/typed/core/v1?tab=doc#PodInterface
37-
// nolint: contextcheck // ignore non-inherited new context
38-
pod, err := c.Kubernetes.CoreV1().Pods(c.config.Namespace).Get(
39-
context.Background(),
40-
c.Pod.ObjectMeta.Name,
41-
opts,
42-
)
37+
pod, err := c.Kubernetes.CoreV1().
38+
Pods(c.config.Namespace).
39+
Get(ctx, c.Pod.ObjectMeta.Name, opts)
4340
if err != nil {
4441
return err
4542
}
@@ -104,9 +101,8 @@ func (c *client) RunContainer(ctx context.Context, ctn *pipeline.Container, b *p
104101
// send API call to patch the pod with the new container image
105102
//
106103
// https://pkg.go.dev/k8s.io/client-go/kubernetes/typed/core/v1?tab=doc#PodInterface
107-
// nolint: contextcheck // ignore non-inherited new context
108104
_, err = c.Kubernetes.CoreV1().Pods(c.config.Namespace).Patch(
109-
context.Background(),
105+
ctx,
110106
c.Pod.ObjectMeta.Name,
111107
types.StrategicMergePatchType,
112108
[]byte(fmt.Sprintf(imagePatch, ctn.ID, _image)),
@@ -343,8 +339,9 @@ func (c *client) WaitContainer(ctx context.Context, ctn *pipeline.Container) err
343339
// https://pkg.go.dev/k8s.io/client-go/kubernetes/typed/core/v1?tab=doc#PodInterface
344340
// ->
345341
// https://pkg.go.dev/k8s.io/apimachinery/pkg/watch?tab=doc#Interface
346-
// nolint: contextcheck // ignore non-inherited new context
347-
podWatch, err := c.Kubernetes.CoreV1().Pods(c.config.Namespace).Watch(context.Background(), opts)
342+
podWatch, err := c.Kubernetes.CoreV1().
343+
Pods(c.config.Namespace).
344+
Watch(ctx, opts)
348345
if err != nil {
349346
return err
350347
}

0 commit comments

Comments
 (0)