diff --git a/pkg/control/pubcontrol/pub_control_utils.go b/pkg/control/pubcontrol/pub_control_utils.go index 8ef8ef1a28..9cce295627 100644 --- a/pkg/control/pubcontrol/pub_control_utils.go +++ b/pkg/control/pubcontrol/pub_control_utils.go @@ -64,9 +64,9 @@ func PodUnavailableBudgetValidatePod(pod *corev1.Pod, operation policyv1alpha1.P if pod.Annotations[policyv1alpha1.PodPubNoProtectionAnnotation] == "true" { klog.V(3).Infof("pod(%s/%s) contains annotations[%s]=true, then don't need check pub", pod.Namespace, pod.Name, policyv1alpha1.PodPubNoProtectionAnnotation) return true, "", nil - // If the pod is not ready, it doesn't count towards healthy and we should not decrement - } else if !PubControl.IsPodReady(pod) { - klog.V(3).Infof("pod(%s/%s) is not ready, then don't need check pub", pod.Namespace, pod.Name) + // If the pod is not ready or state is inconsistent, it doesn't count towards healthy and we should not decrement + } else if !PubControl.IsPodReady(pod) || !PubControl.IsPodStateConsistent(pod) { + klog.V(3).Infof("pod(%s/%s) is not ready or state is inconsistent, then don't need check pub", pod.Namespace, pod.Name) return true, "", nil } diff --git a/pkg/control/pubcontrol/pub_control_utils_test.go b/pkg/control/pubcontrol/pub_control_utils_test.go index 9a8da83759..5236615a87 100644 --- a/pkg/control/pubcontrol/pub_control_utils_test.go +++ b/pkg/control/pubcontrol/pub_control_utils_test.go @@ -21,6 +21,7 @@ import ( "testing" "time" + "github.com/openkruise/kruise/apis/apps/pub" appspub "github.com/openkruise/kruise/apis/apps/pub" policyv1alpha1 "github.com/openkruise/kruise/apis/policy/v1alpha1" "github.com/openkruise/kruise/pkg/util/controllerfinder" @@ -274,6 +275,34 @@ func TestPodUnavailableBudgetValidatePod(t *testing.T) { return pubStatus }, }, + { + name: "valid delete pod, pod state is inconsistent(inplace update not completed yet), ignore", + getPod: func() *corev1.Pod { + pod := podDemo.DeepCopy() + pod.Annotations[pub.InPlaceUpdateStateKey] = `{"nextContainerImages":{"main":"nginx:v2"}}` + return pod + }, + getPub: func() *policyv1alpha1.PodUnavailableBudget { + pub := pubDemo.DeepCopy() + return pub + }, + operation: policyv1alpha1.PubDeleteOperation, + expectAllow: true, + }, + { + name: "valid delete pod, pod declared no protect , ignore", + getPod: func() *corev1.Pod { + pod := podDemo.DeepCopy() + pod.Annotations[policyv1alpha1.PodPubNoProtectionAnnotation] = "true" + return pod + }, + getPub: func() *policyv1alpha1.PodUnavailableBudget { + pub := pubDemo.DeepCopy() + return pub + }, + operation: policyv1alpha1.PubDeleteOperation, + expectAllow: true, + }, } for _, cs := range cases {