-
Notifications
You must be signed in to change notification settings - Fork 40k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Task 3: Add MemoryPressure toleration for no BestEffort pod. #50180
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,15 +21,18 @@ import ( | |
"testing" | ||
"time" | ||
|
||
"k8s.io/apimachinery/pkg/api/resource" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apiserver/pkg/admission" | ||
utilfeature "k8s.io/apiserver/pkg/util/feature" | ||
"k8s.io/kubernetes/pkg/api" | ||
clientset "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset" | ||
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/fake" | ||
informers "k8s.io/kubernetes/pkg/client/informers/informers_generated/internalversion" | ||
kubeadmission "k8s.io/kubernetes/pkg/kubeapiserver/admission" | ||
"k8s.io/kubernetes/pkg/util/tolerations" | ||
pluginapi "k8s.io/kubernetes/plugin/pkg/admission/podtolerationrestriction/apis/podtolerationrestriction" | ||
"k8s.io/kubernetes/plugin/pkg/scheduler/algorithm" | ||
) | ||
|
||
// TestPodAdmission verifies various scenarios involving pod/namespace tolerations | ||
|
@@ -50,11 +53,56 @@ func TestPodAdmission(t *testing.T) { | |
defer close(stopCh) | ||
informerFactory.Start(stopCh) | ||
|
||
pod := &api.Pod{ | ||
CPU1000m := resource.MustParse("1000m") | ||
CPU500m := resource.MustParse("500m") | ||
|
||
burstablePod := &api.Pod{ | ||
ObjectMeta: metav1.ObjectMeta{Name: "testPod", Namespace: "testNamespace"}, | ||
Spec: api.PodSpec{ | ||
Containers: []api.Container{ | ||
{ | ||
Name: "test", | ||
Resources: api.ResourceRequirements{ | ||
Limits: api.ResourceList{api.ResourceCPU: CPU1000m}, | ||
Requests: api.ResourceList{api.ResourceCPU: CPU500m}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
guaranteedPod := &api.Pod{ | ||
ObjectMeta: metav1.ObjectMeta{Name: "testPod", Namespace: "testNamespace"}, | ||
Spec: api.PodSpec{ | ||
Containers: []api.Container{ | ||
{ | ||
Name: "test", | ||
Resources: api.ResourceRequirements{ | ||
Limits: api.ResourceList{api.ResourceCPU: CPU1000m}, | ||
Requests: api.ResourceList{api.ResourceCPU: CPU1000m}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
bestEffortPod := &api.Pod{ | ||
ObjectMeta: metav1.ObjectMeta{Name: "testPod", Namespace: "testNamespace"}, | ||
Spec: api.PodSpec{ | ||
Containers: []api.Container{ | ||
{ | ||
Name: "test", | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
if err := utilfeature.DefaultFeatureGate.Set("TaintNodesByCondition=true"); err != nil { | ||
t.Errorf("Failed to enable TaintByCondition feature: %v.", err) | ||
} | ||
|
||
tests := []struct { | ||
pod *api.Pod | ||
defaultClusterTolerations []api.Toleration | ||
namespaceTolerations []api.Toleration | ||
whitelist []api.Toleration | ||
|
@@ -65,6 +113,7 @@ func TestPodAdmission(t *testing.T) { | |
testName string | ||
}{ | ||
{ | ||
pod: bestEffortPod, | ||
defaultClusterTolerations: []api.Toleration{{Key: "testKey", Operator: "Equal", Value: "testValue", Effect: "NoSchedule", TolerationSeconds: nil}}, | ||
namespaceTolerations: []api.Toleration{}, | ||
podTolerations: []api.Toleration{}, | ||
|
@@ -73,6 +122,7 @@ func TestPodAdmission(t *testing.T) { | |
testName: "default cluster tolerations with empty pod tolerations", | ||
}, | ||
{ | ||
pod: bestEffortPod, | ||
defaultClusterTolerations: []api.Toleration{{Key: "testKey", Operator: "Equal", Value: "testValue", Effect: "NoSchedule", TolerationSeconds: nil}}, | ||
namespaceTolerations: []api.Toleration{}, | ||
podTolerations: []api.Toleration{{Key: "testKey", Operator: "Equal", Value: "testValue", Effect: "NoSchedule", TolerationSeconds: nil}}, | ||
|
@@ -81,6 +131,7 @@ func TestPodAdmission(t *testing.T) { | |
testName: "default cluster tolerations with pod tolerations specified", | ||
}, | ||
{ | ||
pod: bestEffortPod, | ||
defaultClusterTolerations: []api.Toleration{}, | ||
namespaceTolerations: []api.Toleration{{Key: "testKey", Operator: "Equal", Value: "testValue", Effect: "NoSchedule", TolerationSeconds: nil}}, | ||
podTolerations: []api.Toleration{{Key: "testKey", Operator: "Equal", Value: "testValue", Effect: "NoSchedule", TolerationSeconds: nil}}, | ||
|
@@ -89,6 +140,7 @@ func TestPodAdmission(t *testing.T) { | |
testName: "namespace tolerations", | ||
}, | ||
{ | ||
pod: bestEffortPod, | ||
defaultClusterTolerations: []api.Toleration{}, | ||
namespaceTolerations: []api.Toleration{{Key: "testKey", Operator: "Equal", Value: "testValue", Effect: "NoSchedule", TolerationSeconds: nil}}, | ||
podTolerations: []api.Toleration{}, | ||
|
@@ -97,20 +149,23 @@ func TestPodAdmission(t *testing.T) { | |
testName: "no pod tolerations", | ||
}, | ||
{ | ||
pod: bestEffortPod, | ||
defaultClusterTolerations: []api.Toleration{}, | ||
namespaceTolerations: []api.Toleration{{Key: "testKey", Operator: "Equal", Value: "testValue", Effect: "NoSchedule", TolerationSeconds: nil}}, | ||
podTolerations: []api.Toleration{{Key: "testKey", Operator: "Equal", Value: "testValue1", Effect: "NoSchedule", TolerationSeconds: nil}}, | ||
admit: false, | ||
testName: "conflicting pod and namespace tolerations", | ||
}, | ||
{ | ||
pod: bestEffortPod, | ||
defaultClusterTolerations: []api.Toleration{{Key: "testKey", Operator: "Equal", Value: "testValue2", Effect: "NoSchedule", TolerationSeconds: nil}}, | ||
namespaceTolerations: []api.Toleration{}, | ||
podTolerations: []api.Toleration{{Key: "testKey", Operator: "Equal", Value: "testValue1", Effect: "NoSchedule", TolerationSeconds: nil}}, | ||
admit: false, | ||
testName: "conflicting pod and default cluster tolerations", | ||
}, | ||
{ | ||
pod: bestEffortPod, | ||
defaultClusterTolerations: []api.Toleration{}, | ||
namespaceTolerations: []api.Toleration{{Key: "testKey", Operator: "Equal", Value: "testValue", Effect: "NoSchedule", TolerationSeconds: nil}}, | ||
whitelist: []api.Toleration{{Key: "testKey", Operator: "Equal", Value: "testValue", Effect: "NoSchedule", TolerationSeconds: nil}}, | ||
|
@@ -120,13 +175,40 @@ func TestPodAdmission(t *testing.T) { | |
testName: "merged pod tolerations satisfy whitelist", | ||
}, | ||
{ | ||
pod: bestEffortPod, | ||
defaultClusterTolerations: []api.Toleration{}, | ||
namespaceTolerations: []api.Toleration{{Key: "testKey", Operator: "Equal", Value: "testValue", Effect: "NoSchedule", TolerationSeconds: nil}}, | ||
whitelist: []api.Toleration{{Key: "testKey", Operator: "Equal", Value: "testValue1", Effect: "NoSchedule", TolerationSeconds: nil}}, | ||
podTolerations: []api.Toleration{}, | ||
admit: false, | ||
testName: "merged pod tolerations conflict with the whitelist", | ||
}, | ||
{ | ||
pod: burstablePod, | ||
defaultClusterTolerations: []api.Toleration{}, | ||
namespaceTolerations: []api.Toleration{{Key: "testKey", Operator: "Equal", Value: "testValue", Effect: "NoSchedule", TolerationSeconds: nil}}, | ||
whitelist: []api.Toleration{}, | ||
podTolerations: []api.Toleration{}, | ||
mergedTolerations: []api.Toleration{ | ||
{Key: algorithm.TaintNodeMemoryPressure, Operator: api.TolerationOpExists, Effect: api.TaintEffectNoSchedule, TolerationSeconds: nil}, | ||
{Key: "testKey", Operator: "Equal", Value: "testValue", Effect: "NoSchedule", TolerationSeconds: nil}, | ||
}, | ||
admit: true, | ||
testName: "added memoryPressure/DiskPressure for Burstable pod", | ||
}, | ||
{ | ||
pod: guaranteedPod, | ||
defaultClusterTolerations: []api.Toleration{}, | ||
namespaceTolerations: []api.Toleration{{Key: "testKey", Operator: "Equal", Value: "testValue", Effect: "NoSchedule", TolerationSeconds: nil}}, | ||
whitelist: []api.Toleration{}, | ||
podTolerations: []api.Toleration{}, | ||
mergedTolerations: []api.Toleration{ | ||
{Key: algorithm.TaintNodeMemoryPressure, Operator: api.TolerationOpExists, Effect: api.TaintEffectNoSchedule, TolerationSeconds: nil}, | ||
{Key: "testKey", Operator: "Equal", Value: "testValue", Effect: "NoSchedule", TolerationSeconds: nil}, | ||
}, | ||
admit: true, | ||
testName: "added memoryPressure/DiskPressure for Guaranteed pod", | ||
}, | ||
} | ||
for _, test := range tests { | ||
if len(test.namespaceTolerations) > 0 { | ||
|
@@ -148,6 +230,7 @@ func TestPodAdmission(t *testing.T) { | |
informerFactory.Core().InternalVersion().Namespaces().Informer().GetStore().Update(namespace) | ||
|
||
handler.pluginConfig = &pluginapi.Configuration{Default: test.defaultClusterTolerations, Whitelist: test.clusterWhitelist} | ||
pod := test.pod | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add this explicitly to all test cases. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done. |
||
pod.Spec.Tolerations = test.podTolerations | ||
|
||
err := handler.Admit(admission.NewAttributesRecord(pod, nil, api.Kind("Pod").WithVersion("version"), "testNamespace", namespace.ObjectMeta.Name, api.Resource("pods").WithVersion("version"), "", admission.Create, nil)) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we need to ensure that this admission controller is run after all resource defaulting controllers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hm... , do you means this admission controller need to be the latest one in apiserver's args?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
its a doc issue. you basically will want this controller to be the one that appears right before
ResourceQuota