diff --git a/pkg/proxy/util/endpoints.go b/pkg/proxy/util/endpoints.go index 28d0d9da71d..3924a087994 100644 --- a/pkg/proxy/util/endpoints.go +++ b/pkg/proxy/util/endpoints.go @@ -36,13 +36,13 @@ func IPPart(s string) string { // Must be IP:port host, _, err := net.SplitHostPort(s) if err != nil { - klog.Errorf("Error parsing '%s': %v", s, err) + klog.ErrorS(err, "Failed to parse host-port", "input", s) return "" } // Check if host string is a valid IP address ip := netutils.ParseIPSloppy(host) if ip == nil { - klog.Errorf("invalid IP part '%s'", host) + klog.ErrorS(nil, "Failed to parse IP", "input", host) return "" } return ip.String() @@ -53,12 +53,12 @@ func PortPart(s string) (int, error) { // Must be IP:port _, port, err := net.SplitHostPort(s) if err != nil { - klog.Errorf("Error parsing '%s': %v", s, err) + klog.ErrorS(err, "Failed to parse host-port", "input", s) return -1, err } portNumber, err := strconv.Atoi(port) if err != nil { - klog.Errorf("Error parsing '%s': %v", port, err) + klog.ErrorS(err, "Failed to parse port", "input", port) return -1, err } return portNumber, nil diff --git a/pkg/proxy/util/iptables/traffic.go b/pkg/proxy/util/iptables/traffic.go index 28e019673ab..2ee0ae015be 100644 --- a/pkg/proxy/util/iptables/traffic.go +++ b/pkg/proxy/util/iptables/traffic.go @@ -81,12 +81,12 @@ func (d *detectLocalByCIDR) IsImplemented() bool { func (d *detectLocalByCIDR) JumpIfLocal(args []string, toChain string) []string { line := append(args, "-s", d.cidr, "-j", toChain) - klog.V(4).Info("[DetectLocalByCIDR (", d.cidr, ")", " Jump Local: ", line) + klog.V(4).InfoS("Detect Local By CIDR", "cidr", d.cidr, "jumpLocal", line) return line } func (d *detectLocalByCIDR) JumpIfNotLocal(args []string, toChain string) []string { line := append(args, "!", "-s", d.cidr, "-j", toChain) - klog.V(4).Info("[DetectLocalByCIDR (", d.cidr, ")]", " Jump Not Local: ", line) + klog.V(4).InfoS("Detect Local By CIDR", "cidr", d.cidr, "jumpNotLocal", line) return line } diff --git a/pkg/proxy/util/utils.go b/pkg/proxy/util/utils.go index e6b5acdbb47..a5d4d921dd3 100644 --- a/pkg/proxy/util/utils.go +++ b/pkg/proxy/util/utils.go @@ -176,12 +176,12 @@ func GetLocalAddrSet() netutils.IPSet { func ShouldSkipService(service *v1.Service) bool { // if ClusterIP is "None" or empty, skip proxying if !helper.IsServiceIPSet(service) { - klog.V(3).Infof("Skipping service %s in namespace %s due to clusterIP = %q", service.Name, service.Namespace, service.Spec.ClusterIP) + klog.V(3).InfoS("Skipping service due to cluster IP", "service", klog.KObj(service), "clusterIP", service.Spec.ClusterIP) return true } // Even if ClusterIP is set, ServiceTypeExternalName services don't get proxied if service.Spec.Type == v1.ServiceTypeExternalName { - klog.V(3).Infof("Skipping service %s in namespace %s due to Type=ExternalName", service.Name, service.Namespace) + klog.V(3).InfoS("Skipping service due to Type=ExternalName", "service", klog.KObj(service)) return true } return false @@ -254,7 +254,7 @@ func GetNodeAddresses(cidrs []string, nw NetworkInterfacer) (sets.String, error) // LogAndEmitIncorrectIPVersionEvent logs and emits incorrect IP version event. func LogAndEmitIncorrectIPVersionEvent(recorder events.EventRecorder, fieldName, fieldValue, svcNamespace, svcName string, svcUID types.UID) { errMsg := fmt.Sprintf("%s in %s has incorrect IP version", fieldValue, fieldName) - klog.Errorf("%s (service %s/%s).", errMsg, svcNamespace, svcName) + klog.ErrorS(nil, "Incorrect IP version", "service", klog.KRef(svcNamespace, svcName), "field", fieldName, "value", fieldValue) if recorder != nil { recorder.Eventf( &v1.ObjectReference{ @@ -274,7 +274,7 @@ func MapIPsByIPFamily(ipStrings []string) map[v1.IPFamily][]string { if ipFamily, err := getIPFamilyFromIP(ip); err == nil { ipFamilyMap[ipFamily] = append(ipFamilyMap[ipFamily], ip) } else { - klog.Errorf("Skipping invalid IP: %s", ip) + klog.ErrorS(nil, "Skipping invalid IP", "ip", ip) } } return ipFamilyMap @@ -288,7 +288,7 @@ func MapCIDRsByIPFamily(cidrStrings []string) map[v1.IPFamily][]string { if ipFamily, err := getIPFamilyFromCIDR(cidr); err == nil { ipFamilyMap[ipFamily] = append(ipFamilyMap[ipFamily], cidr) } else { - klog.Errorf("Skipping invalid cidr: %s", cidr) + klog.ErrorS(nil, "Skipping invalid CIDR", "cidr", cidr) } } return ipFamilyMap @@ -367,7 +367,7 @@ func EnsureSysctl(sysctl utilsysctl.Interface, name string, newVal int) error { if err := sysctl.SetSysctl(name, newVal); err != nil { return fmt.Errorf("can't set sysctl %s to %d: %v", name, newVal, err) } - klog.V(1).Infof("Changed sysctl %q: %d -> %d", name, oldVal, newVal) + klog.V(1).InfoS("Changed sysctl", "name", name, "before", oldVal, "after", newVal) } return nil } @@ -496,7 +496,7 @@ func RevertPorts(replacementPortsMap, originalPortsMap map[netutils.LocalPort]ne for k, v := range replacementPortsMap { // Only close newly opened local ports - leave ones that were open before this update if originalPortsMap[k] == nil { - klog.V(2).Infof("Closing local port %s", k.String()) + klog.V(2).InfoS("Closing local port", "port", k.String()) v.Close() } }