kubernetes/kops · error

task %q is %T, expected *fitasks.ManagedFile

Error message

task %q is %T, expected *fitasks.ManagedFile

What it means

This code fetches a previously registered task by name from the build task map and asserts it is a *fitasks.ManagedFile before reading its contents. If a task with the same name exists but was built as a different task type, the type assertion fails and this error is returned. It prevents reading a Contents field that only ManagedFile has.

Source

Thrown at upup/pkg/fi/cloudup/template_functions_karpenter.go:723

	if key == "kubernetes.io/hostname" {
		return true
	}
	domain, _, found := strings.Cut(key, "/")
	if !found {
		return false
	}
	return domain == "karpenter.sh" || strings.HasSuffix(domain, ".karpenter.sh") ||
		domain == "karpenter.k8s.aws" || strings.HasSuffix(domain, ".karpenter.k8s.aws")
}

func (tf *TemplateFunctions) managedFileContents(name string) (string, error) {
	task, err := tf.Task("ManagedFile", name)
	if err != nil {
		return "", err
	}
	managedFile, ok := task.(*fitasks.ManagedFile)
	if !ok {
		return "", fmt.Errorf("task %q is %T, expected *fitasks.ManagedFile", name, task)
	}
	data, err := fi.ResourceAsBytes(managedFile.Contents)
	if err != nil {
		return "", err
	}
	return string(data), nil
}

View on GitHub (pinned to 4c8573c808)

Solutions

  1. Verify the `name` passed in refers to a ManagedFile task actually built during cluster rendering.
  2. Check the builder code for a naming collision where another task type registers the same name.
  3. Ensure the ManagedFile task for this name is created before this function runs (task registration ordering in the builder).
  4. File/report if it reproduces on a stock kOps cluster spec — it usually indicates an internal bug, not user config.
Defensive patterns

Strategy: type-guard

Validate before calling

task, err := tf.Task("ManagedFile", name)
if err != nil { return "", err }
if _, ok := task.(*fitasks.ManagedFile); !ok {
    return "", fmt.Errorf("no ManagedFile task named %q", name)
}

Type guard

managedFile, ok := task.(*fitasks.ManagedFile)
if !ok {
    return "", fmt.Errorf("task %q is %T, expected *fitasks.ManagedFile", name, task)
}

Try / catch

task, err := tf.Task("ManagedFile", name)
if err != nil {
    return "", fmt.Errorf("failed to fetch ManagedFile %q: %w", name, err)
}

Prevention

When it happens

Trigger: Calling the helper (task-content reader around line 723 of template_functions_karpenter.go) with a name for which tf.Task("ManagedFile", name) resolves to a task of another concrete type registered under that key — i.e. a task-map key collision or the wrong name passed.

Common situations: Two different tasks registered with identical (type,name) ambiguity during internal refactors; a developer calling the helper with a name that actually belongs to e.g. a Keypair or Secret task; kOps version regressions in task naming.

Related errors


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