{"record":{"id":"f301b3eacf6d909a","repo":"kubernetes/kops","slug":"task-q-is-t-expected-fitasks-managedfile","errorCode":null,"errorMessage":"task %q is %T, expected *fitasks.ManagedFile","messagePattern":"task %q is %T, expected \\*fitasks\\.ManagedFile","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"upup/pkg/fi/cloudup/template_functions_karpenter.go","lineNumber":723,"sourceCode":"\tif key == \"kubernetes.io/hostname\" {\n\t\treturn true\n\t}\n\tdomain, _, found := strings.Cut(key, \"/\")\n\tif !found {\n\t\treturn false\n\t}\n\treturn domain == \"karpenter.sh\" || strings.HasSuffix(domain, \".karpenter.sh\") ||\n\t\tdomain == \"karpenter.k8s.aws\" || strings.HasSuffix(domain, \".karpenter.k8s.aws\")\n}\n\nfunc (tf *TemplateFunctions) managedFileContents(name string) (string, error) {\n\ttask, err := tf.Task(\"ManagedFile\", name)\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\tmanagedFile, ok := task.(*fitasks.ManagedFile)\n\tif !ok {\n\t\treturn \"\", fmt.Errorf(\"task %q is %T, expected *fitasks.ManagedFile\", name, task)\n\t}\n\tdata, err := fi.ResourceAsBytes(managedFile.Contents)\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\treturn string(data), nil\n}\n","sourceCodeStart":705,"sourceCodeEnd":731,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/upup/pkg/fi/cloudup/template_functions_karpenter.go#L705-L731","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Verify the `name` passed in refers to a ManagedFile task actually built during cluster rendering.","Check the builder code for a naming collision where another task type registers the same name.","Ensure the ManagedFile task for this name is created before this function runs (task registration ordering in the builder).","File/report if it reproduces on a stock kOps cluster spec — it usually indicates an internal bug, not user config."],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":"task, err := tf.Task(\"ManagedFile\", name)\nif err != nil { return \"\", err }\nif _, ok := task.(*fitasks.ManagedFile); !ok {\n    return \"\", fmt.Errorf(\"no ManagedFile task named %q\", name)\n}","typeGuard":"managedFile, ok := task.(*fitasks.ManagedFile)\nif !ok {\n    return \"\", fmt.Errorf(\"task %q is %T, expected *fitasks.ManagedFile\", name, task)\n}","tryCatchPattern":"task, err := tf.Task(\"ManagedFile\", name)\nif err != nil {\n    return \"\", fmt.Errorf(\"failed to fetch ManagedFile %q: %w\", name, err)\n}","preventionTips":["Ensure task names are unique across all task types in the builder.","Register the ManagedFile before reading it back.","Verify the exact name string passed matches the registered task key."],"tags":["kops","type-assertion","tasks","internal"],"backgroundTag":"unexpected-task-type","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"}