From c05d5060193221dd5ebcf031d2b2708af5d00c5f Mon Sep 17 00:00:00 2001 From: Himanshu Pandey Date: Tue, 23 Jul 2019 13:59:12 -0700 Subject: [PATCH] changed IsCriticalPod to return true in case of static pods --- pkg/kubelet/eviction/BUILD | 1 - pkg/kubelet/eviction/eviction_manager.go | 3 +-- pkg/kubelet/kubelet.go | 2 +- pkg/kubelet/pod/pod_manager.go | 2 +- pkg/kubelet/status/status_manager.go | 2 +- pkg/kubelet/status/status_manager_test.go | 4 ++-- pkg/kubelet/types/pod_update.go | 9 +++++++++ pkg/kubelet/types/pod_update_test.go | 12 ++++++++++++ 8 files changed, 27 insertions(+), 8 deletions(-) diff --git a/pkg/kubelet/eviction/BUILD b/pkg/kubelet/eviction/BUILD index 2e6a49bd6f0..a72186508ee 100644 --- a/pkg/kubelet/eviction/BUILD +++ b/pkg/kubelet/eviction/BUILD @@ -56,7 +56,6 @@ go_library( "//pkg/kubelet/eviction/api:go_default_library", "//pkg/kubelet/lifecycle:go_default_library", "//pkg/kubelet/metrics:go_default_library", - "//pkg/kubelet/pod:go_default_library", "//pkg/kubelet/server/stats:go_default_library", "//pkg/kubelet/types:go_default_library", "//pkg/kubelet/util/format:go_default_library", diff --git a/pkg/kubelet/eviction/eviction_manager.go b/pkg/kubelet/eviction/eviction_manager.go index f87544b76e7..de92d6eab24 100644 --- a/pkg/kubelet/eviction/eviction_manager.go +++ b/pkg/kubelet/eviction/eviction_manager.go @@ -37,7 +37,6 @@ import ( evictionapi "k8s.io/kubernetes/pkg/kubelet/eviction/api" "k8s.io/kubernetes/pkg/kubelet/lifecycle" "k8s.io/kubernetes/pkg/kubelet/metrics" - kubepod "k8s.io/kubernetes/pkg/kubelet/pod" "k8s.io/kubernetes/pkg/kubelet/server/stats" kubelettypes "k8s.io/kubernetes/pkg/kubelet/types" "k8s.io/kubernetes/pkg/kubelet/util/format" @@ -547,7 +546,7 @@ func (m *managerImpl) evictPod(pod *v1.Pod, gracePeriodOverride int64, evictMsg // If the pod is marked as critical and static, and support for critical pod annotations is enabled, // do not evict such pods. Static pods are not re-admitted after evictions. // https://github.com/kubernetes/kubernetes/issues/40573 has more details. - if kubepod.IsStaticPod(pod) { + if kubelettypes.IsStaticPod(pod) { // need mirrorPod to check its "priority" value; static pod doesn't carry it if mirrorPod, ok := m.mirrorPodFunc(pod); ok && mirrorPod != nil { // skip only when it's a static and critical pod diff --git a/pkg/kubelet/kubelet.go b/pkg/kubelet/kubelet.go index 8b4596a3563..60a302b988a 100644 --- a/pkg/kubelet/kubelet.go +++ b/pkg/kubelet/kubelet.go @@ -1634,7 +1634,7 @@ func (kl *Kubelet) syncPod(o syncPodOptions) error { } // Create Mirror Pod for Static Pod if it doesn't already exist - if kubepod.IsStaticPod(pod) { + if kubetypes.IsStaticPod(pod) { podFullName := kubecontainer.GetPodFullName(pod) deleted := false if mirrorPod != nil { diff --git a/pkg/kubelet/pod/pod_manager.go b/pkg/kubelet/pod/pod_manager.go index 9a67f0ff2c5..7e3ef5edd4a 100644 --- a/pkg/kubelet/pod/pod_manager.go +++ b/pkg/kubelet/pod/pod_manager.go @@ -307,7 +307,7 @@ func (pm *basicManager) GetUIDTranslations() (podToMirror map[kubetypes.Resolved mirrorToPod = make(map[kubetypes.MirrorPodUID]kubetypes.ResolvedPodUID, len(pm.translationByUID)) // Insert empty translation mapping for all static pods. for uid, pod := range pm.podByUID { - if !IsStaticPod(pod) { + if !kubetypes.IsStaticPod(pod) { continue } podToMirror[uid] = "" diff --git a/pkg/kubelet/status/status_manager.go b/pkg/kubelet/status/status_manager.go index efbc8667924..e4d56b94925 100644 --- a/pkg/kubelet/status/status_manager.go +++ b/pkg/kubelet/status/status_manager.go @@ -559,7 +559,7 @@ func (m *manager) needsReconcile(uid types.UID, status v1.PodStatus) bool { return false } // If the pod is a static pod, we should check its mirror pod, because only status in mirror pod is meaningful to us. - if kubepod.IsStaticPod(pod) { + if kubetypes.IsStaticPod(pod) { mirrorPod, ok := m.podManager.GetMirrorPodByPod(pod) if !ok { klog.V(4).Infof("Static pod %q has no corresponding mirror pod, no need to reconcile", format.Pod(pod)) diff --git a/pkg/kubelet/status/status_manager_test.go b/pkg/kubelet/status/status_manager_test.go index b882ddfe029..ab3bd2c760b 100644 --- a/pkg/kubelet/status/status_manager_test.go +++ b/pkg/kubelet/status/status_manager_test.go @@ -519,7 +519,7 @@ func TestStaticPod(t *testing.T) { t.Logf("Create the static pod") m.podManager.AddPod(staticPod) - assert.True(t, kubepod.IsStaticPod(staticPod), "SetUp error: staticPod") + assert.True(t, kubetypes.IsStaticPod(staticPod), "SetUp error: staticPod") status := getRandomPodStatus() now := metav1.Now() @@ -805,7 +805,7 @@ func TestDoNotDeleteMirrorPods(t *testing.T) { m.podManager.AddPod(staticPod) m.podManager.AddPod(mirrorPod) t.Logf("Verify setup.") - assert.True(t, kubepod.IsStaticPod(staticPod), "SetUp error: staticPod") + assert.True(t, kubetypes.IsStaticPod(staticPod), "SetUp error: staticPod") assert.True(t, kubepod.IsMirrorPod(mirrorPod), "SetUp error: mirrorPod") assert.Equal(t, m.podManager.TranslatePodUID(mirrorPod.UID), kubetypes.ResolvedPodUID(staticPod.UID)) diff --git a/pkg/kubelet/types/pod_update.go b/pkg/kubelet/types/pod_update.go index 82a5f9a4020..c4dfad18649 100644 --- a/pkg/kubelet/types/pod_update.go +++ b/pkg/kubelet/types/pod_update.go @@ -146,6 +146,9 @@ func (sp SyncPodType) String() string { // or equal to SystemCriticalPriority. Both the default scheduler and the kubelet use this function // to make admission and scheduling decisions. func IsCriticalPod(pod *v1.Pod) bool { + if IsStaticPod(pod) { + return true + } if pod.Spec.Priority != nil && IsCriticalPodBasedOnPriority(*pod.Spec.Priority) { return true } @@ -193,3 +196,9 @@ func IsCriticalPodBasedOnPriority(priority int32) bool { } return false } + +// IsStaticPod returns true if the pod is a static pod. +func IsStaticPod(pod *v1.Pod) bool { + source, err := GetPodSource(pod) + return err == nil && source != ApiserverSource +} diff --git a/pkg/kubelet/types/pod_update_test.go b/pkg/kubelet/types/pod_update_test.go index 42cc2fae97c..cde006788cb 100644 --- a/pkg/kubelet/types/pod_update_test.go +++ b/pkg/kubelet/types/pod_update_test.go @@ -171,6 +171,18 @@ func TestIsCriticalPod(t *testing.T) { }, expected: true, }, + { + pod: v1.Pod{ + ObjectMeta: metav1.ObjectMeta{ + Name: "pod5", + Namespace: "kube-system", + Annotations: map[string]string{ + ConfigSourceAnnotationKey: "abc", + }, + }, + }, + expected: true, + }, } for i, data := range cases { actual := IsCriticalPod(&data.pod)