{"record":{"id":"85324e6a01e17522","repo":"kubernetes/kops","slug":"error-executing-template-q-w","errorCode":null,"errorMessage":"error executing template %q: %w","messagePattern":"error executing template %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"upup/pkg/fi/cloudup/template_functions.go","lineNumber":133,"sourceCode":"\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) {\n\tcluster := tf.Cluster\n\n\tdest[\"ToJSON\"] = tf.ToJSON\n\tdest[\"ToYAML\"] = tf.ToYAML\n\tdest[\"KubeObjectToApplyYAML\"] = kubemanifest.KubeObjectToApplyYAML","sourceCodeStart":115,"sourceCodeEnd":151,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/upup/pkg/fi/cloudup/template_functions.go#L115-L151","documentation":"After successfully parsing, RenderTemplate executes the template against cluster.spec. This error wraps any runtime execution failure — nil map index issues aside (missingkey=zero), these are typically data/type errors such as calling a template function with wrong arguments or ranging over a non-iterable value.","triggerScenarios":"Template parses but fails at ExecuteTemplate: calling a template function with wrong argument types (e.g. AddInt on a non-integer), indexing a field that doesn't exist on ClusterSpec in this kOps version, or a custom func returning an error.","commonSituations":"Templates written for a different kOps version referencing removed ClusterSpec fields or renamed template functions; custom addons calling helpers with wrong signatures.","solutions":["Read the wrapped inner error to find the failing template line and fix the expression or function call","Check the template functions available in your kOps version (template_functions.go) and update calls to match","Test-render with the same cluster spec via `kops toolbox template` if available to iterate quickly"],"exampleFix":"// before\nregion: {{ Region }}\n// after\nregion: {{ Region . }}","handlingStrategy":"try-catch","validationCode":"// render against real ClusterSpec in a unit test before deploy\ntmpl := template.New(name).Funcs(funcMap).Option(\"missingkey=zero\")\nif err := tmpl.Execute(io.Discard, cluster.Spec); err != nil {\n\tt.Fatalf(\"template %s fails at runtime: %v\", name, err)\n}","typeGuard":null,"tryCatchPattern":"out, err := r.RenderTemplate(name, source)\nif err != nil && strings.Contains(err.Error(), \"error executing template\") {\n\t// inspect wrapped error for the failing line/function\n\treturn fmt.Errorf(\"rendering %s: %w\", name, err)\n}","preventionTips":["Add a unit test executing every custom template against a real ClusterSpec","Only call template functions that exist in your kOps version's funcMap","Use missingkey=zero semantics consciously and guard optional fields"],"tags":["template","go-templates","execution","kops"],"backgroundTag":"template-execution-error","analyzedSha":"4c8573c808a73d578c5eadc86d410646ea0b0d73","analyzedAt":"2026-09-05T04:13:19.212Z","contentChangedAt":"2026-09-05T04:13:19.212Z","schemaVersion":2},"datasetVersion":"2026-09-12T07:17:12.445Z"}