From 668a546168f8a190bbd8f30b57469a5b95423587 Mon Sep 17 00:00:00 2001 From: Justin SB Date: Tue, 7 Sep 2021 13:32:07 -0400 Subject: [PATCH] Don't perform expensive go-cmp/cmp comparisons if unneeded The cmp comparison is relatively expensive (#104821). If we're not going to log it, we shouldn't make the comparison. --- .../legacy-cloud-providers/gce/gce_loadbalancer_internal.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/staging/src/k8s.io/legacy-cloud-providers/gce/gce_loadbalancer_internal.go b/staging/src/k8s.io/legacy-cloud-providers/gce/gce_loadbalancer_internal.go index 454617e29f7..15e97362921 100644 --- a/staging/src/k8s.io/legacy-cloud-providers/gce/gce_loadbalancer_internal.go +++ b/staging/src/k8s.io/legacy-cloud-providers/gce/gce_loadbalancer_internal.go @@ -198,8 +198,10 @@ func (g *Cloud) ensureInternalLoadBalancer(clusterName, clusterID string, svc *v // Delete existing forwarding rule before making changes to the backend service. For example - changing protocol // of backend service without first deleting forwarding rule will throw an error since the linked forwarding // rule would show the old protocol. - frDiff := cmp.Diff(existingFwdRule, newFwdRule) - klog.V(2).Infof("ensureInternalLoadBalancer(%v): forwarding rule changed - Existing - %+v\n, New - %+v\n, Diff(-existing, +new) - %s\n. Deleting existing forwarding rule.", loadBalancerName, existingFwdRule, newFwdRule, frDiff) + if klog.V(2).Enabled() { + frDiff := cmp.Diff(existingFwdRule, newFwdRule) + klog.V(2).Infof("ensureInternalLoadBalancer(%v): forwarding rule changed - Existing - %+v\n, New - %+v\n, Diff(-existing, +new) - %s\n. Deleting existing forwarding rule.", loadBalancerName, existingFwdRule, newFwdRule, frDiff) + } if err = ignoreNotFound(g.DeleteRegionForwardingRule(loadBalancerName, g.region)); err != nil { return nil, err }