Skip to content

Commit

Permalink
core: add ceph daemon command support
Browse files Browse the repository at this point in the history
adding `ceph daemon *` command support

Signed-off-by: subhamkrai <srai@redhat.com>
  • Loading branch information
subhamkrai committed Apr 24, 2024
1 parent 697617a commit 811456f
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 8 deletions.
12 changes: 11 additions & 1 deletion .github/workflows/go-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,16 @@ jobs:
set -ex
kubectl rook-ceph ceph status
- name: Ceph daemon
run: |
set -ex
kubectl rook-ceph ceph daemon mon.a dump_historic_ops
- name: Ceph status using context
run: |
set -ex
kubectl rook-ceph --context=$(kubectl config current-context) ceph status
- name: Rados df using context
run: |
set -ex
Expand Down Expand Up @@ -215,6 +220,11 @@ jobs:
set -ex
kubectl rook-ceph --operator-namespace test-operator -n test-cluster ceph status
- name: Ceph daemon
run: |
set -ex
kubectl rook-ceph --operator-namespace test-operator -n test-cluster ceph daemon osd.0 dump_historic_ops
- name: Rados df
run: |
set -ex
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,12 @@ These are args currently supported:
kubectl rook-ceph --context=$(kubectl config current-context) mons
```


### Commands

- `ceph <args>` : Run a Ceph CLI command. Supports any arguments the `ceph` command supports. See [Ceph docs](https://docs.ceph.com/en/pacific/start/intro/) for more.

- `ceph daemon <daemon.id> <args>`: Run a Ceph daemon command by connecting to its admin socket.

- `rados <args>` : 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.

- `rbd <args>` : Call a 'rbd' CLI command with arbitrary args
Expand Down Expand Up @@ -92,6 +93,7 @@ These are args currently supported:
Visit docs below for complete details about each command and their flags uses.

1. [Running ceph commands](docs/ceph.md)
1. [Running ceph daemon commands](docs/ceph.md#Daemon)
1. [Running rbd commands](docs/rbd.md)
1. [Get mon endpoints](docs/mons.md#print-mon-endpoints)
1. [Get cluster health status](docs/health.md)
Expand All @@ -107,7 +109,7 @@ Visit docs below for complete details about each command and their flags uses.
1. [Disaster Recovery](docs/dr-health.md)
1. [Restore deleted CRs](docs/crd.md)
1. [Destroy cluster](docs/destroy-cluster.md)
2. [Running rados commands](docs/rados.md)
1. [Running rados commands](docs/rados.md)

## Examples

Expand Down
29 changes: 26 additions & 3 deletions cmd/commands/ceph.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ limitations under the License.
package command

import (
"fmt"
"strings"

"github.com/rook/kubectl-rook-ceph/pkg/exec"
"github.com/rook/kubectl-rook-ceph/pkg/logging"
"github.com/spf13/cobra"
Expand All @@ -33,9 +36,29 @@ var CephCmd = &cobra.Command{
},
Run: func(cmd *cobra.Command, args []string) {
logging.Info("running 'ceph' command with args: %v", args)
_, err := exec.RunCommandInOperatorPod(cmd.Context(), clientSets, cmd.Use, args, operatorNamespace, cephClusterNamespace, false)
if err != nil {
logging.Fatal(err)
if args[0] == "daemon" {
if len(args) < 2 {
logging.Fatal(fmt.Errorf("too few arguments to run the 'ceph daemon' command"))
}
cephDaemonNameAndID := splitCephDaemonNameAndID(args[1])
_, err := exec.RunCommandInLabeledPod(cmd.Context(), clientSets, fmt.Sprintf("%s=%s", cephDaemonNameAndID[0], cephDaemonNameAndID[1]), cephDaemonNameAndID[0], cmd.Use, args, cephClusterNamespace, false)
if err != nil {
logging.Fatal(err)
}

} else {
_, err := exec.RunCommandInOperatorPod(cmd.Context(), clientSets, cmd.Use, args, operatorNamespace, cephClusterNamespace, false)
if err != nil {
logging.Fatal(err)
}
}
},
}

// splitCephDaemonNameAndID splits the arg based on '.' so that we use it with label, example osd.0 to osd and 0
func splitCephDaemonNameAndID(args string) []string {
if !strings.Contains(args, ".") {
logging.Fatal(fmt.Errorf("Invalid argument to 'ceph daemon' command: %v. The arg should be in the format of '<daemon.id>'", args))
}
return strings.Split(args, ".")
}
30 changes: 30 additions & 0 deletions cmd/commands/ceph_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
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 (
"testing"

"github.com/stretchr/testify/assert"
)

func TestSplitCephDaemonNameAndID(t *testing.T) {
daemon := "osd.0"
cephDaemonNameAndID := splitCephDaemonNameAndID(daemon)
assert.Equal(t, cephDaemonNameAndID[0], "osd")
assert.Equal(t, cephDaemonNameAndID[1], "0")
}
15 changes: 15 additions & 0 deletions docs/ceph.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,18 @@ kubectl rook-ceph ceph status --format json-pretty
# "progress_events": {}
# }
```

## Daemon

Run the Ceph daemon command by connecting to its admin socket.

```bash
kubectl rook-ceph ceph daemon osd.0 dump_historic_ops

Info: running 'ceph' command with args: [daemon osd.0 dump_historic_ops]
{
"size": 20,
"duration": 600,
"ops": []
}
```
8 changes: 6 additions & 2 deletions pkg/exec/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,12 @@ func execCmdInPod(ctx context.Context, clientsets *k8sutil.Clientsets,

if containerName == "rook-ceph-tools" {
cmd = append(cmd, "--connect-timeout=10")
} else if cmd[0] == "ceph" && args[0] != "daemon" {
cmd = append(cmd, "--connect-timeout=10", fmt.Sprintf("--conf=/var/lib/rook/%s/%s.config", clusterNamespace, clusterNamespace))
} else if cmd[0] == "ceph" {
if len(cmd) > 1 && cmd[1] == "daemon" {
cmd = append(cmd, "--connect-timeout=10")
} else {
cmd = append(cmd, "--connect-timeout=10", fmt.Sprintf("--conf=/var/lib/rook/%s/%s.config", clusterNamespace, clusterNamespace))
}
} else if cmd[0] == "rbd" {
cmd = append(cmd, fmt.Sprintf("--conf=/var/lib/rook/%s/%s.config", clusterNamespace, clusterNamespace))
} else if cmd[0] == "rados" {
Expand Down

0 comments on commit 811456f

Please sign in to comment.