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
@@ -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))
}