@@ -37,7 +37,8 @@ import (
37
37
const XFS = "xfs"
38
38
39
39
var (
40
- force = false
40
+ force = false
41
+ unrelease = false
41
42
)
42
43
43
44
var formatDrivesCmd = & cobra.Command {
@@ -57,8 +58,8 @@ $ kubectl direct-csi drives format --nodes=directcsi-1
57
58
# Format all drives based on the access-tier set [hot|cold|warm]
58
59
$ kubectl direct-csi drives format --access-tier=hot
59
60
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
62
63
63
64
# Combine multiple parameters using multi-arg
64
65
$ 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
75
76
func init () {
76
77
formatDrivesCmd .PersistentFlags ().StringSliceVarP (& drives , "drives" , "d" , drives , "glog selector for drive paths" )
77
78
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 " )
79
80
formatDrivesCmd .PersistentFlags ().BoolVarP (& all , "all" , "a" , all , "format all available drives" )
80
81
81
82
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 {
92
93
}
93
94
}
94
95
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
-
108
96
utils .Init ()
109
97
110
98
directClient := utils .GetDirectCSIClient ()
@@ -160,9 +148,9 @@ func formatDrives(ctx context.Context, args []string) error {
160
148
}
161
149
162
150
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 " ))
166
154
continue
167
155
}
168
156
d .Status .DriveStatus = directcsi .DriveStatusAvailable
0 commit comments