{"record":{"id":"3c4db3a159bdfbad","repo":"kubernetes/kops","slug":"error-writing-cluster-yaml-to-stdout-v","errorCode":null,"errorMessage":"error writing cluster yaml to stdout: %v","messagePattern":"error writing cluster yaml to stdout: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/kops/create_cluster.go","lineNumber":811,"sourceCode":"\t\t\t\t\tName: name,\n\t\t\t\t\tLabels: map[string]string{\n\t\t\t\t\t\tapi.LabelClusterName: cluster.Name,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\tSpec: api.SSHCredentialSpec{\n\t\t\t\t\tPublicKey: strings.TrimSpace(string(key)),\n\t\t\t\t},\n\t\t\t})\n\t\t}\n\n\t\tfor _, o := range addons {\n\t\t\tobj = append(obj, o.ToUnstructured())\n\t\t}\n\n\t\tswitch c.Output {\n\t\tcase OutputYaml:\n\t\t\tif err := fullOutputYAML(out, obj...); err != nil {\n\t\t\t\treturn fmt.Errorf(\"error writing cluster yaml to stdout: %v\", err)\n\t\t\t}\n\t\t\treturn nil\n\t\tcase OutputJSON:\n\t\t\tif err := fullOutputJSON(out, true, obj...); err != nil {\n\t\t\t\treturn fmt.Errorf(\"error writing cluster json to stdout: %v\", err)\n\t\t\t}\n\t\t\treturn nil\n\t\tdefault:\n\t\t\treturn fmt.Errorf(\"unsupported output type %q\", c.Output)\n\t\t}\n\t}\n\n\t// Note we perform as much validation as we can, before writing a bad config\n\terr = registry.CreateClusterConfig(ctx, clientset, cluster, instanceGroups, addons)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error writing updated configuration: %v\", err)\n\t}\n","sourceCodeStart":793,"sourceCodeEnd":829,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/cmd/kops/create_cluster.go#L793-L829","documentation":"In DryRun mode, RunCreateCluster serializes the cluster and objects to YAML via fullOutputYAML and writes them to stdout. This error means YAML marshaling or writing to the output writer failed. It wraps the underlying marshal/write error and only occurs with --dry-run --output yaml.","triggerScenarios":"`kops create cluster --dry-run --output yaml` where fullOutputYAML fails to marshal the runtime.Objects or the underlying writer (e.g. a piped stdout) errors on write.","commonSituations":"Stdout piped to a closed/full pipe or unwritable file in scripts; an internal serialization bug on an unexpected object type attached via addons.","solutions":["Retry without piping stdout, or redirect to a writable file (e.g. > cluster.yaml).","Check the wrapped error to distinguish marshal vs write failure.","Re-run with a plain terminal to confirm it is an environment, not a spec, problem.","Report a bug if marshaling a stock spec fails (likely a kops defect)."],"exampleFix":"// before\nkops create cluster ... --dry-run --output yaml | head -1   # broken pipe\n// after\nkops create cluster ... --dry-run --output yaml > cluster.yaml","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"out, err := os.Create(\"cluster.yaml\")\nif err != nil { return err }\ndefer out.Close()\nif err := runCreateCluster(ctx, out, ...); err != nil {\n\tif strings.Contains(err.Error(), \"error writing cluster yaml\") {\n\t\t// marshal or write failed; retry with a fresh writer/file\n\t}\n\treturn err\n}","preventionTips":["Redirect dry-run output to a real file, not a fragile pipe.","Ensure the output file's directory exists and has space.","Keep kops updated; marshal failures on stock specs are usually bugs.","Avoid `| head` style pipelines with kops output."],"tags":["cli","dry-run","yaml-output"],"backgroundTag":"stdout-write-failed","analyzedSha":"4c8573c808a73d578c5eadc86d410646ea0b0d73","analyzedAt":"2026-09-05T04:13:19.212Z","contentChangedAt":"2026-09-05T04:13:19.212Z","schemaVersion":2},"datasetVersion":"2026-09-12T07:17:12.445Z"}