From 2c7b03b4aa46b94fdba6a855ee30637dfb3e3343 Mon Sep 17 00:00:00 2001 From: kadisi Date: Tue, 12 Jan 2021 16:30:43 +0800 Subject: [PATCH] bugfix: nodepool taint sync error Signed-off-by: kadisi --- .../controller/nodepool/nodepool_controller.go | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/pkg/yurtappmanager/controller/nodepool/nodepool_controller.go b/pkg/yurtappmanager/controller/nodepool/nodepool_controller.go index c428bd4f2d1..d259f534410 100644 --- a/pkg/yurtappmanager/controller/nodepool/nodepool_controller.go +++ b/pkg/yurtappmanager/controller/nodepool/nodepool_controller.go @@ -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 } } @@ -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 } @@ -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 } } @@ -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 }