kubernetes/kops · error

error writing cluster json to stdout: %v

Error message

error writing cluster json to stdout: %v

What it means

Same flow as the YAML variant but for --output json: fullOutputJSON fails to marshal the objects or write them to stdout. RunCreateCluster wraps and returns the error, aborting the dry-run output path.

Source

Thrown at cmd/kops/create_cluster.go:816

				Spec: api.SSHCredentialSpec{
					PublicKey: strings.TrimSpace(string(key)),
				},
			})
		}

		for _, o := range addons {
			obj = append(obj, o.ToUnstructured())
		}

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

	// Note we perform as much validation as we can, before writing a bad config
	err = registry.CreateClusterConfig(ctx, clientset, cluster, instanceGroups, addons)
	if err != nil {
		return fmt.Errorf("error writing updated configuration: %v", err)
	}

	if len(c.SSHPublicKeys) == 0 {
		autoloadSSHPublicKeys := true
		switch c.CloudProvider {
		case "gce", "aws":
			autoloadSSHPublicKeys = false

View on GitHub (pinned to 4c8573c808)

Solutions

  1. Ensure the redirect target is writable and the pipe stays open.
  2. Re-run without redirection to isolate the cause.
  3. Use --output yaml as a fallback to still inspect the dry-run spec.
  4. File an issue with the wrapped error if it is a marshal failure on a default spec.

Example fix

// before
kops create cluster ... --dry-run --output json > /dev/full
// after
kops create cluster ... --dry-run --output json > cluster.json
Defensive patterns

Strategy: try-catch

Try / catch

if err := runCreateCluster(...); err != nil {
	if strings.Contains(err.Error(), "error writing cluster json") {
		// fall back to --output yaml, which uses a different serializer
	}
	return err
}

Prevention

When it happens

Trigger: `kops create cluster --dry-run --output json` where fullOutputJSON returns an error (JSON marshal failure or writer failure).

Common situations: Stdout redirected to an unwritable target in shell pipelines; an object set containing something not JSON-serializable (rare; usually a kops bug).

Related errors


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