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

  1. Remove Task/TasksByType/HasTask calls from templates rendered in early phases and use spec data instead
  2. Move the template to a render phase that has the task graph available, or wire tf.tasks in the renderer
  3. 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

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


AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05). Data as JSON: /api/errors/cdbe537739edc9e0. Report an issue: GitHub.