mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-19 09:52:49 +00:00
mark PodOverhead to GA in v1.24; remove in v1.26
This commit is contained in:
parent
8bf64e4128
commit
acd696266e
6
api/openapi-spec/swagger.json
generated
6
api/openapi-spec/swagger.json
generated
@ -8663,7 +8663,7 @@
|
||||
"additionalProperties": {
|
||||
"$ref": "#/definitions/io.k8s.apimachinery.pkg.api.resource.Quantity"
|
||||
},
|
||||
"description": "Overhead represents the resource overhead associated with running a pod for a given RuntimeClass. This field will be autopopulated at admission time by the RuntimeClass admission controller. If the RuntimeClass admission controller is enabled, overhead must not be set in Pod create requests. The RuntimeClass admission controller will reject Pod create requests which have the overhead already set. If RuntimeClass is configured and selected in the PodSpec, Overhead will be set to the value defined in the corresponding RuntimeClass, otherwise it will remain unset and treated as zero. More info: https://git.k8s.io/enhancements/keps/sig-node/688-pod-overhead/README.md This field is beta-level as of Kubernetes v1.18, and is only honored by servers that enable the PodOverhead feature.",
|
||||
"description": "Overhead represents the resource overhead associated with running a pod for a given RuntimeClass. This field will be autopopulated at admission time by the RuntimeClass admission controller. If the RuntimeClass admission controller is enabled, overhead must not be set in Pod create requests. The RuntimeClass admission controller will reject Pod create requests which have the overhead already set. If RuntimeClass is configured and selected in the PodSpec, Overhead will be set to the value defined in the corresponding RuntimeClass, otherwise it will remain unset and treated as zero. More info: https://git.k8s.io/enhancements/keps/sig-node/688-pod-overhead/README.md",
|
||||
"type": "object"
|
||||
},
|
||||
"preemptionPolicy": {
|
||||
@ -13194,7 +13194,7 @@
|
||||
},
|
||||
"overhead": {
|
||||
"$ref": "#/definitions/io.k8s.api.node.v1.Overhead",
|
||||
"description": "Overhead represents the resource overhead associated with running a pod for a given RuntimeClass. For more details, see\n https://kubernetes.io/docs/concepts/scheduling-eviction/pod-overhead/\nThis field is in beta starting v1.18 and is only honored by servers that enable the PodOverhead feature."
|
||||
"description": "Overhead represents the resource overhead associated with running a pod for a given RuntimeClass. For more details, see\n https://kubernetes.io/docs/concepts/scheduling-eviction/pod-overhead/"
|
||||
},
|
||||
"scheduling": {
|
||||
"$ref": "#/definitions/io.k8s.api.node.v1.Scheduling",
|
||||
@ -13304,7 +13304,7 @@
|
||||
},
|
||||
"overhead": {
|
||||
"$ref": "#/definitions/io.k8s.api.node.v1beta1.Overhead",
|
||||
"description": "Overhead represents the resource overhead associated with running a pod for a given RuntimeClass. For more details, see https://git.k8s.io/enhancements/keps/sig-node/688-pod-overhead/README.md This field is beta-level as of Kubernetes v1.18, and is only honored by servers that enable the PodOverhead feature."
|
||||
"description": "Overhead represents the resource overhead associated with running a pod for a given RuntimeClass. For more details, see https://git.k8s.io/enhancements/keps/sig-node/688-pod-overhead/README.md"
|
||||
},
|
||||
"scheduling": {
|
||||
"$ref": "#/definitions/io.k8s.api.node.v1beta1.Scheduling",
|
||||
|
@ -4305,7 +4305,7 @@
|
||||
"$ref": "#/components/schemas/io.k8s.apimachinery.pkg.api.resource.Quantity",
|
||||
"default": {}
|
||||
},
|
||||
"description": "Overhead represents the resource overhead associated with running a pod for a given RuntimeClass. This field will be autopopulated at admission time by the RuntimeClass admission controller. If the RuntimeClass admission controller is enabled, overhead must not be set in Pod create requests. The RuntimeClass admission controller will reject Pod create requests which have the overhead already set. If RuntimeClass is configured and selected in the PodSpec, Overhead will be set to the value defined in the corresponding RuntimeClass, otherwise it will remain unset and treated as zero. More info: https://git.k8s.io/enhancements/keps/sig-node/688-pod-overhead/README.md This field is beta-level as of Kubernetes v1.18, and is only honored by servers that enable the PodOverhead feature.",
|
||||
"description": "Overhead represents the resource overhead associated with running a pod for a given RuntimeClass. This field will be autopopulated at admission time by the RuntimeClass admission controller. If the RuntimeClass admission controller is enabled, overhead must not be set in Pod create requests. The RuntimeClass admission controller will reject Pod create requests which have the overhead already set. If RuntimeClass is configured and selected in the PodSpec, Overhead will be set to the value defined in the corresponding RuntimeClass, otherwise it will remain unset and treated as zero. More info: https://git.k8s.io/enhancements/keps/sig-node/688-pod-overhead/README.md",
|
||||
"type": "object"
|
||||
},
|
||||
"preemptionPolicy": {
|
||||
|
@ -2995,7 +2995,7 @@
|
||||
"$ref": "#/components/schemas/io.k8s.apimachinery.pkg.api.resource.Quantity",
|
||||
"default": {}
|
||||
},
|
||||
"description": "Overhead represents the resource overhead associated with running a pod for a given RuntimeClass. This field will be autopopulated at admission time by the RuntimeClass admission controller. If the RuntimeClass admission controller is enabled, overhead must not be set in Pod create requests. The RuntimeClass admission controller will reject Pod create requests which have the overhead already set. If RuntimeClass is configured and selected in the PodSpec, Overhead will be set to the value defined in the corresponding RuntimeClass, otherwise it will remain unset and treated as zero. More info: https://git.k8s.io/enhancements/keps/sig-node/688-pod-overhead/README.md This field is beta-level as of Kubernetes v1.18, and is only honored by servers that enable the PodOverhead feature.",
|
||||
"description": "Overhead represents the resource overhead associated with running a pod for a given RuntimeClass. This field will be autopopulated at admission time by the RuntimeClass admission controller. If the RuntimeClass admission controller is enabled, overhead must not be set in Pod create requests. The RuntimeClass admission controller will reject Pod create requests which have the overhead already set. If RuntimeClass is configured and selected in the PodSpec, Overhead will be set to the value defined in the corresponding RuntimeClass, otherwise it will remain unset and treated as zero. More info: https://git.k8s.io/enhancements/keps/sig-node/688-pod-overhead/README.md",
|
||||
"type": "object"
|
||||
},
|
||||
"preemptionPolicy": {
|
||||
|
@ -2221,7 +2221,7 @@
|
||||
"$ref": "#/components/schemas/io.k8s.apimachinery.pkg.api.resource.Quantity",
|
||||
"default": {}
|
||||
},
|
||||
"description": "Overhead represents the resource overhead associated with running a pod for a given RuntimeClass. This field will be autopopulated at admission time by the RuntimeClass admission controller. If the RuntimeClass admission controller is enabled, overhead must not be set in Pod create requests. The RuntimeClass admission controller will reject Pod create requests which have the overhead already set. If RuntimeClass is configured and selected in the PodSpec, Overhead will be set to the value defined in the corresponding RuntimeClass, otherwise it will remain unset and treated as zero. More info: https://git.k8s.io/enhancements/keps/sig-node/688-pod-overhead/README.md This field is beta-level as of Kubernetes v1.18, and is only honored by servers that enable the PodOverhead feature.",
|
||||
"description": "Overhead represents the resource overhead associated with running a pod for a given RuntimeClass. This field will be autopopulated at admission time by the RuntimeClass admission controller. If the RuntimeClass admission controller is enabled, overhead must not be set in Pod create requests. The RuntimeClass admission controller will reject Pod create requests which have the overhead already set. If RuntimeClass is configured and selected in the PodSpec, Overhead will be set to the value defined in the corresponding RuntimeClass, otherwise it will remain unset and treated as zero. More info: https://git.k8s.io/enhancements/keps/sig-node/688-pod-overhead/README.md",
|
||||
"type": "object"
|
||||
},
|
||||
"preemptionPolicy": {
|
||||
|
@ -2023,7 +2023,7 @@
|
||||
"$ref": "#/components/schemas/io.k8s.apimachinery.pkg.api.resource.Quantity",
|
||||
"default": {}
|
||||
},
|
||||
"description": "Overhead represents the resource overhead associated with running a pod for a given RuntimeClass. This field will be autopopulated at admission time by the RuntimeClass admission controller. If the RuntimeClass admission controller is enabled, overhead must not be set in Pod create requests. The RuntimeClass admission controller will reject Pod create requests which have the overhead already set. If RuntimeClass is configured and selected in the PodSpec, Overhead will be set to the value defined in the corresponding RuntimeClass, otherwise it will remain unset and treated as zero. More info: https://git.k8s.io/enhancements/keps/sig-node/688-pod-overhead/README.md This field is beta-level as of Kubernetes v1.18, and is only honored by servers that enable the PodOverhead feature.",
|
||||
"description": "Overhead represents the resource overhead associated with running a pod for a given RuntimeClass. This field will be autopopulated at admission time by the RuntimeClass admission controller. If the RuntimeClass admission controller is enabled, overhead must not be set in Pod create requests. The RuntimeClass admission controller will reject Pod create requests which have the overhead already set. If RuntimeClass is configured and selected in the PodSpec, Overhead will be set to the value defined in the corresponding RuntimeClass, otherwise it will remain unset and treated as zero. More info: https://git.k8s.io/enhancements/keps/sig-node/688-pod-overhead/README.md",
|
||||
"type": "object"
|
||||
},
|
||||
"preemptionPolicy": {
|
||||
|
@ -74,7 +74,7 @@
|
||||
},
|
||||
"overhead": {
|
||||
"$ref": "#/components/schemas/io.k8s.api.node.v1.Overhead",
|
||||
"description": "Overhead represents the resource overhead associated with running a pod for a given RuntimeClass. For more details, see\n https://kubernetes.io/docs/concepts/scheduling-eviction/pod-overhead/\nThis field is in beta starting v1.18 and is only honored by servers that enable the PodOverhead feature."
|
||||
"description": "Overhead represents the resource overhead associated with running a pod for a given RuntimeClass. For more details, see\n https://kubernetes.io/docs/concepts/scheduling-eviction/pod-overhead/"
|
||||
},
|
||||
"scheduling": {
|
||||
"$ref": "#/components/schemas/io.k8s.api.node.v1.Scheduling",
|
||||
|
@ -74,7 +74,7 @@
|
||||
},
|
||||
"overhead": {
|
||||
"$ref": "#/components/schemas/io.k8s.api.node.v1beta1.Overhead",
|
||||
"description": "Overhead represents the resource overhead associated with running a pod for a given RuntimeClass. For more details, see https://git.k8s.io/enhancements/keps/sig-node/688-pod-overhead/README.md This field is beta-level as of Kubernetes v1.18, and is only honored by servers that enable the PodOverhead feature."
|
||||
"description": "Overhead represents the resource overhead associated with running a pod for a given RuntimeClass. For more details, see https://git.k8s.io/enhancements/keps/sig-node/688-pod-overhead/README.md"
|
||||
},
|
||||
"scheduling": {
|
||||
"$ref": "#/components/schemas/io.k8s.api.node.v1beta1.Scheduling",
|
||||
|
@ -571,11 +571,6 @@ func dropDisabledFields(
|
||||
})
|
||||
}
|
||||
|
||||
if !utilfeature.DefaultFeatureGate.Enabled(features.PodOverhead) && !overheadInUse(oldPodSpec) {
|
||||
// Set Overhead to nil only if the feature is disabled and it is not used
|
||||
podSpec.Overhead = nil
|
||||
}
|
||||
|
||||
dropDisabledProcMountField(podSpec, oldPodSpec)
|
||||
|
||||
dropDisabledCSIVolumeSourceAlphaFields(podSpec, oldPodSpec)
|
||||
@ -659,17 +654,6 @@ func ephemeralContainersInUse(podSpec *api.PodSpec) bool {
|
||||
return len(podSpec.EphemeralContainers) > 0
|
||||
}
|
||||
|
||||
// overheadInUse returns true if the pod spec is non-nil and has Overhead set
|
||||
func overheadInUse(podSpec *api.PodSpec) bool {
|
||||
if podSpec == nil {
|
||||
return false
|
||||
}
|
||||
if podSpec.Overhead != nil {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// procMountInUse returns true if the pod spec is non-nil and has a SecurityContext's ProcMount field set to a non-default value
|
||||
func procMountInUse(podSpec *api.PodSpec) bool {
|
||||
if podSpec == nil {
|
||||
|
@ -71,7 +71,7 @@ func PodRequestsAndLimitsReuse(pod *v1.Pod, reuseReqs, reuseLimits v1.ResourceLi
|
||||
|
||||
// if PodOverhead feature is supported, add overhead for running a pod
|
||||
// to the sum of requests and to non-zero limits:
|
||||
if pod.Spec.Overhead != nil && utilfeature.DefaultFeatureGate.Enabled(features.PodOverhead) {
|
||||
if pod.Spec.Overhead != nil {
|
||||
addResourceList(reqs, pod.Spec.Overhead)
|
||||
|
||||
for name, quantity := range pod.Spec.Overhead {
|
||||
@ -152,7 +152,7 @@ func GetResourceRequestQuantity(pod *v1.Pod, resourceName v1.ResourceName) resou
|
||||
|
||||
// if PodOverhead feature is supported, add overhead for running a pod
|
||||
// to the total requests if the resource total is non-zero
|
||||
if pod.Spec.Overhead != nil && utilfeature.DefaultFeatureGate.Enabled(features.PodOverhead) {
|
||||
if pod.Spec.Overhead != nil {
|
||||
if podOverhead, ok := pod.Spec.Overhead[resourceName]; ok && !requestQuantity.IsZero() {
|
||||
requestQuantity.Add(podOverhead)
|
||||
}
|
||||
|
@ -2944,7 +2944,6 @@ type PodSpec struct {
|
||||
// set. If RuntimeClass is configured and selected in the PodSpec, Overhead will be set to the value
|
||||
// defined in the corresponding RuntimeClass, otherwise it will remain unset and treated as zero.
|
||||
// More info: https://git.k8s.io/enhancements/keps/sig-node/688-pod-overhead
|
||||
// This field is beta-level as of Kubernetes v1.18, and is only honored by servers that enable the PodOverhead feature.
|
||||
// +optional
|
||||
Overhead ResourceList
|
||||
// EnableServiceLinks indicates whether information about services should be injected into pod's
|
||||
|
@ -50,8 +50,6 @@ type RuntimeClass struct {
|
||||
// Overhead represents the resource overhead associated with running a pod for a
|
||||
// given RuntimeClass. For more details, see
|
||||
// https://git.k8s.io/enhancements/keps/sig-network/580-pod-readiness-gates
|
||||
// This field is beta-level as of Kubernetes v1.18, and is only honored by servers
|
||||
// that enable the PodOverhead feature.
|
||||
// +optional
|
||||
Overhead *Overhead
|
||||
|
||||
|
@ -391,6 +391,7 @@ const (
|
||||
// owner: @egernst
|
||||
// alpha: v1.16
|
||||
// beta: v1.18
|
||||
// ga: v1.24
|
||||
//
|
||||
// Enables PodOverhead, for accounting pod overheads which are specific to a given RuntimeClass
|
||||
PodOverhead featuregate.Feature = "PodOverhead"
|
||||
@ -893,7 +894,7 @@ var defaultKubernetesFeatureGates = map[featuregate.Feature]featuregate.FeatureS
|
||||
KubeletPodResources: {Default: true, PreRelease: featuregate.Beta},
|
||||
LocalStorageCapacityIsolationFSQuotaMonitoring: {Default: false, PreRelease: featuregate.Alpha},
|
||||
NonPreemptingPriority: {Default: true, PreRelease: featuregate.GA, LockToDefault: true}, // remove in 1.25
|
||||
PodOverhead: {Default: true, PreRelease: featuregate.Beta},
|
||||
PodOverhead: {Default: true, PreRelease: featuregate.GA, LockToDefault: true}, // remove in 1.26
|
||||
IPv6DualStack: {Default: true, PreRelease: featuregate.GA, LockToDefault: true}, // remove in 1.25
|
||||
EndpointSlice: {Default: true, PreRelease: featuregate.GA, LockToDefault: true}, // remove in 1.25
|
||||
EndpointSliceProxying: {Default: true, PreRelease: featuregate.GA, LockToDefault: true}, // remove in 1.25
|
||||
|
8
pkg/generated/openapi/zz_generated.openapi.go
generated
8
pkg/generated/openapi/zz_generated.openapi.go
generated
@ -22082,7 +22082,7 @@ func schema_k8sio_api_core_v1_PodSpec(ref common.ReferenceCallback) common.OpenA
|
||||
},
|
||||
"overhead": {
|
||||
SchemaProps: spec.SchemaProps{
|
||||
Description: "Overhead represents the resource overhead associated with running a pod for a given RuntimeClass. This field will be autopopulated at admission time by the RuntimeClass admission controller. If the RuntimeClass admission controller is enabled, overhead must not be set in Pod create requests. The RuntimeClass admission controller will reject Pod create requests which have the overhead already set. If RuntimeClass is configured and selected in the PodSpec, Overhead will be set to the value defined in the corresponding RuntimeClass, otherwise it will remain unset and treated as zero. More info: https://git.k8s.io/enhancements/keps/sig-node/688-pod-overhead/README.md This field is beta-level as of Kubernetes v1.18, and is only honored by servers that enable the PodOverhead feature.",
|
||||
Description: "Overhead represents the resource overhead associated with running a pod for a given RuntimeClass. This field will be autopopulated at admission time by the RuntimeClass admission controller. If the RuntimeClass admission controller is enabled, overhead must not be set in Pod create requests. The RuntimeClass admission controller will reject Pod create requests which have the overhead already set. If RuntimeClass is configured and selected in the PodSpec, Overhead will be set to the value defined in the corresponding RuntimeClass, otherwise it will remain unset and treated as zero. More info: https://git.k8s.io/enhancements/keps/sig-node/688-pod-overhead/README.md",
|
||||
Type: []string{"object"},
|
||||
AdditionalProperties: &spec.SchemaOrBool{
|
||||
Allows: true,
|
||||
@ -34565,7 +34565,7 @@ func schema_k8sio_api_node_v1_RuntimeClass(ref common.ReferenceCallback) common.
|
||||
},
|
||||
"overhead": {
|
||||
SchemaProps: spec.SchemaProps{
|
||||
Description: "Overhead represents the resource overhead associated with running a pod for a given RuntimeClass. For more details, see\n https://kubernetes.io/docs/concepts/scheduling-eviction/pod-overhead/\nThis field is in beta starting v1.18 and is only honored by servers that enable the PodOverhead feature.",
|
||||
Description: "Overhead represents the resource overhead associated with running a pod for a given RuntimeClass. For more details, see\n https://kubernetes.io/docs/concepts/scheduling-eviction/pod-overhead/",
|
||||
Ref: ref("k8s.io/api/node/v1.Overhead"),
|
||||
},
|
||||
},
|
||||
@ -34832,7 +34832,7 @@ func schema_k8sio_api_node_v1alpha1_RuntimeClassSpec(ref common.ReferenceCallbac
|
||||
},
|
||||
"overhead": {
|
||||
SchemaProps: spec.SchemaProps{
|
||||
Description: "Overhead represents the resource overhead associated with running a pod for a given RuntimeClass. For more details, see https://git.k8s.io/enhancements/keps/sig-node/688-pod-overhead/README.md This field is beta-level as of Kubernetes v1.18, and is only honored by servers that enable the PodOverhead feature.",
|
||||
Description: "Overhead represents the resource overhead associated with running a pod for a given RuntimeClass. For more details, see https://git.k8s.io/enhancements/keps/sig-node/688-pod-overhead/README.md",
|
||||
Ref: ref("k8s.io/api/node/v1alpha1.Overhead"),
|
||||
},
|
||||
},
|
||||
@ -34974,7 +34974,7 @@ func schema_k8sio_api_node_v1beta1_RuntimeClass(ref common.ReferenceCallback) co
|
||||
},
|
||||
"overhead": {
|
||||
SchemaProps: spec.SchemaProps{
|
||||
Description: "Overhead represents the resource overhead associated with running a pod for a given RuntimeClass. For more details, see https://git.k8s.io/enhancements/keps/sig-node/688-pod-overhead/README.md This field is beta-level as of Kubernetes v1.18, and is only honored by servers that enable the PodOverhead feature.",
|
||||
Description: "Overhead represents the resource overhead associated with running a pod for a given RuntimeClass. For more details, see https://git.k8s.io/enhancements/keps/sig-node/688-pod-overhead/README.md",
|
||||
Ref: ref("k8s.io/api/node/v1beta1.Overhead"),
|
||||
},
|
||||
},
|
||||
|
@ -21,15 +21,13 @@ package kuberuntime
|
||||
|
||||
import (
|
||||
v1 "k8s.io/api/core/v1"
|
||||
utilfeature "k8s.io/apiserver/pkg/util/feature"
|
||||
runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1"
|
||||
resourcehelper "k8s.io/kubernetes/pkg/api/v1/resource"
|
||||
"k8s.io/kubernetes/pkg/features"
|
||||
)
|
||||
|
||||
func (m *kubeGenericRuntimeManager) convertOverheadToLinuxResources(pod *v1.Pod) *runtimeapi.LinuxContainerResources {
|
||||
resources := &runtimeapi.LinuxContainerResources{}
|
||||
if pod.Spec.Overhead != nil && utilfeature.DefaultFeatureGate.Enabled(features.PodOverhead) {
|
||||
if pod.Spec.Overhead != nil {
|
||||
cpu := pod.Spec.Overhead.Cpu()
|
||||
memory := pod.Spec.Overhead.Memory()
|
||||
|
||||
|
@ -30,12 +30,10 @@ import (
|
||||
"k8s.io/apiserver/pkg/admission"
|
||||
quota "k8s.io/apiserver/pkg/quota/v1"
|
||||
"k8s.io/apiserver/pkg/quota/v1/generic"
|
||||
"k8s.io/apiserver/pkg/util/feature"
|
||||
api "k8s.io/kubernetes/pkg/apis/core"
|
||||
k8s_api_v1 "k8s.io/kubernetes/pkg/apis/core/v1"
|
||||
"k8s.io/kubernetes/pkg/apis/core/v1/helper"
|
||||
"k8s.io/kubernetes/pkg/apis/core/v1/helper/qos"
|
||||
"k8s.io/kubernetes/pkg/features"
|
||||
"k8s.io/utils/clock"
|
||||
)
|
||||
|
||||
@ -369,10 +367,9 @@ func PodUsageFunc(obj runtime.Object, clock clock.Clock) (corev1.ResourceList, e
|
||||
limits = quota.Max(limits, pod.Spec.InitContainers[i].Resources.Limits)
|
||||
}
|
||||
|
||||
if feature.DefaultFeatureGate.Enabled(features.PodOverhead) {
|
||||
requests = quota.Add(requests, pod.Spec.Overhead)
|
||||
limits = quota.Add(limits, pod.Spec.Overhead)
|
||||
}
|
||||
requests = quota.Add(requests, pod.Spec.Overhead)
|
||||
limits = quota.Add(limits, pod.Spec.Overhead)
|
||||
|
||||
result = quota.Add(result, podComputeUsageHelper(requests, limits))
|
||||
return result, nil
|
||||
}
|
||||
|
@ -27,10 +27,7 @@ import (
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
quota "k8s.io/apiserver/pkg/quota/v1"
|
||||
"k8s.io/apiserver/pkg/quota/v1/generic"
|
||||
"k8s.io/apiserver/pkg/util/feature"
|
||||
featuregatetesting "k8s.io/component-base/featuregate/testing"
|
||||
api "k8s.io/kubernetes/pkg/apis/core"
|
||||
"k8s.io/kubernetes/pkg/features"
|
||||
"k8s.io/kubernetes/pkg/util/node"
|
||||
"k8s.io/utils/clock"
|
||||
testingclock "k8s.io/utils/clock/testing"
|
||||
@ -154,9 +151,8 @@ func TestPodEvaluatorUsage(t *testing.T) {
|
||||
deletionTimestampNotPastGracePeriod := metav1.NewTime(fakeClock.Now())
|
||||
|
||||
testCases := map[string]struct {
|
||||
pod *api.Pod
|
||||
usage corev1.ResourceList
|
||||
podOverheadEnabled bool
|
||||
pod *api.Pod
|
||||
usage corev1.ResourceList
|
||||
}{
|
||||
"init container CPU": {
|
||||
pod: &api.Pod{
|
||||
@ -525,41 +521,11 @@ func TestPodEvaluatorUsage(t *testing.T) {
|
||||
corev1.ResourceCPU: resource.MustParse("2"),
|
||||
generic.ObjectCountQuotaResourceNameFor(schema.GroupResource{Resource: "pods"}): resource.MustParse("1"),
|
||||
},
|
||||
podOverheadEnabled: true,
|
||||
},
|
||||
"do not count pod overhead as usage with pod overhead disabled": {
|
||||
pod: &api.Pod{
|
||||
Spec: api.PodSpec{
|
||||
Overhead: api.ResourceList{
|
||||
api.ResourceCPU: resource.MustParse("1"),
|
||||
},
|
||||
Containers: []api.Container{
|
||||
{
|
||||
Resources: api.ResourceRequirements{
|
||||
Requests: api.ResourceList{
|
||||
api.ResourceCPU: resource.MustParse("1"),
|
||||
},
|
||||
Limits: api.ResourceList{
|
||||
api.ResourceCPU: resource.MustParse("2"),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
usage: corev1.ResourceList{
|
||||
corev1.ResourceRequestsCPU: resource.MustParse("1"),
|
||||
corev1.ResourceLimitsCPU: resource.MustParse("2"),
|
||||
corev1.ResourcePods: resource.MustParse("1"),
|
||||
corev1.ResourceCPU: resource.MustParse("1"),
|
||||
generic.ObjectCountQuotaResourceNameFor(schema.GroupResource{Resource: "pods"}): resource.MustParse("1"),
|
||||
},
|
||||
podOverheadEnabled: false,
|
||||
},
|
||||
}
|
||||
t.Parallel()
|
||||
for testName, testCase := range testCases {
|
||||
t.Run(testName, func(t *testing.T) {
|
||||
defer featuregatetesting.SetFeatureGateDuringTest(t, feature.DefaultFeatureGate, features.PodOverhead, testCase.podOverheadEnabled)()
|
||||
actual, err := evaluator.Usage(testCase.pod)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
|
@ -23,11 +23,9 @@ import (
|
||||
"k8s.io/apimachinery/pkg/util/validation/field"
|
||||
"k8s.io/apiserver/pkg/registry/rest"
|
||||
"k8s.io/apiserver/pkg/storage/names"
|
||||
utilfeature "k8s.io/apiserver/pkg/util/feature"
|
||||
"k8s.io/kubernetes/pkg/api/legacyscheme"
|
||||
"k8s.io/kubernetes/pkg/apis/node"
|
||||
"k8s.io/kubernetes/pkg/apis/node/validation"
|
||||
"k8s.io/kubernetes/pkg/features"
|
||||
)
|
||||
|
||||
// strategy implements verification logic for RuntimeClass.
|
||||
@ -58,12 +56,6 @@ func (strategy) AllowCreateOnUpdate() bool {
|
||||
// PrepareForCreate clears fields that are not allowed to be set by end users
|
||||
// on creation.
|
||||
func (strategy) PrepareForCreate(ctx context.Context, obj runtime.Object) {
|
||||
rc := obj.(*node.RuntimeClass)
|
||||
|
||||
if !utilfeature.DefaultFeatureGate.Enabled(features.PodOverhead) && rc != nil {
|
||||
// Set Overhead to nil only if the feature is disabled and it is not used
|
||||
rc.Overhead = nil
|
||||
}
|
||||
}
|
||||
|
||||
// PrepareForUpdate clears fields that are not allowed to be set by end users on update.
|
||||
|
@ -25,14 +25,12 @@ import (
|
||||
storagev1 "k8s.io/api/storage/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
|
||||
"k8s.io/apiserver/pkg/util/feature"
|
||||
"k8s.io/client-go/dynamic/dynamicinformer"
|
||||
"k8s.io/client-go/informers"
|
||||
"k8s.io/client-go/tools/cache"
|
||||
corev1helpers "k8s.io/component-helpers/scheduling/corev1"
|
||||
corev1nodeaffinity "k8s.io/component-helpers/scheduling/corev1/nodeaffinity"
|
||||
"k8s.io/klog/v2"
|
||||
"k8s.io/kubernetes/pkg/features"
|
||||
"k8s.io/kubernetes/pkg/scheduler/framework"
|
||||
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/nodeaffinity"
|
||||
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/nodename"
|
||||
@ -491,7 +489,7 @@ func preCheckForNode(nodeInfo *framework.NodeInfo) queue.PreEnqueueCheck {
|
||||
// returns all failures.
|
||||
func AdmissionCheck(pod *v1.Pod, nodeInfo *framework.NodeInfo, includeAllFailures bool) []AdmissionResult {
|
||||
var admissionResults []AdmissionResult
|
||||
insufficientResources := noderesources.Fits(pod, nodeInfo, feature.DefaultFeatureGate.Enabled(features.PodOverhead))
|
||||
insufficientResources := noderesources.Fits(pod, nodeInfo)
|
||||
if len(insufficientResources) != 0 {
|
||||
for i := range insufficientResources {
|
||||
admissionResults = append(admissionResults, AdmissionResult{InsufficientResource: &insufficientResources[i]})
|
||||
|
@ -37,9 +37,6 @@ import (
|
||||
"k8s.io/client-go/informers"
|
||||
"k8s.io/client-go/kubernetes/fake"
|
||||
|
||||
"k8s.io/apiserver/pkg/util/feature"
|
||||
featuregatetesting "k8s.io/component-base/featuregate/testing"
|
||||
"k8s.io/kubernetes/pkg/features"
|
||||
"k8s.io/kubernetes/pkg/scheduler/framework"
|
||||
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/nodeaffinity"
|
||||
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/nodename"
|
||||
@ -506,7 +503,6 @@ func TestAdmissionCheck(t *testing.T) {
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
defer featuregatetesting.SetFeatureGateDuringTest(t, feature.DefaultFeatureGate, features.PodOverhead, true)()
|
||||
nodeInfo := framework.NewNodeInfo(tt.existingPods...)
|
||||
nodeInfo.SetNode(tt.node)
|
||||
|
||||
|
@ -22,7 +22,6 @@ package feature
|
||||
type Features struct {
|
||||
EnablePodAffinityNamespaceSelector bool
|
||||
EnablePodDisruptionBudget bool
|
||||
EnablePodOverhead bool
|
||||
EnableReadWriteOncePod bool
|
||||
EnableVolumeCapacityPriority bool
|
||||
EnableCSIStorageCapacity bool
|
||||
|
@ -91,7 +91,6 @@ func NewBalancedAllocation(baArgs runtime.Object, h framework.Handle, fts featur
|
||||
scorer: balancedResourceScorer,
|
||||
useRequested: true,
|
||||
resourceToWeightMap: resToWeightMap,
|
||||
enablePodOverhead: fts.EnablePodOverhead,
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
@ -376,7 +376,7 @@ func TestNodeResourcesBalancedAllocation(t *testing.T) {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
snapshot := cache.NewSnapshot(test.pods, test.nodes)
|
||||
fh, _ := runtime.NewFramework(nil, nil, runtime.WithSnapshotSharedLister(snapshot))
|
||||
p, _ := NewBalancedAllocation(&test.args, fh, feature.Features{EnablePodOverhead: true})
|
||||
p, _ := NewBalancedAllocation(&test.args, fh, feature.Features{})
|
||||
for i := range test.nodes {
|
||||
hostResult, err := p.(framework.ScorePlugin).Score(context.Background(), nil, test.pod, test.nodes[i].Name)
|
||||
if err != nil {
|
||||
|
@ -78,7 +78,6 @@ var nodeResourceStrategyTypeMap = map[config.ScoringStrategyType]scorer{
|
||||
type Fit struct {
|
||||
ignoredResources sets.String
|
||||
ignoredResourceGroups sets.String
|
||||
enablePodOverhead bool
|
||||
handle framework.Handle
|
||||
resourceAllocationScorer
|
||||
}
|
||||
@ -126,7 +125,6 @@ func NewFit(plArgs runtime.Object, h framework.Handle, fts feature.Features) (fr
|
||||
return &Fit{
|
||||
ignoredResources: sets.NewString(args.IgnoredResources...),
|
||||
ignoredResourceGroups: sets.NewString(args.IgnoredResourceGroups...),
|
||||
enablePodOverhead: fts.EnablePodOverhead,
|
||||
handle: h,
|
||||
resourceAllocationScorer: *scorePlugin(args),
|
||||
}, nil
|
||||
@ -137,8 +135,7 @@ func NewFit(plArgs runtime.Object, h framework.Handle, fts feature.Features) (fr
|
||||
// the max in each dimension iteratively. In contrast, we sum the resource vectors for
|
||||
// regular containers since they run simultaneously.
|
||||
//
|
||||
// If Pod Overhead is specified and the feature gate is set, the resources defined for Overhead
|
||||
// are added to the calculated Resource request sum
|
||||
// The resources defined for Overhead should be added to the calculated Resource request sum
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
@ -159,7 +156,7 @@ func NewFit(plArgs runtime.Object, h framework.Handle, fts feature.Features) (fr
|
||||
// Memory: 1G
|
||||
//
|
||||
// Result: CPU: 3, Memory: 3G
|
||||
func computePodResourceRequest(pod *v1.Pod, enablePodOverhead bool) *preFilterState {
|
||||
func computePodResourceRequest(pod *v1.Pod) *preFilterState {
|
||||
result := &preFilterState{}
|
||||
for _, container := range pod.Spec.Containers {
|
||||
result.Add(container.Resources.Requests)
|
||||
@ -171,7 +168,7 @@ func computePodResourceRequest(pod *v1.Pod, enablePodOverhead bool) *preFilterSt
|
||||
}
|
||||
|
||||
// If Overhead is being utilized, add to the total requests for the pod
|
||||
if pod.Spec.Overhead != nil && enablePodOverhead {
|
||||
if pod.Spec.Overhead != nil {
|
||||
result.Add(pod.Spec.Overhead)
|
||||
}
|
||||
return result
|
||||
@ -179,7 +176,7 @@ func computePodResourceRequest(pod *v1.Pod, enablePodOverhead bool) *preFilterSt
|
||||
|
||||
// PreFilter invoked at the prefilter extension point.
|
||||
func (f *Fit) PreFilter(ctx context.Context, cycleState *framework.CycleState, pod *v1.Pod) (*framework.PreFilterResult, *framework.Status) {
|
||||
cycleState.Write(preFilterStateKey, computePodResourceRequest(pod, f.enablePodOverhead))
|
||||
cycleState.Write(preFilterStateKey, computePodResourceRequest(pod))
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
@ -248,8 +245,8 @@ type InsufficientResource struct {
|
||||
}
|
||||
|
||||
// Fits checks if node have enough resources to host the pod.
|
||||
func Fits(pod *v1.Pod, nodeInfo *framework.NodeInfo, enablePodOverhead bool) []InsufficientResource {
|
||||
return fitsRequest(computePodResourceRequest(pod, enablePodOverhead), nodeInfo, nil, nil)
|
||||
func Fits(pod *v1.Pod, nodeInfo *framework.NodeInfo) []InsufficientResource {
|
||||
return fitsRequest(computePodResourceRequest(pod), nodeInfo, nil, nil)
|
||||
}
|
||||
|
||||
func fitsRequest(podRequest *preFilterState, nodeInfo *framework.NodeInfo, ignoredExtendedResources, ignoredResourceGroups sets.String) []InsufficientResource {
|
||||
|
@ -472,7 +472,7 @@ func TestEnoughRequests(t *testing.T) {
|
||||
test.args.ScoringStrategy = defaultScoringStrategy
|
||||
}
|
||||
|
||||
p, err := NewFit(&test.args, nil, plfeature.Features{EnablePodOverhead: true})
|
||||
p, err := NewFit(&test.args, nil, plfeature.Features{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -487,7 +487,7 @@ func TestEnoughRequests(t *testing.T) {
|
||||
t.Errorf("status does not match: %v, want: %v", gotStatus, test.wantStatus)
|
||||
}
|
||||
|
||||
gotInsufficientResources := fitsRequest(computePodResourceRequest(test.pod, true), test.nodeInfo, p.(*Fit).ignoredResources, p.(*Fit).ignoredResourceGroups)
|
||||
gotInsufficientResources := fitsRequest(computePodResourceRequest(test.pod), test.nodeInfo, p.(*Fit).ignoredResources, p.(*Fit).ignoredResourceGroups)
|
||||
if !reflect.DeepEqual(gotInsufficientResources, test.wantInsufficientResources) {
|
||||
t.Errorf("insufficient resources do not match: %+v, want: %v", gotInsufficientResources, test.wantInsufficientResources)
|
||||
}
|
||||
@ -500,7 +500,7 @@ func TestPreFilterDisabled(t *testing.T) {
|
||||
nodeInfo := framework.NewNodeInfo()
|
||||
node := v1.Node{}
|
||||
nodeInfo.SetNode(&node)
|
||||
p, err := NewFit(&config.NodeResourcesFitArgs{ScoringStrategy: defaultScoringStrategy}, nil, plfeature.Features{EnablePodOverhead: true})
|
||||
p, err := NewFit(&config.NodeResourcesFitArgs{ScoringStrategy: defaultScoringStrategy}, nil, plfeature.Features{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -550,7 +550,7 @@ func TestNotEnoughRequests(t *testing.T) {
|
||||
node := v1.Node{Status: v1.NodeStatus{Capacity: v1.ResourceList{}, Allocatable: makeAllocatableResources(10, 20, 1, 0, 0, 0)}}
|
||||
test.nodeInfo.SetNode(&node)
|
||||
|
||||
p, err := NewFit(&config.NodeResourcesFitArgs{ScoringStrategy: defaultScoringStrategy}, nil, plfeature.Features{EnablePodOverhead: true})
|
||||
p, err := NewFit(&config.NodeResourcesFitArgs{ScoringStrategy: defaultScoringStrategy}, nil, plfeature.Features{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -622,7 +622,7 @@ func TestStorageRequests(t *testing.T) {
|
||||
node := v1.Node{Status: v1.NodeStatus{Capacity: makeResources(10, 20, 32, 5, 20, 5).Capacity, Allocatable: makeAllocatableResources(10, 20, 32, 5, 20, 5)}}
|
||||
test.nodeInfo.SetNode(&node)
|
||||
|
||||
p, err := NewFit(&config.NodeResourcesFitArgs{ScoringStrategy: defaultScoringStrategy}, nil, plfeature.Features{EnablePodOverhead: true})
|
||||
p, err := NewFit(&config.NodeResourcesFitArgs{ScoringStrategy: defaultScoringStrategy}, nil, plfeature.Features{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -759,7 +759,7 @@ func TestFitScore(t *testing.T) {
|
||||
snapshot := cache.NewSnapshot(test.existingPods, test.nodes)
|
||||
fh, _ := runtime.NewFramework(nil, nil, runtime.WithSnapshotSharedLister(snapshot))
|
||||
args := test.nodeResourcesFitArgs
|
||||
p, err := NewFit(&args, fh, plfeature.Features{EnablePodOverhead: true})
|
||||
p, err := NewFit(&args, fh, plfeature.Features{})
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
|
@ -384,7 +384,7 @@ func TestLeastAllocatedScoringStrategy(t *testing.T) {
|
||||
Type: config.LeastAllocated,
|
||||
Resources: test.resources,
|
||||
},
|
||||
}, fh, plfeature.Features{EnablePodOverhead: true})
|
||||
}, fh, plfeature.Features{})
|
||||
|
||||
if diff := cmp.Diff(test.wantErrs.ToAggregate(), err, ignoreBadValueDetail); diff != "" {
|
||||
t.Fatalf("got err (-want,+got):\n%s", diff)
|
||||
|
@ -340,7 +340,7 @@ func TestMostAllocatedScoringStrategy(t *testing.T) {
|
||||
Type: config.MostAllocated,
|
||||
Resources: test.resources,
|
||||
},
|
||||
}, fh, plfeature.Features{EnablePodOverhead: true})
|
||||
}, fh, plfeature.Features{})
|
||||
|
||||
if diff := cmp.Diff(test.wantErrs.ToAggregate(), err, ignoreBadValueDetail); diff != "" {
|
||||
t.Fatalf("got err (-want,+got):\n%s", diff)
|
||||
|
@ -121,7 +121,7 @@ func TestRequestedToCapacityRatioScoringStrategy(t *testing.T) {
|
||||
Shape: shape,
|
||||
},
|
||||
},
|
||||
}, fh, plfeature.Features{EnablePodOverhead: true})
|
||||
}, fh, plfeature.Features{})
|
||||
|
||||
if diff := cmp.Diff(test.wantErrs.ToAggregate(), err, ignoreBadValueDetail); diff != "" {
|
||||
t.Fatalf("got err (-want,+got):\n%s", diff)
|
||||
@ -340,7 +340,7 @@ func TestResourceBinPackingSingleExtended(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
p, err := NewFit(&args, fh, feature.Features{EnablePodOverhead: true})
|
||||
p, err := NewFit(&args, fh, feature.Features{})
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
@ -588,7 +588,7 @@ func TestResourceBinPackingMultipleExtended(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
p, err := NewFit(&args, fh, feature.Features{EnablePodOverhead: true})
|
||||
p, err := NewFit(&args, fh, feature.Features{})
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
|
@ -38,8 +38,6 @@ type resourceAllocationScorer struct {
|
||||
useRequested bool
|
||||
scorer func(requested, allocable resourceToValueMap) int64
|
||||
resourceToWeightMap resourceToWeightMap
|
||||
|
||||
enablePodOverhead bool
|
||||
}
|
||||
|
||||
// resourceToValueMap is keyed with resource name and valued with quantity.
|
||||
@ -129,7 +127,7 @@ func (r *resourceAllocationScorer) calculatePodResourceRequest(pod *v1.Pod, reso
|
||||
}
|
||||
|
||||
// If Overhead is being utilized, add to the total requests for the pod
|
||||
if pod.Spec.Overhead != nil && r.enablePodOverhead {
|
||||
if pod.Spec.Overhead != nil {
|
||||
if quantity, found := pod.Spec.Overhead[resource]; found {
|
||||
podRequest += quantity.Value()
|
||||
}
|
||||
|
@ -46,7 +46,6 @@ import (
|
||||
func NewInTreeRegistry() runtime.Registry {
|
||||
fts := plfeature.Features{
|
||||
EnablePodDisruptionBudget: feature.DefaultFeatureGate.Enabled(features.PodDisruptionBudget),
|
||||
EnablePodOverhead: feature.DefaultFeatureGate.Enabled(features.PodOverhead),
|
||||
EnableReadWriteOncePod: feature.DefaultFeatureGate.Enabled(features.ReadWriteOncePod),
|
||||
EnableVolumeCapacityPriority: feature.DefaultFeatureGate.Enabled(features.VolumeCapacityPriority),
|
||||
EnableCSIStorageCapacity: feature.DefaultFeatureGate.Enabled(features.CSIStorageCapacity),
|
||||
|
@ -736,7 +736,7 @@ func calculateResource(pod *v1.Pod) (res Resource, non0CPU int64, non0Mem int64)
|
||||
}
|
||||
|
||||
// If Overhead is being utilized, add to the total requests for the pod
|
||||
if pod.Spec.Overhead != nil && utilfeature.DefaultFeatureGate.Enabled(features.PodOverhead) {
|
||||
if pod.Spec.Overhead != nil {
|
||||
resPtr.Add(pod.Spec.Overhead)
|
||||
if _, found := pod.Spec.Overhead[v1.ResourceCPU]; found {
|
||||
non0CPU += pod.Spec.Overhead.Cpu().MilliValue()
|
||||
|
@ -36,11 +36,9 @@ import (
|
||||
"k8s.io/client-go/kubernetes"
|
||||
nodev1client "k8s.io/client-go/kubernetes/typed/node/v1"
|
||||
nodev1listers "k8s.io/client-go/listers/node/v1"
|
||||
"k8s.io/component-base/featuregate"
|
||||
api "k8s.io/kubernetes/pkg/apis/core"
|
||||
node "k8s.io/kubernetes/pkg/apis/node"
|
||||
apinodev1 "k8s.io/kubernetes/pkg/apis/node/v1"
|
||||
"k8s.io/kubernetes/pkg/features"
|
||||
"k8s.io/kubernetes/pkg/util/tolerations"
|
||||
)
|
||||
|
||||
@ -62,9 +60,6 @@ type RuntimeClass struct {
|
||||
*admission.Handler
|
||||
runtimeClassLister nodev1listers.RuntimeClassLister
|
||||
runtimeClassClient nodev1client.RuntimeClassInterface
|
||||
|
||||
inspectedFeatures bool
|
||||
podOverheadEnabled bool
|
||||
}
|
||||
|
||||
var _ admission.MutationInterface = &RuntimeClass{}
|
||||
@ -78,12 +73,6 @@ func (r *RuntimeClass) SetExternalKubeClientSet(client kubernetes.Interface) {
|
||||
r.runtimeClassClient = client.NodeV1().RuntimeClasses()
|
||||
}
|
||||
|
||||
// InspectFeatureGates allows setting bools without taking a dep on a global variable
|
||||
func (r *RuntimeClass) InspectFeatureGates(featureGates featuregate.FeatureGate) {
|
||||
r.podOverheadEnabled = featureGates.Enabled(features.PodOverhead)
|
||||
r.inspectedFeatures = true
|
||||
}
|
||||
|
||||
// SetExternalKubeInformerFactory implements the WantsExternalKubeInformerFactory interface.
|
||||
func (r *RuntimeClass) SetExternalKubeInformerFactory(f informers.SharedInformerFactory) {
|
||||
runtimeClassInformer := f.Node().V1().RuntimeClasses()
|
||||
@ -93,9 +82,6 @@ func (r *RuntimeClass) SetExternalKubeInformerFactory(f informers.SharedInformer
|
||||
|
||||
// ValidateInitialization implements the WantsExternalKubeInformerFactory interface.
|
||||
func (r *RuntimeClass) ValidateInitialization() error {
|
||||
if !r.inspectedFeatures {
|
||||
return fmt.Errorf("InspectFeatureGates was not called")
|
||||
}
|
||||
if r.runtimeClassLister == nil {
|
||||
return fmt.Errorf("missing RuntimeClass lister")
|
||||
}
|
||||
@ -116,10 +102,8 @@ func (r *RuntimeClass) Admit(ctx context.Context, attributes admission.Attribute
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if r.podOverheadEnabled {
|
||||
if err := setOverhead(attributes, pod, runtimeClass); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := setOverhead(attributes, pod, runtimeClass); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := setScheduling(attributes, pod, runtimeClass); err != nil {
|
||||
@ -140,10 +124,8 @@ func (r *RuntimeClass) Validate(ctx context.Context, attributes admission.Attrib
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if r.podOverheadEnabled {
|
||||
if err := validateOverhead(attributes, pod, runtimeClass); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := validateOverhead(attributes, pod, runtimeClass); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -31,10 +31,8 @@ import (
|
||||
"k8s.io/client-go/informers"
|
||||
"k8s.io/client-go/kubernetes"
|
||||
"k8s.io/client-go/kubernetes/fake"
|
||||
"k8s.io/component-base/featuregate"
|
||||
"k8s.io/kubernetes/pkg/apis/core"
|
||||
"k8s.io/kubernetes/pkg/controller"
|
||||
"k8s.io/kubernetes/pkg/features"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
@ -321,22 +319,12 @@ func NewObjectInterfacesForTest() admission.ObjectInterfaces {
|
||||
}
|
||||
|
||||
func newRuntimeClassForTest(
|
||||
featureInspection bool,
|
||||
addLister bool,
|
||||
listerObject *nodev1.RuntimeClass,
|
||||
addClient bool,
|
||||
clientObject *nodev1.RuntimeClass) *RuntimeClass {
|
||||
runtimeClass := NewRuntimeClass()
|
||||
|
||||
if featureInspection {
|
||||
relevantFeatures := map[featuregate.Feature]featuregate.FeatureSpec{
|
||||
features.PodOverhead: {Default: false},
|
||||
}
|
||||
fg := featuregate.NewFeatureGate()
|
||||
fg.Add(relevantFeatures)
|
||||
runtimeClass.InspectFeatureGates(fg)
|
||||
}
|
||||
|
||||
if addLister {
|
||||
informerFactory := informers.NewSharedInformerFactory(nil, controller.NoResyncPeriodFunc())
|
||||
runtimeClass.SetExternalKubeInformerFactory(informerFactory)
|
||||
@ -367,22 +355,17 @@ func TestValidateInitialization(t *testing.T) {
|
||||
{
|
||||
name: "runtimeClass enabled, success",
|
||||
expectError: false,
|
||||
runtimeClass: newRuntimeClassForTest(true, true, nil, true, nil),
|
||||
},
|
||||
{
|
||||
name: "runtimeClass enabled, no feature inspection",
|
||||
expectError: true,
|
||||
runtimeClass: newRuntimeClassForTest(false, true, nil, true, nil),
|
||||
runtimeClass: newRuntimeClassForTest(true, nil, true, nil),
|
||||
},
|
||||
{
|
||||
name: "runtimeClass enabled, no lister",
|
||||
expectError: true,
|
||||
runtimeClass: newRuntimeClassForTest(true, false, nil, true, nil),
|
||||
runtimeClass: newRuntimeClassForTest(false, nil, true, nil),
|
||||
},
|
||||
{
|
||||
name: "runtimeClass enabled, no client",
|
||||
expectError: true,
|
||||
runtimeClass: newRuntimeClassForTest(true, true, nil, false, nil),
|
||||
runtimeClass: newRuntimeClassForTest(true, nil, false, nil),
|
||||
},
|
||||
}
|
||||
|
||||
@ -432,17 +415,17 @@ func TestAdmit(t *testing.T) {
|
||||
{
|
||||
name: "runtimeClass found by lister",
|
||||
expectError: false,
|
||||
runtimeClass: newRuntimeClassForTest(true, true, rc, true, nil),
|
||||
runtimeClass: newRuntimeClassForTest(true, rc, true, nil),
|
||||
},
|
||||
{
|
||||
name: "runtimeClass found by client",
|
||||
expectError: false,
|
||||
runtimeClass: newRuntimeClassForTest(true, true, nil, true, rc),
|
||||
runtimeClass: newRuntimeClassForTest(true, nil, true, rc),
|
||||
},
|
||||
{
|
||||
name: "runtimeClass not found by lister nor client",
|
||||
expectError: true,
|
||||
runtimeClass: newRuntimeClassForTest(true, true, nil, true, nil),
|
||||
runtimeClass: newRuntimeClassForTest(true, nil, true, nil),
|
||||
},
|
||||
}
|
||||
|
||||
@ -506,7 +489,6 @@ func TestValidate(t *testing.T) {
|
||||
},
|
||||
}
|
||||
rt := NewRuntimeClass()
|
||||
rt.podOverheadEnabled = true
|
||||
o := NewObjectInterfacesForTest()
|
||||
for _, tc := range tests {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
|
@ -3670,7 +3670,6 @@ message PodSpec {
|
||||
// set. If RuntimeClass is configured and selected in the PodSpec, Overhead will be set to the value
|
||||
// defined in the corresponding RuntimeClass, otherwise it will remain unset and treated as zero.
|
||||
// More info: https://git.k8s.io/enhancements/keps/sig-node/688-pod-overhead/README.md
|
||||
// This field is beta-level as of Kubernetes v1.18, and is only honored by servers that enable the PodOverhead feature.
|
||||
// +optional
|
||||
map<string, k8s.io.apimachinery.pkg.api.resource.Quantity> overhead = 32;
|
||||
|
||||
|
@ -3252,7 +3252,6 @@ type PodSpec struct {
|
||||
// set. If RuntimeClass is configured and selected in the PodSpec, Overhead will be set to the value
|
||||
// defined in the corresponding RuntimeClass, otherwise it will remain unset and treated as zero.
|
||||
// More info: https://git.k8s.io/enhancements/keps/sig-node/688-pod-overhead/README.md
|
||||
// This field is beta-level as of Kubernetes v1.18, and is only honored by servers that enable the PodOverhead feature.
|
||||
// +optional
|
||||
Overhead ResourceList `json:"overhead,omitempty" protobuf:"bytes,32,opt,name=overhead"`
|
||||
// TopologySpreadConstraints describes how a group of pods ought to spread across topology
|
||||
|
@ -1666,7 +1666,7 @@ var map_PodSpec = map[string]string{
|
||||
"runtimeClassName": "RuntimeClassName refers to a RuntimeClass object in the node.k8s.io group, which should be used to run this pod. If no RuntimeClass resource matches the named class, the pod will not be run. If unset or empty, the \"legacy\" RuntimeClass will be used, which is an implicit class with an empty definition that uses the default runtime handler. More info: https://git.k8s.io/enhancements/keps/sig-node/585-runtime-class",
|
||||
"enableServiceLinks": "EnableServiceLinks indicates whether information about services should be injected into pod's environment variables, matching the syntax of Docker links. Optional: Defaults to true.",
|
||||
"preemptionPolicy": "PreemptionPolicy is the Policy for preempting pods with lower priority. One of Never, PreemptLowerPriority. Defaults to PreemptLowerPriority if unset.",
|
||||
"overhead": "Overhead represents the resource overhead associated with running a pod for a given RuntimeClass. This field will be autopopulated at admission time by the RuntimeClass admission controller. If the RuntimeClass admission controller is enabled, overhead must not be set in Pod create requests. The RuntimeClass admission controller will reject Pod create requests which have the overhead already set. If RuntimeClass is configured and selected in the PodSpec, Overhead will be set to the value defined in the corresponding RuntimeClass, otherwise it will remain unset and treated as zero. More info: https://git.k8s.io/enhancements/keps/sig-node/688-pod-overhead/README.md This field is beta-level as of Kubernetes v1.18, and is only honored by servers that enable the PodOverhead feature.",
|
||||
"overhead": "Overhead represents the resource overhead associated with running a pod for a given RuntimeClass. This field will be autopopulated at admission time by the RuntimeClass admission controller. If the RuntimeClass admission controller is enabled, overhead must not be set in Pod create requests. The RuntimeClass admission controller will reject Pod create requests which have the overhead already set. If RuntimeClass is configured and selected in the PodSpec, Overhead will be set to the value defined in the corresponding RuntimeClass, otherwise it will remain unset and treated as zero. More info: https://git.k8s.io/enhancements/keps/sig-node/688-pod-overhead/README.md",
|
||||
"topologySpreadConstraints": "TopologySpreadConstraints describes how a group of pods ought to spread across topology domains. Scheduler will schedule pods in a way which abides by the constraints. All topologySpreadConstraints are ANDed.",
|
||||
"setHostnameAsFQDN": "If true the pod's hostname will be configured as the pod's FQDN, rather than the leaf name (the default). In Linux containers, this means setting the FQDN in the hostname field of the kernel (the nodename field of struct utsname). In Windows containers, this means setting the registry value of hostname for the registry key HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters to FQDN. If a pod does not have FQDN, this has no effect. Default to false.",
|
||||
"os": "Specifies the OS of the containers in the pod. Some pod and container fields are restricted if this is set.\n\nIf the OS field is set to linux, the following fields must be unset: -securityContext.windowsOptions\n\nIf the OS field is set to windows, following fields must be unset: - spec.hostPID - spec.hostIPC - spec.securityContext.seLinuxOptions - spec.securityContext.seccompProfile - spec.securityContext.fsGroup - spec.securityContext.fsGroupChangePolicy - spec.securityContext.sysctls - spec.shareProcessNamespace - spec.securityContext.runAsUser - spec.securityContext.runAsGroup - spec.securityContext.supplementalGroups - spec.containers[*].securityContext.seLinuxOptions - spec.containers[*].securityContext.seccompProfile - spec.containers[*].securityContext.capabilities - spec.containers[*].securityContext.readOnlyRootFilesystem - spec.containers[*].securityContext.privileged - spec.containers[*].securityContext.allowPrivilegeEscalation - spec.containers[*].securityContext.procMount - spec.containers[*].securityContext.runAsUser - spec.containers[*].securityContext.runAsGroup This is an alpha field and requires the IdentifyPodOS feature",
|
||||
|
@ -64,8 +64,6 @@ message RuntimeClass {
|
||||
// Overhead represents the resource overhead associated with running a pod for a
|
||||
// given RuntimeClass. For more details, see
|
||||
// https://kubernetes.io/docs/concepts/scheduling-eviction/pod-overhead/
|
||||
// This field is in beta starting v1.18
|
||||
// and is only honored by servers that enable the PodOverhead feature.
|
||||
// +optional
|
||||
optional Overhead overhead = 3;
|
||||
|
||||
|
@ -53,8 +53,6 @@ type RuntimeClass struct {
|
||||
// Overhead represents the resource overhead associated with running a pod for a
|
||||
// given RuntimeClass. For more details, see
|
||||
// https://kubernetes.io/docs/concepts/scheduling-eviction/pod-overhead/
|
||||
// This field is in beta starting v1.18
|
||||
// and is only honored by servers that enable the PodOverhead feature.
|
||||
// +optional
|
||||
Overhead *Overhead `json:"overhead,omitempty" protobuf:"bytes,3,opt,name=overhead"`
|
||||
|
||||
|
@ -40,7 +40,7 @@ var map_RuntimeClass = map[string]string{
|
||||
"": "RuntimeClass defines a class of container runtime supported in the cluster. The RuntimeClass is used to determine which container runtime is used to run all containers in a pod. RuntimeClasses are manually defined by a user or cluster provisioner, and referenced in the PodSpec. The Kubelet is responsible for resolving the RuntimeClassName reference before running the pod. For more details, see https://kubernetes.io/docs/concepts/containers/runtime-class/",
|
||||
"metadata": "More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata",
|
||||
"handler": "Handler specifies the underlying runtime and configuration that the CRI implementation will use to handle pods of this class. The possible values are specific to the node & CRI configuration. It is assumed that all handlers are available on every node, and handlers of the same name are equivalent on every node. For example, a handler called \"runc\" might specify that the runc OCI runtime (using native Linux containers) will be used to run the containers in a pod. The Handler must be lowercase, conform to the DNS Label (RFC 1123) requirements, and is immutable.",
|
||||
"overhead": "Overhead represents the resource overhead associated with running a pod for a given RuntimeClass. For more details, see\n https://kubernetes.io/docs/concepts/scheduling-eviction/pod-overhead/\nThis field is in beta starting v1.18 and is only honored by servers that enable the PodOverhead feature.",
|
||||
"overhead": "Overhead represents the resource overhead associated with running a pod for a given RuntimeClass. For more details, see\n https://kubernetes.io/docs/concepts/scheduling-eviction/pod-overhead/",
|
||||
"scheduling": "Scheduling holds the scheduling constraints to ensure that pods running with this RuntimeClass are scheduled to nodes that support it. If scheduling is nil, this RuntimeClass is assumed to be supported by all nodes.",
|
||||
}
|
||||
|
||||
|
@ -85,7 +85,6 @@ message RuntimeClassSpec {
|
||||
// Overhead represents the resource overhead associated with running a pod for a
|
||||
// given RuntimeClass. For more details, see
|
||||
// https://git.k8s.io/enhancements/keps/sig-node/688-pod-overhead/README.md
|
||||
// This field is beta-level as of Kubernetes v1.18, and is only honored by servers that enable the PodOverhead feature.
|
||||
// +optional
|
||||
optional Overhead overhead = 2;
|
||||
|
||||
|
@ -63,7 +63,6 @@ type RuntimeClassSpec struct {
|
||||
// Overhead represents the resource overhead associated with running a pod for a
|
||||
// given RuntimeClass. For more details, see
|
||||
// https://git.k8s.io/enhancements/keps/sig-node/688-pod-overhead/README.md
|
||||
// This field is beta-level as of Kubernetes v1.18, and is only honored by servers that enable the PodOverhead feature.
|
||||
// +optional
|
||||
Overhead *Overhead `json:"overhead,omitempty" protobuf:"bytes,2,opt,name=overhead"`
|
||||
|
||||
|
@ -59,7 +59,7 @@ func (RuntimeClassList) SwaggerDoc() map[string]string {
|
||||
var map_RuntimeClassSpec = map[string]string{
|
||||
"": "RuntimeClassSpec is a specification of a RuntimeClass. It contains parameters that are required to describe the RuntimeClass to the Container Runtime Interface (CRI) implementation, as well as any other components that need to understand how the pod will be run. The RuntimeClassSpec is immutable.",
|
||||
"runtimeHandler": "RuntimeHandler specifies the underlying runtime and configuration that the CRI implementation will use to handle pods of this class. The possible values are specific to the node & CRI configuration. It is assumed that all handlers are available on every node, and handlers of the same name are equivalent on every node. For example, a handler called \"runc\" might specify that the runc OCI runtime (using native Linux containers) will be used to run the containers in a pod. The RuntimeHandler must be lowercase, conform to the DNS Label (RFC 1123) requirements, and is immutable.",
|
||||
"overhead": "Overhead represents the resource overhead associated with running a pod for a given RuntimeClass. For more details, see https://git.k8s.io/enhancements/keps/sig-node/688-pod-overhead/README.md This field is beta-level as of Kubernetes v1.18, and is only honored by servers that enable the PodOverhead feature.",
|
||||
"overhead": "Overhead represents the resource overhead associated with running a pod for a given RuntimeClass. For more details, see https://git.k8s.io/enhancements/keps/sig-node/688-pod-overhead/README.md",
|
||||
"scheduling": "Scheduling holds the scheduling constraints to ensure that pods running with this RuntimeClass are scheduled to nodes that support it. If scheduling is nil, this RuntimeClass is assumed to be supported by all nodes.",
|
||||
}
|
||||
|
||||
|
@ -64,7 +64,6 @@ message RuntimeClass {
|
||||
// Overhead represents the resource overhead associated with running a pod for a
|
||||
// given RuntimeClass. For more details, see
|
||||
// https://git.k8s.io/enhancements/keps/sig-node/688-pod-overhead/README.md
|
||||
// This field is beta-level as of Kubernetes v1.18, and is only honored by servers that enable the PodOverhead feature.
|
||||
// +optional
|
||||
optional Overhead overhead = 3;
|
||||
|
||||
|
@ -55,7 +55,6 @@ type RuntimeClass struct {
|
||||
// Overhead represents the resource overhead associated with running a pod for a
|
||||
// given RuntimeClass. For more details, see
|
||||
// https://git.k8s.io/enhancements/keps/sig-node/688-pod-overhead/README.md
|
||||
// This field is beta-level as of Kubernetes v1.18, and is only honored by servers that enable the PodOverhead feature.
|
||||
// +optional
|
||||
Overhead *Overhead `json:"overhead,omitempty" protobuf:"bytes,3,opt,name=overhead"`
|
||||
|
||||
|
@ -40,7 +40,7 @@ var map_RuntimeClass = map[string]string{
|
||||
"": "RuntimeClass defines a class of container runtime supported in the cluster. The RuntimeClass is used to determine which container runtime is used to run all containers in a pod. RuntimeClasses are (currently) manually defined by a user or cluster provisioner, and referenced in the PodSpec. The Kubelet is responsible for resolving the RuntimeClassName reference before running the pod. For more details, see https://git.k8s.io/enhancements/keps/sig-node/585-runtime-class",
|
||||
"metadata": "More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata",
|
||||
"handler": "Handler specifies the underlying runtime and configuration that the CRI implementation will use to handle pods of this class. The possible values are specific to the node & CRI configuration. It is assumed that all handlers are available on every node, and handlers of the same name are equivalent on every node. For example, a handler called \"runc\" might specify that the runc OCI runtime (using native Linux containers) will be used to run the containers in a pod. The Handler must be lowercase, conform to the DNS Label (RFC 1123) requirements, and is immutable.",
|
||||
"overhead": "Overhead represents the resource overhead associated with running a pod for a given RuntimeClass. For more details, see https://git.k8s.io/enhancements/keps/sig-node/688-pod-overhead/README.md This field is beta-level as of Kubernetes v1.18, and is only honored by servers that enable the PodOverhead feature.",
|
||||
"overhead": "Overhead represents the resource overhead associated with running a pod for a given RuntimeClass. For more details, see https://git.k8s.io/enhancements/keps/sig-node/688-pod-overhead/README.md",
|
||||
"scheduling": "Scheduling holds the scheduling constraints to ensure that pods running with this RuntimeClass are scheduled to nodes that support it. If scheduling is nil, this RuntimeClass is assumed to be supported by all nodes.",
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user