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

Migrate pkg/kubelet/cm/devicemanager to structured logging #99976

Merged
merged 1 commit into from Mar 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
17 changes: 8 additions & 9 deletions pkg/kubelet/cm/devicemanager/device_plugin_stub.go
Expand Up @@ -139,8 +139,7 @@ func (m *Stub) Start() error {
return lastDialErr
}

klog.Infof("Starting to serve on %v", m.socket)

klog.InfoS("Starting to serve on socket", "socket", m.socket)
return nil
}

Expand All @@ -161,7 +160,7 @@ func (m *Stub) Stop() error {

// GetInfo is the RPC which return pluginInfo
func (m *Stub) GetInfo(ctx context.Context, req *watcherapi.InfoRequest) (*watcherapi.PluginInfo, error) {
klog.Info("GetInfo")
klog.InfoS("GetInfo")
return &watcherapi.PluginInfo{
Type: watcherapi.DevicePlugin,
Name: m.resourceName,
Expand All @@ -175,7 +174,7 @@ func (m *Stub) NotifyRegistrationStatus(ctx context.Context, status *watcherapi.
m.registrationStatus <- *status
}
if !status.PluginRegistered {
klog.Infof("Registration failed: %v", status.Error)
klog.InfoS("Registration failed", "err", status.Error)
}
return &watcherapi.RegistrationStatusResponse{}, nil
}
Expand All @@ -184,7 +183,7 @@ func (m *Stub) NotifyRegistrationStatus(ctx context.Context, status *watcherapi.
func (m *Stub) Register(kubeletEndpoint, resourceName string, pluginSockDir string) error {
if pluginSockDir != "" {
if _, err := os.Stat(pluginSockDir + "DEPRECATION"); err == nil {
klog.Info("Deprecation file found. Skip registration.")
klog.InfoS("Deprecation file found. Skip registration")
return nil
}
}
Expand Down Expand Up @@ -229,13 +228,13 @@ func (m *Stub) GetDevicePluginOptions(ctx context.Context, e *pluginapi.Empty) (

// PreStartContainer resets the devices received
func (m *Stub) PreStartContainer(ctx context.Context, r *pluginapi.PreStartContainerRequest) (*pluginapi.PreStartContainerResponse, error) {
klog.Infof("PreStartContainer, %+v", r)
klog.InfoS("PreStartContainer", "request", r)
return &pluginapi.PreStartContainerResponse{}, nil
}

// ListAndWatch lists devices and update that list according to the Update call
func (m *Stub) ListAndWatch(e *pluginapi.Empty, s pluginapi.DevicePlugin_ListAndWatchServer) error {
klog.Info("ListAndWatch")
klog.InfoS("ListAndWatch")

s.Send(&pluginapi.ListAndWatchResponse{Devices: m.devs})

Expand All @@ -256,7 +255,7 @@ func (m *Stub) Update(devs []*pluginapi.Device) {

// GetPreferredAllocation gets the preferred allocation from a set of available devices
func (m *Stub) GetPreferredAllocation(ctx context.Context, r *pluginapi.PreferredAllocationRequest) (*pluginapi.PreferredAllocationResponse, error) {
klog.Infof("GetPreferredAllocation, %+v", r)
klog.InfoS("GetPreferredAllocation", "request", r)

devs := make(map[string]pluginapi.Device)

Expand All @@ -269,7 +268,7 @@ func (m *Stub) GetPreferredAllocation(ctx context.Context, r *pluginapi.Preferre

// Allocate does a mock allocation
func (m *Stub) Allocate(ctx context.Context, r *pluginapi.AllocateRequest) (*pluginapi.AllocateResponse, error) {
klog.Infof("Allocate, %+v", r)
klog.InfoS("Allocate", "request", r)

devs := make(map[string]pluginapi.Device)

Expand Down
8 changes: 4 additions & 4 deletions pkg/kubelet/cm/devicemanager/endpoint.go
Expand Up @@ -60,7 +60,7 @@ type endpointImpl struct {
func newEndpointImpl(socketPath, resourceName string, callback monitorCallback) (*endpointImpl, error) {
client, c, err := dial(socketPath)
if err != nil {
klog.Errorf("Can't create new endpoint with path %s err %v", socketPath, err)
klog.ErrorS(err, "Can't create new endpoint with socket path", "path", socketPath)
return nil, err
}

Expand Down Expand Up @@ -96,20 +96,20 @@ func (e *endpointImpl) callback(resourceName string, devices []pluginapi.Device)
func (e *endpointImpl) run() {
stream, err := e.client.ListAndWatch(context.Background(), &pluginapi.Empty{})
if err != nil {
klog.Errorf(errListAndWatch, e.resourceName, err)
klog.ErrorS(err, "listAndWatch ended unexpectedly for device plugin", "resourceName", e.resourceName)

return
}

for {
response, err := stream.Recv()
if err != nil {
klog.Errorf(errListAndWatch, e.resourceName, err)
klog.ErrorS(err, "listAndWatch ended unexpectedly for device plugin", "resourceName", e.resourceName)
return
}

devs := response.Devices
klog.V(2).Infof("State pushed for device plugin %s", e.resourceName)
klog.V(2).InfoS("State pushed for device plugin", "resourceName", e.resourceName)

var newDevs []pluginapi.Device
for _, d := range devs {
Expand Down