mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-12 20:57:20 +00:00
mark PodOverhead to GA in v1.24; remove in v1.26
This commit is contained in:
@@ -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) {
|
||||
|
Reference in New Issue
Block a user