forked from ipedrazas/drone-helm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
173 lines (168 loc) · 4.8 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
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
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: "kube-config",
Usage: "Kubernetes configuration file path",
EnvVar: "PLUGIN_KUBE_CONFIG,KUBE_CONFIG",
Value: "/root/.kube/config",
},
cli.StringFlag{
Name: "namespace",
Usage: "Kubernetes namespace",
EnvVar: "PLUGIN_NAMESPACE,NAMESPACE",
},
cli.StringFlag{
Name: "release",
Usage: "Kubernetes helm release",
EnvVar: "PLUGIN_RELEASE,RELEASE",
},
cli.StringSliceFlag{
Name: "helm_repos",
Usage: "Repos helm should add",
EnvVar: "PLUGIN_HELM_REPOS,HELM_REPOS",
},
cli.StringFlag{
Name: "chart",
Usage: "Kubernetes helm chart name",
EnvVar: "PLUGIN_CHART,CHART",
},
cli.StringFlag{
Name: "chart-version",
Usage: "specify the exact chart version to use. If this is not specified, the latest version is used",
EnvVar: "PLUGIN_CHART_VERSION,CHART_VERSION",
},
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",
},
cli.BoolFlag{
Name: "wait",
Usage: "if set, will wait until all Pods, PVCs, and Services are in a ready state before marking the release as successful.",
EnvVar: "PLUGIN_WAIT,WAIT",
},
cli.BoolFlag{
Name: "recreate-pods",
Usage: "performs pods restart for the resource if applicable",
EnvVar: "PLUGIN_RECREATE_PODS,RECREATE_PODS",
},
cli.BoolFlag{
Name: "upgrade",
Usage: "if set, will upgrade tiller to the latest version",
EnvVar: "PLUGIN_UPGRADE,UPGRADE",
},
cli.BoolFlag{
Name: "client-only",
Usage: "if set, Helm will use the canary tiller image",
EnvVar: "PLUGIN_CANARY_IMAGE,CANARY_IMAGE",
},
cli.BoolFlag{
Name: "canary-image",
Usage: "if set, it will initilises helm in the client side only",
EnvVar: "PLUGIN_CLIENT_ONLY,CLIENT_ONLY",
},
cli.BoolFlag{
Name: "reuse-values",
Usage: "when upgrading, reuse the last release's values, and merge in any new values",
EnvVar: "PLUGIN_REUSE_VALUES,REUSE_VALUES",
},
cli.StringFlag{
Name: "timeout",
Usage: "time in seconds to wait for any individual kubernetes operation (like Jobs for hooks) (default 300)",
EnvVar: "PLUGIN_TIMEOUT,TIMEOUT",
},
cli.BoolFlag{
Name: "force",
Usage: "force resource update through delete/recreate if needed",
EnvVar: "PLUGIN_FORCE,FORCE",
},
}
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"),
ServiceAccount: c.String("service-account"),
KubeConfig: c.String("kube-config"),
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"),
HelmRepos: c.StringSlice("helm_repos"),
Chart: c.String("chart"),
Version: c.String("chart-version"),
Debug: c.Bool("debug"),
DryRun: c.Bool("dry-run"),
Secrets: c.StringSlice("secrets"),
Prefix: c.String("prefix"),
TillerNs: c.String("tiller-ns"),
Wait: c.Bool("wait"),
RecreatePods: c.Bool("recreate-pods"),
ClientOnly: c.Bool("client-only"),
CanaryImage: c.Bool("canary-image"),
Upgrade: c.Bool("upgrade"),
ReuseValues: c.Bool("reuse-values"),
Timeout: c.String("timeout"),
Force: c.Bool("force"),
},
}
return plugin.Exec()
}