Commit 4b7787c0 authored by Bill Maxwell's avatar Bill Maxwell Committed by Alena Prokharchyk
Browse files

Update isEqual method to handle nil empty maps as the same

The node objects were constantly being updated when one of the objects
had a an empty map {} vs a nil map. This comparison takes that into account
and treats them the same. Also, if the objects are not equal a debug
statement was added to see which comparison test was false.
parent 0c846501
Showing with 9 additions and 7 deletions
+9 -7
......@@ -236,11 +236,7 @@ func deleteNode(nodeDir string, node *v3.Node) error {
return err
}
if err := command.Wait(); err != nil {
return err
}
return nil
return command.Wait()
}
func getSSHPrivateKey(nodeDir string, node *v3.Node) (string, error) {
......
......@@ -5,6 +5,7 @@ import (
"reflect"
"github.com/pkg/errors"
"github.com/rancher/norman/types/convert"
nodehelper "github.com/rancher/rancher/pkg/node"
"github.com/rancher/types/apis/core/v1"
"github.com/rancher/types/apis/management.cattle.io/v3"
......@@ -344,7 +345,12 @@ func objectsAreEqual(existing *v3.Node, toUpdate *v3.Node) bool {
nodeNameEqual := toUpdateToCompare.Status.NodeName == existingToCompare.Status.NodeName
requestsEqual := isEqual(toUpdateToCompare.Status.Requested, existingToCompare.Status.Requested)
limitsEqual := isEqual(toUpdateToCompare.Status.Limits, existingToCompare.Status.Limits)
return statusEqual && specEqual && nodeNameEqual && labelsEqual && annotationsEqual && requestsEqual && limitsEqual
retVal := statusEqual && specEqual && nodeNameEqual && labelsEqual && annotationsEqual && requestsEqual && limitsEqual
if !retVal {
logrus.Debugf("ObjectsAreEqualResults for %s: statusEqual: %t specEqual: %t nodeNameEqual: %t labelsEqual: %t annotationsEqual: %t requestsEqual: %t limitsEqual: %t", toUpdate.Name, statusEqual, specEqual, nodeNameEqual, labelsEqual, annotationsEqual, requestsEqual, limitsEqual)
}
return retVal
}
func (m *NodesSyncer) convertNodeToNode(node *corev1.Node, existing *v3.Node, pods map[string][]*corev1.Pod) (*v3.Node, error) {
......@@ -456,7 +462,7 @@ func aggregateRequestAndLimitsForNode(pods []*corev1.Pod) (map[corev1.ResourceNa
}
func isEqual(data1 map[corev1.ResourceName]resource.Quantity, data2 map[corev1.ResourceName]resource.Quantity) bool {
if data1 == nil && data2 == nil {
if convert.IsEmpty(data1) && convert.IsEmpty(data2) {
return true
}
if data1 == nil || data2 == nil {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment