From ccecc59ff2d50f9f813a1327e90b9abd4cdd5a0c Mon Sep 17 00:00:00 2001 From: Chao Xu Date: Wed, 8 Jun 2016 16:32:30 -0700 Subject: [PATCH] In kubelet's handler of pod update, prints out deletiontimestamp if it's not nil --- pkg/kubelet/kubelet.go | 2 +- pkg/kubelet/util/format/pod.go | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/pkg/kubelet/kubelet.go b/pkg/kubelet/kubelet.go index 37b758fc387..5d5d1b737f5 100644 --- a/pkg/kubelet/kubelet.go +++ b/pkg/kubelet/kubelet.go @@ -2638,7 +2638,7 @@ func (kl *Kubelet) syncLoopIteration(configCh <-chan kubetypes.PodUpdate, handle // once we have checkpointing. handler.HandlePodAdditions(u.Pods) case kubetypes.UPDATE: - glog.V(2).Infof("SyncLoop (UPDATE, %q): %q", u.Source, format.Pods(u.Pods)) + glog.V(2).Infof("SyncLoop (UPDATE, %q): %q", u.Source, format.PodsWithDeletiontimestamps(u.Pods)) handler.HandlePodUpdates(u.Pods) case kubetypes.REMOVE: glog.V(2).Infof("SyncLoop (REMOVE, %q): %q", u.Source, format.Pods(u.Pods)) diff --git a/pkg/kubelet/util/format/pod.go b/pkg/kubelet/util/format/pod.go index 506f2a78519..da69f0e5d3e 100644 --- a/pkg/kubelet/util/format/pod.go +++ b/pkg/kubelet/util/format/pod.go @@ -19,6 +19,7 @@ package format import ( "fmt" "strings" + "time" "k8s.io/kubernetes/pkg/api" ) @@ -33,12 +34,28 @@ func Pod(pod *api.Pod) string { return fmt.Sprintf("%s_%s(%s)", pod.Name, pod.Namespace, pod.UID) } +// PodWithDeletionTimestamp is the same as Pod. In addition, it prints the +// deletion timestamp of the pod if it's not nil. +func PodWithDeletionTimestamp(pod *api.Pod) string { + var deletionTimestamp string + if pod.DeletionTimestamp != nil { + deletionTimestamp = ":DeletionTimestamp=" + pod.DeletionTimestamp.UTC().Format(time.RFC3339) + } + return Pod(pod) + deletionTimestamp +} + // Pods returns a string representating a list of pods in a human // readable format. func Pods(pods []*api.Pod) string { return aggregatePods(pods, Pod) } +// PodsWithDeletiontimestamps is the same as Pods. In addition, it prints the +// deletion timestamps of the pods if they are not nil. +func PodsWithDeletiontimestamps(pods []*api.Pod) string { + return aggregatePods(pods, PodWithDeletionTimestamp) +} + func aggregatePods(pods []*api.Pod, handler podHandler) string { podStrings := make([]string, 0, len(pods)) for _, pod := range pods {