Skip to content

Commit

Permalink
Merge pull request red-hat-storage#10 from yati1998/subvolume
Browse files Browse the repository at this point in the history
cmd: add command to include subvolume operations
  • Loading branch information
openshift-merge-bot[bot] authored Dec 11, 2023
2 parents 4c0b779 + c0bb409 commit 8dad004
Show file tree
Hide file tree
Showing 6 changed files with 152 additions and 52 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ The ODF CLI tool provides configuration and troubleshooting commands for OpenShi
More information about the ceph subsystems can be found [here](https://docs.ceph.com/en/latest/rados/troubleshooting/log-and-debug/#ceph-subsystems)
- `odf ceph purge-osd <ID>`: Permanently remove an OSD from the cluster.
- `odf help` : Display help text
- `odf subvolume ls`: Display all the subvolumes
- `odf subvolume delete <subvolume> <filesystem> <subvolumegroup>`: Deletes the stale subvolumes

## Documentation

Expand Down
2 changes: 2 additions & 0 deletions cmd/odf/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"github.com/red-hat-storage/odf-cli/cmd/odf/get"
"github.com/red-hat-storage/odf-cli/cmd/odf/root"
"github.com/red-hat-storage/odf-cli/cmd/odf/set"
"github.com/red-hat-storage/odf-cli/cmd/odf/subvolume"
"github.com/rook/kubectl-rook-ceph/pkg/logging"
)

Expand All @@ -21,5 +22,6 @@ func addcommands() {
set.SetCmd,
get.GetCmd,
rook.CephCmd,
subvolume.SubvolumeCmd,
)
}
58 changes: 58 additions & 0 deletions cmd/odf/subvolume/subvolume.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
Copyright 2023 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 subvolume

import (
"github.com/red-hat-storage/odf-cli/cmd/odf/root"
subvolume "github.com/rook/kubectl-rook-ceph/pkg/filesystem"
"github.com/spf13/cobra"
)

var SubvolumeCmd = &cobra.Command{
Use: "subvolume",
Short: "Manages subvolumes",
Args: cobra.ExactArgs(1),
}

var listCmd = &cobra.Command{
Use: "ls",
Short: "Print the list of stale subvolumes no longer in use.",
Run: func(cmd *cobra.Command, args []string) {
ctx := cmd.Context()
clientsets := root.GetClientsets(ctx)
staleSubvol, _ := cmd.Flags().GetBool("stale")
subvolume.List(ctx, clientsets, root.OperatorNamespace, root.StorageClusterNamespace, staleSubvol)
},
}

var deleteCmd = &cobra.Command{
Use: "delete",
Short: "Deletes a stale subvolume",
DisableFlagParsing: true,
Args: cobra.ExactArgs(3),
Run: func(cmd *cobra.Command, args []string) {
ctx := cmd.Context()
clientsets := root.GetClientsets(ctx)
subList := args[0]
fs := args[1]
svg := args[2]
subvolume.Delete(ctx, clientsets, root.OperatorNamespace, root.StorageClusterNamespace, subList, fs, svg)
},
}

func init() {
SubvolumeCmd.AddCommand(listCmd)
SubvolumeCmd.PersistentFlags().Bool("stale", false, "Only list stale subvolumes")
SubvolumeCmd.AddCommand(deleteCmd)
}
54 changes: 54 additions & 0 deletions docs/subvolume.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Subvolume cleanup

The subvolume command is used to clean the stale subvolumes
which have no parent-pvc attached to them.
The command would list out all such subvolumes which needs to be removed.
This would consider all the cases where we can have stale subvolume
and delete them without impacting other resources and attached volumes.

