sigs.k8s.io/cluster-api@v1.6.3/internal/util/taints/taints.go (about)

     1  /*
     2  Copyright 2023 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  // Package taints implements taint helper functions.
    18  package taints
    19  
    20  import (
    21  	corev1 "k8s.io/api/core/v1"
    22  )
    23  
    24  // RemoveNodeTaint drops the taint from the list of node taints.
    25  // It returns true if the taints are modified, false otherwise.
    26  func RemoveNodeTaint(node *corev1.Node, drop corev1.Taint) bool {
    27  	droppedTaint := false
    28  	taints := []corev1.Taint{}
    29  	for _, taint := range node.Spec.Taints {
    30  		if taint.MatchTaint(&drop) {
    31  			droppedTaint = true
    32  			continue
    33  		}
    34  		taints = append(taints, taint)
    35  	}
    36  	node.Spec.Taints = taints
    37  	return droppedTaint
    38  }
    39  
    40  // HasTaint returns true if the targetTaint is in the list of taints.
    41  func HasTaint(taints []corev1.Taint, targetTaint corev1.Taint) bool {
    42  	for _, taint := range taints {
    43  		if taint.MatchTaint(&targetTaint) {
    44  			return true
    45  		}
    46  	}
    47  	return false
    48  }