Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix: nodepool taint sync error #196

Merged
merged 1 commit into from
Jan 12, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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