The subvolume command supports the following sub commands:
* `ls` : [ls](#ls)
* `delete`: [delete](#delete)
*
## ls

This command will lists all the subvolumes. It also accepts the stale flag to check for stale subvolumes.
* `--stale`: lists only stale subvolumes

```bash
odf subvolume ls

# Filesystem Subvolume Subvolumegroup State
# ocs-storagecluster-cephfilesystem csi-vol-427774b4-340b-11ed-8d66-0242ac110004 csi
# ocs-storagecluster-cephfilesystem csi-vol-427774b4-340b-11ed-8d66-0242ac110005 csi
# ocs-storagecluster-cephfilesystem csi-vol-427774b4-340b-11ed-8d66-0242ac110006 csi
# ocs-storagecluster-cephfilesystem csi-vol-427774b4-340b-11ed-8d66-0242ac110007 stale
```

```bash
odf subvolume ls --stale

# Filesystem Subvolume Subvolumegroup State
# ocs-storagecluster-cephfilesystem csi-vol-427774b4-340b-11ed-8d66-0242ac110004 csi stale
# ocs-storagecluster-cephfilesystem csi-vol-427774b4-340b-11ed-8d66-0242ac110005 csi stale
```

## delete

This command deletes stale subvolumes after user's confirmation.
`delete <subvolumes> <filesystem> <subvolumegroup>`:
It will delete only the stale subvolumes to prevent any loss of data.
* subvolumes: comma-separated list of subvolumes of same filesystem and subvolumegroup.

```bash
odf subvolume delete csi-vol-427774b4-340b-11ed-8d66-0242ac110004 ocs-storagecluster csi

# Info: subvolume csi-vol-427774b4-340b-11ed-8d66-0242ac110004 deleted
```

```bash
odf subvolume delete csi-vol-427774b4-340b-11ed-8d66-0242ac110004,csi-vol-427774b4-340b-11ed-8d66-0242ac110005 ocs-storagecluster csi

# Info: subvolume csi-vol-427774b4-340b-11ed-8d66-0242ac110004 deleted
# Info: subvolume csi-vol-427774b4-340b-11ed-8d66-0242ac110004 deleted
```
34 changes: 17 additions & 17 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ go 1.21

require (
github.com/pkg/errors v0.9.1
github.com/rook/kubectl-rook-ceph v0.6.0
github.com/rook/rook v1.12.7
github.com/spf13/cobra v1.7.0
k8s.io/apimachinery v0.28.3
k8s.io/client-go v0.28.3
github.com/rook/kubectl-rook-ceph v0.6.1-0.20231211183203-70ede2704719
github.com/rook/rook v1.12.8
github.com/spf13/cobra v1.8.0
k8s.io/apimachinery v0.28.4
k8s.io/client-go v0.28.4
)

require (
Expand All @@ -21,7 +21,7 @@ require (
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
github.com/evanphx/json-patch/v5 v5.7.0 // indirect
github.com/fatih/color v1.15.0 // indirect
github.com/fatih/color v1.16.0 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/go-jose/go-jose/v3 v3.0.0 // indirect
github.com/go-logr/logr v1.2.4 // indirect
Expand Down Expand Up @@ -54,7 +54,7 @@ require (
github.com/libopenstorage/secrets v0.0.0-20231011182615-5f4b25ceede1 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
Expand All @@ -73,7 +73,7 @@ require (
golang.org/x/crypto v0.14.0 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/oauth2 v0.13.0 // indirect
golang.org/x/sys v0.13.0 // indirect
golang.org/x/sys v0.14.0 // indirect
golang.org/x/term v0.13.0 // indirect
golang.org/x/text v0.13.0 // indirect
golang.org/x/time v0.3.0 // indirect
Expand All @@ -83,7 +83,7 @@ require (
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/api v0.28.3 // indirect
k8s.io/api v0.28.4 // indirect
k8s.io/klog/v2 v2.100.1 // indirect
k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00 // indirect
k8s.io/utils v0.0.0-20230726121419-3b25d923346b // indirect
Expand All @@ -108,21 +108,21 @@ exclude (
k8s.io/client-go v1.5.0
k8s.io/client-go v1.5.1
k8s.io/client-go v1.5.2
k8s.io/client-go v2.0.0-alpha.1+incompatible
k8s.io/client-go v10.0.0+incompatible
k8s.io/client-go v11.0.0+incompatible
k8s.io/client-go v11.0.1-0.20190409021438-1a26190bd76a+incompatible
k8s.io/client-go v12.0.0+incompatible
k8s.io/client-go v2.0.0+incompatible
k8s.io/client-go v3.0.0-beta.0+incompatible
k8s.io/client-go v2.0.0-alpha.1+incompatible
k8s.io/client-go v3.0.0+incompatible
k8s.io/client-go v4.0.0-beta.0+incompatible
k8s.io/client-go v3.0.0-beta.0+incompatible
k8s.io/client-go v4.0.0+incompatible
k8s.io/client-go v4.0.0-beta.0+incompatible
k8s.io/client-go v5.0.0+incompatible
k8s.io/client-go v5.0.1+incompatible
k8s.io/client-go v6.0.0+incompatible
k8s.io/client-go v7.0.0+incompatible
k8s.io/client-go v8.0.0+incompatible
k8s.io/client-go v9.0.0-invalid+incompatible
k8s.io/client-go v9.0.0+incompatible
k8s.io/client-go v10.0.0+incompatible
k8s.io/client-go v11.0.0+incompatible
k8s.io/client-go v11.0.1-0.20190409021438-1a26190bd76a+incompatible
k8s.io/client-go v12.0.0+incompatible
k8s.io/client-go v9.0.0-invalid+incompatible
)
Loading

0 comments on commit 8dad004

Please sign in to comment.