mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-04 04:08:16 +00:00 
			
		
		
		
	Auto update of staging client.
This commit is contained in:
		@@ -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 {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user