mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-04 10:47:25 +00:00
Merge pull request #59740 from hzxuzhonghu/defaulttoleration-admission
Automatic merge from submit-queue (batch tested with PRs 59740, 59728, 60080, 60086, 58714). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. optimize DefaultTolerationSeconds admission controller **What this PR does / why we need it**: As `DefaultTolerationSeconds ` will be enabled by default, so this improves its performance. **Release note**: ```release-note NONE ```
This commit is contained in:
@@ -24,7 +24,6 @@ go_library(
|
|||||||
importpath = "k8s.io/kubernetes/plugin/pkg/admission/defaulttolerationseconds",
|
importpath = "k8s.io/kubernetes/plugin/pkg/admission/defaulttolerationseconds",
|
||||||
deps = [
|
deps = [
|
||||||
"//pkg/apis/core:go_default_library",
|
"//pkg/apis/core:go_default_library",
|
||||||
"//pkg/apis/core/helper:go_default_library",
|
|
||||||
"//pkg/scheduler/algorithm:go_default_library",
|
"//pkg/scheduler/algorithm:go_default_library",
|
||||||
"//vendor/k8s.io/apimachinery/pkg/api/errors:go_default_library",
|
"//vendor/k8s.io/apimachinery/pkg/api/errors:go_default_library",
|
||||||
"//vendor/k8s.io/apiserver/pkg/admission:go_default_library",
|
"//vendor/k8s.io/apiserver/pkg/admission:go_default_library",
|
||||||
|
@@ -24,7 +24,6 @@ import (
|
|||||||
"k8s.io/apimachinery/pkg/api/errors"
|
"k8s.io/apimachinery/pkg/api/errors"
|
||||||
"k8s.io/apiserver/pkg/admission"
|
"k8s.io/apiserver/pkg/admission"
|
||||||
api "k8s.io/kubernetes/pkg/apis/core"
|
api "k8s.io/kubernetes/pkg/apis/core"
|
||||||
"k8s.io/kubernetes/pkg/apis/core/helper"
|
|
||||||
"k8s.io/kubernetes/pkg/scheduler/algorithm"
|
"k8s.io/kubernetes/pkg/scheduler/algorithm"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -39,6 +38,20 @@ var (
|
|||||||
defaultUnreachableTolerationSeconds = flag.Int64("default-unreachable-toleration-seconds", 300,
|
defaultUnreachableTolerationSeconds = flag.Int64("default-unreachable-toleration-seconds", 300,
|
||||||
"Indicates the tolerationSeconds of the toleration for unreachable:NoExecute"+
|
"Indicates the tolerationSeconds of the toleration for unreachable:NoExecute"+
|
||||||
" that is added by default to every pod that does not already have such a toleration.")
|
" that is added by default to every pod that does not already have such a toleration.")
|
||||||
|
|
||||||
|
notReadyToleration = api.Toleration{
|
||||||
|
Key: algorithm.TaintNodeNotReady,
|
||||||
|
Operator: api.TolerationOpExists,
|
||||||
|
Effect: api.TaintEffectNoExecute,
|
||||||
|
TolerationSeconds: defaultNotReadyTolerationSeconds,
|
||||||
|
}
|
||||||
|
|
||||||
|
unreachableToleration = api.Toleration{
|
||||||
|
Key: algorithm.TaintNodeUnreachable,
|
||||||
|
Operator: api.TolerationOpExists,
|
||||||
|
Effect: api.TaintEffectNoExecute,
|
||||||
|
TolerationSeconds: defaultUnreachableTolerationSeconds,
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
// Register registers a plugin
|
// Register registers a plugin
|
||||||
@@ -99,27 +112,13 @@ func (p *Plugin) Admit(attributes admission.Attributes) (err error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// no change is required, return immediately
|
|
||||||
if toleratesNodeNotReady && toleratesNodeUnreachable {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if !toleratesNodeNotReady {
|
if !toleratesNodeNotReady {
|
||||||
helper.AddOrUpdateTolerationInPod(pod, &api.Toleration{
|
pod.Spec.Tolerations = append(pod.Spec.Tolerations, notReadyToleration)
|
||||||
Key: algorithm.TaintNodeNotReady,
|
|
||||||
Operator: api.TolerationOpExists,
|
|
||||||
Effect: api.TaintEffectNoExecute,
|
|
||||||
TolerationSeconds: defaultNotReadyTolerationSeconds,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if !toleratesNodeUnreachable {
|
if !toleratesNodeUnreachable {
|
||||||
helper.AddOrUpdateTolerationInPod(pod, &api.Toleration{
|
pod.Spec.Tolerations = append(pod.Spec.Tolerations, unreachableToleration)
|
||||||
Key: algorithm.TaintNodeUnreachable,
|
|
||||||
Operator: api.TolerationOpExists,
|
|
||||||
Effect: api.TaintEffectNoExecute,
|
|
||||||
TolerationSeconds: defaultUnreachableTolerationSeconds,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user