mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-20 18:31:15 +00:00
Merge pull request #104944 from jyz0309/migrate-log
Migrate `cmd/proxy/{config, healthcheck, winkernel}` to structured logging
This commit is contained in:
commit
acbeaf8b8e
@ -132,14 +132,14 @@ func (c *EndpointsConfig) RegisterEventHandler(handler EndpointsHandler) {
|
||||
|
||||
// Run waits for cache synced and invokes handlers after syncing.
|
||||
func (c *EndpointsConfig) Run(stopCh <-chan struct{}) {
|
||||
klog.Info("Starting endpoints config controller")
|
||||
klog.InfoS("Starting endpoints config controller")
|
||||
|
||||
if !cache.WaitForNamedCacheSync("endpoints config", stopCh, c.listerSynced) {
|
||||
return
|
||||
}
|
||||
|
||||
for i := range c.eventHandlers {
|
||||
klog.V(3).Infof("Calling handler.OnEndpointsSynced()")
|
||||
klog.V(3).InfoS("Calling handler.OnEndpointsSynced()")
|
||||
c.eventHandlers[i].OnEndpointsSynced()
|
||||
}
|
||||
}
|
||||
@ -151,7 +151,7 @@ func (c *EndpointsConfig) handleAddEndpoints(obj interface{}) {
|
||||
return
|
||||
}
|
||||
for i := range c.eventHandlers {
|
||||
klog.V(4).Infof("Calling handler.OnEndpointsAdd")
|
||||
klog.V(4).InfoS("Calling handler.OnEndpointsAdd")
|
||||
c.eventHandlers[i].OnEndpointsAdd(endpoints)
|
||||
}
|
||||
}
|
||||
@ -168,7 +168,7 @@ func (c *EndpointsConfig) handleUpdateEndpoints(oldObj, newObj interface{}) {
|
||||
return
|
||||
}
|
||||
for i := range c.eventHandlers {
|
||||
klog.V(4).Infof("Calling handler.OnEndpointsUpdate")
|
||||
klog.V(4).InfoS("Calling handler.OnEndpointsUpdate")
|
||||
c.eventHandlers[i].OnEndpointsUpdate(oldEndpoints, endpoints)
|
||||
}
|
||||
}
|
||||
@ -187,7 +187,7 @@ func (c *EndpointsConfig) handleDeleteEndpoints(obj interface{}) {
|
||||
}
|
||||
}
|
||||
for i := range c.eventHandlers {
|
||||
klog.V(4).Infof("Calling handler.OnEndpointsDelete")
|
||||
klog.V(4).InfoS("Calling handler.OnEndpointsDelete")
|
||||
c.eventHandlers[i].OnEndpointsDelete(endpoints)
|
||||
}
|
||||
}
|
||||
@ -223,14 +223,14 @@ func (c *EndpointSliceConfig) RegisterEventHandler(handler EndpointSliceHandler)
|
||||
|
||||
// Run waits for cache synced and invokes handlers after syncing.
|
||||
func (c *EndpointSliceConfig) Run(stopCh <-chan struct{}) {
|
||||
klog.Info("Starting endpoint slice config controller")
|
||||
klog.InfoS("Starting endpoint slice config controller")
|
||||
|
||||
if !cache.WaitForNamedCacheSync("endpoint slice config", stopCh, c.listerSynced) {
|
||||
return
|
||||
}
|
||||
|
||||
for _, h := range c.eventHandlers {
|
||||
klog.V(3).Infof("Calling handler.OnEndpointSlicesSynced()")
|
||||
klog.V(3).InfoS("Calling handler.OnEndpointSlicesSynced()")
|
||||
h.OnEndpointSlicesSynced()
|
||||
}
|
||||
}
|
||||
@ -242,7 +242,7 @@ func (c *EndpointSliceConfig) handleAddEndpointSlice(obj interface{}) {
|
||||
return
|
||||
}
|
||||
for _, h := range c.eventHandlers {
|
||||
klog.V(4).Infof("Calling handler.OnEndpointSliceAdd %+v", endpointSlice)
|
||||
klog.V(4).InfoS("Calling handler.OnEndpointSliceAdd", "endpoints", klog.KObj(endpointSlice))
|
||||
h.OnEndpointSliceAdd(endpointSlice)
|
||||
}
|
||||
}
|
||||
@ -259,7 +259,7 @@ func (c *EndpointSliceConfig) handleUpdateEndpointSlice(oldObj, newObj interface
|
||||
return
|
||||
}
|
||||
for _, h := range c.eventHandlers {
|
||||
klog.V(4).Infof("Calling handler.OnEndpointSliceUpdate")
|
||||
klog.V(4).InfoS("Calling handler.OnEndpointSliceUpdate")
|
||||
h.OnEndpointSliceUpdate(oldEndpointSlice, newEndpointSlice)
|
||||
}
|
||||
}
|
||||
@ -278,7 +278,7 @@ func (c *EndpointSliceConfig) handleDeleteEndpointSlice(obj interface{}) {
|
||||
}
|
||||
}
|
||||
for _, h := range c.eventHandlers {
|
||||
klog.V(4).Infof("Calling handler.OnEndpointsDelete")
|
||||
klog.V(4).InfoS("Calling handler.OnEndpointsDelete")
|
||||
h.OnEndpointSliceDelete(endpointSlice)
|
||||
}
|
||||
}
|
||||
@ -314,14 +314,14 @@ func (c *ServiceConfig) RegisterEventHandler(handler ServiceHandler) {
|
||||
|
||||
// Run waits for cache synced and invokes handlers after syncing.
|
||||
func (c *ServiceConfig) Run(stopCh <-chan struct{}) {
|
||||
klog.Info("Starting service config controller")
|
||||
klog.InfoS("Starting service config controller")
|
||||
|
||||
if !cache.WaitForNamedCacheSync("service config", stopCh, c.listerSynced) {
|
||||
return
|
||||
}
|
||||
|
||||
for i := range c.eventHandlers {
|
||||
klog.V(3).Info("Calling handler.OnServiceSynced()")
|
||||
klog.V(3).InfoS("Calling handler.OnServiceSynced()")
|
||||
c.eventHandlers[i].OnServiceSynced()
|
||||
}
|
||||
}
|
||||
@ -333,7 +333,7 @@ func (c *ServiceConfig) handleAddService(obj interface{}) {
|
||||
return
|
||||
}
|
||||
for i := range c.eventHandlers {
|
||||
klog.V(4).Info("Calling handler.OnServiceAdd")
|
||||
klog.V(4).InfoS("Calling handler.OnServiceAdd")
|
||||
c.eventHandlers[i].OnServiceAdd(service)
|
||||
}
|
||||
}
|
||||
@ -350,7 +350,7 @@ func (c *ServiceConfig) handleUpdateService(oldObj, newObj interface{}) {
|
||||
return
|
||||
}
|
||||
for i := range c.eventHandlers {
|
||||
klog.V(4).Info("Calling handler.OnServiceUpdate")
|
||||
klog.V(4).InfoS("Calling handler.OnServiceUpdate")
|
||||
c.eventHandlers[i].OnServiceUpdate(oldService, service)
|
||||
}
|
||||
}
|
||||
@ -369,7 +369,7 @@ func (c *ServiceConfig) handleDeleteService(obj interface{}) {
|
||||
}
|
||||
}
|
||||
for i := range c.eventHandlers {
|
||||
klog.V(4).Info("Calling handler.OnServiceDelete")
|
||||
klog.V(4).InfoS("Calling handler.OnServiceDelete")
|
||||
c.eventHandlers[i].OnServiceDelete(service)
|
||||
}
|
||||
}
|
||||
@ -441,14 +441,14 @@ func (c *NodeConfig) RegisterEventHandler(handler NodeHandler) {
|
||||
|
||||
// Run starts the goroutine responsible for calling registered handlers.
|
||||
func (c *NodeConfig) Run(stopCh <-chan struct{}) {
|
||||
klog.Info("Starting node config controller")
|
||||
klog.InfoS("Starting node config controller")
|
||||
|
||||
if !cache.WaitForNamedCacheSync("node config", stopCh, c.listerSynced) {
|
||||
return
|
||||
}
|
||||
|
||||
for i := range c.eventHandlers {
|
||||
klog.V(3).Infof("Calling handler.OnNodeSynced()")
|
||||
klog.V(3).InfoS("Calling handler.OnNodeSynced()")
|
||||
c.eventHandlers[i].OnNodeSynced()
|
||||
}
|
||||
}
|
||||
@ -460,7 +460,7 @@ func (c *NodeConfig) handleAddNode(obj interface{}) {
|
||||
return
|
||||
}
|
||||
for i := range c.eventHandlers {
|
||||
klog.V(4).Infof("Calling handler.OnNodeAdd")
|
||||
klog.V(4).InfoS("Calling handler.OnNodeAdd")
|
||||
c.eventHandlers[i].OnNodeAdd(node)
|
||||
}
|
||||
}
|
||||
@ -477,7 +477,7 @@ func (c *NodeConfig) handleUpdateNode(oldObj, newObj interface{}) {
|
||||
return
|
||||
}
|
||||
for i := range c.eventHandlers {
|
||||
klog.V(5).Infof("Calling handler.OnNodeUpdate")
|
||||
klog.V(5).InfoS("Calling handler.OnNodeUpdate")
|
||||
c.eventHandlers[i].OnNodeUpdate(oldNode, node)
|
||||
}
|
||||
}
|
||||
@ -496,7 +496,7 @@ func (c *NodeConfig) handleDeleteNode(obj interface{}) {
|
||||
}
|
||||
}
|
||||
for i := range c.eventHandlers {
|
||||
klog.V(4).Infof("Calling handler.OnNodeDelete")
|
||||
klog.V(4).InfoS("Calling handler.OnNodeDelete")
|
||||
c.eventHandlers[i].OnNodeDelete(node)
|
||||
}
|
||||
}
|
||||
|
@ -104,7 +104,7 @@ 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).Infof("Closing healthcheck %v on port %d", nsn.String(), svc.port)
|
||||
klog.V(2).InfoS("Closing healthcheck", "service", nsn.String(), "port", svc.port)
|
||||
|
||||
// errors are loged in closeAll()
|
||||
_ = svc.closeAll()
|
||||
@ -116,11 +116,11 @@ func (hcs *server) SyncServices(newServices map[types.NamespacedName]uint16) err
|
||||
// Add any that are needed.
|
||||
for nsn, port := range newServices {
|
||||
if hcs.services[nsn] != nil {
|
||||
klog.V(3).Infof("Existing healthcheck %q on port %d", nsn.String(), port)
|
||||
klog.V(3).InfoS("Existing healthcheck", "service", nsn.String(), "port", port)
|
||||
continue
|
||||
}
|
||||
|
||||
klog.V(2).Infof("Opening healthcheck %s on port %v", nsn.String(), port)
|
||||
klog.V(2).InfoS("Opening healthcheck", "service", nsn.String(), "port", port)
|
||||
|
||||
svc := &hcInstance{nsn: nsn, port: port}
|
||||
err := svc.listenAndServeAll(hcs)
|
||||
@ -137,7 +137,7 @@ func (hcs *server) SyncServices(newServices map[types.NamespacedName]uint16) err
|
||||
UID: types.UID(nsn.String()),
|
||||
}, nil, api.EventTypeWarning, "FailedToStartServiceHealthcheck", "Listen", msg)
|
||||
}
|
||||
klog.Error(msg)
|
||||
klog.ErrorS(err, "failed to start healthcheck", "node", hcs.hostname, "service", nsn.String(), "port", port)
|
||||
continue
|
||||
}
|
||||
hcs.services[nsn] = svc
|
||||
@ -181,12 +181,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).Infof("Starting goroutine for healthcheck %q on %s", hcI.nsn.String(), listener.Addr().String())
|
||||
klog.V(3).InfoS("Starting goroutine for healthcheck", "service", hcI.nsn.String(), "address", listener.Addr().String())
|
||||
if err := httpSrv.Serve(listener); err != nil {
|
||||
klog.V(3).Infof("Healthcheck %q closed: %v", hcI.nsn.String(), err)
|
||||
klog.ErrorS(err, "Healthcheck closed", "service", hcI.nsn.String())
|
||||
return
|
||||
}
|
||||
klog.V(3).Infof("Healthcheck %q on %s closed", hcI.nsn.String(), listener.Addr().String())
|
||||
klog.V(3).InfoS("Healthcheck closed", "service", hcI.nsn.String(), "address", listener.Addr().String())
|
||||
}(hcI, listener, httpSrv)
|
||||
|
||||
hcI.listeners = append(hcI.listeners, listener)
|
||||
@ -224,7 +224,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.Errorf("Received request for closed healthcheck %q", h.name.String())
|
||||
klog.ErrorS(nil, "Received request for closed healthcheck", "service", h.name.String())
|
||||
return
|
||||
}
|
||||
count := svc.endpoints
|
||||
@ -254,10 +254,10 @@ func (hcs *server) SyncEndpoints(newEndpoints map[types.NamespacedName]int) erro
|
||||
|
||||
for nsn, count := range newEndpoints {
|
||||
if hcs.services[nsn] == nil {
|
||||
klog.V(3).Infof("Not saving endpoints for unknown healthcheck %q", nsn.String())
|
||||
klog.V(3).InfoS("Not saving endpoints for unknown healthcheck", "service", nsn.String())
|
||||
continue
|
||||
}
|
||||
klog.V(3).Infof("Reporting %d endpoints for healthcheck %q", count, nsn.String())
|
||||
klog.V(3).InfoS("Reporting endpoints for healthcheck", "endpointCount", count, "service", nsn.String())
|
||||
hcs.services[nsn].endpoints = count
|
||||
}
|
||||
for nsn, hci := range hcs.services {
|
||||
|
@ -45,7 +45,7 @@ type hnsV1 struct{}
|
||||
func (hns hnsV1) getNetworkByName(name string) (*hnsNetworkInfo, error) {
|
||||
hnsnetwork, err := hcsshim.GetHNSNetworkByName(name)
|
||||
if err != nil {
|
||||
klog.Errorf("%v", err)
|
||||
klog.ErrorS(err, "failed to get HNS network by name", "name", name)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@ -58,7 +58,7 @@ func (hns hnsV1) getNetworkByName(name string) (*hnsNetworkInfo, error) {
|
||||
func (hns hnsV1) getEndpointByID(id string) (*endpointsInfo, error) {
|
||||
hnsendpoint, err := hcsshim.GetHNSEndpointByID(id)
|
||||
if err != nil {
|
||||
klog.Errorf("%v", err)
|
||||
klog.ErrorS(err, "failed to get HNS endpoint by id", "id", id)
|
||||
return nil, err
|
||||
}
|
||||
return &endpointsInfo{
|
||||
@ -77,7 +77,7 @@ func (hns hnsV1) getEndpointByID(id string) (*endpointsInfo, error) {
|
||||
func (hns hnsV1) getEndpointByIpAddress(ip string, networkName string) (*endpointsInfo, error) {
|
||||
hnsnetwork, err := hcsshim.GetHNSNetworkByName(networkName)
|
||||
if err != nil {
|
||||
klog.Errorf("%v", err)
|
||||
klog.ErrorS(err, "failed to get HNS network by name", "name", networkName)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@ -162,7 +162,7 @@ func (hns hnsV1) deleteEndpoint(hnsID string) error {
|
||||
}
|
||||
_, err = hnsendpoint.Delete()
|
||||
if err == nil {
|
||||
klog.V(3).Infof("Remote endpoint resource deleted id %s", hnsID)
|
||||
klog.V(3).InfoS("Remote endpoint resource deleted id", "id", hnsID)
|
||||
}
|
||||
return err
|
||||
}
|
||||
@ -174,7 +174,7 @@ func (hns hnsV1) getLoadBalancer(endpoints []endpointsInfo, flags loadBalancerFl
|
||||
}
|
||||
|
||||
if flags.isDSR {
|
||||
klog.V(3).Info("DSR is not supported in V1. Using non DSR instead")
|
||||
klog.V(3).InfoS("DSR is not supported in V1. Using non DSR instead")
|
||||
}
|
||||
|
||||
for _, plist := range plists {
|
||||
|
Loading…
Reference in New Issue
Block a user