kubernetes/kops · error

error writing yaml to stdout: %v

Error message

error writing yaml to stdout: %v

What it means

Wraps any error from fullOutputYAML, which serializes all fetched objects (cluster, instance groups, addons) to YAML and writes them to stdout. The marshal step itself may fail (codec issues like error 340) or the write to the output writer may fail. The wrapper contextualizes the failure as a YAML output problem.

Source

Thrown at cmd/kops/get_all.go:129

			addonObjects = append(addonObjects, addon.ToUnstructured())
		}
	}

	var allObjects []runtime.Object
	if options.Output != OutputTable {
		allObjects = append(allObjects, cluster)
		for _, group := range instancegroups {
			allObjects = append(allObjects, group)
		}
		for _, additionalObject := range addonObjects {
			allObjects = append(allObjects, additionalObject)
		}
	}

	switch options.Output {
	case OutputYaml:
		if err := fullOutputYAML(out, allObjects...); err != nil {
			return fmt.Errorf("error writing yaml to stdout: %v", err)
		}

		return nil

	case OutputJSON:
		if err := fullOutputJSON(out, false, allObjects...); err != nil {
			return fmt.Errorf("error writing json to stdout: %v", err)
		}
		return nil

	case OutputTable:
		fmt.Fprintf(out, "Cluster\n")
		err = clusterOutputTable([]*api.Cluster{cluster}, out)
		if err != nil {
			return err
		}
		fmt.Fprintf(out, "\nInstance Groups\n")
		err = igOutputTable(cluster, instancegroups, out)

View on GitHub (pinned to 4c8573c808)

Solutions

  1. Read the wrapped inner error to distinguish marshal failure from write failure
  2. Avoid closing the pipe early (e.g. don't use `| head` or redirect to a writable file)
  3. Check for unregistered/unsupported object kinds and align kops version with cluster state
  4. Retry writing to a file instead of stdout to rule out terminal/pipe issues

Example fix

// before
kops get all mycluster.example.com -o yaml | head -5
// after
kops get all mycluster.example.com -o yaml > cluster.yaml
Defensive patterns

Strategy: try-catch

Try / catch

if err := fullOutputYAML(out, allObjects...); err != nil {
    if errors.Is(err, syscall.EPIPE) {
        return nil // consumer closed the pipe; treat as benign
    }
    return fmt.Errorf("error writing yaml to stdout: %v", err)
}

Prevention

When it happens

Trigger: `kops get all <cluster> -o yaml` where any of the collected objects fails YAML/JSON conversion (unregistered kind, versioning failure) or writing to stdout fails (closed pipe, full disk).

Common situations: Piping output to `head`/a closed pipe causing EPIPE; an addon or instance group object the codecs cannot version; kops version skew with objects stored in the state store.

Related errors


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