Skip to content

Commit

Permalink
update pub readiness check in pub validating (openkruise#1512)
Browse files Browse the repository at this point in the history
Co-authored-by: Spground <[email protected]>
  • Loading branch information
Spground and Spground authored Feb 28, 2024
1 parent e93fca5 commit 01b2dab
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
6 changes: 3 additions & 3 deletions pkg/control/pubcontrol/pub_control_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
29 changes: 29 additions & 0 deletions pkg/control/pubcontrol/pub_control_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 01b2dab

Please sign in to comment.