2017-09-28 06:43:45 +00:00
|
|
|
/*
|
|
|
|
Copyright 2017 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 scheduler
|
|
|
|
|
|
|
|
// This file tests the Taint feature.
|
|
|
|
|
|
|
|
import (
|
2018-07-17 21:05:48 +00:00
|
|
|
"fmt"
|
2017-09-28 06:43:45 +00:00
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"k8s.io/api/core/v1"
|
|
|
|
"k8s.io/apimachinery/pkg/api/resource"
|
|
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
2018-05-01 14:54:37 +00:00
|
|
|
"k8s.io/apimachinery/pkg/runtime/schema"
|
2017-09-28 06:43:45 +00:00
|
|
|
utilfeature "k8s.io/apiserver/pkg/util/feature"
|
|
|
|
restclient "k8s.io/client-go/rest"
|
|
|
|
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
|
|
|
|
internalinformers "k8s.io/kubernetes/pkg/client/informers/informers_generated/internalversion"
|
2017-10-11 23:36:39 +00:00
|
|
|
"k8s.io/kubernetes/pkg/controller/nodelifecycle"
|
2017-09-28 06:43:45 +00:00
|
|
|
kubeadmission "k8s.io/kubernetes/pkg/kubeapiserver/admission"
|
2018-01-04 02:12:18 +00:00
|
|
|
"k8s.io/kubernetes/pkg/scheduler/algorithm"
|
|
|
|
"k8s.io/kubernetes/pkg/scheduler/algorithmprovider"
|
2017-09-28 06:43:45 +00:00
|
|
|
"k8s.io/kubernetes/plugin/pkg/admission/podtolerationrestriction"
|
|
|
|
pluginapi "k8s.io/kubernetes/plugin/pkg/admission/podtolerationrestriction/apis/podtolerationrestriction"
|
|
|
|
)
|
|
|
|
|
2018-07-17 21:05:48 +00:00
|
|
|
func newPod(nsName, name string, req, limit v1.ResourceList) *v1.Pod {
|
|
|
|
return &v1.Pod{
|
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
|
Name: name,
|
|
|
|
Namespace: nsName,
|
|
|
|
},
|
|
|
|
Spec: v1.PodSpec{
|
|
|
|
Containers: []v1.Container{
|
|
|
|
{
|
|
|
|
Name: "busybox",
|
|
|
|
Image: "busybox",
|
|
|
|
Resources: v1.ResourceRequirements{
|
|
|
|
Requests: req,
|
|
|
|
Limits: limit,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// TestTaintNodeByCondition tests related cases for TaintNodeByCondition feature.
|
2017-09-28 06:43:45 +00:00
|
|
|
func TestTaintNodeByCondition(t *testing.T) {
|
2018-03-19 10:25:12 +00:00
|
|
|
enabled := utilfeature.DefaultFeatureGate.Enabled("TaintNodesByCondition")
|
|
|
|
defer func() {
|
|
|
|
if !enabled {
|
|
|
|
utilfeature.DefaultFeatureGate.Set("TaintNodesByCondition=False")
|
|
|
|
}
|
|
|
|
}()
|
2017-09-28 06:43:45 +00:00
|
|
|
// Enable TaintNodeByCondition
|
|
|
|
utilfeature.DefaultFeatureGate.Set("TaintNodesByCondition=True")
|
|
|
|
|
2018-03-12 01:07:10 +00:00
|
|
|
// Build PodToleration Admission.
|
|
|
|
admission := podtolerationrestriction.NewPodTolerationsPlugin(&pluginapi.Configuration{})
|
|
|
|
|
|
|
|
context := initTestMaster(t, "default", admission)
|
|
|
|
|
2017-09-28 06:43:45 +00:00
|
|
|
// Build clientset and informers for controllers.
|
2018-03-12 01:07:10 +00:00
|
|
|
internalClientset := internalclientset.NewForConfigOrDie(&restclient.Config{
|
|
|
|
QPS: -1,
|
|
|
|
Host: context.httpServer.URL,
|
2018-05-01 14:54:37 +00:00
|
|
|
ContentConfig: restclient.ContentConfig{GroupVersion: &schema.GroupVersion{Group: "", Version: "v1"}}})
|
2017-09-28 06:43:45 +00:00
|
|
|
internalInformers := internalinformers.NewSharedInformerFactory(internalClientset, time.Second)
|
|
|
|
|
|
|
|
kubeadmission.WantsInternalKubeClientSet(admission).SetInternalKubeClientSet(internalClientset)
|
|
|
|
kubeadmission.WantsInternalKubeInformerFactory(admission).SetInternalKubeInformerFactory(internalInformers)
|
|
|
|
|
|
|
|
controllerCh := make(chan struct{})
|
|
|
|
defer close(controllerCh)
|
|
|
|
|
2018-03-12 01:07:10 +00:00
|
|
|
// Apply feature gates to enable TaintNodesByCondition
|
|
|
|
algorithmprovider.ApplyFeatureGates()
|
|
|
|
|
|
|
|
context = initTestScheduler(t, context, controllerCh, false, nil)
|
2018-07-17 21:05:48 +00:00
|
|
|
cs := context.clientSet
|
2018-03-12 01:07:10 +00:00
|
|
|
informers := context.informerFactory
|
|
|
|
nsName := context.ns.Name
|
|
|
|
|
2017-10-11 23:36:39 +00:00
|
|
|
// Start NodeLifecycleController for taint.
|
|
|
|
nc, err := nodelifecycle.NewNodeLifecycleController(
|
2017-09-28 06:43:45 +00:00
|
|
|
informers.Core().V1().Pods(),
|
|
|
|
informers.Core().V1().Nodes(),
|
|
|
|
informers.Extensions().V1beta1().DaemonSets(),
|
|
|
|
nil, // CloudProvider
|
2018-07-17 21:05:48 +00:00
|
|
|
cs,
|
2018-08-31 11:42:10 +00:00
|
|
|
time.Hour, // Node monitor grace period
|
2017-10-11 23:36:39 +00:00
|
|
|
time.Second, // Node startup grace period
|
|
|
|
time.Second, // Node monitor period
|
2017-09-28 06:43:45 +00:00
|
|
|
time.Second, // Pod eviction timeout
|
|
|
|
100, // Eviction limiter QPS
|
|
|
|
100, // Secondary eviction limiter QPS
|
|
|
|
100, // Large cluster threshold
|
|
|
|
100, // Unhealthy zone threshold
|
2017-10-11 23:36:39 +00:00
|
|
|
true, // Run taint manager
|
|
|
|
true, // Use taint based evictions
|
|
|
|
true, // Enabled TaintNodeByCondition feature
|
2017-09-28 06:43:45 +00:00
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Failed to create node controller: %v", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
go nc.Run(controllerCh)
|
|
|
|
|
|
|
|
// Waiting for all controller sync.
|
|
|
|
internalInformers.Start(controllerCh)
|
|
|
|
internalInformers.WaitForCacheSync(controllerCh)
|
2018-08-31 11:42:10 +00:00
|
|
|
informers.Start(controllerCh)
|
|
|
|
informers.WaitForCacheSync(controllerCh)
|
2017-09-28 06:43:45 +00:00
|
|
|
|
|
|
|
// -------------------------------------------
|
|
|
|
// Test TaintNodeByCondition feature.
|
|
|
|
// -------------------------------------------
|
2018-07-17 21:05:48 +00:00
|
|
|
nodeRes := v1.ResourceList{
|
|
|
|
v1.ResourceCPU: resource.MustParse("4000m"),
|
|
|
|
v1.ResourceMemory: resource.MustParse("16Gi"),
|
|
|
|
v1.ResourcePods: resource.MustParse("110"),
|
|
|
|
}
|
|
|
|
|
|
|
|
podRes := v1.ResourceList{
|
|
|
|
v1.ResourceCPU: resource.MustParse("100m"),
|
|
|
|
v1.ResourceMemory: resource.MustParse("100Mi"),
|
|
|
|
}
|
|
|
|
|
|
|
|
notReadyToleration := v1.Toleration{
|
|
|
|
Key: algorithm.TaintNodeNotReady,
|
|
|
|
Operator: v1.TolerationOpExists,
|
|
|
|
Effect: v1.TaintEffectNoSchedule,
|
|
|
|
}
|
|
|
|
|
|
|
|
unreachableToleration := v1.Toleration{
|
|
|
|
Key: algorithm.TaintNodeUnreachable,
|
|
|
|
Operator: v1.TolerationOpExists,
|
|
|
|
Effect: v1.TaintEffectNoSchedule,
|
|
|
|
}
|
|
|
|
|
|
|
|
unschedulableToleration := v1.Toleration{
|
|
|
|
Key: algorithm.TaintNodeUnschedulable,
|
|
|
|
Operator: v1.TolerationOpExists,
|
|
|
|
Effect: v1.TaintEffectNoSchedule,
|
|
|
|
}
|
|
|
|
|
|
|
|
outOfDiskToleration := v1.Toleration{
|
|
|
|
Key: algorithm.TaintNodeOutOfDisk,
|
|
|
|
Operator: v1.TolerationOpExists,
|
|
|
|
Effect: v1.TaintEffectNoSchedule,
|
|
|
|
}
|
|
|
|
|
2017-09-28 06:43:45 +00:00
|
|
|
memoryPressureToleration := v1.Toleration{
|
|
|
|
Key: algorithm.TaintNodeMemoryPressure,
|
|
|
|
Operator: v1.TolerationOpExists,
|
|
|
|
Effect: v1.TaintEffectNoSchedule,
|
|
|
|
}
|
|
|
|
|
2018-07-17 21:05:48 +00:00
|
|
|
diskPressureToleration := v1.Toleration{
|
|
|
|
Key: algorithm.TaintNodeDiskPressure,
|
|
|
|
Operator: v1.TolerationOpExists,
|
|
|
|
Effect: v1.TaintEffectNoSchedule,
|
2017-09-28 06:43:45 +00:00
|
|
|
}
|
|
|
|
|
2018-07-17 21:05:48 +00:00
|
|
|
networkUnavailableToleration := v1.Toleration{
|
|
|
|
Key: algorithm.TaintNodeNetworkUnavailable,
|
|
|
|
Operator: v1.TolerationOpExists,
|
|
|
|
Effect: v1.TaintEffectNoSchedule,
|
2017-09-28 06:43:45 +00:00
|
|
|
}
|
|
|
|
|
2018-07-17 21:05:48 +00:00
|
|
|
pidPressureToleration := v1.Toleration{
|
|
|
|
Key: algorithm.TaintNodePIDPressure,
|
|
|
|
Operator: v1.TolerationOpExists,
|
|
|
|
Effect: v1.TaintEffectNoSchedule,
|
2017-09-28 06:43:45 +00:00
|
|
|
}
|
|
|
|
|
2018-07-17 21:05:48 +00:00
|
|
|
bestEffortPod := newPod(nsName, "besteffort-pod", nil, nil)
|
|
|
|
burstablePod := newPod(nsName, "burstable-pod", podRes, nil)
|
|
|
|
guaranteePod := newPod(nsName, "guarantee-pod", podRes, podRes)
|
|
|
|
|
|
|
|
type podCase struct {
|
|
|
|
pod *v1.Pod
|
|
|
|
tolerations []v1.Toleration
|
|
|
|
fits bool
|
2017-09-28 06:43:45 +00:00
|
|
|
}
|
|
|
|
|
2018-07-17 21:05:48 +00:00
|
|
|
// switch to table driven testings
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
existingTaints []v1.Taint
|
|
|
|
nodeConditions []v1.NodeCondition
|
|
|
|
unschedulable bool
|
|
|
|
expectedTaints []v1.Taint
|
|
|
|
pods []podCase
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "not-ready node",
|
|
|
|
nodeConditions: []v1.NodeCondition{
|
|
|
|
{
|
|
|
|
Type: v1.NodeReady,
|
|
|
|
Status: v1.ConditionFalse,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expectedTaints: []v1.Taint{
|
|
|
|
{
|
|
|
|
Key: algorithm.TaintNodeNotReady,
|
|
|
|
Effect: v1.TaintEffectNoSchedule,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
pods: []podCase{
|
|
|
|
{
|
|
|
|
pod: bestEffortPod,
|
|
|
|
fits: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
pod: burstablePod,
|
|
|
|
fits: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
pod: guaranteePod,
|
|
|
|
fits: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
pod: bestEffortPod,
|
|
|
|
tolerations: []v1.Toleration{notReadyToleration},
|
|
|
|
fits: true,
|
|
|
|
},
|
|
|
|
},
|
2017-09-28 06:43:45 +00:00
|
|
|
},
|
2018-07-17 21:05:48 +00:00
|
|
|
{
|
|
|
|
name: "unreachable node",
|
|
|
|
existingTaints: []v1.Taint{
|
|
|
|
{
|
|
|
|
Key: algorithm.TaintNodeUnreachable,
|
|
|
|
Effect: v1.TaintEffectNoSchedule,
|
|
|
|
},
|
2017-09-28 06:43:45 +00:00
|
|
|
},
|
2018-07-17 21:05:48 +00:00
|
|
|
nodeConditions: []v1.NodeCondition{
|
|
|
|
{
|
|
|
|
Type: v1.NodeReady,
|
|
|
|
Status: v1.ConditionUnknown, // node status is "Unknown"
|
|
|
|
},
|
2017-09-28 06:43:45 +00:00
|
|
|
},
|
2018-07-17 21:05:48 +00:00
|
|
|
expectedTaints: []v1.Taint{
|
2017-09-28 06:43:45 +00:00
|
|
|
{
|
2018-07-17 21:05:48 +00:00
|
|
|
Key: algorithm.TaintNodeUnreachable,
|
|
|
|
Effect: v1.TaintEffectNoSchedule,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
pods: []podCase{
|
|
|
|
{
|
|
|
|
pod: bestEffortPod,
|
|
|
|
fits: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
pod: burstablePod,
|
|
|
|
fits: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
pod: guaranteePod,
|
|
|
|
fits: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
pod: bestEffortPod,
|
|
|
|
tolerations: []v1.Toleration{unreachableToleration},
|
|
|
|
fits: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "unschedulable node",
|
|
|
|
unschedulable: true, // node.spec.unschedulable = true
|
|
|
|
nodeConditions: []v1.NodeCondition{
|
|
|
|
{
|
|
|
|
Type: v1.NodeReady,
|
|
|
|
Status: v1.ConditionTrue,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expectedTaints: []v1.Taint{
|
|
|
|
{
|
|
|
|
Key: algorithm.TaintNodeUnschedulable,
|
|
|
|
Effect: v1.TaintEffectNoSchedule,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
pods: []podCase{
|
|
|
|
{
|
|
|
|
pod: bestEffortPod,
|
|
|
|
fits: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
pod: burstablePod,
|
|
|
|
fits: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
pod: guaranteePod,
|
|
|
|
fits: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
pod: bestEffortPod,
|
|
|
|
tolerations: []v1.Toleration{unschedulableToleration},
|
|
|
|
fits: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "out of disk node",
|
|
|
|
nodeConditions: []v1.NodeCondition{
|
|
|
|
{
|
|
|
|
Type: v1.NodeOutOfDisk,
|
2017-09-28 06:43:45 +00:00
|
|
|
Status: v1.ConditionTrue,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Type: v1.NodeReady,
|
2018-07-17 21:05:48 +00:00
|
|
|
Status: v1.ConditionTrue,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expectedTaints: []v1.Taint{
|
|
|
|
{
|
|
|
|
Key: algorithm.TaintNodeOutOfDisk,
|
|
|
|
Effect: v1.TaintEffectNoSchedule,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
// In OutOfDisk condition, only pods with toleration can be scheduled.
|
|
|
|
pods: []podCase{
|
|
|
|
{
|
|
|
|
pod: bestEffortPod,
|
|
|
|
fits: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
pod: burstablePod,
|
|
|
|
fits: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
pod: guaranteePod,
|
|
|
|
fits: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
pod: bestEffortPod,
|
|
|
|
tolerations: []v1.Toleration{outOfDiskToleration},
|
|
|
|
fits: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
pod: bestEffortPod,
|
|
|
|
tolerations: []v1.Toleration{diskPressureToleration},
|
|
|
|
fits: false,
|
2017-09-28 06:43:45 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2018-07-17 21:05:48 +00:00
|
|
|
{
|
|
|
|
name: "memory pressure node",
|
|
|
|
nodeConditions: []v1.NodeCondition{
|
|
|
|
{
|
|
|
|
Type: v1.NodeMemoryPressure,
|
|
|
|
Status: v1.ConditionTrue,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Type: v1.NodeReady,
|
|
|
|
Status: v1.ConditionTrue,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expectedTaints: []v1.Taint{
|
|
|
|
{
|
|
|
|
Key: algorithm.TaintNodeMemoryPressure,
|
|
|
|
Effect: v1.TaintEffectNoSchedule,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
// In MemoryPressure condition, both Burstable and Guarantee pods are scheduled;
|
|
|
|
// BestEffort pod with toleration are also scheduled.
|
|
|
|
pods: []podCase{
|
|
|
|
{
|
|
|
|
pod: bestEffortPod,
|
|
|
|
fits: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
pod: bestEffortPod,
|
|
|
|
tolerations: []v1.Toleration{memoryPressureToleration},
|
|
|
|
fits: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
pod: bestEffortPod,
|
|
|
|
tolerations: []v1.Toleration{diskPressureToleration},
|
|
|
|
fits: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
pod: burstablePod,
|
|
|
|
fits: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
pod: guaranteePod,
|
|
|
|
fits: true,
|
|
|
|
},
|
|
|
|
},
|
2017-09-28 06:43:45 +00:00
|
|
|
},
|
2018-07-17 21:05:48 +00:00
|
|
|
{
|
|
|
|
name: "disk pressure node",
|
|
|
|
nodeConditions: []v1.NodeCondition{
|
|
|
|
{
|
|
|
|
Type: v1.NodeDiskPressure,
|
|
|
|
Status: v1.ConditionTrue,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Type: v1.NodeReady,
|
|
|
|
Status: v1.ConditionTrue,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expectedTaints: []v1.Taint{
|
|
|
|
{
|
|
|
|
Key: algorithm.TaintNodeDiskPressure,
|
|
|
|
Effect: v1.TaintEffectNoSchedule,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
// In DiskPressure condition, only pods with toleration can be scheduled.
|
|
|
|
pods: []podCase{
|
|
|
|
{
|
|
|
|
pod: bestEffortPod,
|
|
|
|
fits: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
pod: burstablePod,
|
|
|
|
fits: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
pod: guaranteePod,
|
|
|
|
fits: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
pod: bestEffortPod,
|
|
|
|
tolerations: []v1.Toleration{diskPressureToleration},
|
|
|
|
fits: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
pod: bestEffortPod,
|
|
|
|
tolerations: []v1.Toleration{memoryPressureToleration},
|
|
|
|
fits: false,
|
|
|
|
},
|
|
|
|
},
|
2017-09-28 06:43:45 +00:00
|
|
|
},
|
2018-07-17 21:05:48 +00:00
|
|
|
{
|
|
|
|
name: "network unavailable and node is ready",
|
|
|
|
nodeConditions: []v1.NodeCondition{
|
2017-09-28 06:43:45 +00:00
|
|
|
{
|
2018-07-17 21:05:48 +00:00
|
|
|
Type: v1.NodeNetworkUnavailable,
|
|
|
|
Status: v1.ConditionTrue,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Type: v1.NodeReady,
|
|
|
|
Status: v1.ConditionTrue,
|
2017-09-28 06:43:45 +00:00
|
|
|
},
|
|
|
|
},
|
2018-07-17 21:05:48 +00:00
|
|
|
expectedTaints: []v1.Taint{
|
2017-09-28 06:43:45 +00:00
|
|
|
{
|
2018-07-17 21:05:48 +00:00
|
|
|
Key: algorithm.TaintNodeNetworkUnavailable,
|
|
|
|
Effect: v1.TaintEffectNoSchedule,
|
2017-09-28 06:43:45 +00:00
|
|
|
},
|
2018-07-17 21:05:48 +00:00
|
|
|
},
|
|
|
|
pods: []podCase{
|
2018-05-09 13:36:05 +00:00
|
|
|
{
|
2018-07-17 21:05:48 +00:00
|
|
|
pod: bestEffortPod,
|
|
|
|
fits: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
pod: burstablePod,
|
|
|
|
fits: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
pod: guaranteePod,
|
|
|
|
fits: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
pod: burstablePod,
|
|
|
|
tolerations: []v1.Toleration{
|
|
|
|
networkUnavailableToleration,
|
|
|
|
},
|
|
|
|
fits: true,
|
2018-05-09 13:36:05 +00:00
|
|
|
},
|
2017-09-28 06:43:45 +00:00
|
|
|
},
|
|
|
|
},
|
2018-07-17 21:05:48 +00:00
|
|
|
{
|
|
|
|
name: "network unavailable and node is not ready",
|
|
|
|
nodeConditions: []v1.NodeCondition{
|
|
|
|
{
|
|
|
|
Type: v1.NodeNetworkUnavailable,
|
|
|
|
Status: v1.ConditionTrue,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Type: v1.NodeReady,
|
|
|
|
Status: v1.ConditionFalse,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expectedTaints: []v1.Taint{
|
|
|
|
{
|
|
|
|
Key: algorithm.TaintNodeNetworkUnavailable,
|
|
|
|
Effect: v1.TaintEffectNoSchedule,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Key: algorithm.TaintNodeNotReady,
|
|
|
|
Effect: v1.TaintEffectNoSchedule,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
pods: []podCase{
|
|
|
|
{
|
|
|
|
pod: bestEffortPod,
|
|
|
|
fits: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
pod: burstablePod,
|
|
|
|
fits: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
pod: guaranteePod,
|
|
|
|
fits: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
pod: burstablePod,
|
|
|
|
tolerations: []v1.Toleration{
|
|
|
|
networkUnavailableToleration,
|
|
|
|
},
|
|
|
|
fits: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
pod: burstablePod,
|
|
|
|
tolerations: []v1.Toleration{
|
|
|
|
networkUnavailableToleration,
|
|
|
|
notReadyToleration,
|
|
|
|
},
|
|
|
|
fits: true,
|
|
|
|
},
|
|
|
|
},
|
2018-03-14 07:08:17 +00:00
|
|
|
},
|
2018-07-17 21:05:48 +00:00
|
|
|
{
|
|
|
|
name: "pid pressure node",
|
|
|
|
nodeConditions: []v1.NodeCondition{
|
|
|
|
{
|
|
|
|
Type: v1.NodePIDPressure,
|
|
|
|
Status: v1.ConditionTrue,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Type: v1.NodeReady,
|
|
|
|
Status: v1.ConditionTrue,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expectedTaints: []v1.Taint{
|
|
|
|
{
|
|
|
|
Key: algorithm.TaintNodePIDPressure,
|
|
|
|
Effect: v1.TaintEffectNoSchedule,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
pods: []podCase{
|
|
|
|
{
|
|
|
|
pod: bestEffortPod,
|
|
|
|
fits: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
pod: burstablePod,
|
|
|
|
fits: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
pod: guaranteePod,
|
|
|
|
fits: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
pod: bestEffortPod,
|
|
|
|
tolerations: []v1.Toleration{pidPressureToleration},
|
|
|
|
fits: true,
|
|
|
|
},
|
|
|
|
},
|
2018-03-14 07:08:17 +00:00
|
|
|
},
|
2018-07-17 21:05:48 +00:00
|
|
|
{
|
|
|
|
name: "multi taints on node",
|
|
|
|
nodeConditions: []v1.NodeCondition{
|
|
|
|
{
|
|
|
|
Type: v1.NodePIDPressure,
|
|
|
|
Status: v1.ConditionTrue,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Type: v1.NodeMemoryPressure,
|
|
|
|
Status: v1.ConditionTrue,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Type: v1.NodeDiskPressure,
|
|
|
|
Status: v1.ConditionTrue,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Type: v1.NodeReady,
|
|
|
|
Status: v1.ConditionTrue,
|
|
|
|
},
|
2018-03-14 07:08:17 +00:00
|
|
|
},
|
2018-07-17 21:05:48 +00:00
|
|
|
expectedTaints: []v1.Taint{
|
|
|
|
{
|
|
|
|
Key: algorithm.TaintNodeDiskPressure,
|
|
|
|
Effect: v1.TaintEffectNoSchedule,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Key: algorithm.TaintNodeMemoryPressure,
|
|
|
|
Effect: v1.TaintEffectNoSchedule,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Key: algorithm.TaintNodePIDPressure,
|
|
|
|
Effect: v1.TaintEffectNoSchedule,
|
|
|
|
},
|
2018-03-14 07:08:17 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2018-07-17 21:05:48 +00:00
|
|
|
for _, test := range tests {
|
|
|
|
t.Run(test.name, func(t *testing.T) {
|
|
|
|
node := &v1.Node{
|
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
|
Name: "node-1",
|
|
|
|
},
|
|
|
|
Spec: v1.NodeSpec{
|
|
|
|
Unschedulable: test.unschedulable,
|
|
|
|
Taints: test.existingTaints,
|
|
|
|
},
|
|
|
|
Status: v1.NodeStatus{
|
|
|
|
Capacity: nodeRes,
|
|
|
|
Allocatable: nodeRes,
|
|
|
|
Conditions: test.nodeConditions,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
if _, err := cs.CoreV1().Nodes().Create(node); err != nil {
|
|
|
|
t.Errorf("Failed to create node, err: %v", err)
|
|
|
|
}
|
|
|
|
if err := waitForNodeTaints(cs, node, test.expectedTaints); err != nil {
|
|
|
|
t.Errorf("Failed to taint node, err: %v", err)
|
2018-03-14 07:08:17 +00:00
|
|
|
}
|
|
|
|
|
2018-07-17 21:05:48 +00:00
|
|
|
var pods []*v1.Pod
|
|
|
|
for i, p := range test.pods {
|
|
|
|
pod := p.pod.DeepCopy()
|
|
|
|
pod.Name = fmt.Sprintf("%s-%d", pod.Name, i)
|
|
|
|
pod.Spec.Tolerations = p.tolerations
|
|
|
|
|
|
|
|
createdPod, err := cs.CoreV1().Pods(pod.Namespace).Create(pod)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Failed to create pod %s/%s, error: %v",
|
|
|
|
pod.Namespace, pod.Name, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
pods = append(pods, createdPod)
|
|
|
|
|
|
|
|
if p.fits {
|
|
|
|
if err := waitForPodToSchedule(cs, createdPod); err != nil {
|
|
|
|
t.Errorf("Failed to schedule pod %s/%s on the node, err: %v",
|
|
|
|
pod.Namespace, pod.Name, err)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if err := waitForPodUnschedulable(cs, createdPod); err != nil {
|
|
|
|
t.Errorf("Unschedulable pod %s/%s gets scheduled on the node, err: %v",
|
|
|
|
pod.Namespace, pod.Name, err)
|
|
|
|
}
|
2018-03-14 07:08:17 +00:00
|
|
|
}
|
|
|
|
}
|
2018-07-17 21:05:48 +00:00
|
|
|
|
|
|
|
cleanupPods(cs, t, pods)
|
|
|
|
cleanupNodes(cs, t)
|
2018-08-31 11:42:10 +00:00
|
|
|
waitForSchedulerCacheCleanup(context.scheduler, t)
|
2018-07-17 21:05:48 +00:00
|
|
|
})
|
2018-03-14 07:08:17 +00:00
|
|
|
}
|
2017-09-28 06:43:45 +00:00
|
|
|
}
|