Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: wait: true in each release #222

Merged
merged 1 commit into from
Aug 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 15 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,9 @@ helmDefaults:
tillerNamespace: tiller-namespace #dedicated default key for tiller-namespace
kubeContext: kube-context #dedicated default key for kube-context
args:
- "--wait"
- "--recreate-pods"
- "--timeout=600"
- "--force"
- "--reset-values"

releases:
# Published chart example
Expand All @@ -59,21 +57,23 @@ releases:
chart: roboll/vault-secret-manager # the chart being installed to create this release, referenced by `repository/chart` syntax
version: ~1.24.1 # the semver of the chart. range constraint is supported
values:
- vault.yaml # value files (--values)
- db: # inline values. Passed via a temporary values file (--values)
# value files passed via --values
- vault.yaml
# inline values, passed via a temporary values file and --values
- address: https://vault.example.com
db:
username: {{ requiredEnv "DB_USERNAME" }}
# value taken from environment variable. Quotes are necessary. Will throw an error if the environment variable is not set. $DB_PASSWORD needs to be set in the calling environment ex: export DB_PASSWORD='password1'
password: {{ requiredEnv "DB_PASSWORD" }}
proxy:
# Interpolate environment variable with a fixed string
domain: {{ requiredEnv "PLATFORM_ID" }}.my-domain.com
scheme: {{ env "SCHEME" | default "https" }}
# will attempt to decrypt it using helm-secrets plugin
secrets:
- vault_secret.yaml # will attempt to decrypt it using helm-secrets plugin
set: # values (--set)
- name: address
value: https://vault.example.com
- name: db.password
value: {{ requiredEnv "DB_PASSWORD" }} # value taken from environment variable. Quotes are necessary. Will throw an error if the environment variable is not set. $DB_PASSWORD needs to be set in the calling environment ex: export DB_PASSWORD='password1'
- name: proxy.domain
value: {{ requiredEnv "PLATFORM_ID" }}.my-domain.com # Interpolate environment variable with a fixed string
- name: proxy.scheme
value: {{ env "SCHEME" | default "https" }}
- vault_secret.yaml
# wait for k8s resources via --wait. Defaults to `false`
wait: true

# Local chart example
- name: grafana # name of this release
Expand All @@ -82,6 +82,7 @@ releases:
values:
- "../../my-values/grafana/values.yaml" # Values file (relative path to manifest)
- ./values/{{ requiredEnv "PLATFORM_ENV" }}/config.yaml # Values file taken from path with environment variable. $PLATFORM_ENV must be set in the calling environment.
wait: true

```

Expand Down
56 changes: 36 additions & 20 deletions state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ type ReleaseSpec struct {
Chart string `yaml:"chart"`
Version string `yaml:"version"`
Verify bool `yaml:"verify"`
Wait bool `yaml:"wait"`

// Name is the name of this release
Name string `yaml:"name"`
Expand Down Expand Up @@ -215,7 +216,7 @@ func (state *HelmState) SyncReleases(helm helmexec.Interface, additionalValues [
go func() {
for release := range jobQueue {
state.applyDefaultsTo(release)
flags, flagsErr := state.flagsForRelease(helm, state.BaseChartPath, release)
flags, flagsErr := state.flagsForUpgrade(helm, state.BaseChartPath, release)
if flagsErr != nil {
errQueue <- flagsErr
doneQueue <- true
Expand Down Expand Up @@ -295,7 +296,7 @@ func (state *HelmState) DiffReleases(helm helmexec.Interface, additionalValues [

state.applyDefaultsTo(release)

flags, err := state.flagsForRelease(helm, state.BaseChartPath, release)
flags, err := state.flagsForDiff(helm, state.BaseChartPath, release)
if err != nil {
errs = append(errs, err)
}
Expand Down Expand Up @@ -379,7 +380,7 @@ func (state *HelmState) LintReleases(helm helmexec.Interface, additionalValues [
go func() {
for release := range jobQueue {
errs := []error{}
flags, err := state.flagsForRelease(helm, state.BaseChartPath, release)
flags, err := state.flagsForLint(helm, state.BaseChartPath, release)
if err != nil {
errs = append(errs, err)
}
Expand Down Expand Up @@ -417,21 +418,8 @@ func (state *HelmState) LintReleases(helm helmexec.Interface, additionalValues [
chartPath = path.Join(chartPath, chartNameWithoutRepository(release.Chart))
}

// strip version from the slice returned from flagsForRelease
realFlags := []string{}
isVersion := false
for _, v := range flags {
if v == "--version" {
isVersion = true
} else if isVersion {
isVersion = false
} else {
realFlags = append(realFlags, v)
}
}

if len(errs) == 0 {
if err := helm.Lint(chartPath, realFlags...); err != nil {
if err := helm.Lint(chartPath, flags...); err != nil {
errs = append(errs, err)
}
}
Expand Down Expand Up @@ -663,14 +651,42 @@ func chartNameWithoutRepository(chart string) string {
return chartSplit[len(chartSplit)-1]
}

func (state *HelmState) flagsForRelease(helm helmexec.Interface, basePath string, release *ReleaseSpec) ([]string, error) {
func (state *HelmState) flagsForUpgrade(helm helmexec.Interface, basePath string, release *ReleaseSpec) ([]string, error) {
flags := []string{}
if release.Verify {
flags = append(flags, "--verify")
}
if release.Wait {
flags = append(flags, "--wait")
}
if release.Version != "" {
flags = append(flags, "--version", release.Version)
}
if release.Verify {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

verify: true in helmfile.yaml should have been failing on helmfile lint and helmfile diff due to that the unsupported --verify flag is passed.

This PR also fix that.

flags = append(flags, "--verify")
common, err := state.namespaceAndValuesFlags(helm, basePath, release)
if err != nil {
return nil, err
}
return append(flags, common...), nil
}

func (state *HelmState) flagsForDiff(helm helmexec.Interface, basePath string, release *ReleaseSpec) ([]string, error) {
flags := []string{}
if release.Version != "" {
flags = append(flags, "--version", release.Version)
}
common, err := state.namespaceAndValuesFlags(helm, basePath, release)
if err != nil {
return nil, err
}
return append(flags, common...), nil
}

func (state *HelmState) flagsForLint(helm helmexec.Interface, basePath string, release *ReleaseSpec) ([]string, error) {
return state.namespaceAndValuesFlags(helm, basePath, release)
}

func (state *HelmState) namespaceAndValuesFlags(helm helmexec.Interface, basePath string, release *ReleaseSpec) ([]string, error) {
flags := []string{}
if release.Namespace != "" {
flags = append(flags, "--namespace", release.Namespace)
}
Expand Down