{"record":{"id":"d0abee3d743a63a4","repo":"kubernetes/kops","slug":"error-parsing-template-q-w","errorCode":null,"errorMessage":"error parsing template %q: %w","messagePattern":"error parsing template %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"upup/pkg/fi/cloudup/template_functions.go","lineNumber":128,"sourceCode":"// RenderTemplate parses and executes an addon template source against a func map\n// derived from a per-call *TemplateFunctions bound to the given task graph.\n// When tasks is nil, task-based functions return empty stubs so templates still\n// render — used for Build-time image discovery before the task graph exists.\nfunc (r *addonTemplateRenderer) RenderTemplate(name string, source []byte, tasks map[string]fi.CloudupTask) ([]byte, error) {\n\ttf := r.newTemplateFunctions(tasks)\n\tfuncMap := template.FuncMap{}\n\tif err := tf.AddTo(funcMap, r.secretStore); err != nil {\n\t\treturn nil, err\n\t}\n\tif tasks == nil {\n\t\tfuncMap[\"Task\"] = func(typeName, name string) (fi.CloudupTask, error) { return nil, nil }\n\t\tfuncMap[\"HasTask\"] = func(typeName, name string) bool { return false }\n\t\tfuncMap[\"TasksByType\"] = func(typeName string) ([]fi.CloudupTask, error) { return nil, nil }\n\t}\n\n\tt := template.New(name).Funcs(funcMap).Option(\"missingkey=zero\")\n\tif _, err := t.Parse(string(source)); err != nil {\n\t\treturn nil, fmt.Errorf(\"error parsing template %q: %w\", name, err)\n\t}\n\n\tvar buf bytes.Buffer\n\tif err := t.ExecuteTemplate(&buf, name, r.modelContext.Cluster.Spec); err != nil {\n\t\treturn nil, fmt.Errorf(\"error executing template %q: %w\", name, err)\n\t}\n\treturn buf.Bytes(), nil\n}\n\n// CloudControllerConfigArgv returns the cloud controller argv without binding any task graph.\nfunc (r *addonTemplateRenderer) CloudControllerConfigArgv() ([]string, error) {\n\treturn r.newTemplateFunctions(nil).CloudControllerConfigArgv()\n}\n\n// AddTo defines the available functions we can use in our YAML models.\n// If we are trying to get a new function implemented it MUST\n// be defined here.\nfunc (tf *TemplateFunctions) AddTo(dest template.FuncMap, secretStore fi.SecretStore) (err error) {","sourceCodeStart":110,"sourceCodeEnd":146,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/upup/pkg/fi/cloudup/template_functions.go#L110-L146","documentation":"kOps renders cluster templates (e.g. addons, manifests) as Go text/template with a set of template functions. RenderTemplate wraps any template.Parse failure — syntax errors, unclosed actions, bad pipeline — with this message so the offending template name is identifiable.","triggerScenarios":"Calling RenderTemplate with template source containing Go template syntax errors: `{{ end }}` without `{{ if }}`, unclosed `{{`, unknown constructs, or invalid usage of registered funcs.","commonSituations":"Custom addon manifests edited by hand; broken templated cluster spec files; upgrading kOps changes available template functions leaving invalid calls.","solutions":["Fix the template syntax in the named file (check for balanced {{ if }}/{{ range }} with {{ end }})","Render the template locally with a minimal Go text/template harness to see the raw parser error wrapped by %w","Diff the template against a stock kOps template of the same version to spot incompatible function usage"],"exampleFix":"// before\n{{ range .Subnets }}\n  name: {{ .Name }}\n{{ range }}\n// after\n{{ range .Subnets }}\n  name: {{ .Name }}\n{{ end }}","handlingStrategy":"try-catch","validationCode":"var buf bytes.Buffer\ntmpl := template.New(name).Funcs(safeFuncMap)\nif err := tmpl.Parse(source); err != nil {\n\treturn fmt.Errorf(\"template %s has syntax errors: %w\", name, err)\n}","typeGuard":null,"tryCatchPattern":"out, err := r.RenderTemplate(name, source)\nif err != nil && strings.Contains(err.Error(), \"error parsing template\") {\n\tlog.Fatalf(\"fix syntax in template %s: %v\", name, err)\n}","preventionTips":["Lint Go templates in CI (e.g. parse them with text/template as a test)","Balance every {{ if }}/{{ range }} with {{ end }} before committing","Pin template function usage to your kOps version's funcMap"],"tags":["template","go-templates","parsing","kops"],"backgroundTag":"template-parse-error","analyzedSha":"4c8573c808a73d578c5eadc86d410646ea0b0d73","analyzedAt":"2026-09-05T04:13:19.212Z","contentChangedAt":"2026-09-05T04:13:19.212Z","schemaVersion":2},"datasetVersion":"2026-09-12T12:17:11.808Z"}