Skip to content

Commit

Permalink
update(pkg): pass contexts
Browse files Browse the repository at this point in the history
Signed-off-by: Leonardo Di Donato <[email protected]>
  • Loading branch information
leodido authored and fntlnz committed Oct 30, 2020
1 parent 792ff8b commit 7d7cd27
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
4 changes: 2 additions & 2 deletions pkg/attacher/attach.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/kubernetes/scheme"
tcorev1 "k8s.io/client-go/kubernetes/typed/core/v1"
"k8s.io/kubernetes/pkg/kubectl/util/term"
"k8s.io/kubectl/pkg/util/term"

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -58,7 +58,7 @@ func (a *Attacher) Attach(selector, namespace string) {
Jitter: 0.0,
Steps: 100,
}, func() (bool, error) {
pl, err := a.CoreV1Client.Pods(namespace).List(metav1.ListOptions{
pl, err := a.CoreV1Client.Pods(namespace).List(context.Background(), metav1.ListOptions{
LabelSelector: selector,
})

Expand Down
6 changes: 4 additions & 2 deletions pkg/logs/logs.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package logs

import (
"context"

"github.com/iovisor/kubectl-trace/pkg/meta"
tcorev1 "k8s.io/client-go/kubernetes/typed/core/v1"

Expand Down Expand Up @@ -34,7 +36,7 @@ const (
)

func (l *Logs) Run(jobID types.UID, namespace string, follow bool, timestamps bool) error {
pl, err := l.coreV1Client.Pods(namespace).List(metav1.ListOptions{
pl, err := l.coreV1Client.Pods(namespace).List(context.Background(), metav1.ListOptions{
LabelSelector: fmt.Sprintf("%s=%s", meta.TraceIDLabelKey, jobID),
})

Expand Down Expand Up @@ -70,7 +72,7 @@ func (l *Logs) Run(jobID types.UID, namespace string, follow bool, timestamps bo
}

func consumeRequest(request *rest.Request, out io.Writer) error {
readCloser, err := request.Stream()
readCloser, err := request.Stream(context.Background())
if err != nil {
return err
}
Expand Down
13 changes: 7 additions & 6 deletions pkg/tracejob/job.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package tracejob

import (
"context"
"fmt"
"io"
"io/ioutil"
Expand Down Expand Up @@ -86,7 +87,7 @@ func (t *TraceJobClient) findJobsWithFilter(nf TraceJobFilter) ([]batchv1.Job, e
return []batchv1.Job{}, nil
}

jl, err := t.JobClient.List(selectorOptions)
jl, err := t.JobClient.List(context.Background(), selectorOptions)

if err != nil {
return nil, err
Expand All @@ -100,7 +101,7 @@ func (t *TraceJobClient) findConfigMapsWithFilter(nf TraceJobFilter) ([]apiv1.Co
return []apiv1.ConfigMap{}, nil
}

cm, err := t.ConfigClient.List(selectorOptions)
cm, err := t.ConfigClient.List(context.Background(), selectorOptions)

if err != nil {
return nil, err
Expand Down Expand Up @@ -152,7 +153,7 @@ func (t *TraceJobClient) DeleteJobs(nf TraceJobFilter) error {

dp := metav1.DeletePropagationForeground
for _, j := range jl {
err := t.JobClient.Delete(j.Name, &metav1.DeleteOptions{
err := t.JobClient.Delete(context.Background(), j.Name, metav1.DeleteOptions{
GracePeriodSeconds: int64Ptr(0),
PropagationPolicy: &dp,
})
Expand All @@ -170,7 +171,7 @@ func (t *TraceJobClient) DeleteJobs(nf TraceJobFilter) error {
}

for _, c := range cl {
err := t.ConfigClient.Delete(c.Name, nil)
err := t.ConfigClient.Delete(context.Background(), c.Name, metav1.DeleteOptions{})
if err != nil {
return err
}
Expand Down Expand Up @@ -469,10 +470,10 @@ func (t *TraceJobClient) CreateJob(nj TraceJob) (*batchv1.Job, error) {
ReadOnly: true,
})
}
if _, err := t.ConfigClient.Create(cm); err != nil {
if _, err := t.ConfigClient.Create(context.Background(), cm, metav1.CreateOptions{}); err != nil {
return nil, err
}
return t.JobClient.Create(job)
return t.JobClient.Create(context.Background(), job, metav1.CreateOptions{})
}

func int32Ptr(i int32) *int32 { return &i }
Expand Down

0 comments on commit 7d7cd27

Please sign in to comment.