{"record":{"id":"cdbe537739edc9e0","repo":"kubernetes/kops","slug":"template-tasks-are-not-available-during-this-rende","errorCode":null,"errorMessage":"template tasks are not available during this render phase","messagePattern":"template tasks are not available during this render phase","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"upup/pkg/fi/cloudup/template_functions.go","lineNumber":524,"sourceCode":"\t\treturn \"\"\n\t}\n\n\treturn string(encoded)\n}\n\n// ToYAML returns a yaml representation of the struct or on error an empty string\nfunc (tf *TemplateFunctions) ToYAML(data interface{}) string {\n\tencoded, err := yaml.Marshal(data)\n\tif err != nil {\n\t\treturn \"\"\n\t}\n\n\treturn string(encoded)\n}\n\nfunc (tf *TemplateFunctions) taskMap() (map[string]fi.CloudupTask, error) {\n\tif tf.tasks == nil {\n\t\treturn nil, fmt.Errorf(\"template tasks are not available during this render phase\")\n\t}\n\treturn tf.tasks, nil\n}\n\n// Task returns a task by type and name, for example Task \"IAMRole\" \"nodes.example.com\".\nfunc (tf *TemplateFunctions) Task(typeName, name string) (fi.CloudupTask, error) {\n\ttasks, err := tf.taskMap()\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tkey := typeName + \"/\" + name\n\ttask := tasks[key]\n\tif task == nil {\n\t\treturn nil, fmt.Errorf(\"task %q not found\", key)\n\t}\n\treturn task, nil\n}","sourceCodeStart":506,"sourceCodeEnd":542,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/upup/pkg/fi/cloudup/template_functions.go#L506-L542","documentation":"TemplateFunctions.taskMap only has access to the built task graph in certain render phases. When tf.tasks is nil — e.g. during early template rendering before tasks are constructed — calling Task/TasksByType-driven helpers returns this error instead of an empty map, signaling the functions are unavailable in this phase.","triggerScenarios":"A cluster template or addon manifest calls {{ Task \"IAMRole\" \"x\" }} or {{ TasksByType \"IAMRole\" }} during a render phase where the task graph has not been built (tasks == nil).","commonSituations":"Addon templates copied from code that ran in the full task-enabled phase into a phase (e.g. early cluster spec templating) that stubs these functions; custom tooling invoking RenderTemplate directly without wiring tasks.","solutions":["Remove Task/TasksByType/HasTask calls from templates rendered in early phases and use spec data instead","Move the template to a render phase that has the task graph available, or wire tf.tasks in the renderer","Render phase stubs return empty results — restructure the template so it doesn't depend on task existence"],"exampleFix":"// before\n{{ if (Task \"IAMRole\" \"nodes.example.com\") }}...{{ end }}\n// after\n{{ range $name, $_ := .Subnets }}...{{ end }}  // use spec data instead of tasks","handlingStrategy":"type-guard","validationCode":"// in template: only use Task/TasksByType when available\n{{ if HasTask \"IAMRole\" \"nodes.example.com\" }}...{{ end }}","typeGuard":"func tasksAvailable(tf *TemplateFunctions) bool { return tf.tasks != nil }","tryCatchPattern":"m, err := tf.taskMap()\nif err != nil {\n\t// fall back to spec-only rendering path\n\treturn renderFromSpecOnly()\n}","preventionTips":["Do not call Task/TasksByType in early render phases where stubs are installed","Structure templates to derive data from ClusterSpec, not the task graph","Check kOps source for which render phase provides the task graph before using task helpers"],"tags":["template","go-templates","render-phase","kops"],"backgroundTag":"api-not-available-in-phase","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"}