mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-13 10:33:35 +00:00
vendor files
This commit is contained in:
44
vendor/k8s.io/kubernetes/pkg/kubelet/qos/BUILD
generated
vendored
Normal file
44
vendor/k8s.io/kubernetes/pkg/kubelet/qos/BUILD
generated
vendored
Normal file
@ -0,0 +1,44 @@
|
||||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
load(
|
||||
"@io_bazel_rules_go//go:def.bzl",
|
||||
"go_library",
|
||||
"go_test",
|
||||
)
|
||||
|
||||
go_test(
|
||||
name = "go_default_test",
|
||||
srcs = ["policy_test.go"],
|
||||
importpath = "k8s.io/kubernetes/pkg/kubelet/qos",
|
||||
library = ":go_default_library",
|
||||
deps = [
|
||||
"//vendor/k8s.io/api/core/v1:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/api/resource:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = [
|
||||
"doc.go",
|
||||
"policy.go",
|
||||
],
|
||||
importpath = "k8s.io/kubernetes/pkg/kubelet/qos",
|
||||
deps = [
|
||||
"//pkg/apis/core/v1/helper/qos:go_default_library",
|
||||
"//vendor/k8s.io/api/core/v1:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "package-srcs",
|
||||
srcs = glob(["**"]),
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:private"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "all-srcs",
|
||||
srcs = [":package-srcs"],
|
||||
tags = ["automanaged"],
|
||||
)
|
25
vendor/k8s.io/kubernetes/pkg/kubelet/qos/doc.go
generated
vendored
Normal file
25
vendor/k8s.io/kubernetes/pkg/kubelet/qos/doc.go
generated
vendored
Normal file
@ -0,0 +1,25 @@
|
||||
/*
|
||||
Copyright 2015 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
// package qos contains helper functions for quality of service.
|
||||
// For each resource (memory, CPU) Kubelet supports three classes of containers.
|
||||
// Memory guaranteed containers will receive the highest priority and will get all the resources
|
||||
// they need.
|
||||
// Burstable containers will be guaranteed their request and can “burst” and use more resources
|
||||
// when available.
|
||||
// Best-Effort containers, which don’t specify a request, can use resources only if not being used
|
||||
// by other pods.
|
||||
package qos // import "k8s.io/kubernetes/pkg/kubelet/qos"
|
72
vendor/k8s.io/kubernetes/pkg/kubelet/qos/policy.go
generated
vendored
Normal file
72
vendor/k8s.io/kubernetes/pkg/kubelet/qos/policy.go
generated
vendored
Normal file
@ -0,0 +1,72 @@
|
||||
/*
|
||||
Copyright 2015 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package qos
|
||||
|
||||
import (
|
||||
"k8s.io/api/core/v1"
|
||||
v1qos "k8s.io/kubernetes/pkg/apis/core/v1/helper/qos"
|
||||
)
|
||||
|
||||
const (
|
||||
// PodInfraOOMAdj is very docker specific. For arbitrary runtime, it may not make
|
||||
// sense to set sandbox level oom score, e.g. a sandbox could only be a namespace
|
||||
// without a process.
|
||||
// TODO: Handle infra container oom score adj in a runtime agnostic way.
|
||||
PodInfraOOMAdj int = -998
|
||||
KubeletOOMScoreAdj int = -999
|
||||
DockerOOMScoreAdj int = -999
|
||||
KubeProxyOOMScoreAdj int = -999
|
||||
guaranteedOOMScoreAdj int = -998
|
||||
besteffortOOMScoreAdj int = 1000
|
||||
)
|
||||
|
||||
// GetContainerOOMAdjust returns the amount by which the OOM score of all processes in the
|
||||
// container should be adjusted.
|
||||
// The OOM score of a process is the percentage of memory it consumes
|
||||
// multiplied by 10 (barring exceptional cases) + a configurable quantity which is between -1000
|
||||
// and 1000. Containers with higher OOM scores are killed if the system runs out of memory.
|
||||
// See https://lwn.net/Articles/391222/ for more information.
|
||||
func GetContainerOOMScoreAdjust(pod *v1.Pod, container *v1.Container, memoryCapacity int64) int {
|
||||
switch v1qos.GetPodQOS(pod) {
|
||||
case v1.PodQOSGuaranteed:
|
||||
// Guaranteed containers should be the last to get killed.
|
||||
return guaranteedOOMScoreAdj
|
||||
case v1.PodQOSBestEffort:
|
||||
return besteffortOOMScoreAdj
|
||||
}
|
||||
|
||||
// Burstable containers are a middle tier, between Guaranteed and Best-Effort. Ideally,
|
||||
// we want to protect Burstable containers that consume less memory than requested.
|
||||
// The formula below is a heuristic. A container requesting for 10% of a system's
|
||||
// memory will have an OOM score adjust of 900. If a process in container Y
|
||||
// uses over 10% of memory, its OOM score will be 1000. The idea is that containers
|
||||
// which use more than their request will have an OOM score of 1000 and will be prime
|
||||
// targets for OOM kills.
|
||||
// Note that this is a heuristic, it won't work if a container has many small processes.
|
||||
memoryRequest := container.Resources.Requests.Memory().Value()
|
||||
oomScoreAdjust := 1000 - (1000*memoryRequest)/memoryCapacity
|
||||
// A guaranteed pod using 100% of memory can have an OOM score of 10. Ensure
|
||||
// that burstable pods have a higher OOM score adjustment.
|
||||
if int(oomScoreAdjust) < (1000 + guaranteedOOMScoreAdj) {
|
||||
return (1000 + guaranteedOOMScoreAdj)
|
||||
}
|
||||
// Give burstable pods a higher chance of survival over besteffort pods.
|
||||
if int(oomScoreAdjust) == besteffortOOMScoreAdj {
|
||||
return int(oomScoreAdjust - 1)
|
||||
}
|
||||
return int(oomScoreAdjust)
|
||||
}
|
198
vendor/k8s.io/kubernetes/pkg/kubelet/qos/policy_test.go
generated
vendored
Normal file
198
vendor/k8s.io/kubernetes/pkg/kubelet/qos/policy_test.go
generated
vendored
Normal file
@ -0,0 +1,198 @@
|
||||
/*
|
||||
Copyright 2015 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package qos
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"testing"
|
||||
|
||||
"k8s.io/api/core/v1"
|
||||
"k8s.io/apimachinery/pkg/api/resource"
|
||||
)
|
||||
|
||||
const (
|
||||
standardMemoryAmount = 8000000000
|
||||
)
|
||||
|
||||
var (
|
||||
cpuLimit = v1.Pod{
|
||||
Spec: v1.PodSpec{
|
||||
Containers: []v1.Container{
|
||||
{
|
||||
Resources: v1.ResourceRequirements{
|
||||
Limits: v1.ResourceList{
|
||||
v1.ResourceName(v1.ResourceCPU): resource.MustParse("10"),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
memoryLimitCPURequest = v1.Pod{
|
||||
Spec: v1.PodSpec{
|
||||
Containers: []v1.Container{
|
||||
{
|
||||
Resources: v1.ResourceRequirements{
|
||||
Requests: v1.ResourceList{
|
||||
v1.ResourceName(v1.ResourceCPU): resource.MustParse("0"),
|
||||
},
|
||||
Limits: v1.ResourceList{
|
||||
v1.ResourceName(v1.ResourceMemory): resource.MustParse("10G"),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
zeroMemoryLimit = v1.Pod{
|
||||
Spec: v1.PodSpec{
|
||||
Containers: []v1.Container{
|
||||
{
|
||||
Resources: v1.ResourceRequirements{
|
||||
Limits: v1.ResourceList{
|
||||
v1.ResourceName(v1.ResourceMemory): resource.MustParse("0"),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
noRequestLimit = v1.Pod{
|
||||
Spec: v1.PodSpec{
|
||||
Containers: []v1.Container{
|
||||
{
|
||||
Resources: v1.ResourceRequirements{},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
equalRequestLimitCPUMemory = v1.Pod{
|
||||
Spec: v1.PodSpec{
|
||||
Containers: []v1.Container{
|
||||
{
|
||||
Resources: v1.ResourceRequirements{
|
||||
Requests: v1.ResourceList{
|
||||
v1.ResourceName(v1.ResourceMemory): resource.MustParse("10G"),
|
||||
v1.ResourceName(v1.ResourceCPU): resource.MustParse("5m"),
|
||||
},
|
||||
Limits: v1.ResourceList{
|
||||
v1.ResourceName(v1.ResourceCPU): resource.MustParse("5m"),
|
||||
v1.ResourceName(v1.ResourceMemory): resource.MustParse("10G"),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
cpuUnlimitedMemoryLimitedWithRequests = v1.Pod{
|
||||
Spec: v1.PodSpec{
|
||||
Containers: []v1.Container{
|
||||
{
|
||||
Resources: v1.ResourceRequirements{
|
||||
Requests: v1.ResourceList{
|
||||
v1.ResourceName(v1.ResourceMemory): resource.MustParse(strconv.Itoa(standardMemoryAmount / 2)),
|
||||
v1.ResourceName(v1.ResourceCPU): resource.MustParse("5m"),
|
||||
},
|
||||
Limits: v1.ResourceList{
|
||||
v1.ResourceName(v1.ResourceMemory): resource.MustParse("10G"),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
requestNoLimit = v1.Pod{
|
||||
Spec: v1.PodSpec{
|
||||
Containers: []v1.Container{
|
||||
{
|
||||
Resources: v1.ResourceRequirements{
|
||||
Requests: v1.ResourceList{
|
||||
v1.ResourceName(v1.ResourceMemory): resource.MustParse(strconv.Itoa(standardMemoryAmount - 1)),
|
||||
v1.ResourceName(v1.ResourceCPU): resource.MustParse("5m"),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
type oomTest struct {
|
||||
pod *v1.Pod
|
||||
memoryCapacity int64
|
||||
lowOOMScoreAdj int // The max oom_score_adj score the container should be assigned.
|
||||
highOOMScoreAdj int // The min oom_score_adj score the container should be assigned.
|
||||
}
|
||||
|
||||
func TestGetContainerOOMScoreAdjust(t *testing.T) {
|
||||
oomTests := []oomTest{
|
||||
{
|
||||
pod: &cpuLimit,
|
||||
memoryCapacity: 4000000000,
|
||||
lowOOMScoreAdj: 999,
|
||||
highOOMScoreAdj: 999,
|
||||
},
|
||||
{
|
||||
pod: &memoryLimitCPURequest,
|
||||
memoryCapacity: 8000000000,
|
||||
lowOOMScoreAdj: 999,
|
||||
highOOMScoreAdj: 999,
|
||||
},
|
||||
{
|
||||
pod: &zeroMemoryLimit,
|
||||
memoryCapacity: 7230457451,
|
||||
lowOOMScoreAdj: 1000,
|
||||
highOOMScoreAdj: 1000,
|
||||
},
|
||||
{
|
||||
pod: &noRequestLimit,
|
||||
memoryCapacity: 4000000000,
|
||||
lowOOMScoreAdj: 1000,
|
||||
highOOMScoreAdj: 1000,
|
||||
},
|
||||
{
|
||||
pod: &equalRequestLimitCPUMemory,
|
||||
memoryCapacity: 123456789,
|
||||
lowOOMScoreAdj: -998,
|
||||
highOOMScoreAdj: -998,
|
||||
},
|
||||
{
|
||||
pod: &cpuUnlimitedMemoryLimitedWithRequests,
|
||||
memoryCapacity: standardMemoryAmount,
|
||||
lowOOMScoreAdj: 495,
|
||||
highOOMScoreAdj: 505,
|
||||
},
|
||||
{
|
||||
pod: &requestNoLimit,
|
||||
memoryCapacity: standardMemoryAmount,
|
||||
lowOOMScoreAdj: 2,
|
||||
highOOMScoreAdj: 2,
|
||||
},
|
||||
}
|
||||
for _, test := range oomTests {
|
||||
oomScoreAdj := GetContainerOOMScoreAdjust(test.pod, &test.pod.Spec.Containers[0], test.memoryCapacity)
|
||||
if oomScoreAdj < test.lowOOMScoreAdj || oomScoreAdj > test.highOOMScoreAdj {
|
||||
t.Errorf("oom_score_adj should be between %d and %d, but was %d", test.lowOOMScoreAdj, test.highOOMScoreAdj, oomScoreAdj)
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user