Skip to content

Commit

Permalink
Optimize event handler performance for PodUnavailableBudget
Browse files Browse the repository at this point in the history
Signed-off-by: FillZpp <[email protected]>
  • Loading branch information
FillZpp committed Jul 16, 2022
1 parent 58713b5 commit 774f788
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 5 deletions.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@ func (p *enqueueRequestForPod) Update(evt event.UpdateEvent, q workqueue.RateLim
func (p *enqueueRequestForPod) updatePod(q workqueue.RateLimitingInterface, old, cur runtime.Object) {
newPod := cur.(*corev1.Pod)
oldPod := old.(*corev1.Pod)
if !isPodValidChanged(oldPod, newPod) {
return
}
pps := p.fetchPersistentPodState(newPod)
if pps == nil {
return
}
if !isPodValidChanged(oldPod, newPod) {
return
}
q.Add(reconcile.Request{
NamespacedName: types.NamespacedName{
Name: pps.Name,
Expand Down
2 changes: 0 additions & 2 deletions pkg/controller/podunavailablebudget/pub_pod_event_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,6 @@ func (p *enqueueRequestForPod) addPod(q workqueue.RateLimitingInterface, obj run
var pub *policyv1alpha1.PodUnavailableBudget
if pod.Annotations[pubcontrol.PodRelatedPubAnnotation] == "" {
pub, _ = GetPubForPod(p.client, pod)
} else {
pub, _ = p.pubControl.GetPubForPod(pod)
}
if pub == nil {
return
Expand Down
7 changes: 7 additions & 0 deletions pkg/webhook/pod/validating/pod_unavailable_budget.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ func (p *PodCreateHandler) podUnavailableBudgetValidatingPod(ctx context.Context
if err != nil {
return false, "", err
}
if newPod.Annotations[pubcontrol.PodRelatedPubAnnotation] == "" {
return true, "", nil
}
oldPod := &corev1.Pod{}
if err = p.Decoder.Decode(
admission.Request{AdmissionRequest: admissionv1.AdmissionRequest{Object: req.AdmissionRequest.OldObject}},
Expand Down Expand Up @@ -131,6 +134,10 @@ func (p *PodCreateHandler) podUnavailableBudgetValidatingPod(ctx context.Context
operation = policyv1alpha1.PubDeleteOperation
}

if checkPod.Annotations[pubcontrol.PodRelatedPubAnnotation] == "" {
return true, "", nil
}

// Get the workload corresponding to the pod, if it has been deleted then it is not protected
if ref := metav1.GetControllerOf(checkPod); ref != nil {
workload, err := p.finders.GetScaleAndSelectorForRef(ref.APIVersion, ref.Kind, checkPod.Namespace, ref.Name, ref.UID)
Expand Down

0 comments on commit 774f788

Please sign in to comment.