mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 12:43:23 +00:00
Merge pull request #31578 from kevin-wangzefeng/add-retries-for-taints-e2e
Automatic merge from submit-queue add retries for add/update/remove taints on node in taints e2e fixes taint update conflict in taints e2e by adding retries for add/update/remove taints on node. ref #27655 and #31066
This commit is contained in:
commit
6dd8b975cb
@ -2851,37 +2851,48 @@ func RemoveLabelOffNode(c *client.Client, nodeName string, labelKey string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func AddOrUpdateTaintOnNode(c *client.Client, nodeName string, taint api.Taint) {
|
func AddOrUpdateTaintOnNode(c *client.Client, nodeName string, taint api.Taint) {
|
||||||
node, err := c.Nodes().Get(nodeName)
|
for attempt := 0; attempt < UpdateRetries; attempt++ {
|
||||||
ExpectNoError(err)
|
node, err := c.Nodes().Get(nodeName)
|
||||||
|
ExpectNoError(err)
|
||||||
|
|
||||||
nodeTaints, err := api.GetTaintsFromNodeAnnotations(node.Annotations)
|
nodeTaints, err := api.GetTaintsFromNodeAnnotations(node.Annotations)
|
||||||
ExpectNoError(err)
|
ExpectNoError(err)
|
||||||
|
|
||||||
var newTaints []api.Taint
|
var newTaints []api.Taint
|
||||||
updated := false
|
updated := false
|
||||||
for _, existingTaint := range nodeTaints {
|
for _, existingTaint := range nodeTaints {
|
||||||
if existingTaint.Key == taint.Key {
|
if existingTaint.Key == taint.Key {
|
||||||
newTaints = append(newTaints, taint)
|
newTaints = append(newTaints, taint)
|
||||||
updated = true
|
updated = true
|
||||||
continue
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
newTaints = append(newTaints, existingTaint)
|
||||||
}
|
}
|
||||||
|
|
||||||
newTaints = append(newTaints, existingTaint)
|
if !updated {
|
||||||
}
|
newTaints = append(newTaints, taint)
|
||||||
|
}
|
||||||
|
|
||||||
if !updated {
|
taintsData, err := json.Marshal(newTaints)
|
||||||
newTaints = append(newTaints, taint)
|
ExpectNoError(err)
|
||||||
}
|
|
||||||
|
|
||||||
taintsData, err := json.Marshal(newTaints)
|
if node.Annotations == nil {
|
||||||
ExpectNoError(err)
|
node.Annotations = make(map[string]string)
|
||||||
|
}
|
||||||
if node.Annotations == nil {
|
node.Annotations[api.TaintsAnnotationKey] = string(taintsData)
|
||||||
node.Annotations = make(map[string]string)
|
_, err = c.Nodes().Update(node)
|
||||||
|
if err != nil {
|
||||||
|
if !apierrs.IsConflict(err) {
|
||||||
|
ExpectNoError(err)
|
||||||
|
} else {
|
||||||
|
Logf("Conflict when trying to add/update taint %v to %v", taint, nodeName)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
time.Sleep(100 * time.Millisecond)
|
||||||
}
|
}
|
||||||
node.Annotations[api.TaintsAnnotationKey] = string(taintsData)
|
|
||||||
_, err = c.Nodes().Update(node)
|
|
||||||
ExpectNoError(err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func taintExists(taints []api.Taint, taintKey string) bool {
|
func taintExists(taints []api.Taint, taintKey string) bool {
|
||||||
@ -2927,28 +2938,41 @@ func deleteTaintByKey(taints []api.Taint, taintKey string) ([]api.Taint, error)
|
|||||||
// won't fail if target taint doesn't exist or has been removed.
|
// won't fail if target taint doesn't exist or has been removed.
|
||||||
func RemoveTaintOffNode(c *client.Client, nodeName string, taintKey string) {
|
func RemoveTaintOffNode(c *client.Client, nodeName string, taintKey string) {
|
||||||
By("removing the taint " + taintKey + " off the node " + nodeName)
|
By("removing the taint " + taintKey + " off the node " + nodeName)
|
||||||
node, err := c.Nodes().Get(nodeName)
|
for attempt := 0; attempt < UpdateRetries; attempt++ {
|
||||||
ExpectNoError(err)
|
node, err := c.Nodes().Get(nodeName)
|
||||||
|
ExpectNoError(err)
|
||||||
|
|
||||||
nodeTaints, err := api.GetTaintsFromNodeAnnotations(node.Annotations)
|
nodeTaints, err := api.GetTaintsFromNodeAnnotations(node.Annotations)
|
||||||
ExpectNoError(err)
|
ExpectNoError(err)
|
||||||
if len(nodeTaints) == 0 {
|
if len(nodeTaints) == 0 {
|
||||||
return
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if !taintExists(nodeTaints, taintKey) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
newTaints, err := deleteTaintByKey(nodeTaints, taintKey)
|
||||||
|
ExpectNoError(err)
|
||||||
|
|
||||||
|
taintsData, err := json.Marshal(newTaints)
|
||||||
|
ExpectNoError(err)
|
||||||
|
node.Annotations[api.TaintsAnnotationKey] = string(taintsData)
|
||||||
|
_, err = c.Nodes().Update(node)
|
||||||
|
if err != nil {
|
||||||
|
if !apierrs.IsConflict(err) {
|
||||||
|
ExpectNoError(err)
|
||||||
|
} else {
|
||||||
|
Logf("Conflict when trying to add/update taint %v to %v", taintKey, nodeName)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
time.Sleep(100 * time.Millisecond)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !taintExists(nodeTaints, taintKey) {
|
nodeUpdated, err := c.Nodes().Get(nodeName)
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
newTaints, err := deleteTaintByKey(nodeTaints, taintKey)
|
|
||||||
ExpectNoError(err)
|
ExpectNoError(err)
|
||||||
|
|
||||||
taintsData, err := json.Marshal(newTaints)
|
|
||||||
ExpectNoError(err)
|
|
||||||
node.Annotations[api.TaintsAnnotationKey] = string(taintsData)
|
|
||||||
nodeUpdated, err := c.Nodes().Update(node)
|
|
||||||
ExpectNoError(err)
|
|
||||||
|
|
||||||
By("verifying the node doesn't have the taint " + taintKey)
|
By("verifying the node doesn't have the taint " + taintKey)
|
||||||
taintsGot, err := api.GetTaintsFromNodeAnnotations(nodeUpdated.Annotations)
|
taintsGot, err := api.GetTaintsFromNodeAnnotations(nodeUpdated.Annotations)
|
||||||
ExpectNoError(err)
|
ExpectNoError(err)
|
||||||
|
Loading…
Reference in New Issue
Block a user