Skip to content

Commit

Permalink
Merge pull request #82 from Kayuii/master
Browse files Browse the repository at this point in the history
issue #68 add stable_repo_url to change default stable repository
  • Loading branch information
ipedrazas authored Nov 29, 2018
2 parents c2f9210 + 504963d commit 3505f3b
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 3 deletions.
24 changes: 22 additions & 2 deletions DOCS.md
Original file line number Diff line number Diff line change
Expand Up @@ -279,13 +279,33 @@ pipeline_production:
release: ${DRONE_BRANCH}
values: image.tag=${DRONE_BRANCH}-${DRONE_COMMIT_SHA:0:7}
prefix: STAGING
dry-run:true
dry-run: true
when:
branch: [master]
```

This plugin init stable repository in the cluster, if you want to specify the stable repository, use the `stable_repo_url` attribute.

The following example will init `stable_repo_url` in the `https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts` repo:

```YAML
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
stable_repo_url: https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts
when:
branch: [master]
```


Happy Helming!

## Known issues

* Drone secrets that are part of `values` can be leaked in debug mode and in case of error as the whole helm command will be printed in the logs. See #52
* Drone secrets that are part of `values` can be leaked in debug mode and in case of error as the whole helm command will be printed in the logs. See #52

6 changes: 6 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,11 @@ func main() {
Usage: "update dependency charts based on the contents of requirements.yaml file of the local chart",
EnvVar: "PLUGIN_UPDATE_DEPENDENCIES,UPDATE_DEPENDENCIES",
},
cli.StringFlag{
Name: "stable-repo-url",
Usage: "URL for stable repository (default 'https://kubernetes-charts.storage.googleapis.com')",
EnvVar: "PLUGIN_STABLE_REPO_URL,STABLE_REPO_URL",
},
}
if err := app.Run(os.Args); err != nil {
logrus.Fatal(err)
Expand Down Expand Up @@ -201,6 +206,7 @@ func run(c *cli.Context) error {
Timeout: c.String("timeout"),
Force: c.Bool("force"),
UpdateDependencies: c.Bool("update-dependencies"),
StableRepoURL: c.String("stable_repo_url"),
},
}
return p.Exec()
Expand Down
6 changes: 5 additions & 1 deletion plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"regexp"
"strconv"
"strings"

"text/template"
)

Expand Down Expand Up @@ -51,6 +50,7 @@ type (
HelmRepos []string `json:"helm_repos"`
Purge bool `json:"purge"`
UpdateDependencies bool `json:"update_dependencies"`
StableRepoURL string `json:"stable_repo_url"`
}
// Plugin default
Plugin struct {
Expand Down Expand Up @@ -196,6 +196,10 @@ func doHelmRepoAdd(repo string) ([]string, error) {
func doHelmInit(p *Plugin) []string {
init := make([]string, 1)
init[0] = "init"
if p.Config.StableRepoURL != "" {
init = append(init, "--stable-repo-url")
init = append(init, p.Config.StableRepoURL)
}
if p.Config.TillerNs != "" {
init = append(init, "--tiller-namespace")
init = append(init, p.Config.TillerNs)
Expand Down
27 changes: 27 additions & 0 deletions plugin/plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -555,3 +555,30 @@ func TestResolveSecretsFallback(t *testing.T) {
t.Errorf("envar ${NOTTOKEN} has not been resolved to 99999, not using prefix")
}
}
func TestHelmInitByAliyunStableRepo(t *testing.T) {
plugin := &Plugin{
Config: Config{
HelmCommand: "",
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}",
StringValues: "long_string_value=1234567890",
StableRepoURL: "https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts",
},
}
init := doHelmInit(plugin)
result := strings.Join(init, " ")
expected := "init "
if plugin.Config.StableRepoURL != "" {
expected = expected + "--stable-repo-url"
}

if expected != result {
t.Error("Helm cannot init for stable repository")
}
}

0 comments on commit 3505f3b

Please sign in to comment.