Skip to content

Commit

Permalink
bugfix: nodepool taint sync error
Browse files Browse the repository at this point in the history
Signed-off-by: kadisi <[email protected]>
  • Loading branch information
kadisi committed Jan 12, 2021
1 parent 3863756 commit 2c7b03b
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions pkg/yurtappmanager/controller/nodepool/nodepool_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ func (r *NodePoolReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {

if attrUpdated || ownerLabelUpdated {
if err := r.Update(ctx, &node); err != nil {
klog.Errorf("Update Node %s error %v", node.Name, err)
return ctrl.Result{}, err
}
}
Expand Down Expand Up @@ -311,7 +312,16 @@ func conciliatePoolRelatedAttrs(node *corev1.Node,
if !exist {
node.Labels = mergeMap(node.Labels, npra.Labels)
node.Annotations = mergeMap(node.Annotations, npra.Annotations)
node.Spec.Taints = append(node.Spec.Taints, npra.Taints...)
for _, npt := range npra.Taints {
for i, nt := range node.Spec.Taints {
if npt.Effect == nt.Effect && npt.Key == nt.Key {
node.Spec.Taints = append(node.Spec.Taints[:i], node.Spec.Taints[i+1:]...)
break
}
}
node.Spec.Taints = append(node.Spec.Taints, npt)
}

if err := cachePrevPoolAttrs(node, npra); err != nil {
return attrUpdated, err
}
Expand Down Expand Up @@ -409,14 +419,12 @@ func conciliateNodePoolStatus(cli client.Client,
return ctrl.Result{}, nil
}

/*********************** util functions ***********************/

// containTaint checks if `taint` is in `taints`, if yes it will return
// the index of the taint and true, otherwise, it will return 0 and false.
// N.B. the uniqueness of the taint is based on both key and effect pair
func containTaint(taint corev1.Taint, taints []corev1.Taint) (int, bool) {
for i, t := range taints {
if reflect.DeepEqual(taint, t) {
if taint.Effect == t.Effect && taint.Key == t.Key {
return i, true
}
}
Expand All @@ -443,7 +451,7 @@ func mergeMap(m1, m2 map[string]string) map[string]string {
// removeTaint removes `taint` from `taints` if exist
func removeTaint(taint corev1.Taint, taints []corev1.Taint) []corev1.Taint {
for i := 0; i < len(taints); i++ {
if reflect.DeepEqual(taint, taints[i]) {
if taint.Key == taints[i].Key && taint.Effect == taints[i].Effect {
taints = append(taints[:i], taints[i+1:]...)
break
}
Expand Down

0 comments on commit 2c7b03b

Please sign in to comment.