controller: Update node when there is a modification
@@ -2,6 +2,7 @@ package controller
import (
"fmt"
+ "reflect"
"strings"
"time"
@@ -185,15 +186,6 @@ func (knc *KubernetesNodeController) syncKubernetesNode(key string) (err error)
return nil
}
- defer func() {
- // requeue if it's conflict
- if apierrors.IsConflict(errors.Cause(err)) {
- logrus.Debugf("Requeue %v due to conflict: %v", key, err)
- knc.enqueueNode(kubeNode)
- err = nil
- }
- }()
-
if knc.controllerID != kubeNode.Name {
return nil
}
@@ -204,6 +196,19 @@ func (knc *KubernetesNodeController) syncKubernetesNode(key string) (err error)
return nil
}
+ existingNode := node.DeepCopy()
+ defer func() {
+ if err == nil && !reflect.DeepEqual(existingNode.Spec, node.Spec) {
+ _, err = knc.ds.UpdateNode(node)
+ }
+ // requeue if it's conflict
+ if apierrors.IsConflict(errors.Cause(err)) {
+ logrus.Debugf("Requeue %v due to conflict: %v", key, err)
+ knc.enqueueLonghornNode(node)
+ err = nil
+ }
+ }()
+
// sync default disks on labeled Nodes
if err := knc.syncDefaultDisks(node); err != nil {
return err
@@ -313,11 +318,6 @@ func (knc *KubernetesNodeController) syncDefaultDisks(node *longhorn.Node) (err
node.Spec.Disks = disks
- updatedNode, err := knc.ds.UpdateNode(node)
- if err != nil {
- return err
- }
- node = updatedNode
return nil
}
@@ -338,12 +338,6 @@ func (knc *KubernetesNodeController) syncDefaultNodeTags(node *longhorn.Node) er
return nil
}
node.Spec.Tags = tags
-
- updatedNode, err := knc.ds.UpdateNode(node)
- if err != nil {
- return err
- }
- node = updatedNode
}
return nil
}
