mirror of
https://github.com/k8snetworkplumbingwg/multus-cni.git
synced 2025-07-17 09:12:33 +00:00
Merge pull request #1372 from pmtk/dont-wait-too-long-for-apiserver
Thin plugin: don't wait too long for an answer from API Server
This commit is contained in:
commit
5338017bf6
@ -82,6 +82,15 @@ func (c *ClientInfo) GetPod(namespace, name string) (*v1.Pod, error) {
|
|||||||
return c.Client.CoreV1().Pods(namespace).Get(context.TODO(), name, metav1.GetOptions{})
|
return c.Client.CoreV1().Pods(namespace).Get(context.TODO(), name, metav1.GetOptions{})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetPodContext gets pod from kubernetes with context
|
||||||
|
func (c *ClientInfo) GetPodContext(ctx context.Context, namespace, name string) (*v1.Pod, error) {
|
||||||
|
if c.PodInformer != nil {
|
||||||
|
logging.Debugf("GetPod for [%s/%s] will use informer cache", namespace, name)
|
||||||
|
return listers.NewPodLister(c.PodInformer.GetIndexer()).Pods(namespace).Get(name)
|
||||||
|
}
|
||||||
|
return c.Client.CoreV1().Pods(namespace).Get(ctx, 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{})
|
||||||
|
@ -542,7 +542,10 @@ func GetPod(kubeClient *k8s.ClientInfo, k8sArgs *types.K8sArgs, isDel bool) (*v1
|
|||||||
var pod *v1.Pod
|
var pod *v1.Pod
|
||||||
if err := wait.PollImmediate(pollDuration, shortPollTimeout, func() (bool, error) {
|
if err := wait.PollImmediate(pollDuration, shortPollTimeout, func() (bool, error) {
|
||||||
var getErr error
|
var getErr error
|
||||||
pod, getErr = kubeClient.GetPod(podNamespace, podName)
|
// Use context with a short timeout so the call to API server doesn't take too long.
|
||||||
|
ctx, cancel := context.WithTimeout(context.TODO(), pollDuration)
|
||||||
|
defer cancel()
|
||||||
|
pod, getErr = kubeClient.GetPodContext(ctx, podNamespace, podName)
|
||||||
if isCriticalRequestRetriable(getErr) || retryOnNotFound(getErr) {
|
if isCriticalRequestRetriable(getErr) || retryOnNotFound(getErr) {
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
@ -555,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;
|
// 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.
|
||||||
pod, err = kubeClient.GetPod(podNamespace, podName)
|
ctx, cancel := context.WithTimeout(context.TODO(), pollDuration)
|
||||||
|
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)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user