From f7fd7e9687e5f3e7c38fb423b099604de828717e Mon Sep 17 00:00:00 2001 From: Yu-Ju Hong Date: Wed, 24 Jun 2015 15:53:25 -0700 Subject: [PATCH] Kubelet: add and modify some logging messsages This helps debug #6651 --- pkg/kubelet/config/config.go | 2 ++ pkg/kubelet/kubelet.go | 3 ++- pkg/kubelet/status_manager.go | 7 +++--- pkg/kubelet/util/doc.go | 18 ++++++++++++++ pkg/kubelet/util/format.go | 44 +++++++++++++++++++++++++++++++++++ 5 files changed, 70 insertions(+), 4 deletions(-) create mode 100644 pkg/kubelet/util/doc.go create mode 100644 pkg/kubelet/util/format.go diff --git a/pkg/kubelet/config/config.go b/pkg/kubelet/config/config.go index 7466333eeed..3a68ec76a9f 100644 --- a/pkg/kubelet/config/config.go +++ b/pkg/kubelet/config/config.go @@ -27,6 +27,7 @@ import ( "github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet" kubecontainer "github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/container" kubeletTypes "github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/types" + kubeletUtil "github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/util" "github.com/GoogleCloudPlatform/kubernetes/pkg/util" "github.com/GoogleCloudPlatform/kubernetes/pkg/util/config" utilerrors "github.com/GoogleCloudPlatform/kubernetes/pkg/util/errors" @@ -186,6 +187,7 @@ func (s *podStorage) Merge(source string, change interface{}) error { // recordFirstSeenTime records the first seen time of this pod. func recordFirstSeenTime(pod *api.Pod) { + glog.V(4).Infof("Receiving a new pod %q", kubeletUtil.FormatPodName(pod)) pod.Annotations[kubelet.ConfigFirstSeenAnnotationKey] = kubeletTypes.NewTimestamp().GetString() } diff --git a/pkg/kubelet/kubelet.go b/pkg/kubelet/kubelet.go index 47e86f6c9c2..f19cd99021b 100644 --- a/pkg/kubelet/kubelet.go +++ b/pkg/kubelet/kubelet.go @@ -51,6 +51,7 @@ import ( "github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/network" "github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/rkt" kubeletTypes "github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/types" + kubeletUtil "github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/util" "github.com/GoogleCloudPlatform/kubernetes/pkg/labels" "github.com/GoogleCloudPlatform/kubernetes/pkg/runtime" "github.com/GoogleCloudPlatform/kubernetes/pkg/types" @@ -1390,7 +1391,7 @@ func (kl *Kubelet) SyncPods(allPods []*api.Pod, podSyncTypes map[types.UID]SyncP // Handles pod admission. pods := kl.admitPods(allPods, podSyncTypes) - glog.V(4).Infof("Desired: %#v", pods) + glog.V(4).Infof("Desired pods: %s", kubeletUtil.FormatPodNames(pods)) var err error desiredPods := make(map[types.UID]empty) diff --git a/pkg/kubelet/status_manager.go b/pkg/kubelet/status_manager.go index 750e217ea12..bff75925a97 100644 --- a/pkg/kubelet/status_manager.go +++ b/pkg/kubelet/status_manager.go @@ -26,6 +26,7 @@ import ( "github.com/GoogleCloudPlatform/kubernetes/pkg/client" kubecontainer "github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/container" kubeletTypes "github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/types" + kubeletUtil "github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/util" "github.com/GoogleCloudPlatform/kubernetes/pkg/util" "github.com/golang/glog" ) @@ -118,7 +119,7 @@ func (s *statusManager) SetPodStatus(pod *api.Pod, status api.PodStatus) { s.podStatuses[podFullName] = status s.podStatusChannel <- podStatusSyncRequest{pod, status} } else { - glog.V(3).Infof("Ignoring same pod status for %q - old: %+v new: %+v", podFullName, oldStatus, status) + glog.V(3).Infof("Ignoring same status for pod %q, status: %+v", kubeletUtil.FormatPodName(pod), status) } } @@ -158,7 +159,7 @@ func (s *statusManager) syncBatch() error { _, err = s.kubeClient.Pods(pod.Namespace).UpdateStatus(statusPod) // TODO: handle conflict as a retry, make that easier too. if err == nil { - glog.V(3).Infof("Status for pod %q updated successfully", pod.Name) + glog.V(3).Infof("Status for pod %q updated successfully", kubeletUtil.FormatPodName(pod)) return nil } } @@ -171,5 +172,5 @@ func (s *statusManager) syncBatch() error { // to clear the channel. Even if this delete never runs subsequent container // changes on the node should trigger updates. go s.DeletePodStatus(podFullName) - return fmt.Errorf("error updating status for pod %q: %v", pod.Name, err) + return fmt.Errorf("error updating status for pod %q: %v", kubeletUtil.FormatPodName(pod), err) } diff --git a/pkg/kubelet/util/doc.go b/pkg/kubelet/util/doc.go new file mode 100644 index 00000000000..b7e74c7f296 --- /dev/null +++ b/pkg/kubelet/util/doc.go @@ -0,0 +1,18 @@ +/* +Copyright 2015 The Kubernetes Authors All rights reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Utility functions. +package util diff --git a/pkg/kubelet/util/format.go b/pkg/kubelet/util/format.go new file mode 100644 index 00000000000..bd0ffab09bb --- /dev/null +++ b/pkg/kubelet/util/format.go @@ -0,0 +1,44 @@ +/* +Copyright 2015 The Kubernetes Authors All rights reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package util + +import ( + "fmt" + "strings" + + "github.com/GoogleCloudPlatform/kubernetes/pkg/api" +) + +// FormatPodName returns a string representating a pod in a human readable +// format. This function currently is the same as GetPodFullName in +// kubelet/containers, but may differ in the future. As opposed to +// GetPodFullName, FormatPodName is mainly used for logging. +func FormatPodName(pod *api.Pod) string { + // Use underscore as the delimiter because it is not allowed in pod name + // (DNS subdomain format), while allowed in the container name format. + return fmt.Sprintf("%s_%s", pod.Name, pod.Namespace) +} + +// FormatPodNames returns a string representating a list of pods in a human +// readable format. +func FormatPodNames(pods []*api.Pod) string { + podStrings := make([]string, 0, len(pods)) + for _, pod := range pods { + podStrings = append(podStrings, FormatPodName(pod)) + } + return fmt.Sprintf(strings.Join(podStrings, ", ")) +}