Add test case for a pod becoming schedulable when a node is updated

Also, avoid unnecessary copying when changing node taints
This commit is contained in:
Andrea Nodari
2020-05-20 17:41:42 +02:00
parent 4e8b56e667
commit 8a39a2c24e
2 changed files with 49 additions and 5 deletions

View File

@@ -219,9 +219,25 @@ func AddTaintToNode(cs clientset.Interface, nodeName string, taint v1.Taint) err
if err != nil {
return err
}
copy := node.DeepCopy()
copy.Spec.Taints = append(copy.Spec.Taints, taint)
_, err = cs.CoreV1().Nodes().Update(context.TODO(), copy, metav1.UpdateOptions{})
node.Spec.Taints = append(node.Spec.Taints, taint)
_, err = cs.CoreV1().Nodes().Update(context.TODO(), node, metav1.UpdateOptions{})
return err
}
// RemoveTaintOffNode removes a specific taint from a node
func RemoveTaintOffNode(cs clientset.Interface, nodeName string, taint v1.Taint) error {
node, err := cs.CoreV1().Nodes().Get(context.TODO(), nodeName, metav1.GetOptions{})
if err != nil {
return err
}
var taints []v1.Taint
for _, t := range node.Spec.Taints {
if !t.MatchTaint(&taint) {
taints = append(taints, t)
}
}
node.Spec.Taints = taints
_, err = cs.CoreV1().Nodes().Update(context.TODO(), node, metav1.UpdateOptions{})
return err
}