diff --git a/.github/workflows/go-test.yaml b/.github/workflows/go-test.yaml index dc99dc50..fcc4aad1 100644 --- a/.github/workflows/go-test.yaml +++ b/.github/workflows/go-test.yaml @@ -67,6 +67,11 @@ jobs: set -ex kubectl rook-ceph --context=$(kubectl config current-context) rados df + - name: radosgw-admin create user + run: | + set -ex + kubectl rook-ceph radosgw-admin user create --display-name="johnny rotten" --uid=johnny + - name: Mon restore run: | set -ex @@ -238,6 +243,11 @@ jobs: set -ex kubectl rook-ceph --operator-namespace test-operator -n test-cluster rados df + - name: radosgw-admin create user + run: | + set -ex + kubectl rook-ceph --operator-namespace test-operator -n test-cluster radosgw-admin user create --display-name="johnny rotten" --uid=johnny + - name: Ceph status using context run: | set -ex diff --git a/README.md b/README.md index 3cb10b9d..0746e432 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,8 @@ These are args currently supported: - `rados ` : Run a Rados CLI command. Supports any arguments the `rados` command supports. See [Rados docs](https://docs.ceph.com/en/latest/man/8/rados/) for more. +- `radosgw-admin ` : Run an RGW CLI command. Supports any arguments the `radosgw-admin` command supports. See the [radosgw-admin docs](https://docs.ceph.com/en/latest/man/8/radosgw-admin/) for more. + - `rbd ` : Call a 'rbd' CLI command with arbitrary args - `mons` : Print mon endpoints diff --git a/cmd/commands/radosgw.go b/cmd/commands/radosgw.go new file mode 100644 index 00000000..16aa3c2d --- /dev/null +++ b/cmd/commands/radosgw.go @@ -0,0 +1,42 @@ +/* +Copyright 2024 The Rook Authors. All rights reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +*/ + +package command + +import ( + "github.com/rook/kubectl-rook-ceph/pkg/exec" + "github.com/rook/kubectl-rook-ceph/pkg/logging" + "github.com/spf13/cobra" +) + +// RadosgwCmd represents the radosgw command +var RadosgwCmd = &cobra.Command{ + Use: "radosgw-admin", + Short: "call a 'radosgw-admin' CLI command", + DisableFlagParsing: true, + Args: cobra.MinimumNArgs(1), + PreRun: func(cmd *cobra.Command, args []string) { + verifyOperatorPodIsRunning(cmd.Context(), clientSets) + }, + Run: func(cmd *cobra.Command, args []string) { + logging.Info("running 'radosgw-admin' command with args: %v", args) + _, err := exec.RunCommandInOperatorPod(cmd.Context(), clientSets, cmd.Use, args, operatorNamespace, cephClusterNamespace, false) + if err != nil { + logging.Fatal(err) + } + }, +} diff --git a/cmd/main.go b/cmd/main.go index a965bba9..a5ad9270 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -43,5 +43,6 @@ func addcommands() { command.SubvolumeCmd, command.RadosCmd, command.FlattenRBDPVCCmd, + command.RadosgwCmd, ) } diff --git a/docs/radosgw-admin.md b/docs/radosgw-admin.md new file mode 100644 index 00000000..cc055ab0 --- /dev/null +++ b/docs/radosgw-admin.md @@ -0,0 +1,18 @@ +# radosgw-admin + +This runs any radosgw-admin CLI command with arbitrary args. + +## Examples + +```bash +kubectl rook-ceph radosgw-admin user create --display-name="my user" --uid=myuser + +# Info: running 'radosgw-admin' command with args: [user create --display-name=my-user --uid=myuser] +# { +# "user_id": "myuser", +# "display_name": "my user", +# ... +# ... +# ... +# } +``` diff --git a/pkg/exec/exec.go b/pkg/exec/exec.go index 19b3dd19..10d4c13d 100644 --- a/pkg/exec/exec.go +++ b/pkg/exec/exec.go @@ -136,6 +136,8 @@ func execCmdInPod(ctx context.Context, clientsets *k8sutil.Clientsets, cmd = append(cmd, fmt.Sprintf("--conf=/var/lib/rook/%s/%s.config", clusterNamespace, clusterNamespace)) } else if cmd[0] == "rados" { cmd = append(cmd, fmt.Sprintf("--conf=/var/lib/rook/%s/%s.config", clusterNamespace, clusterNamespace)) + } else if cmd[0] == "radosgw-admin" { + cmd = append(cmd, fmt.Sprintf("--conf=/var/lib/rook/%s/%s.config", clusterNamespace, clusterNamespace)) } // Prepare the API URL used to execute another process within the Pod. In