-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.go
More file actions
137 lines (123 loc) · 3.04 KB
/
main.go
File metadata and controls
137 lines (123 loc) · 3.04 KB
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
package main
import (
"os"
log "github.com/Sirupsen/logrus"
"github.com/codegangsta/cli"
"github.com/flexiant/kdeploy/delete"
"github.com/flexiant/kdeploy/deploy"
"github.com/flexiant/kdeploy/list"
"github.com/flexiant/kdeploy/show"
"github.com/flexiant/kdeploy/upgrade"
"github.com/flexiant/kdeploy/utils"
)
func cmdNotFound(c *cli.Context, command string) {
log.Fatalf(
"%s: '%s' is not a %s command. See '%s --help'.",
c.App.Name,
command,
c.App.Name,
c.App.Name,
)
}
func prepareFlags(c *cli.Context) error {
if c.Bool("debug") {
os.Setenv("DEBUG", "1")
log.SetOutput(os.Stderr)
log.SetLevel(log.DebugLevel)
}
// Initialize cached config
utils.InitializeConfig(c)
return nil
}
func main() {
app := cli.NewApp()
app.Name = "kdeploy"
app.Author = "Concerto Contributors"
app.Email = "https://github.com/flexiant/kdeploy"
app.Usage = "Deploys Kubeware in kubernetes clusters"
app.Version = utils.VERSION
app.CommandNotFound = cmdNotFound
app.Before = prepareFlags
config := utils.PreReadConfig()
// TODO we shouldn't be pre-reading, since it fills default values for flags.
// If someone uses a config file as cmd argument, some of the values could be
// overwritten
app.Flags = []cli.Flag{
cli.BoolFlag{
Name: "debug, D",
Usage: "Enable debug mode",
},
cli.BoolFlag{
Name: "insecure",
Usage: "Do not validate server certificates",
},
cli.StringFlag{
EnvVar: "KUBERNETES_CA_CERT",
Name: "ca-cert",
Value: config.Connection.CACert,
Usage: "CA to verify remote connections",
},
cli.StringFlag{
EnvVar: "KUBERNETES_CLIENT_CERT",
Name: "client-cert",
Value: config.Connection.Cert,
Usage: "Client cert to use for Kubernetes",
},
cli.StringFlag{
EnvVar: "KUBERNETES_CLIENT_KEY",
Name: "client-key",
Value: config.Connection.Key,
Usage: "Private key used in client Kubernetes auth",
},
cli.StringFlag{
EnvVar: "KUBERNETES_ENDPOINT",
Name: "kubernetes-endpoint",
Value: config.Connection.APIEndpoint,
Usage: "Kubernetes Endpoint",
},
cli.StringFlag{
EnvVar: "KUBECONFIG",
Name: "kubeconfig",
Value: config.Path,
Usage: "Kubeconfig client file",
},
}
app.Commands = []cli.Command{
{
Name: "deploy",
Usage: "Deploys a Kubeware",
Before: deploy.PrepareFlags,
Action: deploy.CmdDeploy,
Flags: deploy.Flags(),
},
{
Name: "delete",
Usage: "Deletes a Kubeware",
Before: delete.PrepareFlags,
Action: delete.CmdDelete,
Flags: delete.Flags(),
},
{
Name: "list",
Usage: "List's Kubewares deployed",
Before: list.PrepareFlags,
Action: list.CmdList,
Flags: list.Flags(),
},
{
Name: "show",
Usage: "Shows how a Kubeware would be created once resolved with the indicated attributes",
Before: show.PrepareFlags,
Action: show.CmdShow,
Flags: show.Flags(),
},
{
Name: "upgrade",
Usage: "Upgrades a Kubeware to a new version",
Before: upgrade.PrepareFlags,
Action: upgrade.CmdUpgrade,
Flags: upgrade.Flags(),
},
}
app.Run(os.Args)
}