Merge pull request #222 from mumoshu/wait-for-release
feat: `wait: true` in each release
This commit is contained in:
		
						commit
						0541731350
					
				
							
								
								
									
										29
									
								
								README.md
								
								
								
								
							
							
						
						
									
										29
									
								
								README.md
								
								
								
								
							|  | @ -44,11 +44,9 @@ helmDefaults: | ||||||
|   tillerNamespace: tiller-namespace  #dedicated default key for tiller-namespace |   tillerNamespace: tiller-namespace  #dedicated default key for tiller-namespace | ||||||
|   kubeContext: kube-context          #dedicated default key for kube-context |   kubeContext: kube-context          #dedicated default key for kube-context | ||||||
|   args: |   args: | ||||||
|     - "--wait" |  | ||||||
|     - "--recreate-pods" |     - "--recreate-pods" | ||||||
|     - "--timeout=600" |     - "--timeout=600" | ||||||
|     - "--force" |     - "--force" | ||||||
|     - "--reset-values" |  | ||||||
| 
 | 
 | ||||||
| releases: | releases: | ||||||
|   # Published chart example |   # Published chart example | ||||||
|  | @ -59,21 +57,23 @@ releases: | ||||||
|     chart: roboll/vault-secret-manager     # the chart being installed to create this release, referenced by `repository/chart` syntax |     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 |     version: ~1.24.1                       # the semver of the chart. range constraint is supported | ||||||
|     values: |     values: | ||||||
|       - vault.yaml                         # value files (--values) |       # value files passed via --values | ||||||
|       - db:                                # inline values. Passed via a temporary values file (--values) |       - vault.yaml | ||||||
|  |       # inline values, passed via a temporary values file and --values | ||||||
|  |       - address: https://vault.example.com | ||||||
|  |         db: | ||||||
|           username: {{ requiredEnv "DB_USERNAME" }} |           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" }} |           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: |     secrets: | ||||||
|       - vault_secret.yaml                  # will attempt to decrypt it using helm-secrets plugin |       - vault_secret.yaml | ||||||
|     set:                                   # values (--set) |     # wait for k8s resources via --wait. Defaults to `false` | ||||||
|       - name: address |     wait: true | ||||||
|         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" }} |  | ||||||
| 
 | 
 | ||||||
|   # Local chart example |   # Local chart example | ||||||
|   - name: grafana                            # name of this release |   - name: grafana                            # name of this release | ||||||
|  | @ -82,6 +82,7 @@ releases: | ||||||
|     values: |     values: | ||||||
|     - "../../my-values/grafana/values.yaml"             # Values file (relative path to manifest) |     - "../../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. |     - ./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 | ||||||
| 
 | 
 | ||||||
| ``` | ``` | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -60,6 +60,7 @@ type ReleaseSpec struct { | ||||||
| 	Chart   string `yaml:"chart"` | 	Chart   string `yaml:"chart"` | ||||||
| 	Version string `yaml:"version"` | 	Version string `yaml:"version"` | ||||||
| 	Verify  bool   `yaml:"verify"` | 	Verify  bool   `yaml:"verify"` | ||||||
|  | 	Wait    bool   `yaml:"wait"` | ||||||
| 
 | 
 | ||||||
| 	// Name is the name of this release
 | 	// Name is the name of this release
 | ||||||
| 	Name      string            `yaml:"name"` | 	Name      string            `yaml:"name"` | ||||||
|  | @ -215,7 +216,7 @@ func (state *HelmState) SyncReleases(helm helmexec.Interface, additionalValues [ | ||||||
| 		go func() { | 		go func() { | ||||||
| 			for release := range jobQueue { | 			for release := range jobQueue { | ||||||
| 				state.applyDefaultsTo(release) | 				state.applyDefaultsTo(release) | ||||||
| 				flags, flagsErr := state.flagsForRelease(helm, state.BaseChartPath, release) | 				flags, flagsErr := state.flagsForUpgrade(helm, state.BaseChartPath, release) | ||||||
| 				if flagsErr != nil { | 				if flagsErr != nil { | ||||||
| 					errQueue <- flagsErr | 					errQueue <- flagsErr | ||||||
| 					doneQueue <- true | 					doneQueue <- true | ||||||
|  | @ -295,7 +296,7 @@ func (state *HelmState) DiffReleases(helm helmexec.Interface, additionalValues [ | ||||||
| 
 | 
 | ||||||
| 				state.applyDefaultsTo(release) | 				state.applyDefaultsTo(release) | ||||||
| 
 | 
 | ||||||
| 				flags, err := state.flagsForRelease(helm, state.BaseChartPath, release) | 				flags, err := state.flagsForDiff(helm, state.BaseChartPath, release) | ||||||
| 				if err != nil { | 				if err != nil { | ||||||
| 					errs = append(errs, err) | 					errs = append(errs, err) | ||||||
| 				} | 				} | ||||||
|  | @ -379,7 +380,7 @@ func (state *HelmState) LintReleases(helm helmexec.Interface, additionalValues [ | ||||||
| 		go func() { | 		go func() { | ||||||
| 			for release := range jobQueue { | 			for release := range jobQueue { | ||||||
| 				errs := []error{} | 				errs := []error{} | ||||||
| 				flags, err := state.flagsForRelease(helm, state.BaseChartPath, release) | 				flags, err := state.flagsForLint(helm, state.BaseChartPath, release) | ||||||
| 				if err != nil { | 				if err != nil { | ||||||
| 					errs = append(errs, err) | 					errs = append(errs, err) | ||||||
| 				} | 				} | ||||||
|  | @ -417,21 +418,8 @@ func (state *HelmState) LintReleases(helm helmexec.Interface, additionalValues [ | ||||||
| 					chartPath = path.Join(chartPath, chartNameWithoutRepository(release.Chart)) | 					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 len(errs) == 0 { | ||||||
| 					if err := helm.Lint(chartPath, realFlags...); err != nil { | 					if err := helm.Lint(chartPath, flags...); err != nil { | ||||||
| 						errs = append(errs, err) | 						errs = append(errs, err) | ||||||
| 					} | 					} | ||||||
| 				} | 				} | ||||||
|  | @ -663,14 +651,42 @@ func chartNameWithoutRepository(chart string) string { | ||||||
| 	return chartSplit[len(chartSplit)-1] | 	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) | ||||||
|  | 	} | ||||||
|  | 	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{} | 	flags := []string{} | ||||||
| 	if release.Version != "" { | 	if release.Version != "" { | ||||||
| 		flags = append(flags, "--version", release.Version) | 		flags = append(flags, "--version", release.Version) | ||||||
| 	} | 	} | ||||||
| 	if release.Verify { | 	common, err := state.namespaceAndValuesFlags(helm, basePath, release) | ||||||
| 		flags = append(flags, "--verify") | 	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 != "" { | 	if release.Namespace != "" { | ||||||
| 		flags = append(flags, "--namespace", release.Namespace) | 		flags = append(flags, "--namespace", release.Namespace) | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue