Merge pull request #100558 from yangjunmyfm192085/run-test31

Optimize the structured Logging migration.
This commit is contained in:
Kubernetes Prow Robot 2021-06-01 20:54:37 -07:00 committed by GitHub
commit 61db6e05f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 33 deletions

View File

@ -108,7 +108,7 @@ func (info *ServiceInfo) IsAlive() bool {
func logTimeout(err error) bool { func logTimeout(err error) bool {
if e, ok := err.(net.Error); ok { if e, ok := err.(net.Error); ok {
if e.Timeout() { if e.Timeout() {
klog.V(3).InfoS("connection to endpoint closed due to inactivity") klog.V(3).InfoS("Connection to endpoint closed due to inactivity")
return true return true
} }
} }
@ -270,7 +270,7 @@ func createProxier(loadBalancer LoadBalancer, listenIP net.IP, iptables iptables
exec: exec, exec: exec,
stopChan: make(chan struct{}), stopChan: make(chan struct{}),
} }
klog.V(3).InfoS("record sync param", "minSyncPeriod", minSyncPeriod, "syncPeriod", syncPeriod, "burstSyncs", numBurstSyncs) klog.V(3).InfoS("Record sync param", "minSyncPeriod", minSyncPeriod, "syncPeriod", syncPeriod, "burstSyncs", numBurstSyncs)
proxier.syncRunner = async.NewBoundedFrequencyRunner("userspace-proxy-sync-runner", proxier.syncProxyRules, minSyncPeriod, syncPeriod, numBurstSyncs) proxier.syncRunner = async.NewBoundedFrequencyRunner("userspace-proxy-sync-runner", proxier.syncProxyRules, minSyncPeriod, syncPeriod, numBurstSyncs)
return proxier, nil return proxier, nil
} }
@ -368,7 +368,7 @@ func (proxier *Proxier) Sync() {
func (proxier *Proxier) syncProxyRules() { func (proxier *Proxier) syncProxyRules() {
start := time.Now() start := time.Now()
defer func() { defer func() {
klog.V(4).InfoS("userspace syncProxyRules complete", "elapsed", time.Since(start)) klog.V(4).InfoS("Userspace syncProxyRules complete", "elapsed", time.Since(start))
}() }()
// don't sync rules till we've received services and endpoints // don't sync rules till we've received services and endpoints
@ -412,7 +412,7 @@ func (proxier *Proxier) ensurePortals() {
for name, info := range proxier.serviceMap { for name, info := range proxier.serviceMap {
err := proxier.openPortal(name, info) err := proxier.openPortal(name, info)
if err != nil { if err != nil {
klog.ErrorS(err, "Failed to ensure portal", "servicePortName", name.String()) klog.ErrorS(err, "Failed to ensure portal", "servicePortName", name)
} }
} }
} }
@ -469,7 +469,7 @@ func (proxier *Proxier) addServiceOnPortInternal(service proxy.ServicePortName,
} }
proxier.serviceMap[service] = si proxier.serviceMap[service] = si
klog.V(2).InfoS("Proxying for service", "service", service.String(), "protocol", protocol, "port", portStr) klog.V(2).InfoS("Proxying for service", "service", service, "protocol", protocol, "portNum", portNum)
go func() { go func() {
defer runtime.HandleCrash() defer runtime.HandleCrash()
sock.ProxyLoop(service, si, proxier.loadBalancer) sock.ProxyLoop(service, si, proxier.loadBalancer)
@ -508,7 +508,7 @@ func (proxier *Proxier) mergeService(service *v1.Service) sets.String {
continue continue
} }
if exists { if exists {
klog.V(4).InfoS("Something changed for service: stopping it", "serviceName", serviceName.String()) klog.V(4).InfoS("Something changed for service: stopping it", "serviceName", serviceName)
if err := proxier.cleanupPortalAndProxy(serviceName, info); err != nil { if err := proxier.cleanupPortalAndProxy(serviceName, info); err != nil {
klog.ErrorS(err, "Failed to cleanup portal and proxy") klog.ErrorS(err, "Failed to cleanup portal and proxy")
} }
@ -516,7 +516,7 @@ func (proxier *Proxier) mergeService(service *v1.Service) sets.String {
} }
proxyPort, err := proxier.proxyPorts.AllocateNext() proxyPort, err := proxier.proxyPorts.AllocateNext()
if err != nil { if err != nil {
klog.ErrorS(err, "Failed to allocate proxy port", "serviceName", serviceName.String()) klog.ErrorS(err, "Failed to allocate proxy port", "serviceName", serviceName)
continue continue
} }
@ -539,10 +539,10 @@ func (proxier *Proxier) mergeService(service *v1.Service) sets.String {
info.stickyMaxAgeSeconds = int(*service.Spec.SessionAffinityConfig.ClientIP.TimeoutSeconds) info.stickyMaxAgeSeconds = int(*service.Spec.SessionAffinityConfig.ClientIP.TimeoutSeconds)
} }
klog.V(4).InfoS("record serviceInfo", "serviceInfo", info) klog.V(4).InfoS("Record serviceInfo", "serviceInfo", info)
if err := proxier.openPortal(serviceName, info); err != nil { if err := proxier.openPortal(serviceName, info); err != nil {
klog.ErrorS(err, "Failed to open portal", "serviceName", serviceName.String()) klog.ErrorS(err, "Failed to open portal", "serviceName", serviceName)
} }
proxier.loadBalancer.NewService(serviceName, info.sessionAffinityType, info.stickyMaxAgeSeconds) proxier.loadBalancer.NewService(serviceName, info.sessionAffinityType, info.stickyMaxAgeSeconds)
@ -569,7 +569,7 @@ func (proxier *Proxier) unmergeService(service *v1.Service, existingPorts sets.S
} }
serviceName := proxy.ServicePortName{NamespacedName: svcName, Port: servicePort.Name} serviceName := proxy.ServicePortName{NamespacedName: svcName, Port: servicePort.Name}
klog.V(1).InfoS("Stopping service", "serviceName", serviceName.String()) klog.V(1).InfoS("Stopping service", "serviceName", serviceName)
info, exists := proxier.serviceMap[serviceName] info, exists := proxier.serviceMap[serviceName]
if !exists { if !exists {
klog.ErrorS(nil, "Service is being removed but doesn't exist", "serviceName", serviceName) klog.ErrorS(nil, "Service is being removed but doesn't exist", "serviceName", serviceName)
@ -581,7 +581,7 @@ func (proxier *Proxier) unmergeService(service *v1.Service, existingPorts sets.S
} }
if err := proxier.cleanupPortalAndProxy(serviceName, info); err != nil { if err := proxier.cleanupPortalAndProxy(serviceName, info); err != nil {
klog.ErrorS(err, "clean up portal and proxy") klog.ErrorS(err, "Clean up portal and proxy")
} }
proxier.loadBalancer.DeleteService(serviceName) proxier.loadBalancer.DeleteService(serviceName)
info.setFinished() info.setFinished()
@ -600,7 +600,7 @@ func (proxier *Proxier) serviceChange(previous, current *v1.Service, detail stri
} else { } else {
svcName = types.NamespacedName{Namespace: previous.Namespace, Name: previous.Name} svcName = types.NamespacedName{Namespace: previous.Namespace, Name: previous.Name}
} }
klog.V(4).InfoS("record service change", "action", detail, "svcName", svcName.String()) klog.V(4).InfoS("Record service change", "action", detail, "svcName", svcName)
proxier.serviceChangesLock.Lock() proxier.serviceChangesLock.Lock()
defer proxier.serviceChangesLock.Unlock() defer proxier.serviceChangesLock.Unlock()
@ -648,7 +648,7 @@ func (proxier *Proxier) OnServiceDelete(service *v1.Service) {
// OnServiceSynced is called once all the initial event handlers were // OnServiceSynced is called once all the initial event handlers were
// called and the state is fully propagated to local cache. // called and the state is fully propagated to local cache.
func (proxier *Proxier) OnServiceSynced() { func (proxier *Proxier) OnServiceSynced() {
klog.V(2).InfoS("userspace OnServiceSynced") klog.V(2).InfoS("Userspace OnServiceSynced")
// Mark services as initialized and (if endpoints are already // Mark services as initialized and (if endpoints are already
// initialized) the entire proxy as initialized // initialized) the entire proxy as initialized
@ -684,7 +684,7 @@ func (proxier *Proxier) OnEndpointsDelete(endpoints *v1.Endpoints) {
// OnEndpointsSynced is called once all the initial event handlers were // OnEndpointsSynced is called once all the initial event handlers were
// called and the state is fully propagated to local cache. // called and the state is fully propagated to local cache.
func (proxier *Proxier) OnEndpointsSynced() { func (proxier *Proxier) OnEndpointsSynced() {
klog.V(2).InfoS("userspace OnEndpointsSynced") klog.V(2).InfoS("Userspace OnEndpointsSynced")
proxier.loadBalancer.OnEndpointsSynced() proxier.loadBalancer.OnEndpointsSynced()
// Mark endpoints as initialized and (if services are already // Mark endpoints as initialized and (if services are already
@ -772,7 +772,7 @@ func (proxier *Proxier) openOnePortal(portal portal, protocol v1.Protocol, proxy
portalAddress := net.JoinHostPort(portal.ip.String(), strconv.Itoa(portal.port)) portalAddress := net.JoinHostPort(portal.ip.String(), strconv.Itoa(portal.port))
existed, err := proxier.iptables.EnsureRule(iptables.Append, iptables.TableNAT, iptablesContainerPortalChain, args...) existed, err := proxier.iptables.EnsureRule(iptables.Append, iptables.TableNAT, iptablesContainerPortalChain, args...)
if err != nil { if err != nil {
klog.ErrorS(err, "Failed to install iptables rule for service", "chain", iptablesContainerPortalChain, "servicePortName", name.String(), "args", args) klog.ErrorS(err, "Failed to install iptables rule for service", "chain", iptablesContainerPortalChain, "servicePortName", name, "args", args)
return err return err
} }
if !existed { if !existed {
@ -857,7 +857,7 @@ func (proxier *Proxier) releaseNodePort(ip net.IP, port int, protocol v1.Protoco
existing, found := proxier.portMap[key] existing, found := proxier.portMap[key]
if !found { if !found {
// We tolerate this, it happens if we are cleaning up a failed allocation // We tolerate this, it happens if we are cleaning up a failed allocation
klog.InfoS("Ignoring release on unowned port", "port", key.String()) klog.InfoS("Ignoring release on unowned port", "port", key)
return nil return nil
} }
if existing.owner != owner { if existing.owner != owner {
@ -881,32 +881,32 @@ func (proxier *Proxier) openNodePort(nodePort int, protocol v1.Protocol, proxyIP
args := proxier.iptablesContainerPortalArgs(nil, false, false, nodePort, protocol, proxyIP, proxyPort, name) args := proxier.iptablesContainerPortalArgs(nil, false, false, nodePort, protocol, proxyIP, proxyPort, name)
existed, err := proxier.iptables.EnsureRule(iptables.Append, iptables.TableNAT, iptablesContainerNodePortChain, args...) existed, err := proxier.iptables.EnsureRule(iptables.Append, iptables.TableNAT, iptablesContainerNodePortChain, args...)
if err != nil { if err != nil {
klog.ErrorS(err, "Failed to install iptables rule for service", "chain", iptablesContainerNodePortChain, "servicePortName", name.String()) klog.ErrorS(err, "Failed to install iptables rule for service", "chain", iptablesContainerNodePortChain, "servicePortName", name)
return err return err
} }
if !existed { if !existed {
klog.InfoS("Opened iptables from-containers public port for service", "servicePortName", name.String(), "protocol", protocol, "nodePort", nodePort) klog.InfoS("Opened iptables from-containers public port for service", "servicePortName", name, "protocol", protocol, "nodePort", nodePort)
} }
// Handle traffic from the host. // Handle traffic from the host.
args = proxier.iptablesHostNodePortArgs(nodePort, protocol, proxyIP, proxyPort, name) args = proxier.iptablesHostNodePortArgs(nodePort, protocol, proxyIP, proxyPort, name)
existed, err = proxier.iptables.EnsureRule(iptables.Append, iptables.TableNAT, iptablesHostNodePortChain, args...) existed, err = proxier.iptables.EnsureRule(iptables.Append, iptables.TableNAT, iptablesHostNodePortChain, args...)
if err != nil { if err != nil {
klog.ErrorS(err, "Failed to install iptables rule for service", "chain", iptablesHostNodePortChain, "servicePortName", name.String()) klog.ErrorS(err, "Failed to install iptables rule for service", "chain", iptablesHostNodePortChain, "servicePortName", name)
return err return err
} }
if !existed { if !existed {
klog.InfoS("Opened iptables from-host public port for service", "servicePortName", name.String(), "protocol", protocol, "nodePort", nodePort) klog.InfoS("Opened iptables from-host public port for service", "servicePortName", name, "protocol", protocol, "nodePort", nodePort)
} }
args = proxier.iptablesNonLocalNodePortArgs(nodePort, protocol, proxyIP, proxyPort, name) args = proxier.iptablesNonLocalNodePortArgs(nodePort, protocol, proxyIP, proxyPort, name)
existed, err = proxier.iptables.EnsureRule(iptables.Append, iptables.TableFilter, iptablesNonLocalNodePortChain, args...) existed, err = proxier.iptables.EnsureRule(iptables.Append, iptables.TableFilter, iptablesNonLocalNodePortChain, args...)
if err != nil { if err != nil {
klog.ErrorS(err, "Failed to install iptables rule for service", "chain", iptablesNonLocalNodePortChain, "servicePortName", name.String()) klog.ErrorS(err, "Failed to install iptables rule for service", "chain", iptablesNonLocalNodePortChain, "servicePortName", name)
return err return err
} }
if !existed { if !existed {
klog.InfoS("Opened iptables from-non-local public port for service", "servicePortName", name.String(), "protocol", protocol, "nodePort", nodePort) klog.InfoS("Opened iptables from-non-local public port for service", "servicePortName", name, "protocol", protocol, "nodePort", nodePort)
} }
return nil return nil
@ -927,9 +927,9 @@ func (proxier *Proxier) closePortal(service proxy.ServicePortName, info *Service
el = append(el, proxier.closeNodePort(info.nodePort, info.protocol, proxier.listenIP, info.proxyPort, service)...) el = append(el, proxier.closeNodePort(info.nodePort, info.protocol, proxier.listenIP, info.proxyPort, service)...)
} }
if len(el) == 0 { if len(el) == 0 {
klog.V(3).InfoS("Closed iptables portals for service", "servicePortName", service.String()) klog.V(3).InfoS("Closed iptables portals for service", "servicePortName", service)
} else { } else {
klog.ErrorS(nil, "Some errors closing iptables portals for service", "servicePortName", service.String()) klog.ErrorS(nil, "Some errors closing iptables portals for service", "servicePortName", service)
} }
return utilerrors.NewAggregate(el) return utilerrors.NewAggregate(el)
} }
@ -945,20 +945,20 @@ func (proxier *Proxier) closeOnePortal(portal portal, protocol v1.Protocol, prox
// Handle traffic from containers. // Handle traffic from containers.
args := proxier.iptablesContainerPortalArgs(portal.ip, portal.isExternal, false, portal.port, protocol, proxyIP, proxyPort, name) args := proxier.iptablesContainerPortalArgs(portal.ip, portal.isExternal, false, portal.port, protocol, proxyIP, proxyPort, name)
if err := proxier.iptables.DeleteRule(iptables.TableNAT, iptablesContainerPortalChain, args...); err != nil { if err := proxier.iptables.DeleteRule(iptables.TableNAT, iptablesContainerPortalChain, args...); err != nil {
klog.ErrorS(err, "Failed to delete iptables rule for service", "chain", iptablesContainerPortalChain, "servicePortName", name.String()) klog.ErrorS(err, "Failed to delete iptables rule for service", "chain", iptablesContainerPortalChain, "servicePortName", name)
el = append(el, err) el = append(el, err)
} }
if portal.isExternal { if portal.isExternal {
args := proxier.iptablesContainerPortalArgs(portal.ip, false, true, portal.port, protocol, proxyIP, proxyPort, name) args := proxier.iptablesContainerPortalArgs(portal.ip, false, true, portal.port, protocol, proxyIP, proxyPort, name)
if err := proxier.iptables.DeleteRule(iptables.TableNAT, iptablesContainerPortalChain, args...); err != nil { if err := proxier.iptables.DeleteRule(iptables.TableNAT, iptablesContainerPortalChain, args...); err != nil {
klog.ErrorS(err, "Failed to delete iptables rule for service", "chain", iptablesContainerPortalChain, "servicePortName", name.String()) klog.ErrorS(err, "Failed to delete iptables rule for service", "chain", iptablesContainerPortalChain, "servicePortName", name)
el = append(el, err) el = append(el, err)
} }
args = proxier.iptablesHostPortalArgs(portal.ip, true, portal.port, protocol, proxyIP, proxyPort, name) args = proxier.iptablesHostPortalArgs(portal.ip, true, portal.port, protocol, proxyIP, proxyPort, name)
if err := proxier.iptables.DeleteRule(iptables.TableNAT, iptablesHostPortalChain, args...); err != nil { if err := proxier.iptables.DeleteRule(iptables.TableNAT, iptablesHostPortalChain, args...); err != nil {
klog.ErrorS(err, "Failed to delete iptables rule for service", "chain", iptablesHostPortalChain, "servicePortName", name.String()) klog.ErrorS(err, "Failed to delete iptables rule for service", "chain", iptablesHostPortalChain, "servicePortName", name)
el = append(el, err) el = append(el, err)
} }
return el return el
@ -967,7 +967,7 @@ func (proxier *Proxier) closeOnePortal(portal portal, protocol v1.Protocol, prox
// Handle traffic from the host (portalIP is not external). // Handle traffic from the host (portalIP is not external).
args = proxier.iptablesHostPortalArgs(portal.ip, false, portal.port, protocol, proxyIP, proxyPort, name) args = proxier.iptablesHostPortalArgs(portal.ip, false, portal.port, protocol, proxyIP, proxyPort, name)
if err := proxier.iptables.DeleteRule(iptables.TableNAT, iptablesHostPortalChain, args...); err != nil { if err := proxier.iptables.DeleteRule(iptables.TableNAT, iptablesHostPortalChain, args...); err != nil {
klog.ErrorS(err, "Failed to delete iptables rule for service", "chain", iptablesHostPortalChain, "servicePortName", name.String()) klog.ErrorS(err, "Failed to delete iptables rule for service", "chain", iptablesHostPortalChain, "servicePortName", name)
el = append(el, err) el = append(el, err)
} }
@ -980,21 +980,21 @@ func (proxier *Proxier) closeNodePort(nodePort int, protocol v1.Protocol, proxyI
// Handle traffic from containers. // Handle traffic from containers.
args := proxier.iptablesContainerPortalArgs(nil, false, false, nodePort, protocol, proxyIP, proxyPort, name) args := proxier.iptablesContainerPortalArgs(nil, false, false, nodePort, protocol, proxyIP, proxyPort, name)
if err := proxier.iptables.DeleteRule(iptables.TableNAT, iptablesContainerNodePortChain, args...); err != nil { if err := proxier.iptables.DeleteRule(iptables.TableNAT, iptablesContainerNodePortChain, args...); err != nil {
klog.ErrorS(err, "Failed to delete iptables rule for service", "chain", iptablesContainerNodePortChain, "servicePortName", name.String()) klog.ErrorS(err, "Failed to delete iptables rule for service", "chain", iptablesContainerNodePortChain, "servicePortName", name)
el = append(el, err) el = append(el, err)
} }
// Handle traffic from the host. // Handle traffic from the host.
args = proxier.iptablesHostNodePortArgs(nodePort, protocol, proxyIP, proxyPort, name) args = proxier.iptablesHostNodePortArgs(nodePort, protocol, proxyIP, proxyPort, name)
if err := proxier.iptables.DeleteRule(iptables.TableNAT, iptablesHostNodePortChain, args...); err != nil { if err := proxier.iptables.DeleteRule(iptables.TableNAT, iptablesHostNodePortChain, args...); err != nil {
klog.ErrorS(err, "Failed to delete iptables rule for service", "chain", iptablesHostNodePortChain, "servicePortName", name.String()) klog.ErrorS(err, "Failed to delete iptables rule for service", "chain", iptablesHostNodePortChain, "servicePortName", name)
el = append(el, err) el = append(el, err)
} }
// Handle traffic not local to the host // Handle traffic not local to the host
args = proxier.iptablesNonLocalNodePortArgs(nodePort, protocol, proxyIP, proxyPort, name) args = proxier.iptablesNonLocalNodePortArgs(nodePort, protocol, proxyIP, proxyPort, name)
if err := proxier.iptables.DeleteRule(iptables.TableFilter, iptablesNonLocalNodePortChain, args...); err != nil { if err := proxier.iptables.DeleteRule(iptables.TableFilter, iptablesNonLocalNodePortChain, args...); err != nil {
klog.ErrorS(err, "Failed to delete iptables rule for service", "chain", iptablesNonLocalNodePortChain, "servicePortName", name.String()) klog.ErrorS(err, "Failed to delete iptables rule for service", "chain", iptablesNonLocalNodePortChain, "servicePortName", name)
el = append(el, err) el = append(el, err)
} }
@ -1103,7 +1103,7 @@ func iptablesFlush(ipt iptables.Interface) error {
el = append(el, err) el = append(el, err)
} }
if len(el) != 0 { if len(el) != 0 {
klog.ErrorS(nil, "Some errors flushing old iptables portals", "errors", el) klog.ErrorS(utilerrors.NewAggregate(el), "Some errors flushing old iptables portals")
} }
return utilerrors.NewAggregate(el) return utilerrors.NewAggregate(el)
} }

View File

@ -1250,7 +1250,7 @@ func (proxier *Proxier) syncProxyRules() {
uint16(svcInfo.Port()), uint16(svcInfo.Port()),
) )
if err != nil { if err != nil {
klog.ErrorS(err, "Policy creation failed", err) klog.ErrorS(err, "Policy creation failed")
continue continue
} }
externalIP.hnsID = hnsLoadBalancer.hnsID externalIP.hnsID = hnsLoadBalancer.hnsID