From 69c3aa08722448acffecfa04d669303c6007a376 Mon Sep 17 00:00:00 2001 From: Yu-Ju Hong Date: Fri, 11 Sep 2015 12:52:22 -0700 Subject: [PATCH] Fix source annotation in kubelet kubelet relies on source annotation to distinguish pods from different sources. It should always annotate the source when receiving the pod to avoid any confusion. This commit fixes that and also make sure we don't overwrite the first seen time. --- pkg/kubelet/config/config.go | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/pkg/kubelet/config/config.go b/pkg/kubelet/config/config.go index 5d0e5bc4722..6d7aeaab640 100644 --- a/pkg/kubelet/config/config.go +++ b/pkg/kubelet/config/config.go @@ -216,6 +216,11 @@ func (s *podStorage) merge(source string, change interface{}) (adds, updates, de filtered := filterInvalidPods(update.Pods, source, s.recorder) for _, ref := range filtered { name := kubecontainer.GetPodFullName(ref) + // Annotate the pod with the source before any comparison. + if ref.Annotations == nil { + ref.Annotations = make(map[string]string) + } + ref.Annotations[kubelet.ConfigSourceAnnotationKey] = source if existing, found := pods[name]; found { if checkAndUpdatePod(existing, ref) { // this is an update @@ -226,10 +231,6 @@ func (s *podStorage) merge(source string, change interface{}) (adds, updates, de continue } // this is an add - if ref.Annotations == nil { - ref.Annotations = make(map[string]string) - } - ref.Annotations[kubelet.ConfigSourceAnnotationKey] = source recordFirstSeenTime(ref) pods[name] = ref adds.Pods = append(adds.Pods, ref) @@ -258,6 +259,11 @@ func (s *podStorage) merge(source string, change interface{}) (adds, updates, de filtered := filterInvalidPods(update.Pods, source, s.recorder) for _, ref := range filtered { name := kubecontainer.GetPodFullName(ref) + // Annotate the pod with the source before any comparison. + if ref.Annotations == nil { + ref.Annotations = make(map[string]string) + } + ref.Annotations[kubelet.ConfigSourceAnnotationKey] = source if existing, found := oldPods[name]; found { pods[name] = existing if checkAndUpdatePod(existing, ref) { @@ -268,10 +274,6 @@ func (s *podStorage) merge(source string, change interface{}) (adds, updates, de // this is a no-op continue } - if ref.Annotations == nil { - ref.Annotations = make(map[string]string) - } - ref.Annotations[kubelet.ConfigSourceAnnotationKey] = source recordFirstSeenTime(ref) pods[name] = ref adds.Pods = append(adds.Pods, ref) @@ -391,6 +393,9 @@ func updateAnnotations(existing, ref *api.Pod) { // checkAndUpdatePod updates existing if ref makes a meaningful change and returns true, or // returns false if there was no update. func checkAndUpdatePod(existing, ref *api.Pod) bool { + // Overwrite the first-seen time with the existing one. This is our own + // internal annotation, there is no need to update. + ref.Annotations[kubelet.ConfigFirstSeenAnnotationKey] = existing.Annotations[kubelet.ConfigFirstSeenAnnotationKey] // TODO: it would be better to update the whole object and only preserve certain things // like the source annotation or the UID (to ensure safety) if reflect.DeepEqual(existing.Spec, ref.Spec) &&