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

Mention template filename in error message. #1401

Merged
merged 1 commit into from
Mar 9, 2020
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
4 changes: 2 additions & 2 deletions pkg/engine/renderer/enhancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ type DefaultEnhancer struct {
func (de *DefaultEnhancer) Apply(templates map[string]string, metadata Metadata) (objsToAdd []runtime.Object, err error) {
objs := make([]runtime.Object, 0, len(templates))

for _, v := range templates {
for name, v := range templates {
parsed, err := YamlToObject(v)
if err != nil {
return nil, fmt.Errorf("parsing YAML failed: %v", err)
return nil, fmt.Errorf("parsing YAML from %s failed: %v", name, err)
}
for _, obj := range parsed {
unstructMap, err := runtime.DefaultUnstructuredConverter.ToUnstructured(obj)
Expand Down
4 changes: 2 additions & 2 deletions pkg/kudoctl/packages/verifier/template/verify_render.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ func templateCompilable(pf *packages.Files) verifier.Result {
// Render the template
s, err := engine.Render(k, v, configs)
if err != nil {
res.AddErrors(err.Error())
res.AddErrors(fmt.Sprintf("rendering template %s failed: %v", k, err))
}

// Try to parse rendered template as valid Kubernetes objects
_, err = renderer.YamlToObject(s)
if err != nil {
res.AddErrors(err.Error())
res.AddErrors(fmt.Sprintf("parsing rendered YAML from %s failed: %v", k, err))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func TestTemplateRenderVerifier(t *testing.T) {

assert.Equal(t, 0, len(res.Warnings))
assert.Equal(t, 1, len(res.Errors))
assert.Equal(t, `error rendering template: template: foo.yaml:2:6: executing "foo.yaml" at <eq>: wrong number of args for eq: want at least 1 got 0`, res.Errors[0])
assert.Equal(t, `rendering template foo.yaml failed: error rendering template: template: foo.yaml:2:6: executing "foo.yaml" at <eq>: wrong number of args for eq: want at least 1 got 0`, res.Errors[0])
}

func TestTemplateRenderVerifier_InvalidYAML(t *testing.T) {
Expand Down Expand Up @@ -59,7 +59,7 @@ spec:
assert.Equal(t, 0, len(res.Warnings))
assert.Equal(t, 1, len(res.Errors))
assert.Equal(t,
`decoding chunk "\napiVersion: batch/v1\nkind: Job\nmetadata:\n name: backup\nspec:\n template:\n spec:\n containers:\n - name: backup\n`+
`parsing rendered YAML from foo.yaml failed: decoding chunk "\napiVersion: batch/v1\nkind: Job\nmetadata:\n name: backup\nspec:\n template:\n spec:\n containers:\n - name: backup\n`+
` restartPolicy: Never\n" failed: error converting YAML to JSON: yaml: line 10: did not find expected key`, res.Errors[0])
}

Expand Down