ceph: update rgw ceph dashboard command
in the latest ceph releases, there are few changes in accessing the rgw ceph dashboard command. This commit updates the commands. old commands ``` $ ceph dashboard set-rgw-api-access-key <access_key> $ ceph dashboard set-rgw-api-secret-key <secret_key> ``` new commands ``` $ ceph dashboard set-rgw-api-access-key -i <file-containing-access-key> $ ceph dashboard set-rgw-api-secret-key -i <file-containing-secret-key> ``` Signed-off-by: subhamkrai <srai@redhat.com>
This commit is contained in:
1 parent
4eb08bb508
commit
bc48dad19a
2 files changed
+65
-5
No files matched your search
@@ -20,6 +20,7 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"syscall"
|
||||
@@ -29,6 +30,7 @@ import (
|
||||
cephv1 "github.com/rook/rook/pkg/apis/ceph.rook.io/v1"
|
||||
"github.com/rook/rook/pkg/clusterd"
|
||||
ceph "github.com/rook/rook/pkg/daemon/ceph/client"
|
||||
"github.com/rook/rook/pkg/operator/ceph/cluster/mgr"
|
||||
"github.com/rook/rook/pkg/operator/ceph/config"
|
||||
opcontroller "github.com/rook/rook/pkg/operator/ceph/controller"
|
||||
"github.com/rook/rook/pkg/operator/k8sutil"
|
||||
@@ -757,15 +759,43 @@ func enableRGWDashboard(context *Context) error {
|
||||
if err != nil || errCode != 0 {
|
||||
return errors.Wrapf(err, "failed to create user %q", DashboardUser)
|
||||
}
|
||||
args := []string{"dashboard", "set-rgw-api-access-key", *u.AccessKey}
|
||||
cephCmd := ceph.NewCephCommand(context.Context, context.clusterInfo, args)
|
||||
|
||||
var accessArgs, secretArgs []string
|
||||
var secretFile *os.File
|
||||
|
||||
// for latest Ceph versions
|
||||
if mgr.FileBasedPasswordSupported(context.clusterInfo) {
|
||||
accessFile, err := mgr.CreateTempPasswordFile(*u.AccessKey)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to create a temporary dashboard access-key file")
|
||||
}
|
||||
|
||||
accessArgs = []string{"dashboard", "set-rgw-api-access-key", "-i", accessFile.Name()}
|
||||
defer func() {
|
||||
if err := os.Remove(accessFile.Name()); err != nil {
|
||||
logger.Errorf("failed to clean up dashboard access-key file. %v", err)
|
||||
}
|
||||
}()
|
||||
|
||||
secretFile, err = mgr.CreateTempPasswordFile(*u.SecretKey)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to create a temporary dashboard secret-key file")
|
||||
}
|
||||
|
||||
secretArgs = []string{"dashboard", "set-rgw-api-secret-key", "-i", secretFile.Name()}
|
||||
} else {
|
||||
// for older Ceph versions
|
||||
accessArgs = []string{"dashboard", "set-rgw-api-access-key", *u.AccessKey}
|
||||
secretArgs = []string{"dashboard", "set-rgw-api-secret-key", *u.SecretKey}
|
||||
}
|
||||
|
||||
cephCmd := ceph.NewCephCommand(context.Context, context.clusterInfo, accessArgs)
|
||||
_, err = cephCmd.Run()
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to set user %q accesskey", DashboardUser)
|
||||
}
|
||||
|
||||
args = []string{"dashboard", "set-rgw-api-secret-key", *u.SecretKey}
|
||||
cephCmd = ceph.NewCephCommand(context.Context, context.clusterInfo, args)
|
||||
cephCmd = ceph.NewCephCommand(context.Context, context.clusterInfo, secretArgs)
|
||||
go func() {
|
||||
// Setting the dashboard api secret started hanging in some clusters
|
||||
// starting in ceph v15.2.8. We run it in a goroutine until the fix
|
||||
@@ -775,8 +805,15 @@ func enableRGWDashboard(context *Context) error {
|
||||
if err != nil {
|
||||
logger.Errorf("failed to set user %q secretkey. %v", DashboardUser, err)
|
||||
}
|
||||
if mgr.FileBasedPasswordSupported(context.clusterInfo) {
|
||||
if err := os.Remove(secretFile.Name()); err != nil {
|
||||
logger.Errorf("failed to clean up dashboard secret-key file. %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
logger.Info("done setting the dashboard api secret key")
|
||||
}()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ import (
|
||||
cephv1 "github.com/rook/rook/pkg/apis/ceph.rook.io/v1"
|
||||
"github.com/rook/rook/pkg/clusterd"
|
||||
"github.com/rook/rook/pkg/daemon/ceph/client"
|
||||
cephver "github.com/rook/rook/pkg/operator/ceph/version"
|
||||
"github.com/rook/rook/pkg/operator/k8sutil"
|
||||
exectest "github.com/rook/rook/pkg/util/exec/test"
|
||||
"github.com/stretchr/testify/assert"
|
||||
@@ -259,7 +260,9 @@ func TestDashboard(t *testing.T) {
|
||||
},
|
||||
}
|
||||
context := &clusterd.Context{Executor: executor}
|
||||
objContext := NewContext(context, &client.ClusterInfo{Namespace: "mycluster"}, storeName)
|
||||
objContext := NewContext(context, &client.ClusterInfo{Namespace: "mycluster",
|
||||
CephVersion: cephver.CephVersion{Major: 15, Minor: 2, Extra: 9}},
|
||||
storeName)
|
||||
checkdashboard, err := checkDashboardUser(objContext)
|
||||
assert.NoError(t, err)
|
||||
assert.False(t, checkdashboard)
|
||||
@@ -278,4 +281,24 @@ func TestDashboard(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
assert.True(t, checkdashboard)
|
||||
disableRGWDashboard(objContext)
|
||||
|
||||
context = &clusterd.Context{Executor: executor}
|
||||
objContext = NewContext(context, &client.ClusterInfo{Namespace: "mycluster",
|
||||
CephVersion: cephver.CephVersion{Major: 15, Minor: 2, Extra: 10}},
|
||||
storeName)
|
||||
err = enableRGWDashboard(objContext)
|
||||
assert.Nil(t, err)
|
||||
executor = &exectest.MockExecutor{
|
||||
MockExecuteCommandWithOutputFile: func(command, outfile string, args ...string) (string, error) {
|
||||
if args[0] == "dashboard" && args[1] == "get-rgw-api-access-key" {
|
||||
return access_key, nil
|
||||
}
|
||||
return "", nil
|
||||
},
|
||||
}
|
||||
objContext.Context.Executor = executor
|
||||
checkdashboard, err = checkDashboardUser(objContext)
|
||||
assert.NoError(t, err)
|
||||
assert.True(t, checkdashboard)
|
||||
disableRGWDashboard(objContext)
|
||||
}
|
||||
Reference in new issue
Block a user