Migrate cmd/kubelet, image, cadvisor and cri to structured logging

This commit is contained in:
afrouz 2021-03-09 12:29:32 +03:30
parent eeccc9f9c0
commit 8f2e927b4a
5 changed files with 11 additions and 11 deletions

View File

@ -43,16 +43,16 @@ func appendPluginBasedOnFeatureFlags(plugins []volume.VolumePlugin, inTreePlugin
migrationComplete, err := csimigration.CheckMigrationFeatureFlags(featureGate, pluginInfo.pluginMigrationFeature, migrationComplete, err := csimigration.CheckMigrationFeatureFlags(featureGate, pluginInfo.pluginMigrationFeature,
pluginInfo.pluginMigrationCompleteFeature, pluginInfo.pluginUnregisterFeature) pluginInfo.pluginMigrationCompleteFeature, pluginInfo.pluginUnregisterFeature)
if err != nil { if err != nil {
klog.Warningf("Unexpected CSI Migration Feature Flags combination detected: %v. CSI Migration may not take effect", err) klog.InfoS("Unexpected CSI Migration Feature Flags combination detected, CSI Migration may not take effect", "err", err)
// TODO: fail and return here once alpha only tests can set the feature flags for a plugin correctly // TODO: fail and return here once alpha only tests can set the feature flags for a plugin correctly
} }
// TODO: This can be removed after feature flag CSIMigrationvSphereComplete is removed. // TODO: This can be removed after feature flag CSIMigrationvSphereComplete is removed.
if migrationComplete { if migrationComplete {
klog.Infof("Skip registration of plugin %s since migration is complete", inTreePluginName) klog.InfoS("Skipped registration of plugin since migration is completed", "pluginName", inTreePluginName)
return plugins, nil return plugins, nil
} }
if featureGate.Enabled(pluginInfo.pluginUnregisterFeature) { if featureGate.Enabled(pluginInfo.pluginUnregisterFeature) {
klog.Infof("Skip registration of plugin %s since feature flag %v is enabled", inTreePluginName, pluginInfo.pluginUnregisterFeature) klog.Infof("Skipped registration of plugin since feature flag is enabled", "pluginName", inTreePluginName, "featureFlag", pluginInfo.pluginUnregisterFeature)
return plugins, nil return plugins, nil
} }

View File

@ -24,19 +24,19 @@ import (
func watchForLockfileContention(path string, done chan struct{}) error { func watchForLockfileContention(path string, done chan struct{}) error {
watcher, err := inotify.NewWatcher() watcher, err := inotify.NewWatcher()
if err != nil { if err != nil {
klog.Errorf("unable to create watcher for lockfile: %v", err) klog.ErrorS(err, "Unable to create watcher for lockfile")
return err return err
} }
if err = watcher.AddWatch(path, inotify.InOpen|inotify.InDeleteSelf); err != nil { if err = watcher.AddWatch(path, inotify.InOpen|inotify.InDeleteSelf); err != nil {
klog.Errorf("unable to watch lockfile: %v", err) klog.ErrorS(err, "Unable to watch lockfile")
return err return err
} }
go func() { go func() {
select { select {
case ev := <-watcher.Event: case ev := <-watcher.Event:
klog.Infof("inotify event: %v", ev) klog.InfoS("inotify event", "event", ev)
case err = <-watcher.Error: case err = <-watcher.Error:
klog.Errorf("inotify watcher error: %v", err) klog.ErrorS(err, "inotify watcher error")
} }
close(done) close(done)
}() }()

View File

@ -79,7 +79,7 @@ func init() {
f.DefValue = defaultValue f.DefValue = defaultValue
f.Value.Set(defaultValue) f.Value.Set(defaultValue)
} else { } else {
klog.Errorf("Expected cAdvisor flag %q not found", name) klog.ErrorS(nil, "Expected cAdvisor flag not found", "flag", name)
} }
} }
} }
@ -186,7 +186,7 @@ func (cc *cadvisorClient) getFsInfo(label string) (cadvisorapiv2.FsInfo, error)
} }
// TODO(vmarmol): Handle this better when a label has more than one image filesystem. // TODO(vmarmol): Handle this better when a label has more than one image filesystem.
if len(res) > 1 { if len(res) > 1 {
klog.Warningf("More than one filesystem labeled %q: %#v. Only using the first one", label, res) klog.InfoS("More than one filesystem labeled. Only using the first one", "label", label, "fileSystem", res)
} }
return res[0], nil return res[0], nil

View File

@ -100,7 +100,7 @@ func parseEndpointWithFallbackProtocol(endpoint string, fallbackProtocol string)
fallbackEndpoint := fallbackProtocol + "://" + endpoint fallbackEndpoint := fallbackProtocol + "://" + endpoint
protocol, addr, err = parseEndpoint(fallbackEndpoint) protocol, addr, err = parseEndpoint(fallbackEndpoint)
if err == nil { if err == nil {
klog.Warningf("Using %q as endpoint is deprecated, please consider using full url format %q.", endpoint, fallbackEndpoint) klog.InfoS("Using this format as endpoint is deprecated, please consider using full url format.", "deprecatedFormat", endpoint, "fullURLFormat", fallbackEndpoint)
} }
} }
return return

View File

@ -90,7 +90,7 @@ func (m *imageManager) EnsureImageExists(pod *v1.Pod, container *v1.Container, p
logPrefix := fmt.Sprintf("%s/%s/%s", pod.Namespace, pod.Name, container.Image) logPrefix := fmt.Sprintf("%s/%s/%s", pod.Namespace, pod.Name, container.Image)
ref, err := kubecontainer.GenerateContainerRef(pod, container) ref, err := kubecontainer.GenerateContainerRef(pod, container)
if err != nil { if err != nil {
klog.Errorf("Couldn't make a ref to pod %v, container %v: '%v'", pod.Name, container.Name, err) klog.ErrorS(err, "Couldn't make a ref to pod", "pod", klog.KObj(pod), "containerName", container.Name)
} }
// If the image contains no tag or digest, a default tag should be applied. // If the image contains no tag or digest, a default tag should be applied.