Cancel rendering helmfile parts once the missing env is detected in the previous part (#941)
* Cancel rendering helmfile parts once the missing env is detected in the previous part Fixes #913 Signed-off-by: Yusuke Kuoka <ykuoka@gmail.com>
This commit is contained in:
parent
b6581ee4bc
commit
858c233272
|
|
@ -241,15 +241,33 @@ func (ld *desiredStateLoader) load(env, overrodeEnv *environment.Environment, ba
|
||||||
env = &finalState.Env
|
env = &finalState.Env
|
||||||
|
|
||||||
ld.logger.Debugf("merged environment: %v", env)
|
ld.logger.Debugf("merged environment: %v", env)
|
||||||
|
|
||||||
|
if len(finalState.Environments) == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// At this point, we are sure that the env has been
|
||||||
|
// read from the vanilla or rendered YAML document.
|
||||||
|
// We can now check if the env is defined in it and fail accordingly.
|
||||||
|
// See https://github.com/helmfile/helmfile/issues/913
|
||||||
|
|
||||||
|
// We defer the missing env detection and failure until
|
||||||
|
// all the helmfile parts are loaded and merged.
|
||||||
|
// Otherwise, any single helmfile part missing the env would fail the whole helmfile run.
|
||||||
|
// That's problematic, because each helmfile part is supposed to be incomplete, and
|
||||||
|
// they become complete only after merging all the parts.
|
||||||
|
// See https://github.com/helmfile/helmfile/issues/807 for the rationale of this.
|
||||||
|
if _, ok := finalState.Environments[env.Name]; evaluateBases && env.Name != state.DefaultEnv && !ok {
|
||||||
|
return nil, &state.StateLoadError{
|
||||||
|
Msg: fmt.Sprintf("failed to read %s", finalState.FilePath),
|
||||||
|
Cause: &state.UndefinedEnvError{Env: env.Name},
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// We defer the missing env detection and failure until
|
// If environments are not defined in the helmfile at all although the env is specified,
|
||||||
// all the helmfile parts are loaded and merged.
|
// it's a missing env situation. Let's fail.
|
||||||
// Otherwise, any single helmfile part missing the env would fail the whole helmfile run.
|
if len(finalState.Environments) == 0 && evaluateBases && env.Name != state.DefaultEnv {
|
||||||
// That's problematic, because each helmfile part is supposed to be incomplete, and
|
|
||||||
// they become complete only after merging all the parts.
|
|
||||||
// See https://github.com/helmfile/helmfile/issues/807 for the rationale of this.
|
|
||||||
if _, ok := finalState.Environments[env.Name]; evaluateBases && env.Name != state.DefaultEnv && !ok {
|
|
||||||
return nil, &state.StateLoadError{
|
return nil, &state.StateLoadError{
|
||||||
Msg: fmt.Sprintf("failed to read %s", finalState.FilePath),
|
Msg: fmt.Sprintf("failed to read %s", finalState.FilePath),
|
||||||
Cause: &state.UndefinedEnvError{Env: env.Name},
|
Cause: &state.UndefinedEnvError{Env: env.Name},
|
||||||
|
|
|
||||||
5
test/e2e/template/helmfile/testdata/snapshot/environment_missing_in_subhelmfile/config.yaml
vendored
Normal file
5
test/e2e/template/helmfile/testdata/snapshot/environment_missing_in_subhelmfile/config.yaml
vendored
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
chartifyTempDir: environment_missing_in_subhelmfile
|
||||||
|
helmfileArgs:
|
||||||
|
- --environment
|
||||||
|
- test
|
||||||
|
- template
|
||||||
|
|
@ -0,0 +1,15 @@
|
||||||
|
environments:
|
||||||
|
prod:
|
||||||
|
values:
|
||||||
|
- foo: prod
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
releases:
|
||||||
|
- name: raw
|
||||||
|
chart: ../../../charts/raw-0.0.1
|
||||||
|
values:
|
||||||
|
- templates:
|
||||||
|
- |
|
||||||
|
subhelmfile: {{ .Values.foo }}
|
||||||
|
envName: {{ .Values.envName }}
|
||||||
|
|
@ -0,0 +1,15 @@
|
||||||
|
environments:
|
||||||
|
test:
|
||||||
|
values:
|
||||||
|
- foo: test
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
releases:
|
||||||
|
- name: raw
|
||||||
|
chart: ../../../charts/raw-0.0.1
|
||||||
|
values:
|
||||||
|
- templates:
|
||||||
|
- |
|
||||||
|
subhelmfile: {{ .Values.foo }}
|
||||||
|
envName: {{ .Values.envName }}
|
||||||
12
test/e2e/template/helmfile/testdata/snapshot/environment_missing_in_subhelmfile/input.yaml
vendored
Normal file
12
test/e2e/template/helmfile/testdata/snapshot/environment_missing_in_subhelmfile/input.yaml
vendored
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
environments:
|
||||||
|
test:
|
||||||
|
values:
|
||||||
|
- test.yaml.gotmpl
|
||||||
|
---
|
||||||
|
helmfiles:
|
||||||
|
- path: helmfiles/test.yaml
|
||||||
|
values:
|
||||||
|
- envName: {{ .Values.envName }}
|
||||||
|
- path: helmfiles/prod.yaml
|
||||||
|
values:
|
||||||
|
- envName: {{ .Values.envName }}
|
||||||
7
test/e2e/template/helmfile/testdata/snapshot/environment_missing_in_subhelmfile/output.yaml
vendored
Normal file
7
test/e2e/template/helmfile/testdata/snapshot/environment_missing_in_subhelmfile/output.yaml
vendored
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
Building dependency release=raw, chart=../../../charts/raw-0.0.1
|
||||||
|
Templating release=raw, chart=../../../charts/raw-0.0.1
|
||||||
|
---
|
||||||
|
# Source: raw/templates/resources.yaml
|
||||||
|
subhelmfile: test
|
||||||
|
envName: test
|
||||||
|
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
envName: {{ .Environment.Name }}
|
||||||
Loading…
Reference in New Issue