kubernetes/kops · error

error writing cluster yaml to stdout: %v

Error message

error writing cluster yaml to stdout: %v

What it means

In --dry-run mode with YAML output, fullOutputYAML(out, ig) failed to serialize/write the generated InstanceGroup to stdout. The error is the YAML marshaling or writer failure, wrapped with the cluster-yaml message.

Source

Thrown at cmd/kops/toolbox_instance-selector.go:331

		ig, err = cloudup.PopulateInstanceGroupSpec(cluster, ig, cloud, channel)
		if err != nil {
			return err
		}

		newInstanceGroups = append(newInstanceGroups, ig)

		if igCount != 1 {
			doubledRatio := (*mutatedFilters.VCpusToMemoryRatio) * 2
			mutatedFilters.VCpusToMemoryRatio = &doubledRatio
		}
	}

	if options.DryRun {
		for _, ig := range newInstanceGroups {
			switch options.Output {
			case OutputYaml:
				if err := fullOutputYAML(out, ig); err != nil {
					return fmt.Errorf("error writing cluster yaml to stdout: %v", err)
				}
			case OutputJSON:
				if err := fullOutputJSON(out, true, ig); err != nil {
					return fmt.Errorf("error writing cluster json to stdout: %v", err)
				}
			default:
				return fmt.Errorf("unsupported output type %q", options.Output)
			}
		}
		return nil
	}

	for _, ig := range newInstanceGroups {
		_, err = clientset.InstanceGroupsFor(cluster).Create(ctx, ig, metav1.CreateOptions{})
		if err != nil {
			return fmt.Errorf("error storing InstanceGroup: %v", err)
		}

View on GitHub (pinned to 4c8573c808)

Solutions

  1. Check the wrapped cause: if it is EPIPE, the downstream consumer closed stdout — rerun without the pipe or with `cat`.
  2. Rerun with --output json to see if JSON serialization succeeds, isolating the YAML issue.
  3. Ensure stdout is a writable, open stream (no redirect to a full disk).
  4. Upgrade/downgrade kOps if the serialized spec fields mismatch your expected schema.

Example fix

// before
kops toolbox instance-selector ... | head -5
// after
kops toolbox instance-selector ... > instance-groups.yaml
Defensive patterns

Strategy: try-catch

Validate before calling

if options.Output != OutputYaml && options.Output != OutputJSON {
	return fmt.Errorf("unsupported output %q; use yaml|json", options.Output)
}

Try / catch

if err := fullOutputYAML(out, ig); err != nil {
	if errors.Is(err, syscall.EPIPE) {
		log.Println("stdout closed by consumer; output discarded")
		return nil
	}
	return fmt.Errorf("error writing cluster yaml to stdout: %v", err)
}

Prevention

When it happens

Trigger: fullOutputYAML returns an error during yaml.Marshal of the InstanceGroup or when writing to the out writer (e.g. broken pipe, serialization of an unsupported field).

Common situations: Piping output into a command that exits early (`| head`) causing EPIPE; an InstanceGroup field that cannot be marshaled due to a kOps version mismatch of schema types.

Related errors


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