mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 09:22:44 +00:00
Merge pull request #122574 from brianpursley/kubectl-1532
Fix kubectl drain error handling bug.
This commit is contained in:
commit
56ecdadd99
@ -417,7 +417,9 @@ func waitForDelete(params waitForDeleteParams) ([]corev1.Pod, error) {
|
|||||||
pendingPods := []corev1.Pod{}
|
pendingPods := []corev1.Pod{}
|
||||||
for i, pod := range pods {
|
for i, pod := range pods {
|
||||||
p, err := params.getPodFn(pod.Namespace, pod.Name)
|
p, err := params.getPodFn(pod.Namespace, pod.Name)
|
||||||
if apierrors.IsNotFound(err) || (p != nil && p.ObjectMeta.UID != pod.ObjectMeta.UID) {
|
// The implementation of getPodFn that uses client-go returns an empty Pod struct when there is an error,
|
||||||
|
// so we need to check that err == nil and p != nil to know that a pod was found successfully.
|
||||||
|
if apierrors.IsNotFound(err) || (err == nil && p != nil && p.ObjectMeta.UID != pod.ObjectMeta.UID) {
|
||||||
if params.onFinishFn != nil {
|
if params.onFinishFn != nil {
|
||||||
params.onFinishFn(&pod, params.usingEviction, nil)
|
params.onFinishFn(&pod, params.usingEviction, nil)
|
||||||
} else if params.onDoneFn != nil {
|
} else if params.onDoneFn != nil {
|
||||||
|
@ -72,10 +72,27 @@ func TestDeletePods(t *testing.T) {
|
|||||||
newPod := newPodMap[name]
|
newPod := newPodMap[name]
|
||||||
return &newPod, nil
|
return &newPod, nil
|
||||||
}
|
}
|
||||||
return nil, apierrors.NewNotFound(schema.GroupResource{Resource: "pods"}, name)
|
return &corev1.Pod{}, apierrors.NewNotFound(schema.GroupResource{Resource: "pods"}, name)
|
||||||
|
|
||||||
}
|
}
|
||||||
return nil, apierrors.NewNotFound(schema.GroupResource{Resource: "pods"}, name)
|
return &corev1.Pod{}, apierrors.NewNotFound(schema.GroupResource{Resource: "pods"}, name)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
description: "Pod found with same name but different UID",
|
||||||
|
interval: 100 * time.Millisecond,
|
||||||
|
timeout: 10 * time.Second,
|
||||||
|
expectPendingPods: false,
|
||||||
|
expectError: false,
|
||||||
|
expectedError: nil,
|
||||||
|
getPodFn: func(namespace, name string) (*corev1.Pod, error) {
|
||||||
|
// Return a pod with the same name, but different UID
|
||||||
|
return &corev1.Pod{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Namespace: namespace,
|
||||||
|
Name: name,
|
||||||
|
UID: "SOME_OTHER_UID",
|
||||||
|
},
|
||||||
|
}, nil
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -90,7 +107,7 @@ func TestDeletePods(t *testing.T) {
|
|||||||
if oldPod, found := oldPodMap[name]; found {
|
if oldPod, found := oldPodMap[name]; found {
|
||||||
return &oldPod, nil
|
return &oldPod, nil
|
||||||
}
|
}
|
||||||
return nil, fmt.Errorf("%q: not found", name)
|
return &corev1.Pod{}, fmt.Errorf("%q: not found", name)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -106,7 +123,7 @@ func TestDeletePods(t *testing.T) {
|
|||||||
if oldPod, found := oldPodMap[name]; found {
|
if oldPod, found := oldPodMap[name]; found {
|
||||||
return &oldPod, nil
|
return &oldPod, nil
|
||||||
}
|
}
|
||||||
return nil, fmt.Errorf("%q: not found", name)
|
return &corev1.Pod{}, fmt.Errorf("%q: not found", name)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -123,7 +140,7 @@ func TestDeletePods(t *testing.T) {
|
|||||||
oldPod.ObjectMeta.SetDeletionTimestamp(dTime)
|
oldPod.ObjectMeta.SetDeletionTimestamp(dTime)
|
||||||
return &oldPod, nil
|
return &oldPod, nil
|
||||||
}
|
}
|
||||||
return nil, fmt.Errorf("%q: not found", name)
|
return &corev1.Pod{}, fmt.Errorf("%q: not found", name)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -134,7 +151,7 @@ func TestDeletePods(t *testing.T) {
|
|||||||
expectError: true,
|
expectError: true,
|
||||||
expectedError: nil,
|
expectedError: nil,
|
||||||
getPodFn: func(namespace, name string) (*corev1.Pod, error) {
|
getPodFn: func(namespace, name string) (*corev1.Pod, error) {
|
||||||
return nil, errors.New("This is a random error for testing")
|
return &corev1.Pod{}, errors.New("This is a random error for testing")
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user