forked from red-hat-storage/odf-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request red-hat-storage#10 from yati1998/subvolume
cmd: add command to include subvolume operations
- Loading branch information
Showing
6 changed files
with
152 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.