From 2b7373f336b9fcf70eb4371d2043f3bef136973d Mon Sep 17 00:00:00 2001 From: kerthcet Date: Sun, 4 Sep 2022 19:34:22 +0800 Subject: [PATCH] kube-proxy: code optimization Signed-off-by: kerthcet --- pkg/proxy/service.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pkg/proxy/service.go b/pkg/proxy/service.go index 2346565ed25..01ae6a69a6d 100644 --- a/pkg/proxy/service.go +++ b/pkg/proxy/service.go @@ -296,14 +296,15 @@ func NewServiceChangeTracker(makeServiceInfo makeServicePortFunc, ipFamily v1.IP // Delete item // - pass as the pair. func (sct *ServiceChangeTracker) Update(previous, current *v1.Service) bool { + // This is unexpected, we should return false directly. + if previous == nil && current == nil { + return false + } + svc := current if svc == nil { svc = previous } - // previous == nil && current == nil is unexpected, we should return false directly. - if svc == nil { - return false - } metrics.ServiceChangesTotal.Inc() namespacedName := types.NamespacedName{Namespace: svc.Namespace, Name: svc.Name}