forked from rexray/rexray
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmds_51_flexrex.go
105 lines (93 loc) · 2.48 KB
/
cmds_51_flexrex.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// +build !agent
// +build !controller
package cli
import (
"os"
"path"
"github.com/akutz/gotil"
"github.com/rexray/rexray/util"
"github.com/spf13/cobra"
apictx "github.com/rexray/rexray/libstorage/api/context"
)
func init() {
initCmdFuncs = append(initCmdFuncs, func(c *CLI) {
c.initFlexRexCmds()
c.initFlexRexFlags()
})
}
func (c *CLI) initFlexRexCmds() {
c.flexRexCmd = &cobra.Command{
Use: "flexrex",
Short: "The FlexVol REX-Ray plug-in manager",
Run: func(cmd *cobra.Command, args []string) {
cmd.Usage()
},
}
c.c.AddCommand(c.flexRexCmd)
c.flexRexInstallCmd = &cobra.Command{
Use: "install",
Short: "Install the FlexVol REX-Ray plug-in",
Run: func(cmd *cobra.Command, args []string) {
scriptPath := path.Join(
apictx.MustPathConfig(c.ctx).Home, c.scriptPath)
c.ctx.WithField("scriptPath", scriptPath).Debug(
"scripts dir path set")
if c.force {
os.RemoveAll(scriptPath)
}
fp := util.ScriptFilePath(c.ctx, "flexrex")
if !gotil.FileExists(fp) {
if _, err := c.installScripts(c.ctx, "flexrex"); err != nil {
c.ctx.Fatal(err)
}
}
err := os.MkdirAll(path.Dir(scriptPath), os.FileMode(0755))
if err != nil {
c.ctx.Fatal(err)
}
c.mustMarshalOutput(&scriptInfo{
Name: "flexrex",
Path: scriptPath,
Installed: true,
Modified: false,
}, os.Symlink(fp, scriptPath))
},
}
c.flexRexCmd.AddCommand(c.flexRexInstallCmd)
c.flexRexUninstallCmd = &cobra.Command{
Use: "uninstall",
Short: "Uninstall the FlexVol REX-Ray plug-in",
Run: func(cmd *cobra.Command, args []string) {
scriptPath := path.Join(
apictx.MustPathConfig(c.ctx).Home, c.scriptPath)
c.ctx.WithField("scriptPath", scriptPath).Debug(
"scripts dir path set")
c.mustMarshalOutput(
[]string{scriptPath},
os.RemoveAll(scriptPath))
},
}
c.flexRexCmd.AddCommand(c.flexRexUninstallCmd)
}
const (
defaultFlexRexPath = "/usr/libexec/kubernetes/kubelet-plugins" +
"/volume/exec/rexray~flexrex/flexrex"
)
func (c *CLI) initFlexRexFlags() {
c.flexRexInstallCmd.Flags().BoolVar(
&c.force,
"force",
false,
"A flag indicating whether to install the script even if it already "+
"exists at the specified path")
c.flexRexInstallCmd.Flags().StringVar(
&c.scriptPath,
"path",
defaultFlexRexPath,
"The absolute path to which the script should be installed")
c.flexRexUninstallCmd.Flags().StringVar(
&c.scriptPath,
"path",
defaultFlexRexPath,
"The absolute path of the script to uninstall")
}