forked from ipedrazas/drone-helm
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
109 lines (104 loc) · 2.53 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
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
package main
import (
"fmt"
"os"
"github.com/Sirupsen/logrus"
"github.com/joho/godotenv"
"github.com/urfave/cli"
)
var build = "0" // build number set at compile-time
func main() {
app := cli.NewApp()
app.Name = "helm plugin"
app.Usage = "helm plugin"
app.Action = run
app.Version = fmt.Sprintf("1.0.%s", build)
app.Flags = []cli.Flag{
cli.StringSliceFlag{
Name: "helm_command",
Usage: "add the command Helm has to execute",
EnvVar: "PLUGIN_HELM_COMMAND,HELM_COMMAND",
},
cli.StringFlag{
Name: "namespace",
Usage: "Kubernetes namespace",
EnvVar: "PLUGIN_NAMESPACE,NAMESPACE",
},
cli.StringFlag{
Name: "release",
Usage: "Kubernetes helm release",
EnvVar: "PLUGIN_RELEASE,RELEASE",
},
cli.StringFlag{
Name: "chart",
Usage: "Kubernetes helm release",
EnvVar: "PLUGIN_CHART,CHART",
},
cli.StringFlag{
Name: "values",
Usage: "Kubernetes helm release",
EnvVar: "PLUGIN_VALUES,VALUES",
},
cli.StringFlag{
Name: "values_files",
Usage: "Helm values override files",
EnvVar: "PLUGIN_VALUES_FILES,VALUES_FILES",
},
cli.BoolFlag{
Name: "skip_tls_verify",
Usage: "Skip TLS verification",
EnvVar: "PLUGIN_SKIP_TLS_VERIFY,SKIP_TLS_VERIFY",
},
cli.BoolFlag{
Name: "debug",
Usage: "Debug",
EnvVar: "PLUGIN_DEBUG,DEBUG",
},
cli.BoolFlag{
Name: "dry-run",
Usage: "Helm dry-run",
EnvVar: "PLUGIN_DRY_RUN,DRY_RUN",
},
cli.StringFlag{
Name: "prefix",
Usage: "Prefix for all the secrets",
EnvVar: "PLUGIN_PREFIX,PREFIX",
},
cli.StringFlag{
Name: "tiller-ns",
Usage: "Namespace to install Tiller",
EnvVar: "PLUGIN_TILLER_NS,TILLER_NS",
},
}
if err := app.Run(os.Args); err != nil {
logrus.Fatal(err)
}
}
func run(c *cli.Context) error {
if c.String("env-file") != "" {
_ = godotenv.Load(c.String("env-file"))
}
plugin := Plugin{
Config: Config{
APIServer: c.String("api_server"),
Token: c.String("token"),
HelmCommand: c.StringSlice("helm_command"),
Namespace: c.String("namespace"),
SkipTLSVerify: c.Bool("skip_tls_verify"),
Values: c.String("values"),
ValuesFiles: c.String("values_files"),
Release: c.String("release"),
Chart: c.String("chart"),
Debug: c.Bool("debug"),
DryRun: c.Bool("dry-run"),
Secrets: c.StringSlice("secrets"),
Prefix: c.String("prefix"),
TillerNs: c.String("tiller-ns"),
},
}
resolveSecrets(&plugin)
if plugin.Config.Debug {
plugin.debug()
}
return plugin.Exec()
}