Skip to content

Commit

Permalink
Critical pods shouldn't be restricted to kube-system
Browse files Browse the repository at this point in the history
  • Loading branch information
ravisantoshgudimetla committed Mar 27, 2018
1 parent 6cca687 commit 5b54626
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
8 changes: 2 additions & 6 deletions pkg/kubelet/types/pod_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func (sp SyncPodType) String() string {
// or equal to SystemCriticalPriority. Both the rescheduler(deprecated in 1.10) and the kubelet use this function
// to make admission and scheduling decisions.
func IsCriticalPod(pod *v1.Pod) bool {
return IsCritical(pod.Namespace, pod.Annotations) || (pod.Spec.Priority != nil && IsCriticalPodBasedOnPriority(pod.Namespace, *pod.Spec.Priority))
return IsCritical(pod.Namespace, pod.Annotations) || (pod.Spec.Priority != nil && IsCriticalPodBasedOnPriority(*pod.Spec.Priority))
}

// IsCritical returns true if parameters bear the critical pod annotation
Expand All @@ -163,11 +163,7 @@ func IsCritical(ns string, annotations map[string]string) bool {
}

// IsCriticalPodBasedOnPriority checks if the given pod is a critical pod based on priority resolved from pod Spec.
func IsCriticalPodBasedOnPriority(ns string, priority int32) bool {
// Critical pods are restricted to "kube-system" namespace as of now.
if ns != kubeapi.NamespaceSystem {
return false
}
func IsCriticalPodBasedOnPriority(priority int32) bool {
if priority >= scheduling.SystemCriticalPriority {
return true
}
Expand Down
25 changes: 25 additions & 0 deletions pkg/kubelet/types/pod_update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,28 @@ func TestIsCriticalPod(t *testing.T) {
}
}
}

func TestIsCriticalPodBasedOnPriority(t *testing.T) {
tests := []struct {
priority int32
description string
expected bool
}{
{
priority: int32(2000000001),
description: "A system critical pod",
expected: true,
},
{
priority: int32(1000000000),
description: "A non system critical pod",
expected: false,
},
}
for _, test := range tests {
actual := IsCriticalPodBasedOnPriority(test.priority)
if actual != test.expected {
t.Errorf("IsCriticalPodBased on priority should have returned %v for test %v but got %v", test.expected, test.description, actual)
}
}
}

0 comments on commit 5b54626

Please sign in to comment.