forked from bakins/zfs-flex-volume
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
77 lines (65 loc) · 1.48 KB
/
main.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
package main
import (
"encoding/json"
"fmt"
"log"
"os"
"github.com/spf13/cobra"
)
type result struct {
Status string `json:"status"`
Message string `json:"message,omitempty"`
Device string `json:"device,omitempty"`
VolumeName string `json:"volumeName,omitempty"`
Attached bool `json:"attached,omitempty"`
}
type params struct {
Dataset string `json:"dataset"`
Compression string `json:"compression"`
Quota string `json:"quota"`
Reservation string `json:"reservation"`
}
func (r result) emit(rc int, message string) {
out := os.Stderr
switch rc {
case 0:
r.Status = "Success"
out = os.Stdout
default:
r.Status = "Failed"
}
r.Message = message
enc := json.NewEncoder(out)
enc.Encode(&r)
os.Exit(rc)
}
func (r result) error(err error) {
out := os.Stderr
r.Status = "Failed"
r.Message = err.Error()
enc := json.NewEncoder(out)
enc.Encode(&r)
os.Exit(-1)
}
func helpCmd(cmd *cobra.Command, args []string) {
cmd.Help()
}
var rootCmd = &cobra.Command{
Use: "zfs-flex-volume",
Short: "Kubernetes Flex Volume Driver for ZFS",
Run: helpCmd,
}
func init() {
rootCmd.PersistentFlags().StringP("parent", "", "k8s/volumes", "parent ZFS dataset")
}
func getParent() string {
return rootCmd.PersistentFlags().Lookup("parent").Value.String()
}
func notSupported(cmd *cobra.Command, args []string) {
fmt.Println(`{ "status": "Not supported" }`)
}
func main() {
if err := rootCmd.Execute(); err != nil {
log.Fatalf("root command failed: %v", err)
}
}