core: dereference pointer before trying to compare with deepequal

Prior to this, we were comparing a pointer (the memory address) with a
struct. This was obviously always failing and returned false. We must
dereference the pointer to access the data contained at that memory
location.

Closes: https://github.com/rook/rook/issues/9544
Signed-off-by: Sébastien Han <seb@redhat.com>
(cherry picked from commit 5404ec13a2)
This commit is contained in:
Sébastien Han authored and mergify-bot committed 2022-01-28 10:20:40 +00:00
1 parent 4c41b5ea07
commit ce9b3ee2f2
9 files changed
+61 -12

No files matched your search

+1 -1
View File
@@ -96,7 +96,7 @@ func wereMonEndpointsUpdated(oldCMData, newCMData map[string]string) bool {
// Iterate over the map and compare the values
for _, v := range oldKeys {
if !reflect.DeepEqual(oldMappingToGo.Schedule[v], newMappingToGo.Schedule[v]) {
if !reflect.DeepEqual(*oldMappingToGo.Schedule[v], *newMappingToGo.Schedule[v]) {
logger.Debugf("oldMappingToGo.Schedule[v] AND newMappingToGo.Schedule[v]: %v | %v", oldMappingToGo.Schedule[v], newMappingToGo.Schedule[v])
return true
}
+4 -4
View File
@@ -186,13 +186,13 @@ func (m *OSDHealthMonitor) removeOSDDeploymentIfSafeToDestroy(outOSDid int) erro
// updateCephStorage updates the CR with deviceclass details
func (m *OSDHealthMonitor) updateCephStatus(devices []string) {
cephCluster := &cephv1.CephCluster{}
cephCluster := cephv1.CephCluster{}
cephClusterStorage := cephv1.CephStorage{}
for _, device := range devices {
cephClusterStorage.DeviceClasses = append(cephClusterStorage.DeviceClasses, cephv1.DeviceClasses{Name: device})
}
err := m.context.Client.Get(m.clusterInfo.Context, m.clusterInfo.NamespacedName(), cephCluster)
err := m.context.Client.Get(m.clusterInfo.Context, m.clusterInfo.NamespacedName(), &cephCluster)
if err != nil {
if kerrors.IsNotFound(err) {
logger.Debug("CephCluster resource not found. Ignoring since object must be deleted.")
@@ -201,9 +201,9 @@ func (m *OSDHealthMonitor) updateCephStatus(devices []string) {
logger.Errorf("failed to retrieve ceph cluster %q to update ceph Storage. %v", m.clusterInfo.NamespacedName().Name, err)
return
}
if !reflect.DeepEqual(cephCluster.Status.CephStorage, &cephClusterStorage) {
if !reflect.DeepEqual(cephCluster.Status.CephStorage, cephClusterStorage) {
cephCluster.Status.CephStorage = &cephClusterStorage
if err := reporting.UpdateStatus(m.context.Client, cephCluster); err != nil {
if err := reporting.UpdateStatus(m.context.Client, &cephCluster); err != nil {
logger.Errorf("failed to update cluster %q Storage. %v", m.clusterInfo.NamespacedName().Name, err)
return
}
+1 -1
View File
@@ -208,7 +208,7 @@ func (r *ReconcileCephRBDMirror) reconcile(request reconcile.Request) (reconcile
// If the version of the Ceph monitor differs from the CephCluster CR image version we assume
// the cluster is being upgraded. So the controller will just wait for the upgrade to finish and
// then versions should match. Obviously using the cmd reporter job adds up to the deployment time
if !reflect.DeepEqual(runningCephVersion, desiredCephVersion) {
if !reflect.DeepEqual(*runningCephVersion, *desiredCephVersion) {
// Upgrade is in progress, let's wait for the mons to be done
return opcontroller.WaitForRequeueIfCephClusterIsUpgrading,
opcontroller.ErrorCephUpgradingRequeue(desiredCephVersion, runningCephVersion)
+5 -2
View File
@@ -743,8 +743,11 @@ func ConfigureExternalMetricsEndpoint(ctx *clusterd.Context, monitoringSpec ceph
}
// If endpoints are identical there is nothing to do
if reflect.DeepEqual(currentEndpoints, endpoint) {
return nil
// First check for nil pointers otherwise dereferencing a nil pointer will cause a panic
if endpoint != nil && currentEndpoints != nil {
if reflect.DeepEqual(*currentEndpoints, *endpoint) {
return nil
}
}
logger.Debugf("diff between current endpoint and newly generated one: %v \n", cmp.Diff(currentEndpoints, endpoint, cmp.Comparer(func(x, y resource.Quantity) bool { return x.Cmp(y) == 0 })))
+1 -1
View File
@@ -302,7 +302,7 @@ func (r *ReconcileCephFilesystem) reconcile(request reconcile.Request) (reconcil
// If the version of the Ceph monitor differs from the CephCluster CR image version we assume
// the cluster is being upgraded. So the controller will just wait for the upgrade to finish and
// then versions should match. Obviously using the cmd reporter job adds up to the deployment time
if !reflect.DeepEqual(runningCephVersion, desiredCephVersion) {
if !reflect.DeepEqual(*runningCephVersion, *desiredCephVersion) {
// Upgrade is in progress, let's wait for the mons to be done
return opcontroller.WaitForRequeueIfCephClusterIsUpgrading,
opcontroller.ErrorCephUpgradingRequeue(desiredCephVersion, runningCephVersion)
+1 -1
View File
@@ -195,7 +195,7 @@ func (r *ReconcileFilesystemMirror) reconcile(request reconcile.Request) (reconc
// If the version of the Ceph monitor differs from the CephCluster CR image version we assume
// the cluster is being upgraded. So the controller will just wait for the upgrade to finish and
// then versions should match. Obviously using the cmd reporter job adds up to the deployment time
if !reflect.DeepEqual(runningCephVersion, desiredCephVersion) {
if !reflect.DeepEqual(*runningCephVersion, *desiredCephVersion) {
// Upgrade is in progress, let's wait for the mons to be done
return opcontroller.WaitForRequeueIfCephClusterIsUpgrading,
opcontroller.ErrorCephUpgradingRequeue(desiredCephVersion, runningCephVersion)
+1 -1
View File
@@ -245,7 +245,7 @@ func (r *ReconcileCephNFS) reconcile(request reconcile.Request) (reconcile.Resul
// If the version of the Ceph monitor differs from the CephCluster CR image version we assume
// the cluster is being upgraded. So the controller will just wait for the upgrade to finish and
// then versions should match. Obviously using the cmd reporter job adds up to the deployment time
if !reflect.DeepEqual(runningCephVersion, desiredCephVersion) {
if !reflect.DeepEqual(*runningCephVersion, *desiredCephVersion) {
// Upgrade is in progress, let's wait for the mons to be done
return opcontroller.WaitForRequeueIfCephClusterIsUpgrading,
opcontroller.ErrorCephUpgradingRequeue(desiredCephVersion, runningCephVersion)
+1 -1
View File
@@ -312,7 +312,7 @@ func (r *ReconcileCephObjectStore) reconcile(request reconcile.Request) (reconci
// If the version of the Ceph monitor differs from the CephCluster CR image version we assume
// the cluster is being upgraded. So the controller will just wait for the upgrade to finish and
// then versions should match. Obviously using the cmd reporter job adds up to the deployment time
if !reflect.DeepEqual(runningCephVersion, desiredCephVersion) {
if !reflect.DeepEqual(*runningCephVersion, *desiredCephVersion) {
// Upgrade is in progress, let's wait for the mons to be done
return opcontroller.WaitForRequeueIfCephClusterIsUpgrading,
cephObjectStore,
@@ -21,6 +21,7 @@ import (
"context"
"net/http"
"os"
"reflect"
"testing"
"time"
@@ -745,3 +746,48 @@ func TestCephObjectStoreControllerMultisite(t *testing.T) {
assert.True(t, calledCommitConfigChanges)
})
}
func TestDiffVersions(t *testing.T) {
executor := &exectest.MockExecutor{
MockExecuteCommandWithOutput: func(command string, args ...string) (string, error) {
if args[0] == "versions" {
return `{
"mon": {
"ceph version 17.0.0-9718-g4ff72306 (4ff723061fc15c803dcf6556d02f56bdf56de5fa) quincy (dev)": 3
},
"mgr": {
"ceph version 17.0.0-9718-g4ff72306 (4ff723061fc15c803dcf6556d02f56bdf56de5fa) quincy (dev)": 1
},
"osd": {
"ceph version 17.0.0-9718-g4ff72306 (4ff723061fc15c803dcf6556d02f56bdf56de5fa) quincy (dev)": 3
},
"mds": {
"ceph version 17.0.0-9718-g4ff72306 (4ff723061fc15c803dcf6556d02f56bdf56de5fa) quincy (dev)": 2
},
"rgw": {
"ceph version 17.0.0-9718-g4ff72306 (4ff723061fc15c803dcf6556d02f56bdf56de5fa) quincy (dev)": 1
},
"overall": {
"ceph version 17.0.0-9718-g4ff72306 (4ff723061fc15c803dcf6556d02f56bdf56de5fa) quincy (dev)": 10
}
}`, nil
}
return "", errors.Errorf("unknown command %s %v", command, args)
},
}
c := &clusterd.Context{Executor: executor}
// desiredCephVersion comes from DetectCephVersion() (ceph --version) which uses ExtractCephVersion()
desiredCephVersion, err := cephver.ExtractCephVersion("ceph version 17.0.0-9718-g4ff72306 (4ff723061fc15c803dcf6556d02f56bdf56de5fa) quincy (dev)")
assert.NoError(t, err)
// runningCephVersion comes from LeastUptodateDaemonVersion()
runningCephVersion, err := client.LeastUptodateDaemonVersion(c, &client.ClusterInfo{Context: context.TODO()}, "mon")
assert.NoError(t, err)
// Compares the pointer's address with the struct so it's wrong
assert.False(t, reflect.DeepEqual(runningCephVersion, desiredCephVersion))
// Compares the actual value of the pointer by dereferencing the pointer
assert.True(t, reflect.DeepEqual(runningCephVersion, *desiredCephVersion))
}