{"record":{"id":"44efcc559ec9218c","repo":"kubernetes/kops","slug":"listing-ssh-key-tasks-w","errorCode":null,"errorMessage":"listing SSH key tasks: %w","messagePattern":"listing SSH key tasks: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"upup/pkg/fi/cloudup/template_functions.go","lineNumber":1261,"sourceCode":"\n\t// Use an encoder with HTML escaping disabled so the embedded cloud-init script stays readable.\n\tvar buf bytes.Buffer\n\tenc := json.NewEncoder(&buf)\n\tenc.SetEscapeHTML(false)\n\tenc.SetIndent(\"\", \"  \")\n\tif err := enc.Encode(config); err != nil {\n\t\treturn \"\", fmt.Errorf(\"marshaling cluster config: %w\", err)\n\t}\n\n\t// Strip the trailing newline that json.Encoder.Encode appends.\n\treturn strings.TrimRight(buf.String(), \"\\n\"), nil\n}\n\n// HCloudSSHKey returns HCLOUD_SSH_KEY as the first SSH key ID.\nfunc (tf *TemplateFunctions) HCloudSSHKey() (string, error) {\n\ttasks, err := tf.TasksByType(\"SSHKey\")\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"listing SSH key tasks: %w\", err)\n\t}\n\tif len(tasks) == 0 {\n\t\treturn \"\", nil\n\t}\n\n\t// Use the first SSH key, since the autoscaler accepts a single HCLOUD_SSH_KEY.\n\tsshKey, ok := tasks[0].(*hetznertasks.SSHKey)\n\tif !ok {\n\t\treturn \"\", fmt.Errorf(\"SSH key task has unexpected type %T\", tasks[0])\n\t}\n\n\tif sshKey.ID != nil {\n\t\treturn strconv.FormatInt(fi.ValueOf(sshKey.ID), 10), nil\n\t}\n\n\treturn \"\", nil\n}\n","sourceCodeStart":1243,"sourceCodeEnd":1279,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/upup/pkg/fi/cloudup/template_functions.go#L1243-L1279","documentation":"Returned by HCloudSSHKey when TasksByType(\"SSHKey\") fails to enumerate the build's SSHKey tasks. This wraps a lower-level task-lookup failure rather than meaning no SSH keys exist (that case returns an empty string). It indicates the task list itself could not be retrieved.","triggerScenarios":"Calling HCloudSSHKey during template rendering when tf.TasksByType(\"SSHKey\") returns an error, e.g. the task map/context used by TemplateFunctions is not initialized or an internal iteration fails.","commonSituations":"Rendering Hetzner CloudCloudConfig/autoscaler templates with a TemplateFunctions instance missing its task context; refactors that break task registration so lookup fails.","solutions":["Inspect the wrapped cause from TasksByType to see why enumeration failed","Ensure the TemplateFunctions is constructed with a valid task map/context during cloudup","Verify SSHKey tasks are registered before HCloudSSHKey is invoked","Update any customized task-lookup code to match current kops APIs"],"exampleFix":"// before\nsshKeyID, err := tf.HCloudSSHKey()\n// after\nsshKeyID, err := tf.HCloudSSHKey()\nif err != nil {\n\treturn fmt.Errorf(\"resolving HCLOUD_SSH_KEY: %w\", err)\n}","handlingStrategy":"try-catch","validationCode":"// verify tasks context exists before invoking template funcs\nif tf == nil || !tf.HasTasks() { return errors.New(\"template functions missing task context\") }","typeGuard":null,"tryCatchPattern":"sshKeyID, err := tf.HCloudSSHKey()\nif err != nil {\n\treturn fmt.Errorf(\"hccloud ssh key lookup failed: %w\", err)\n}\nif sshKeyID == \"\" { /* decide whether empty is acceptable */ }","preventionTips":["Initialize TemplateFunctions with a fully populated task map","Register SSHKey tasks before rendering Hetzner templates","Add integration tests covering Hetzner template rendering","Distinguish enumeration errors from the legitimate empty-key case"],"tags":["hetzner","task-lookup","kops","template"],"backgroundTag":"task-enumeration-failed","analyzedSha":"4c8573c808a73d578c5eadc86d410646ea0b0d73","analyzedAt":"2026-09-05T04:13:19.212Z","contentChangedAt":"2026-09-05T04:13:19.212Z","schemaVersion":2},"datasetVersion":"2026-09-12T07:17:12.445Z"}