Skip to content

Commit

Permalink
use context in k8s function calls
Browse files Browse the repository at this point in the history
  • Loading branch information
laverya committed Aug 1, 2024
1 parent 71a7bdb commit f9d22f3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion cmd/outdated/cli/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func RootCmd() *cobra.Command {
finishedCh <- true
}()

images, err := o.ListImages(KubernetesConfigFlags, foundImageName, v.GetStringSlice("ignore-ns"))
images, err := o.ListImages(cmd.Context(), KubernetesConfigFlags, foundImageName, v.GetStringSlice("ignore-ns"))
if err != nil {
log.Error(err)
log.Info("")
Expand Down
7 changes: 4 additions & 3 deletions pkg/outdated/list.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package outdated

import (
"context"
"fmt"
"strings"

Expand All @@ -20,7 +21,7 @@ type RunningImage struct {
PullableImage string
}

func (o Outdated) ListImages(configFlags *genericclioptions.ConfigFlags, imageNameCh chan string, ignoreNs []string) ([]RunningImage, error) {
func (o Outdated) ListImages(ctx context.Context, configFlags *genericclioptions.ConfigFlags, imageNameCh chan string, ignoreNs []string) ([]RunningImage, error) {
config, err := configFlags.ToRESTConfig()
if err != nil {
return nil, errors.Wrap(err, "failed to read kubeconfig")
Expand All @@ -31,7 +32,7 @@ func (o Outdated) ListImages(configFlags *genericclioptions.ConfigFlags, imageNa
return nil, errors.Wrap(err, "failed to create clientset")
}

namespaces, err := clientset.CoreV1().Namespaces().List(metav1.ListOptions{})
namespaces, err := clientset.CoreV1().Namespaces().List(ctx, metav1.ListOptions{})
if err != nil {
return nil, errors.Wrap(err, "failed to list namespaces")
}
Expand All @@ -44,7 +45,7 @@ func (o Outdated) ListImages(configFlags *genericclioptions.ConfigFlags, imageNa

imageNameCh <- fmt.Sprintf("%s/", namespace.Name)

pods, err := clientset.CoreV1().Pods(namespace.Name).List(metav1.ListOptions{})
pods, err := clientset.CoreV1().Pods(namespace.Name).List(ctx, metav1.ListOptions{})
if err != nil {
return nil, errors.Wrap(err, "failed to list pods")
}
Expand Down

0 comments on commit f9d22f3

Please sign in to comment.