kubernetes/kops · error
error writing to output: %v
Error message
error writing to output: %v
What it means
After successfully YAML-marshaling the key list, the command writes the bytes to the output writer. If that write fails (closed pipe, disk full, permission error on a redirect target), it returns "error writing to output: %v".
Source
Thrown at cmd/kops/get_sshpublickeys.go:126
switch options.Output {
case OutputTable:
if len(items) == 0 {
return fmt.Errorf("no SSH public key found")
}
t := &tables.Table{}
t.AddColumn("ID", func(i *SSHKeyItem) string {
return i.ID
})
return t.Render(items, out, "ID")
case OutputYaml:
y, err := yaml.Marshal(items)
if err != nil {
return fmt.Errorf("unable to marshal YAML: %v", err)
}
if _, err := out.Write(y); err != nil {
return fmt.Errorf("error writing to output: %v", err)
}
case OutputJSON:
j, err := json.Marshal(items)
if err != nil {
return fmt.Errorf("unable to marshal JSON: %v", err)
}
if _, err := out.Write(j); err != nil {
return fmt.Errorf("error writing to output: %v", err)
}
default:
return fmt.Errorf("unknown output format: %q", options.Output)
}
return nil
}
View on GitHub (pinned to 4c8573c808)
Solutions
- Re-run without the early-exiting pipe consumer, or pipe to `cat`
- Check disk space and permissions on the redirect target
- Inspect the wrapped error after 'error writing to output' for the OS-level cause
- Handle EPIPE in wrappers/scripts rather than treating it as a kOps failure
Example fix
// before kops get sshpublickeys -o yaml | head -5 // after kops get sshpublickeys -o yaml | head -5 || true # tolerate SIGPIPE
Defensive patterns
Strategy: try-catch
Validate before calling
out=/path/to/out.yaml; df -h "$(dirname "$out")" | awk 'NR==2 && $5+0 >= 95 {exit 1}'; [ -w "$(dirname "$out")" ] || exit 1 Try / catch
if err := runGetSSHPublicKeys(opts); err != nil {
if strings.HasPrefix(err.Error(), "error writing to output:") && strings.Contains(err.Error(), "broken pipe") {
return nil // consumer closed early; tolerate
}
return err
} Prevention
- Avoid head in pipelines; use awk 'NR<=N' which reads to EOF
- Monitor disk space on CI runners
- Write to a temp file then move, to fail fast on unwritable targets
When it happens
Trigger: `kops get sshpublickeys -o yaml` with stdout piped to a process that exited early (EPIPE), or output redirected to a file on a full filesystem or without write permission.
Common situations: Piping into `head` which closes early; CI logs directory full; redirecting to a read-only file.
Related errors
- error writing to output: %v
- error writing to output: %v
- writing output: %v
- error writing cluster json to stdout: %v
- reading Cilium IPSec config from stdin: %v
AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05).
Data as JSON: /api/errors/466afaa9d73ef9c4.
Report an issue: GitHub.