Merge pull request #80491 from hpandeycodeit/static_pod_priority

Changed IsCriticalPod to return true in case of static pods
This commit is contained in:
Kubernetes Prow Robot 2019-08-08 16:11:39 -07:00 committed by GitHub
commit 806ced34a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 27 additions and 8 deletions

View File

@ -56,7 +56,6 @@ go_library(
"//pkg/kubelet/eviction/api:go_default_library", "//pkg/kubelet/eviction/api:go_default_library",
"//pkg/kubelet/lifecycle:go_default_library", "//pkg/kubelet/lifecycle:go_default_library",
"//pkg/kubelet/metrics:go_default_library", "//pkg/kubelet/metrics:go_default_library",
"//pkg/kubelet/pod:go_default_library",
"//pkg/kubelet/server/stats:go_default_library", "//pkg/kubelet/server/stats:go_default_library",
"//pkg/kubelet/types:go_default_library", "//pkg/kubelet/types:go_default_library",
"//pkg/kubelet/util/format:go_default_library", "//pkg/kubelet/util/format:go_default_library",

View File

@ -37,7 +37,6 @@ import (
evictionapi "k8s.io/kubernetes/pkg/kubelet/eviction/api" evictionapi "k8s.io/kubernetes/pkg/kubelet/eviction/api"
"k8s.io/kubernetes/pkg/kubelet/lifecycle" "k8s.io/kubernetes/pkg/kubelet/lifecycle"
"k8s.io/kubernetes/pkg/kubelet/metrics" "k8s.io/kubernetes/pkg/kubelet/metrics"
kubepod "k8s.io/kubernetes/pkg/kubelet/pod"
"k8s.io/kubernetes/pkg/kubelet/server/stats" "k8s.io/kubernetes/pkg/kubelet/server/stats"
kubelettypes "k8s.io/kubernetes/pkg/kubelet/types" kubelettypes "k8s.io/kubernetes/pkg/kubelet/types"
"k8s.io/kubernetes/pkg/kubelet/util/format" "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, // 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. // do not evict such pods. Static pods are not re-admitted after evictions.
// https://github.com/kubernetes/kubernetes/issues/40573 has more details. // 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 // need mirrorPod to check its "priority" value; static pod doesn't carry it
if mirrorPod, ok := m.mirrorPodFunc(pod); ok && mirrorPod != nil { if mirrorPod, ok := m.mirrorPodFunc(pod); ok && mirrorPod != nil {
// skip only when it's a static and critical pod // skip only when it's a static and critical pod

View File

@ -1634,7 +1634,7 @@ func (kl *Kubelet) syncPod(o syncPodOptions) error {
} }
// Create Mirror Pod for Static Pod if it doesn't already exist // Create Mirror Pod for Static Pod if it doesn't already exist
if kubepod.IsStaticPod(pod) { if kubetypes.IsStaticPod(pod) {
podFullName := kubecontainer.GetPodFullName(pod) podFullName := kubecontainer.GetPodFullName(pod)
deleted := false deleted := false
if mirrorPod != nil { if mirrorPod != nil {

View File

@ -307,7 +307,7 @@ func (pm *basicManager) GetUIDTranslations() (podToMirror map[kubetypes.Resolved
mirrorToPod = make(map[kubetypes.MirrorPodUID]kubetypes.ResolvedPodUID, len(pm.translationByUID)) mirrorToPod = make(map[kubetypes.MirrorPodUID]kubetypes.ResolvedPodUID, len(pm.translationByUID))
// Insert empty translation mapping for all static pods. // Insert empty translation mapping for all static pods.
for uid, pod := range pm.podByUID { for uid, pod := range pm.podByUID {
if !IsStaticPod(pod) { if !kubetypes.IsStaticPod(pod) {
continue continue
} }
podToMirror[uid] = "" podToMirror[uid] = ""

View File

@ -559,7 +559,7 @@ func (m *manager) needsReconcile(uid types.UID, status v1.PodStatus) bool {
return false 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 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) mirrorPod, ok := m.podManager.GetMirrorPodByPod(pod)
if !ok { if !ok {
klog.V(4).Infof("Static pod %q has no corresponding mirror pod, no need to reconcile", format.Pod(pod)) klog.V(4).Infof("Static pod %q has no corresponding mirror pod, no need to reconcile", format.Pod(pod))

View File

@ -519,7 +519,7 @@ func TestStaticPod(t *testing.T) {
t.Logf("Create the static pod") t.Logf("Create the static pod")
m.podManager.AddPod(staticPod) m.podManager.AddPod(staticPod)
assert.True(t, kubepod.IsStaticPod(staticPod), "SetUp error: staticPod") assert.True(t, kubetypes.IsStaticPod(staticPod), "SetUp error: staticPod")
status := getRandomPodStatus() status := getRandomPodStatus()
now := metav1.Now() now := metav1.Now()
@ -805,7 +805,7 @@ func TestDoNotDeleteMirrorPods(t *testing.T) {
m.podManager.AddPod(staticPod) m.podManager.AddPod(staticPod)
m.podManager.AddPod(mirrorPod) m.podManager.AddPod(mirrorPod)
t.Logf("Verify setup.") 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.True(t, kubepod.IsMirrorPod(mirrorPod), "SetUp error: mirrorPod")
assert.Equal(t, m.podManager.TranslatePodUID(mirrorPod.UID), kubetypes.ResolvedPodUID(staticPod.UID)) assert.Equal(t, m.podManager.TranslatePodUID(mirrorPod.UID), kubetypes.ResolvedPodUID(staticPod.UID))

View File

@ -146,6 +146,9 @@ func (sp SyncPodType) String() string {
// or equal to SystemCriticalPriority. Both the default scheduler and the kubelet use this function // or equal to SystemCriticalPriority. Both the default scheduler and the kubelet use this function
// to make admission and scheduling decisions. // to make admission and scheduling decisions.
func IsCriticalPod(pod *v1.Pod) bool { func IsCriticalPod(pod *v1.Pod) bool {
if IsStaticPod(pod) {
return true
}
if pod.Spec.Priority != nil && IsCriticalPodBasedOnPriority(*pod.Spec.Priority) { if pod.Spec.Priority != nil && IsCriticalPodBasedOnPriority(*pod.Spec.Priority) {
return true return true
} }
@ -193,3 +196,9 @@ func IsCriticalPodBasedOnPriority(priority int32) bool {
} }
return false 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
}

View File

@ -171,6 +171,18 @@ func TestIsCriticalPod(t *testing.T) {
}, },
expected: true, 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 { for i, data := range cases {
actual := IsCriticalPod(&data.pod) actual := IsCriticalPod(&data.pod)