Migrate pkg/proxy/util
to structured logging (#104908)
* Migrate to Structured Logs in `pkg/proxy/util` * Minor fixes * change key to cidr and remove namespace arg * Update key from cidr to CIDR Co-authored-by: JUN YANG <69306452+yangjunmyfm192085@users.noreply.github.com> * Update key cidr to CIDR Co-authored-by: JUN YANG <69306452+yangjunmyfm192085@users.noreply.github.com> * Update key ip to IP Co-authored-by: JUN YANG <69306452+yangjunmyfm192085@users.noreply.github.com> * Update key ip to IP Co-authored-by: JUN YANG <69306452+yangjunmyfm192085@users.noreply.github.com> * Interchange svcNamespace and svcName * Change first letter of all messages to capital * Change key names in endpoints.go * Change all keynames to lower bumby caps convention Co-authored-by: JUN YANG <69306452+yangjunmyfm192085@users.noreply.github.com>
This commit is contained in:
@@ -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()
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user