Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update pub readiness check in pub validating #1512

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading