kubernetes/kops · error
listing SSH key tasks: %w
Error message
listing SSH key tasks: %w
What it means
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.
Source
Thrown at upup/pkg/fi/cloudup/template_functions.go:1261
// Use an encoder with HTML escaping disabled so the embedded cloud-init script stays readable.
var buf bytes.Buffer
enc := json.NewEncoder(&buf)
enc.SetEscapeHTML(false)
enc.SetIndent("", " ")
if err := enc.Encode(config); err != nil {
return "", fmt.Errorf("marshaling cluster config: %w", err)
}
// Strip the trailing newline that json.Encoder.Encode appends.
return strings.TrimRight(buf.String(), "\n"), nil
}
// HCloudSSHKey returns HCLOUD_SSH_KEY as the first SSH key ID.
func (tf *TemplateFunctions) HCloudSSHKey() (string, error) {
tasks, err := tf.TasksByType("SSHKey")
if err != nil {
return "", fmt.Errorf("listing SSH key tasks: %w", err)
}
if len(tasks) == 0 {
return "", nil
}
// Use the first SSH key, since the autoscaler accepts a single HCLOUD_SSH_KEY.
sshKey, ok := tasks[0].(*hetznertasks.SSHKey)
if !ok {
return "", fmt.Errorf("SSH key task has unexpected type %T", tasks[0])
}
if sshKey.ID != nil {
return strconv.FormatInt(fi.ValueOf(sshKey.ID), 10), nil
}
return "", nil
}
View on GitHub (pinned to 4c8573c808)
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
Example fix
// before
sshKeyID, err := tf.HCloudSSHKey()
// after
sshKeyID, err := tf.HCloudSSHKey()
if err != nil {
return fmt.Errorf("resolving HCLOUD_SSH_KEY: %w", err)
} Defensive patterns
Strategy: try-catch
Validate before calling
// verify tasks context exists before invoking template funcs
if tf == nil || !tf.HasTasks() { return errors.New("template functions missing task context") } Try / catch
sshKeyID, err := tf.HCloudSSHKey()
if err != nil {
return fmt.Errorf("hccloud ssh key lookup failed: %w", err)
}
if sshKeyID == "" { /* decide whether empty is acceptable */ } Prevention
- 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
When it happens
Trigger: 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.
Common situations: Rendering Hetzner CloudCloudConfig/autoscaler templates with a TemplateFunctions instance missing its task context; refactors that break task registration so lookup fails.
Related errors
- error parsing template %q: %w
- error executing template %q: %w
- template tasks are not available during this render phase
- finding server group task for instance group %q: %w
- marshaling cluster config: %w
AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05).
Data as JSON: /api/errors/44efcc559ec9218c.
Report an issue: GitHub.