Commit 69c3aa08 authored by Yu-Ju Hong's avatar Yu-Ju Hong

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.
parent e46c940c
...@@ -216,6 +216,11 @@ func (s *podStorage) merge(source string, change interface{}) (adds, updates, de ...@@ -216,6 +216,11 @@ func (s *podStorage) merge(source string, change interface{}) (adds, updates, de
filtered := filterInvalidPods(update.Pods, source, s.recorder) filtered := filterInvalidPods(update.Pods, source, s.recorder)
for _, ref := range filtered { for _, ref := range filtered {
name := kubecontainer.GetPodFullName(ref) 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 existing, found := pods[name]; found {
if checkAndUpdatePod(existing, ref) { if checkAndUpdatePod(existing, ref) {
// this is an update // this is an update
...@@ -226,10 +231,6 @@ func (s *podStorage) merge(source string, change interface{}) (adds, updates, de ...@@ -226,10 +231,6 @@ func (s *podStorage) merge(source string, change interface{}) (adds, updates, de
continue continue
} }
// this is an add // this is an add
if ref.Annotations == nil {
ref.Annotations = make(map[string]string)
}
ref.Annotations[kubelet.ConfigSourceAnnotationKey] = source
recordFirstSeenTime(ref) recordFirstSeenTime(ref)
pods[name] = ref pods[name] = ref
adds.Pods = append(adds.Pods, ref) adds.Pods = append(adds.Pods, ref)
...@@ -258,6 +259,11 @@ func (s *podStorage) merge(source string, change interface{}) (adds, updates, de ...@@ -258,6 +259,11 @@ func (s *podStorage) merge(source string, change interface{}) (adds, updates, de
filtered := filterInvalidPods(update.Pods, source, s.recorder) filtered := filterInvalidPods(update.Pods, source, s.recorder)
for _, ref := range filtered { for _, ref := range filtered {
name := kubecontainer.GetPodFullName(ref) 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 { if existing, found := oldPods[name]; found {
pods[name] = existing pods[name] = existing
if checkAndUpdatePod(existing, ref) { if checkAndUpdatePod(existing, ref) {
...@@ -268,10 +274,6 @@ func (s *podStorage) merge(source string, change interface{}) (adds, updates, de ...@@ -268,10 +274,6 @@ func (s *podStorage) merge(source string, change interface{}) (adds, updates, de
// this is a no-op // this is a no-op
continue continue
} }
if ref.Annotations == nil {
ref.Annotations = make(map[string]string)
}
ref.Annotations[kubelet.ConfigSourceAnnotationKey] = source
recordFirstSeenTime(ref) recordFirstSeenTime(ref)
pods[name] = ref pods[name] = ref
adds.Pods = append(adds.Pods, ref) adds.Pods = append(adds.Pods, ref)
...@@ -391,6 +393,9 @@ func updateAnnotations(existing, ref *api.Pod) { ...@@ -391,6 +393,9 @@ func updateAnnotations(existing, ref *api.Pod) {
// checkAndUpdatePod updates existing if ref makes a meaningful change and returns true, or // checkAndUpdatePod updates existing if ref makes a meaningful change and returns true, or
// returns false if there was no update. // returns false if there was no update.
func checkAndUpdatePod(existing, ref *api.Pod) bool { 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 // 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) // like the source annotation or the UID (to ensure safety)
if reflect.DeepEqual(existing.Spec, ref.Spec) && if reflect.DeepEqual(existing.Spec, ref.Spec) &&
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment