-
Notifications
You must be signed in to change notification settings - Fork 72
/
node_unpublish_volume.go
61 lines (47 loc) · 1.2 KB
/
node_unpublish_volume.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package cmd
import (
"context"
"fmt"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/container-storage-interface/spec/lib/go/csi"
)
var nodeUnpublishVolume struct {
targetPath string
}
var nodeUnpublishVolumeCmd = &cobra.Command{
Use: "unpublish",
Aliases: []string{"umount", "unmount"},
Short: `invokes the rpc "NodeUnpublishVolume"`,
Example: `
USAGE
csc node unpublish [flags] VOLUME_ID [VOLUME_ID...]
`,
Args: cobra.MinimumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
req := csi.NodeUnpublishVolumeRequest{
TargetPath: nodeUnpublishVolume.targetPath,
}
for i := range args {
ctx, cancel := context.WithTimeout(root.ctx, root.timeout)
defer cancel()
// Set the volume ID for the current request.
req.VolumeId = args[i]
log.WithField("request", req).Debug("mounting volume")
_, err := node.client.NodeUnpublishVolume(ctx, &req)
if err != nil {
return err
}
fmt.Println(args[i])
}
return nil
},
}
func init() {
nodeCmd.AddCommand(nodeUnpublishVolumeCmd)
nodeUnpublishVolumeCmd.Flags().StringVar(
&nodeUnpublishVolume.targetPath,
"target-path",
"",
"The path from which to unmount the volume")
}