diff --git a/pkg/kubelet/config/common.go b/pkg/kubelet/config/common.go index 2a5733d4f48..20456622a52 100644 --- a/pkg/kubelet/config/common.go +++ b/pkg/kubelet/config/common.go @@ -68,16 +68,16 @@ func applyDefaults(pod *api.Pod, source string, isFile bool, nodeName types.Node fmt.Fprintf(hasher, "url:%s", source) } pod.UID = types.UID(hex.EncodeToString(hasher.Sum(nil)[0:])) - klog.V(5).Infof("Generated UID %q pod %q from %s", pod.UID, pod.Name, source) + klog.V(5).InfoS("Generated UID", "pod", klog.KObj(pod), "podUID", pod.UID, "source", source) } pod.Name = generatePodName(pod.Name, nodeName) - klog.V(5).Infof("Generated Name %q for UID %q from URL %s", pod.Name, pod.UID, source) + klog.V(5).InfoS("Generated pod name", "pod", klog.KObj(pod), "podUID", pod.UID, "source", source) if pod.Namespace == "" { pod.Namespace = metav1.NamespaceDefault } - klog.V(5).Infof("Using namespace %q for pod %q from %s", pod.Namespace, pod.Name, source) + klog.V(5).InfoS("Set namespace for pod", "pod", klog.KObj(pod), "source", source) // Set the Host field to indicate this pod is scheduled on the current node. pod.Spec.NodeName = string(nodeName) @@ -145,7 +145,7 @@ func tryDecodeSinglePod(data []byte, defaultFn defaultFunc) (parsed bool, pod *v } v1Pod := &v1.Pod{} if err := k8s_api_v1.Convert_core_Pod_To_v1_Pod(newPod, v1Pod, nil); err != nil { - klog.Errorf("Pod %q failed to convert to v1", newPod.Name) + klog.ErrorS(err, "Pod failed to convert to v1", "pod", klog.KObj(newPod)) return true, nil, err } return true, v1Pod, nil diff --git a/pkg/kubelet/config/config.go b/pkg/kubelet/config/config.go index b04fdb8f967..ca9a460c20e 100644 --- a/pkg/kubelet/config/config.go +++ b/pkg/kubelet/config/config.go @@ -94,7 +94,7 @@ func (c *PodConfig) SeenAllSources(seenSources sets.String) bool { if c.pods == nil { return false } - klog.V(5).Infof("Looking for %v, have seen %v", c.sources.List(), seenSources) + klog.V(5).InfoS("Looking for sources, have seen", "sources", c.sources.List(), "seenSources", seenSources) return seenSources.HasAll(c.sources.List()...) && c.pods.seenSources(c.sources.List()...) } @@ -254,16 +254,16 @@ func (s *podStorage) merge(source string, change interface{}) (adds, updates, de switch update.Op { case kubetypes.ADD, kubetypes.UPDATE, kubetypes.DELETE: if update.Op == kubetypes.ADD { - klog.V(4).Infof("Adding new pods from source %s : %v", source, update.Pods) + klog.V(4).InfoS("Adding new pods from source", "source", source, "pods", format.Pods(update.Pods)) } else if update.Op == kubetypes.DELETE { - klog.V(4).Infof("Graceful deleting pods from source %s : %v", source, update.Pods) + klog.V(4).InfoS("Gracefully deleting pods from source", "source", source, "pods", format.Pods(update.Pods)) } else { - klog.V(4).Infof("Updating pods from source %s : %v", source, update.Pods) + klog.V(4).InfoS("Updating pods from source", "source", source, "pods", format.Pods(update.Pods)) } updatePodsFunc(update.Pods, pods, pods) case kubetypes.REMOVE: - klog.V(4).Infof("Removing pods from source %s : %v", source, update.Pods) + klog.V(4).InfoS("Removing pods from source", "source", source, "pods", format.Pods(update.Pods)) for _, value := range update.Pods { if existing, found := pods[value.UID]; found { // this is a delete @@ -275,7 +275,7 @@ func (s *podStorage) merge(source string, change interface{}) (adds, updates, de } case kubetypes.SET: - klog.V(4).Infof("Setting pods for source %s", source) + klog.V(4).InfoS("Setting pods for source", "source", source) s.markSourceSet(source) // Clear the old map entries by just creating a new map oldPods := pods @@ -289,7 +289,7 @@ func (s *podStorage) merge(source string, change interface{}) (adds, updates, de } default: - klog.Warningf("Received invalid update type: %v", update) + klog.InfoS("Received invalid update type", "type", update) } @@ -323,7 +323,7 @@ func filterInvalidPods(pods []*v1.Pod, source string, recorder record.EventRecor // This function only checks if there is any naming conflict. name := kubecontainer.GetPodFullName(pod) if names.Has(name) { - klog.Warningf("Pod[%d] (%s) from %s failed validation due to duplicate pod name %q, ignoring", i+1, format.Pod(pod), source, pod.Name) + klog.InfoS("Pod failed validation due to duplicate pod name, ignoring", "index", i, "pod", klog.KObj(pod), "source", source) recorder.Eventf(pod, v1.EventTypeWarning, events.FailedValidation, "Error validating pod %s from %s due to duplicate pod name %q, ignoring", format.Pod(pod), source, pod.Name) continue } else { @@ -380,7 +380,7 @@ func isAnnotationMapEqual(existingMap, candidateMap map[string]string) bool { // recordFirstSeenTime records the first seen time of this pod. func recordFirstSeenTime(pod *v1.Pod) { - klog.V(4).Infof("Receiving a new pod %q", format.Pod(pod)) + klog.V(4).InfoS("Receiving a new pod", "pod", klog.KObj(pod)) pod.Annotations[kubetypes.ConfigFirstSeenAnnotationKey] = kubetypes.NewTimestamp().GetString() } diff --git a/pkg/kubelet/config/file.go b/pkg/kubelet/config/file.go index 68b5d3d22bd..8984f5dee48 100644 --- a/pkg/kubelet/config/file.go +++ b/pkg/kubelet/config/file.go @@ -65,7 +65,7 @@ func NewSourceFile(path string, nodeName types.NodeName, period time.Duration, u path = strings.TrimRight(path, string(os.PathSeparator)) config := newSourceFile(path, nodeName, period, updates) - klog.V(1).Infof("Watching path %q", path) + klog.V(1).InfoS("Watching path", "path", path) config.run() } @@ -95,17 +95,17 @@ func (s *sourceFile) run() { go func() { // Read path immediately to speed up startup. if err := s.listConfig(); err != nil { - klog.Errorf("Unable to read config path %q: %v", s.path, err) + klog.ErrorS(err, "Unable to read config path", "path", s.path) } for { select { case <-listTicker.C: if err := s.listConfig(); err != nil { - klog.Errorf("Unable to read config path %q: %v", s.path, err) + klog.ErrorS(err, "Unable to read config path", "path", s.path) } case e := <-s.watchEvents: if err := s.consumeWatchEvent(e); err != nil { - klog.Errorf("Unable to process watch event: %v", err) + klog.ErrorS(err, "Unable to process watch event") } } } @@ -173,24 +173,24 @@ func (s *sourceFile) extractFromDir(name string) ([]*v1.Pod, error) { for _, path := range dirents { statInfo, err := os.Stat(path) if err != nil { - klog.Errorf("Can't get metadata for %q: %v", path, err) + klog.ErrorS(err, "Could not get metadata", "path", path) continue } switch { case statInfo.Mode().IsDir(): - klog.Errorf("Not recursing into manifest path %q", path) + klog.ErrorS(nil, "Provided manifest path is a directory, not recursing into manifest path", "path", path) case statInfo.Mode().IsRegular(): pod, err := s.extractFromFile(path) if err != nil { if !os.IsNotExist(err) { - klog.Errorf("Can't process manifest file %q: %v", path, err) + klog.ErrorS(err, "Could not process manifest file", "path", path) } } else { pods = append(pods, pod) } default: - klog.Errorf("Manifest path %q is not a directory or file: %v", path, statInfo.Mode()) + klog.ErrorS(nil, "Manifest path is not a directory or file", "path", path, "mode", statInfo.Mode()) } } return pods, nil @@ -198,7 +198,7 @@ func (s *sourceFile) extractFromDir(name string) ([]*v1.Pod, error) { // extractFromFile parses a file for Pod configuration information. func (s *sourceFile) extractFromFile(filename string) (pod *v1.Pod, err error) { - klog.V(3).Infof("Reading config file %q", filename) + klog.V(3).InfoS("Reading config file", "path", filename) defer func() { if err == nil && pod != nil { objKey, keyErr := cache.MetaNamespaceKeyFunc(pod) diff --git a/pkg/kubelet/config/file_linux.go b/pkg/kubelet/config/file_linux.go index f1938afa1a5..5c1930498f2 100644 --- a/pkg/kubelet/config/file_linux.go +++ b/pkg/kubelet/config/file_linux.go @@ -57,7 +57,7 @@ func (s *sourceFile) startWatch() { } if err := s.doWatch(); err != nil { - klog.Errorf("Unable to read config path %q: %v", s.path, err) + klog.ErrorS(err, "Unable to read config path", "path", s.path) if _, retryable := err.(*retryableError); !retryable { backOff.Next(backOffID, time.Now()) } @@ -102,7 +102,7 @@ func (s *sourceFile) doWatch() error { func (s *sourceFile) produceWatchEvent(e *fsnotify.Event) error { // Ignore file start with dots if strings.HasPrefix(filepath.Base(e.Name), ".") { - klog.V(4).Infof("Ignored pod manifest: %s, because it starts with dots", e.Name) + klog.V(4).InfoS("Ignored pod manifest, because it starts with dots", "eventName", e.Name) return nil } var eventType podEventType diff --git a/pkg/kubelet/config/http.go b/pkg/kubelet/config/http.go index 710abb089b0..b0b49e517c3 100644 --- a/pkg/kubelet/config/http.go +++ b/pkg/kubelet/config/http.go @@ -54,7 +54,7 @@ func NewSourceURL(url string, header http.Header, nodeName types.NodeName, perio // read the manifest URL passed to kubelet. client: &http.Client{Timeout: 10 * time.Second}, } - klog.V(1).Infof("Watching URL %s", url) + klog.V(1).InfoS("Watching URL", "URL", url) go wait.Until(config.run, period, wait.NeverStop) } @@ -63,16 +63,16 @@ func (s *sourceURL) run() { // Don't log this multiple times per minute. The first few entries should be // enough to get the point across. if s.failureLogs < 3 { - klog.Warningf("Failed to read pods from URL: %v", err) + klog.InfoS("Failed to read pods from URL", "err", err) } else if s.failureLogs == 3 { - klog.Warningf("Failed to read pods from URL. Dropping verbosity of this message to V(4): %v", err) + klog.InfoS("Failed to read pods from URL. Dropping verbosity of this message to V(4)", "err", err) } else { - klog.V(4).Infof("Failed to read pods from URL: %v", err) + klog.V(4).InfoS("Failed to read pods from URL", "err", err) } s.failureLogs++ } else { if s.failureLogs > 0 { - klog.Info("Successfully read pods from URL.") + klog.InfoS("Successfully read pods from URL") s.failureLogs = 0 } }