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,8 +241,16 @@ func (ld *desiredStateLoader) load(env, overrodeEnv *environment.Environment, ba
|
|||
env = &finalState.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.
|
||||
|
|
@ -255,6 +263,16 @@ func (ld *desiredStateLoader) load(env, overrodeEnv *environment.Environment, ba
|
|||
Cause: &state.UndefinedEnvError{Env: env.Name},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If environments are not defined in the helmfile at all although the env is specified,
|
||||
// it's a missing env situation. Let's fail.
|
||||
if len(finalState.Environments) == 0 && evaluateBases && env.Name != state.DefaultEnv {
|
||||
return nil, &state.StateLoadError{
|
||||
Msg: fmt.Sprintf("failed to read %s", finalState.FilePath),
|
||||
Cause: &state.UndefinedEnvError{Env: env.Name},
|
||||
}
|
||||
}
|
||||
|
||||
return finalState, nil
|
||||
}
|
||||
|
|
|
|||
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