diff --git a/pkg/k8sclient/k8sclient.go b/pkg/k8sclient/k8sclient.go index 5c013499b..ce06486f8 100644 --- a/pkg/k8sclient/k8sclient.go +++ b/pkg/k8sclient/k8sclient.go @@ -92,8 +92,8 @@ func (c *ClientInfo) GetPodContext(ctx context.Context, namespace, name string) } // GetPodAPILiveQuery does a live API query for the pod, instead of using informers, for cases when a failure occurred, as to prevent a cache miss. -func (c *ClientInfo) GetPodAPILiveQuery(namespace, name string) (*v1.Pod, error) { - return c.Client.CoreV1().Pods(namespace).Get(context.TODO(), name, metav1.GetOptions{}) +func (c *ClientInfo) GetPodAPILiveQuery(ctx context.Context, namespace, name string) (*v1.Pod, error) { + return c.Client.CoreV1().Pods(namespace).Get(ctx, name, metav1.GetOptions{}) } // DeletePod deletes a pod from kubernetes diff --git a/pkg/multus/multus.go b/pkg/multus/multus.go index 165ea1816..5fda59163 100644 --- a/pkg/multus/multus.go +++ b/pkg/multus/multus.go @@ -558,7 +558,9 @@ func GetPod(kubeClient *k8s.ClientInfo, k8sArgs *types.K8sArgs, isDel bool) (*v1 // Try one more time to get the pod directly from the apiserver; // TODO: figure out why static pods don't show up via the informer // and always hit this case. - pod, err = kubeClient.GetPodAPILiveQuery(podNamespace, podName) + ctx, cancel := context.WithTimeout(context.TODO(), pollDuration) + defer cancel() + pod, err = kubeClient.GetPodAPILiveQuery(ctx, podNamespace, podName) if err != nil { return nil, cmdErr(k8sArgs, "error waiting for pod: %v", err) }