mirror of
https://github.com/k8snetworkplumbingwg/multus-cni.git
synced 2025-09-09 21:00:03 +00:00
This makes sure that stale caches never result in NotFound errors.
It was explained to me that informers are almost always are more efficient, and in most cases will work, but a live lookup is appropriate after a number of failures. This happens only on the retry portion, so we're still getting the benefits of informers, but, on a retry situation, we don't get a cache miss. Additionally, changes out use of cache get on this, since it already bails out before it on CNI DEL.
This commit is contained in:
@@ -91,6 +91,11 @@ func (c *ClientInfo) GetPodContext(ctx context.Context, namespace, name string)
|
|||||||
return c.Client.CoreV1().Pods(namespace).Get(ctx, name, metav1.GetOptions{})
|
return c.Client.CoreV1().Pods(namespace).Get(ctx, name, metav1.GetOptions{})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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{})
|
||||||
|
}
|
||||||
|
|
||||||
// DeletePod deletes a pod from kubernetes
|
// DeletePod deletes a pod from kubernetes
|
||||||
func (c *ClientInfo) DeletePod(namespace, name string) error {
|
func (c *ClientInfo) DeletePod(namespace, name string) error {
|
||||||
return c.Client.CoreV1().Pods(namespace).Delete(context.TODO(), name, metav1.DeleteOptions{})
|
return c.Client.CoreV1().Pods(namespace).Delete(context.TODO(), name, metav1.DeleteOptions{})
|
||||||
|
@@ -558,9 +558,7 @@ func GetPod(kubeClient *k8s.ClientInfo, k8sArgs *types.K8sArgs, isDel bool) (*v1
|
|||||||
// Try one more time to get the pod directly from the apiserver;
|
// 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
|
// TODO: figure out why static pods don't show up via the informer
|
||||||
// and always hit this case.
|
// and always hit this case.
|
||||||
ctx, cancel := context.WithTimeout(context.TODO(), pollDuration)
|
pod, err = kubeClient.GetPodAPILiveQuery(podNamespace, podName)
|
||||||
defer cancel()
|
|
||||||
pod, err = kubeClient.GetPodContext(ctx, podNamespace, podName)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, cmdErr(k8sArgs, "error waiting for pod: %v", err)
|
return nil, cmdErr(k8sArgs, "error waiting for pod: %v", err)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user