Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed improperly migrated logs #105763

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
77c9c57
fixed improperly migrated logs
shivanshuraj1333 Oct 19, 2021
c3b4426
small fixes
shivanshuraj1333 Oct 19, 2021
205f6e6
small fix
shivanshuraj1333 Oct 19, 2021
e1682af
Update pkg/proxy/iptables/proxier.go
shivanshuraj1333 Oct 19, 2021
cc852ee
Update pkg/proxy/healthcheck/service_health.go
shivanshuraj1333 Oct 19, 2021
7a8f7f3
Update pkg/proxy/iptables/proxier.go
shivanshuraj1333 Oct 19, 2021
de4b7ad
Update pkg/proxy/iptables/proxier.go
shivanshuraj1333 Oct 19, 2021
57f4b5d
Update pkg/proxy/iptables/proxier.go
shivanshuraj1333 Oct 19, 2021
1db2a3a
Update pkg/proxy/iptables/proxier.go
shivanshuraj1333 Oct 19, 2021
85ab26f
Update pkg/proxy/ipvs/proxier.go
shivanshuraj1333 Oct 19, 2021
d8f6539
Update pkg/proxy/ipvs/proxier.go
shivanshuraj1333 Oct 19, 2021
293d959
Update pkg/proxy/ipvs/proxier.go
shivanshuraj1333 Oct 19, 2021
51c5e8c
Update pkg/proxy/winkernel/proxier.go
shivanshuraj1333 Oct 19, 2021
e0d4e7d
Update pkg/proxy/winkernel/proxier.go
shivanshuraj1333 Oct 19, 2021
dc68cf3
Update pkg/proxy/winkernel/proxier.go
shivanshuraj1333 Oct 19, 2021
930aabe
Update pkg/proxy/winkernel/proxier.go
shivanshuraj1333 Oct 19, 2021
db9bf09
Update pkg/proxy/winkernel/proxier.go
shivanshuraj1333 Oct 19, 2021
d451ebc
Update pkg/proxy/winkernel/proxier.go
shivanshuraj1333 Oct 19, 2021
9efe08e
Update pkg/proxy/winkernel/proxier.go
shivanshuraj1333 Oct 19, 2021
eae1be7
Update pkg/proxy/winkernel/proxier.go
shivanshuraj1333 Oct 19, 2021
c636f71
Update pkg/proxy/winkernel/proxier.go
shivanshuraj1333 Oct 19, 2021
953ae09
Update pkg/proxy/winkernel/proxier.go
shivanshuraj1333 Oct 19, 2021
c499052
Update pkg/proxy/winkernel/proxier.go
shivanshuraj1333 Oct 19, 2021
8ed5cc3
Update pkg/proxy/winkernel/proxier.go
shivanshuraj1333 Oct 19, 2021
b91de06
refactoring
shivanshuraj1333 Oct 19, 2021
7951fb5
refactoring
shivanshuraj1333 Oct 19, 2021
9e0bffd
refactoring
shivanshuraj1333 Oct 19, 2021
859ade1
reverted some files back to master
shivanshuraj1333 Oct 19, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions cmd/kube-proxy/app/server.go
Expand Up @@ -498,7 +498,8 @@ with the apiserver API to configure the proxy.`,
}

if err := opts.Run(); err != nil {
klog.Exit(err)
klog.ErrorS(err, "Error running ProxyServer")
os.Exit(1)
}
},
Args: func(cmd *cobra.Command, args []string) error {
Expand Down Expand Up @@ -843,7 +844,7 @@ func detectNodeIP(client clientset.Interface, hostname, bindAddress string) net.
nodeIP = utilnode.GetNodeIP(client, hostname)
}
if nodeIP == nil {
klog.V(0).Infof("can't determine this node's IP, assuming 127.0.0.1; if this is incorrect, please set the --bind-address flag")
klog.V(0).InfoS("Can't determine this node's IP, assuming 127.0.0.1; if this is incorrect, please set the --bind-address flag")
nodeIP = netutils.ParseIPSloppy("127.0.0.1")
}
return nodeIP
Expand Down
2 changes: 1 addition & 1 deletion pkg/proxy/healthcheck/proxier_health.go
Expand Up @@ -104,7 +104,7 @@ func (hs *proxierHealthServer) Run() error {
return fmt.Errorf("%v", msg)
}

klog.V(3).Infof("starting healthz on %s", hs.addr)
klog.V(3).InfoS("Starting healthz HTTP server", "address", hs.addr)

if err := server.Serve(listener); err != nil {
return fmt.Errorf("proxier healthz closed with error: %v", err)
Expand Down
23 changes: 12 additions & 11 deletions pkg/proxy/healthcheck/service_health.go
Expand Up @@ -104,23 +104,24 @@ func (hcs *server) SyncServices(newServices map[types.NamespacedName]uint16) err
// Remove any that are not needed any more.
for nsn, svc := range hcs.services {
if port, found := newServices[nsn]; !found || port != svc.port {
klog.V(2).InfoS("Closing healthcheck", "service", nsn.String(), "port", svc.port)
klog.V(2).InfoS("Closing healthcheck", "service", nsn, "port", svc.port)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a note, we should use keys like "service" for kubernetes objects that are passed to klog.KObj func. Here we have weird case where code doesn't pass K8s object, but type.NamespacedName which can be used to reference an object. We should make sure that passing and K8s object or namespaced name will result in the same log.

At this moment I don't think that type.NamespacedName implements GetName() string and GetNamespace() string methods to be passed to klog.KObj. Would be good to follow up on this.
cc @pohly

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the NamespacedName struct

type NamespacedName struct {
	Namespace string
	Name      string
}

and yes, it doesn't implement GetName() and GetNamspace() functions.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to wrap this in KObj. That would just cause overhead. Instead we should implement the new logr.Marshaler interface. I've created #105782 to track this.


// errors are loged in closeAll()
_ = svc.closeAll()

delete(hcs.services, nsn)

}
}

// Add any that are needed.
for nsn, port := range newServices {
if hcs.services[nsn] != nil {
klog.V(3).InfoS("Existing healthcheck", "service", nsn.String(), "port", port)
klog.V(3).InfoS("Existing healthcheck", "service", nsn, "port", port)
continue
}

klog.V(2).InfoS("Opening healthcheck", "service", nsn.String(), "port", port)
klog.V(2).InfoS("Opening healthcheck", "service", nsn, "port", port)

svc := &hcInstance{nsn: nsn, port: port}
err := svc.listenAndServeAll(hcs)
Expand All @@ -137,7 +138,7 @@ func (hcs *server) SyncServices(newServices map[types.NamespacedName]uint16) err
UID: types.UID(nsn.String()),
}, nil, api.EventTypeWarning, "FailedToStartServiceHealthcheck", "Listen", msg)
}
klog.ErrorS(err, "failed to start healthcheck", "node", hcs.hostname, "service", nsn.String(), "port", port)
klog.ErrorS(err, "failed to start healthcheck", "node", hcs.hostname, "service", nsn, "port", port)
continue
}
hcs.services[nsn] = svc
Expand Down Expand Up @@ -181,12 +182,12 @@ func (hcI *hcInstance) listenAndServeAll(hcs *server) error {
// start serving
go func(hcI *hcInstance, listener net.Listener, httpSrv httpServer) {
// Serve() will exit when the listener is closed.
klog.V(3).InfoS("Starting goroutine for healthcheck", "service", hcI.nsn.String(), "address", listener.Addr().String())
klog.V(3).InfoS("Starting goroutine for healthcheck", "service", hcI.nsn, "address", listener.Addr())
if err := httpSrv.Serve(listener); err != nil {
klog.ErrorS(err, "Healthcheck closed", "service", hcI.nsn.String())
klog.ErrorS(err, "Healthcheck closed", "service", hcI.nsn)
return
}
klog.V(3).InfoS("Healthcheck closed", "service", hcI.nsn.String(), "address", listener.Addr().String())
klog.V(3).InfoS("Healthcheck closed", "service", hcI.nsn, "address", listener.Addr())
}(hcI, listener, httpSrv)

hcI.listeners = append(hcI.listeners, listener)
Expand All @@ -200,7 +201,7 @@ func (hcI *hcInstance) closeAll() error {
errors := []error{}
for _, listener := range hcI.listeners {
if err := listener.Close(); err != nil {
klog.Errorf("Service %q -- CloseListener(%v) error:%v", hcI.nsn, listener.Addr(), err)
klog.ErrorS(err, "Error closing listener for health check service", "healthCheckService", hcI.nsn, "listener", listener.Addr())
shivanshuraj1333 marked this conversation as resolved.
Show resolved Hide resolved
errors = append(errors, err)
}
}
Expand All @@ -224,7 +225,7 @@ func (h hcHandler) ServeHTTP(resp http.ResponseWriter, req *http.Request) {
svc, ok := h.hcs.services[h.name]
if !ok || svc == nil {
h.hcs.lock.RUnlock()
klog.ErrorS(nil, "Received request for closed healthcheck", "service", h.name.String())
klog.ErrorS(nil, "Received request for closed healthcheck", "service", h.name)
return
}
count := svc.endpoints
Expand Down Expand Up @@ -254,10 +255,10 @@ func (hcs *server) SyncEndpoints(newEndpoints map[types.NamespacedName]int) erro

for nsn, count := range newEndpoints {
if hcs.services[nsn] == nil {
klog.V(3).InfoS("Not saving endpoints for unknown healthcheck", "service", nsn.String())
klog.V(3).InfoS("Not saving endpoints for unknown healthcheck", "service", nsn)
continue
}
klog.V(3).InfoS("Reporting endpoints for healthcheck", "endpointCount", count, "service", nsn.String())
klog.V(3).InfoS("Reporting endpoints for healthcheck", "endpointCount", count, "service", nsn)
hcs.services[nsn].endpoints = count
}
for nsn, hci := range hcs.services {
Expand Down
28 changes: 14 additions & 14 deletions pkg/proxy/iptables/proxier.go
Expand Up @@ -737,23 +737,23 @@ func (proxier *Proxier) deleteEndpointConnections(connectionMap []proxy.ServiceE
if nodePort != 0 {
err = conntrack.ClearEntriesForPortNAT(proxier.exec, endpointIP, nodePort, svcProto)
if err != nil {
klog.ErrorS(err, "Failed to delete nodeport-related endpoint connections", "servicePortName", epSvcPair.ServicePortName.String())
klog.ErrorS(err, "Failed to delete nodeport-related endpoint connections", "servicePortName", epSvcPair.ServicePortName)
}
}
err = conntrack.ClearEntriesForNAT(proxier.exec, svcInfo.ClusterIP().String(), endpointIP, svcProto)
if err != nil {
klog.ErrorS(err, "Failed to delete endpoint connections", "servicePortName", epSvcPair.ServicePortName.String())
klog.ErrorS(err, "Failed to delete endpoint connections", "servicePortName", epSvcPair.ServicePortName)
}
for _, extIP := range svcInfo.ExternalIPStrings() {
err := conntrack.ClearEntriesForNAT(proxier.exec, extIP, endpointIP, svcProto)
if err != nil {
klog.ErrorS(err, "Failed to delete endpoint connections for externalIP", "servicePortName", epSvcPair.ServicePortName.String(), "externalIP", extIP)
klog.ErrorS(err, "Failed to delete endpoint connections for externalIP", "servicePortName", epSvcPair.ServicePortName, "externalIP", extIP)
}
}
for _, lbIP := range svcInfo.LoadBalancerIPStrings() {
err := conntrack.ClearEntriesForNAT(proxier.exec, lbIP, endpointIP, svcProto)
if err != nil {
klog.ErrorS(err, "Failed to delete endpoint connections for LoadBalancerIP", "servicePortName", epSvcPair.ServicePortName.String(), "loadBalancerIP", lbIP)
klog.ErrorS(err, "Failed to delete endpoint connections for LoadBalancerIP", "servicePortName", epSvcPair.ServicePortName, "loadBalancerIP", lbIP)
}
}
}
Expand Down Expand Up @@ -807,7 +807,7 @@ func (proxier *Proxier) syncProxyRules() {
// an UDP service that changes from 0 to non-0 endpoints is considered stale.
for _, svcPortName := range endpointUpdateResult.StaleServiceNames {
if svcInfo, ok := proxier.serviceMap[svcPortName]; ok && svcInfo != nil && conntrack.IsClearConntrackNeeded(svcInfo.Protocol()) {
klog.V(2).InfoS("Stale service", "protocol", strings.ToLower(string(svcInfo.Protocol())), "svcPortName", svcPortName.String(), "clusterIP", svcInfo.ClusterIP().String())
klog.V(2).InfoS("Stale service", "protocol", strings.ToLower(string(svcInfo.Protocol())), "svcPortName", svcPortName, "clusterIP", svcInfo.ClusterIP())
shivanshuraj1333 marked this conversation as resolved.
Show resolved Hide resolved
conntrackCleanupServiceIPs.Insert(svcInfo.ClusterIP().String())
for _, extIP := range svcInfo.ExternalIPStrings() {
conntrackCleanupServiceIPs.Insert(extIP)
Expand All @@ -817,7 +817,7 @@ func (proxier *Proxier) syncProxyRules() {
}
nodePort := svcInfo.NodePort()
if svcInfo.Protocol() == v1.ProtocolUDP && nodePort != 0 {
klog.V(2).Infof("Stale %s service NodePort %v -> %d", strings.ToLower(string(svcInfo.Protocol())), svcPortName, nodePort)
klog.V(2).InfoS("Stale service", "protocol", strings.ToLower(string(svcInfo.Protocol())), "svcPortName", svcPortName, "nodePort", nodePort)
shivanshuraj1333 marked this conversation as resolved.
Show resolved Hide resolved
conntrackCleanupServiceNodePorts.Insert(nodePort)
}
}
Expand Down Expand Up @@ -984,7 +984,7 @@ func (proxier *Proxier) syncProxyRules() {
for svcName, svc := range proxier.serviceMap {
svcInfo, ok := svc.(*serviceInfo)
if !ok {
klog.ErrorS(nil, "Failed to cast serviceInfo", "svcName", svcName.String())
klog.ErrorS(nil, "Failed to cast serviceInfo", "svcName", svcName)
shivanshuraj1333 marked this conversation as resolved.
Show resolved Hide resolved
continue
}
isIPv6 := netutils.IsIPv6(svcInfo.ClusterIP())
Expand Down Expand Up @@ -1072,7 +1072,7 @@ func (proxier *Proxier) syncProxyRules() {
Protocol: netutils.Protocol(svcInfo.Protocol()),
}
if proxier.portsMap[lp] != nil {
klog.V(4).InfoS("Port was open before and is still needed", "port", lp.String())
klog.V(4).InfoS("Port was open before and is still needed", "port", lp)
replacementPortsMap[lp] = proxier.portsMap[lp]
} else {
socket, err := proxier.portMapper.OpenLocalPort(&lp)
Expand All @@ -1086,10 +1086,10 @@ func (proxier *Proxier) syncProxyRules() {
UID: types.UID(proxier.hostname),
Namespace: "",
}, nil, v1.EventTypeWarning, err.Error(), "SyncProxyRules", msg)
klog.ErrorS(err, "can't open port, skipping it", "port", lp.String())
klog.ErrorS(err, "can't open port, skipping it", "port", lp)
shivanshuraj1333 marked this conversation as resolved.
Show resolved Hide resolved
continue
}
klog.V(2).InfoS("Opened local port", "port", lp.String())
klog.V(2).InfoS("Opened local port", "port", lp)
replacementPortsMap[lp] = socket
}
}
Expand Down Expand Up @@ -1244,7 +1244,7 @@ func (proxier *Proxier) syncProxyRules() {
// For ports on node IPs, open the actual port and hold it.
for _, lp := range lps {
if proxier.portsMap[lp] != nil {
klog.V(4).InfoS("Port was open before and is still needed", "port", lp.String())
klog.V(4).InfoS("Port was open before and is still needed", "port", lp)
replacementPortsMap[lp] = proxier.portsMap[lp]
} else if svcInfo.Protocol() != v1.ProtocolSCTP {
socket, err := proxier.portMapper.OpenLocalPort(&lp)
Expand All @@ -1258,10 +1258,10 @@ func (proxier *Proxier) syncProxyRules() {
UID: types.UID(proxier.hostname),
Namespace: "",
}, nil, v1.EventTypeWarning, err.Error(), "SyncProxyRules", msg)
klog.ErrorS(err, "can't open port, skipping it", "port", lp.String())
klog.ErrorS(err, "can't open port, skipping it", "port", lp)
shivanshuraj1333 marked this conversation as resolved.
Show resolved Hide resolved
continue
}
klog.V(2).InfoS("Opened local port", "port", lp.String())
klog.V(2).InfoS("Opened local port", "port", lp)
replacementPortsMap[lp] = socket
}
}
Expand Down Expand Up @@ -1328,7 +1328,7 @@ func (proxier *Proxier) syncProxyRules() {
for _, ep := range allEndpoints {
epInfo, ok := ep.(*endpointsInfo)
if !ok {
klog.ErrorS(err, "Failed to cast endpointsInfo", "endpointsInfo", ep.String())
klog.ErrorS(err, "Failed to cast endpointsInfo", "endpointsInfo", ep)
continue
}

Expand Down