Skip to content

Commit

Permalink
lazyload: skip refresh when metric result has not changed
Browse files Browse the repository at this point in the history
Signed-off-by: believening <kang_417@yeah.net>
  • Loading branch information
believening committed Jan 13, 2023
1 parent 74110e7 commit a3dd41a
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions staging/src/slime.io/slime/modules/lazyload/controllers/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ func (r *ServicefenceReconciler) Refresh(req reconcile.Request, value map[string
return reconcile.Result{}, nil
}

log.Debugf("refresh with servicefence %s metricstatus old: %v, new: %v", req.NamespacedName, sf.Status.MetricStatus, value)
// skip refresh when metric result has not changed
if mapStrStrEqual(sf.Status.MetricStatus, value) {
return reconcile.Result{}, nil
}
// use updateVisitedHostStatus to update svf.spec and svf.status
sf.Status.MetricStatus = value
diff := r.updateVisitedHostStatus(sf)
Expand All @@ -109,6 +114,22 @@ func (r *ServicefenceReconciler) Refresh(req reconcile.Request, value map[string
return reconcile.Result{}, nil
}

func mapStrStrEqual(m1, m2 map[string]string) bool {
if len(m1) != len(m2) {
return false
}
for k, v1 := range m1 {
v2, exist := m2[k]
if !exist {
return false
}
if v2 != v1 {
return false
}
}
return true
}

func (r *ServicefenceReconciler) isNsFenced(ns *corev1.Namespace) bool {
if ns != nil && ns.Labels != nil {
switch ns.Labels[LabelServiceFenced] {
Expand Down

0 comments on commit a3dd41a

Please sign in to comment.