Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed IsCriticalPod to return true in case of static pods #80491

Merged
merged 1 commit into from Aug 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion pkg/kubelet/eviction/BUILD
Expand Up @@ -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",
Expand Down
3 changes: 1 addition & 2 deletions pkg/kubelet/eviction/eviction_manager.go
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/kubelet/kubelet.go
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion pkg/kubelet/pod/pod_manager.go
Expand Up @@ -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] = ""
Expand Down
2 changes: 1 addition & 1 deletion pkg/kubelet/status/status_manager.go
Expand Up @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions pkg/kubelet/status/status_manager_test.go
Expand Up @@ -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()
Expand Down Expand Up @@ -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))

Expand Down
9 changes: 9 additions & 0 deletions pkg/kubelet/types/pod_update.go
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
12 changes: 12 additions & 0 deletions pkg/kubelet/types/pod_update_test.go
Expand Up @@ -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)
Expand Down