From 6c7b4b852252f493538bd1cf8fd6cf3f95775f16 Mon Sep 17 00:00:00 2001 From: Doug Hellmann Date: Mon, 6 Mar 2023 09:06:55 -0500 Subject: [PATCH] OCPBUGS-8329: update sysconfwatch-controller logging There is no need to log the gateway IP address every time we look it up, so only log it when it changes. This is somewhat redundant to the logic in the controller itself, but the IP returned from GetHostIP() is not always the gateway IP and GetHostIP() may have other callers. This change also rewords another log message related to how the host IP is being selected to make it clear what effect the failure to find a default route has on the outcome. --- pkg/util/net.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pkg/util/net.go b/pkg/util/net.go index a73bfcae0a..c984299855 100644 --- a/pkg/util/net.go +++ b/pkg/util/net.go @@ -32,19 +32,24 @@ import ( "k8s.io/klog/v2" ) +var previousGatewayIP string = "" + func GetHostIP() (string, error) { // Prefer OVN-K gateway IP if it is the CNI gatewayIP, err := ovn.GetOVNGatewayIP() if err != nil && !strings.Contains(err.Error(), "no such network interface") { return "", err } - klog.V(2).Infof("ovn gateway IP address: %s", gatewayIP) + if gatewayIP != previousGatewayIP { + previousGatewayIP = gatewayIP + klog.V(2).Infof("ovn gateway IP address: %s", gatewayIP) + } ip, err := net.ChooseHostInterface() if err == nil { return ip.String(), nil } - klog.V(2).Infof("failed to find default route IP address: %v", err) + klog.V(2).Infof("could not find default route IP address, using ovn gateway IP %q as host IP: %v", gatewayIP, err) return gatewayIP, nil }