kubernetes/kops · error
template tasks are not available during this render phase
Error message
template tasks are not available during this render phase
What it means
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.
Source
Thrown at upup/pkg/fi/cloudup/template_functions.go:524
return ""
}
return string(encoded)
}
// ToYAML returns a yaml representation of the struct or on error an empty string
func (tf *TemplateFunctions) ToYAML(data interface{}) string {
encoded, err := yaml.Marshal(data)
if err != nil {
return ""
}
return string(encoded)
}
func (tf *TemplateFunctions) taskMap() (map[string]fi.CloudupTask, error) {
if tf.tasks == nil {
return nil, fmt.Errorf("template tasks are not available during this render phase")
}
return tf.tasks, nil
}
// Task returns a task by type and name, for example Task "IAMRole" "nodes.example.com".
func (tf *TemplateFunctions) Task(typeName, name string) (fi.CloudupTask, error) {
tasks, err := tf.taskMap()
if err != nil {
return nil, err
}
key := typeName + "/" + name
task := tasks[key]
if task == nil {
return nil, fmt.Errorf("task %q not found", key)
}
return task, nil
}View on GitHub (pinned to 4c8573c808)
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
Example fix
// before
{{ if (Task "IAMRole" "nodes.example.com") }}...{{ end }}
// after
{{ range $name, $_ := .Subnets }}...{{ end }} // use spec data instead of tasks Defensive patterns
Strategy: type-guard
Validate before calling
// in template: only use Task/TasksByType when available
{{ if HasTask "IAMRole" "nodes.example.com" }}...{{ end }} Type guard
func tasksAvailable(tf *TemplateFunctions) bool { return tf.tasks != nil } Try / catch
m, err := tf.taskMap()
if err != nil {
// fall back to spec-only rendering path
return renderFromSpecOnly()
} Prevention
- 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
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- error parsing template %q: %w
- error executing template %q: %w
- listing SSH key tasks: %w
- error creating kops config template: %w
- error creating gcp machine template: %w
AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05).
Data as JSON: /api/errors/cdbe537739edc9e0.
Report an issue: GitHub.