mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-31 07:20:13 +00:00
Merge pull request #75223 from sjenning/fix-pod-qos-init-containers
kubelet: include init containers when determining pod QoS
This commit is contained in:
commit
cff6e42005
@ -39,7 +39,10 @@ func GetPodQOS(pod *core.Pod) core.PodQOSClass {
|
|||||||
limits := core.ResourceList{}
|
limits := core.ResourceList{}
|
||||||
zeroQuantity := resource.MustParse("0")
|
zeroQuantity := resource.MustParse("0")
|
||||||
isGuaranteed := true
|
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
|
// process requests
|
||||||
for name, quantity := range container.Resources.Requests {
|
for name, quantity := range container.Resources.Requests {
|
||||||
if !isSupportedQoSComputeResource(name) {
|
if !isSupportedQoSComputeResource(name) {
|
||||||
|
@ -17,7 +17,7 @@ limitations under the License.
|
|||||||
package qos
|
package qos
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"k8s.io/api/core/v1"
|
v1 "k8s.io/api/core/v1"
|
||||||
"k8s.io/apimachinery/pkg/api/resource"
|
"k8s.io/apimachinery/pkg/api/resource"
|
||||||
"k8s.io/apimachinery/pkg/util/sets"
|
"k8s.io/apimachinery/pkg/util/sets"
|
||||||
"k8s.io/kubernetes/pkg/apis/core"
|
"k8s.io/kubernetes/pkg/apis/core"
|
||||||
@ -41,7 +41,10 @@ func GetPodQOS(pod *v1.Pod) v1.PodQOSClass {
|
|||||||
limits := v1.ResourceList{}
|
limits := v1.ResourceList{}
|
||||||
zeroQuantity := resource.MustParse("0")
|
zeroQuantity := resource.MustParse("0")
|
||||||
isGuaranteed := true
|
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
|
// process requests
|
||||||
for name, quantity := range container.Resources.Requests {
|
for name, quantity := range container.Resources.Requests {
|
||||||
if !isSupportedQoSComputeResource(name) {
|
if !isSupportedQoSComputeResource(name) {
|
||||||
|
@ -19,7 +19,7 @@ package qos
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"k8s.io/api/core/v1"
|
v1 "k8s.io/api/core/v1"
|
||||||
"k8s.io/apimachinery/pkg/api/resource"
|
"k8s.io/apimachinery/pkg/api/resource"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/kubernetes/pkg/apis/core"
|
"k8s.io/kubernetes/pkg/apis/core"
|
||||||
@ -116,6 +116,16 @@ func TestGetPodQOS(t *testing.T) {
|
|||||||
}),
|
}),
|
||||||
expected: v1.PodQOSBestEffort,
|
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 {
|
for id, testCase := range testCases {
|
||||||
if actual := GetPodQOS(testCase.pod); testCase.expected != actual {
|
if actual := GetPodQOS(testCase.pod); testCase.expected != actual {
|
||||||
@ -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,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user