Skip to content

Commit 7722967

Browse files
Praveenrajmaniwlan0
authored andcommitted
add flag to drives format command
Signed-off-by: Praveenrajmani <praveen@minio.io>
1 parent 56a5d4b commit 7722967

File tree

1 file changed

+8
-20
lines changed

1 file changed

+8
-20
lines changed

cmd/kubectl-direct_csi/drives_format.go

+8-20
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ import (
3737
const XFS = "xfs"
3838

3939
var (
40-
force = false
40+
force = false
41+
unrelease = false
4142
)
4243

4344
var formatDrivesCmd = &cobra.Command{
@@ -57,8 +58,8 @@ $ kubectl direct-csi drives format --nodes=directcsi-1
5758
# Format all drives based on the access-tier set [hot|cold|warm]
5859
$ kubectl direct-csi drives format --access-tier=hot
5960
60-
# Format all 'released' drives
61-
$ kubectl direct-csi drives format --status=released
61+
# Format and unrelease all 'released' drives
62+
$ kubectl direct-csi drives format --unrelease --all
6263
6364
# Combine multiple parameters using multi-arg
6465
$ kubectl direct-csi drives format --nodes=directcsi-1 --nodes=othernode-2 --status=available
@@ -75,7 +76,7 @@ $ kubectl direct-csi drives format --nodes=directcsi-1,othernode-2 --status=avai
7576
func init() {
7677
formatDrivesCmd.PersistentFlags().StringSliceVarP(&drives, "drives", "d", drives, "glog selector for drive paths")
7778
formatDrivesCmd.PersistentFlags().StringSliceVarP(&nodes, "nodes", "n", nodes, "glob selector for node names")
78-
formatDrivesCmd.PersistentFlags().StringSliceVarP(&status, "status", "s", status, "glob prefix match for drive status")
79+
formatDrivesCmd.PersistentFlags().BoolVarP(&unrelease, "unrelease", "u", unrelease, "unrelease drives")
7980
formatDrivesCmd.PersistentFlags().BoolVarP(&all, "all", "a", all, "format all available drives")
8081

8182
formatDrivesCmd.PersistentFlags().BoolVarP(&force, "force", "f", force, "force format a drive even if a FS is already present")
@@ -92,19 +93,6 @@ func formatDrives(ctx context.Context, args []string) error {
9293
}
9394
}
9495

95-
validateStatus := func(status []string) error {
96-
for _, s := range status {
97-
if strings.ToLower(s) != strings.ToLower(directcsi.DriveStatusReleased) {
98-
return fmt.Errorf("only 'released' drives are allowed to be formatted")
99-
}
100-
}
101-
return nil
102-
}
103-
104-
if err := validateStatus(status); err != nil {
105-
return err
106-
}
107-
10896
utils.Init()
10997

11098
directClient := utils.GetDirectCSIClient()
@@ -160,9 +148,9 @@ func formatDrives(ctx context.Context, args []string) error {
160148
}
161149

162150
if d.Status.DriveStatus == directcsi.DriveStatusReleased {
163-
driveAddr := fmt.Sprintf("%s:/dev/%s", d.Status.NodeName, driveName(d.Status.Path))
164-
if !force {
165-
glog.Errorf("%s is in 'released' state. Use %s to overwrite and make it 'ready'", utils.Bold(driveAddr), utils.Bold("--force"))
151+
if !unrelease {
152+
driveAddr := fmt.Sprintf("%s:/dev/%s", d.Status.NodeName, driveName(d.Status.Path))
153+
glog.Errorf("%s is in 'released' state. Use %s to overwrite and make it 'ready'", utils.Bold(driveAddr), utils.Bold("--unrelease"))
166154
continue
167155
}
168156
d.Status.DriveStatus = directcsi.DriveStatusAvailable

0 commit comments

Comments
 (0)