diff --git a/pkg/policy/checker.go b/pkg/policy/checker.go index 3399540e..2023ecea 100644 --- a/pkg/policy/checker.go +++ b/pkg/policy/checker.go @@ -37,7 +37,9 @@ func forbidEnvironmentsWithReleases(filePath string, content []byte) (bool, erro if k == "environments" || k == "releases" || k == "---" { if _, ok := resultKeys[k]; !ok { result = append(result, k) - resultKeys[k] = nil + if k != "---" { + resultKeys[k] = nil + } } } } diff --git a/pkg/policy/checker_test.go b/pkg/policy/checker_test.go index 5da906df..3bdbb6a1 100644 --- a/pkg/policy/checker_test.go +++ b/pkg/policy/checker_test.go @@ -41,6 +41,14 @@ func TestForbidEnvironmentsWithReleases(t *testing.T) { expectedErr: false, isStrict: false, }, + { + name: "no error when has --- between releases and environments, and --- on top of helmfile.yaml.gotmpl", + filePath: "helmfile.yaml.gotmpl", + content: []byte("---\nenvironments:\n---\nreleases:\n"), + v1mode: false, + expectedErr: false, + isStrict: false, + }, { name: "error when both releases and environments", filePath: "helmfile.yaml.gotmpl", @@ -50,8 +58,8 @@ func TestForbidEnvironmentsWithReleases(t *testing.T) { isStrict: false, }, { - name: "no error when both releases and environments for plain yaml on v1", - filePath: "helmfile.yaml.gotmpl", + name: "error when both releases and environments for plain yaml on v1", + filePath: "helmfile.yaml", content: []byte("environments:\nreleases:\n"), v1mode: true, expectedErr: true,