Skip to content

Commit

Permalink
ceph: add missing spec to the object context
Browse files Browse the repository at this point in the history
The CephClusterSpec was missing from the object context, so the check
for the network provider in RunAdminCommandNoMultisite() was not
discovering the network property correctly.

Signed-off-by: Sébastien Han <seb@redhat.com>
  • Loading branch information
leseb committed Jul 12, 2021
1 parent fa14361 commit ad54ed8
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
43 changes: 43 additions & 0 deletions pkg/operator/ceph/object/admin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,14 @@ package object
import (
"encoding/json"
"testing"
"time"

v1 "github.com/rook/rook/pkg/apis/ceph.rook.io/v1"
"github.com/rook/rook/pkg/clusterd"
"github.com/rook/rook/pkg/daemon/ceph/client"
"github.com/rook/rook/pkg/operator/test"
"github.com/rook/rook/pkg/util/exec"
exectest "github.com/rook/rook/pkg/util/exec/test"
"github.com/stretchr/testify/assert"
)

Expand Down Expand Up @@ -115,3 +122,39 @@ this line can't be parsed as json
}
]`, match)
}

func TestRunAdminCommandNoMultisite(t *testing.T) {
objContext := &Context{
Context: &clusterd.Context{RemoteExecutor: exec.RemotePodCommandExecutor{ClientSet: test.New(t, 3)}},
clusterInfo: client.AdminClusterInfo("mycluster"),
}

t.Run("no network provider - we run the radosgw-admin command from the operator", func(t *testing.T) {
executor := &exectest.MockExecutor{
MockExecuteCommandWithTimeout: func(timeout time.Duration, command string, args ...string) (string, error) {
if args[0] == "zone" {
return `{
"id": "237e6250-5f7d-4b85-9359-8cb2b1848507",
"name": "realm-a",
"current_period": "df665ecb-1762-47a9-9c66-f938d251c02a",
"epoch": 2
}`, nil
}
return "", nil
},
}

objContext.Context.Executor = executor
_, err := RunAdminCommandNoMultisite(objContext, true, []string{"zone", "get"}...)
assert.NoError(t, err)
})

t.Run("with multus - we use the remote executor", func(t *testing.T) {
objContext.CephClusterSpec = v1.ClusterSpec{Network: v1.NetworkSpec{Provider: "multus"}}
_, err := RunAdminCommandNoMultisite(objContext, true, []string{"zone", "get"}...)
assert.Error(t, err)

// This is not the best but it shows we go through the right codepath
assert.EqualError(t, err, "no pods found with selector \"rook-ceph-mgr\"")
})
}
5 changes: 5 additions & 0 deletions pkg/operator/ceph/object/user/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,11 @@ func (r *ReconcileObjectStoreUser) initializeObjectStoreContext(u *cephv1.CephOb
if err != nil {
return errors.Wrapf(err, "Multisite failed to set on object context for object store user")
}

// The object store context needs the CephCluster spec to read networkinfo
// Otherwise GetAdminOPSUserCredentials() will fail detecting the network provider when running RunAdminCommandNoMultisite()
objContext.CephClusterSpec = *r.cephClusterSpec

opsContext, err := object.NewMultisiteAdminOpsContext(objContext, &store.Spec)
if err != nil {
return errors.Wrap(err, "failed to initialized rgw admin ops client api")
Expand Down

0 comments on commit ad54ed8

Please sign in to comment.