--tiller-namespace para added

This commit is contained in:
Ivan Pedrazas
2017-01-11 20:10:57 +00:00
parent f735678d10
commit 539cfab8cf
4 changed files with 59 additions and 5 deletions
+14 -1
View File
@@ -81,7 +81,20 @@ To test the plugin, you can run `minikube` and just run the docker image as foll
quay.io/ipedrazas/drone-helm
This plugin expects [Tiller](https://github.com/kubernetes/helm/blob/master/docs/architecture.md) to be already installed in the cluster
This plugin installs [Tiller](https://github.com/kubernetes/helm/blob/master/docs/architecture.md) in the cluster, if you want to specify the namespace where `tiller` ins installed, use the `tiller_ns` attribute.
The following example will install `tiller` in the `operations` namespace:
pipeline_production:
helm_deploy:
image: quay.io/ipedrazas/drone-helm
skip_tls_verify: true
chart: ./charts/my-chart
release: ${DRONE_BRANCH}
values: image.tag=${DRONE_BRANCH}-${DRONE_COMMIT_SHA:0:7}
prefix: PROD
tiller_ns: operations
when:
branch: [master]
Happy Helming!
+6
View File
@@ -63,6 +63,11 @@ func main() {
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)
@@ -87,6 +92,7 @@ func run(c *cli.Context) error {
DryRun: c.Bool("dry-run"),
Secrets: c.StringSlice("secrets"),
Prefix: c.String("prefix"),
TillerNs: c.String("tiller_ns"),
},
}
resolveSecrets(&plugin)
+15 -4
View File
@@ -30,6 +30,7 @@ type (
DryRun bool `json:"dry_run"`
Secrets []string `json:"secrets"`
Prefix string `json:"prefix"`
TillerNs string `json:"tiller_ns"`
}
// Plugin default
Plugin struct {
@@ -83,6 +84,17 @@ func setHelmCommand(p *Plugin) {
}
func doHelmInit(p *Plugin) []string {
init := make([]string, 1)
init[0] = "init"
if p.Config.TillerNs != "" {
init = append(init, "--tiller-namespace")
init = append(init, p.Config.TillerNs)
}
return init
}
// Exec default method
func (p *Plugin) Exec() error {
resolveSecrets(p)
@@ -98,16 +110,15 @@ func (p *Plugin) Exec() error {
p.debug()
}
init := make([]string, 1)
init[0] = "init"
init := doHelmInit(p)
err := runCommand(init)
if err != nil {
return fmt.Errorf("Error running helm comand: " + strings.Join(init[:], " "))
}
setHelmCommand(p)
if p.Config.Debug {
log.Println("helm comand: " + strings.Join(p.Config.HelmCommand[:], " "))
log.Println("helm command: " + strings.Join(p.Config.HelmCommand[:], " "))
}
err = runCommand(p.Config.HelmCommand)
if err != nil {
+24
View File
@@ -143,3 +143,27 @@ func TestSetHelmHelp(t *testing.T) {
t.Error("Helm help is not displayed")
}
}
func TestDetHelmInit(t *testing.T) {
plugin := &Plugin{
Config: Config{
HelmCommand: nil,
Namespace: "default",
SkipTLSVerify: true,
Debug: true,
DryRun: true,
Chart: "./chart/test",
Release: "test-release",
Prefix: "MY",
Values: "image.tag=$TAG,api=${API_SERVER},nameOverride=my-over-app,second.tag=${TAG}",
TillerNs: "system-test",
},
}
init := doHelmInit(plugin)
result := strings.Join(init, " ")
expected := "init --tiller-namespace " + plugin.Config.TillerNs
if expected != result {
t.Error("Tiller not installed in proper namespace")
}
}