mirror of
https://github.com/kubernetes/client-go.git
synced 2025-07-05 19:26:23 +00:00
Auto update of staging client.
Kubernetes-commit: f88c90151840684c687759a1a3a4dc3fc2c1aa9c
This commit is contained in:
parent
ca95d09fc0
commit
41b2639c6a
@ -465,6 +465,44 @@ const (
|
|||||||
ObjectTTLAnnotationKey string = "node.alpha.kubernetes.io/ttl"
|
ObjectTTLAnnotationKey string = "node.alpha.kubernetes.io/ttl"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// AddOrUpdateTolerationInPod tries to add a toleration to the pod's toleration list.
|
||||||
|
// Returns true if something was updated, false otherwise.
|
||||||
|
func AddOrUpdateTolerationInPod(pod *Pod, toleration *Toleration) (bool, error) {
|
||||||
|
podTolerations := pod.Spec.Tolerations
|
||||||
|
|
||||||
|
var newTolerations []Toleration
|
||||||
|
updated := false
|
||||||
|
for i := range podTolerations {
|
||||||
|
if toleration.MatchToleration(&podTolerations[i]) {
|
||||||
|
if Semantic.DeepEqual(toleration, podTolerations[i]) {
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
newTolerations = append(newTolerations, *toleration)
|
||||||
|
updated = true
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
newTolerations = append(newTolerations, podTolerations[i])
|
||||||
|
}
|
||||||
|
|
||||||
|
if !updated {
|
||||||
|
newTolerations = append(newTolerations, *toleration)
|
||||||
|
}
|
||||||
|
|
||||||
|
pod.Spec.Tolerations = newTolerations
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// MatchToleration checks if the toleration matches tolerationToMatch. Tolerations are unique by <key,effect,operator,value>,
|
||||||
|
// if the two tolerations have same <key,effect,operator,value> combination, regard as they match.
|
||||||
|
// TODO: uniqueness check for tolerations in api validations.
|
||||||
|
func (t *Toleration) MatchToleration(tolerationToMatch *Toleration) bool {
|
||||||
|
return t.Key == tolerationToMatch.Key &&
|
||||||
|
t.Effect == tolerationToMatch.Effect &&
|
||||||
|
t.Operator == tolerationToMatch.Operator &&
|
||||||
|
t.Value == tolerationToMatch.Value
|
||||||
|
}
|
||||||
|
|
||||||
// TolerationToleratesTaint checks if the toleration tolerates the taint.
|
// TolerationToleratesTaint checks if the toleration tolerates the taint.
|
||||||
func TolerationToleratesTaint(toleration *Toleration, taint *Taint) bool {
|
func TolerationToleratesTaint(toleration *Toleration, taint *Taint) bool {
|
||||||
if len(toleration.Effect) != 0 && toleration.Effect != taint.Effect {
|
if len(toleration.Effect) != 0 && toleration.Effect != taint.Effect {
|
||||||
|
Loading…
Reference in New Issue
Block a user