mirror of
https://github.com/optim-enterprises-bv/kubernetes.git
synced 2025-11-02 03:08:15 +00:00
add defaultTolerationSeconds admission controller
This commit is contained in:
@@ -296,6 +296,45 @@ func GetPodTolerations(pod *Pod) ([]Toleration, error) {
|
||||
return GetTolerationsFromPodAnnotations(pod.Annotations)
|
||||
}
|
||||
|
||||
// Tries to add a toleration to annotations list. Returns true if something was updated
|
||||
// false otherwise.
|
||||
func AddOrUpdateTolerationInPod(pod *Pod, toleration *Toleration) (bool, error) {
|
||||
podTolerations, err := GetPodTolerations(pod)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
var newTolerations []*Toleration
|
||||
updated := false
|
||||
for i := range podTolerations {
|
||||
if toleration.MatchToleration(&podTolerations[i]) {
|
||||
if api.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)
|
||||
}
|
||||
|
||||
tolerationsData, err := json.Marshal(newTolerations)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
if pod.Annotations == nil {
|
||||
pod.Annotations = make(map[string]string)
|
||||
}
|
||||
pod.Annotations[TolerationsAnnotationKey] = string(tolerationsData)
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// GetTaintsFromNodeAnnotations gets the json serialized taints data from Pod.Annotations
|
||||
// and converts it to the []Taint type in api.
|
||||
func GetTaintsFromNodeAnnotations(annotations map[string]string) ([]Taint, error) {
|
||||
@@ -313,6 +352,16 @@ func GetNodeTaints(node *Node) ([]Taint, error) {
|
||||
return GetTaintsFromNodeAnnotations(node.Annotations)
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
// ToleratesTaint checks if the toleration tolerates the taint.
|
||||
// The matching follows the rules below:
|
||||
// (1) Empty toleration.effect means to match all taint effects,
|
||||
|
||||
Reference in New Issue
Block a user