Skip to content

Commit

Permalink
kubelet: include init containers when determining pod QoS
Browse files Browse the repository at this point in the history
  • Loading branch information
sjenning committed May 17, 2019
1 parent 46a8025 commit bcfa60d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
5 changes: 4 additions & 1 deletion pkg/apis/core/helper/qos/qos.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ func GetPodQOS(pod *core.Pod) core.PodQOSClass {
limits := core.ResourceList{}
zeroQuantity := resource.MustParse("0")
isGuaranteed := true
for _, container := range pod.Spec.Containers {
allContainers := []core.Container{}
allContainers = append(allContainers, pod.Spec.Containers...)
allContainers = append(allContainers, pod.Spec.InitContainers...)
for _, container := range allContainers {
// process requests
for name, quantity := range container.Resources.Requests {
if !isSupportedQoSComputeResource(name) {
Expand Down
7 changes: 5 additions & 2 deletions pkg/apis/core/v1/helper/qos/qos.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ limitations under the License.
package qos

import (
"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/kubernetes/pkg/apis/core"
Expand All @@ -41,7 +41,10 @@ func GetPodQOS(pod *v1.Pod) v1.PodQOSClass {
limits := v1.ResourceList{}
zeroQuantity := resource.MustParse("0")
isGuaranteed := true
for _, container := range pod.Spec.Containers {
allContainers := []v1.Container{}
allContainers = append(allContainers, pod.Spec.Containers...)
allContainers = append(allContainers, pod.Spec.InitContainers...)
for _, container := range allContainers {
// process requests
for name, quantity := range container.Resources.Requests {
if !isSupportedQoSComputeResource(name) {
Expand Down
24 changes: 23 additions & 1 deletion pkg/apis/core/v1/helper/qos/qos_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package qos
import (
"testing"

"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/kubernetes/pkg/apis/core"
Expand Down Expand Up @@ -116,6 +116,16 @@ func TestGetPodQOS(t *testing.T) {
}),
expected: v1.PodQOSBestEffort,
},
{
pod: newPodWithInitContainers("init-container",
[]v1.Container{
newContainer("best-effort", getResourceList("", ""), getResourceList("", "")),
},
[]v1.Container{
newContainer("burstable", getResourceList("10m", "100Mi"), getResourceList("100m", "200Mi")),
}),
expected: v1.PodQOSBurstable,
},
}
for id, testCase := range testCases {
if actual := GetPodQOS(testCase.pod); testCase.expected != actual {
Expand Down Expand Up @@ -172,3 +182,15 @@ func newPod(name string, containers []v1.Container) *v1.Pod {
},
}
}

func newPodWithInitContainers(name string, containers []v1.Container, initContainers []v1.Container) *v1.Pod {
return &v1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: name,
},
Spec: v1.PodSpec{
Containers: containers,
InitContainers: initContainers,
},
}
}

0 comments on commit bcfa60d

Please sign in to comment.