Merge pull request #27101 from caesarxuchao/add-deletiontimestamp-log

Automatic merge from submit-queue

Let kubelet log the DeletionTimestamp if it's not nil in update

This helps to debug if it's the kubelet to blame when a pod is not deleted. 

Example output:
```
SyncLoop (UPDATE, "api"): "redis-master_default(c6782276-2dd4-11e6-b874-64510650ab1c):DeletionTimestamp=2016-06-08T23:58:12Z"
```

ref #26290
cc @Random-Liu
This commit is contained in:
k8s-merge-robot 2016-06-12 22:56:43 -07:00 committed by GitHub
commit d935a02c64
2 changed files with 18 additions and 1 deletions

View File

@ -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))

View File

@ -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 {