{"record":{"id":"a00b72cfeeca17e9","repo":"kubernetes/kops","slug":"unable-to-write-template-s","errorCode":null,"errorMessage":"unable to write template: %s","messagePattern":"unable to write template: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/kops/toolbox_template.go","lineNumber":226,"sourceCode":"\t\t\tdocuments = append(documents, string(formatted))\n\t\t}\n\t}\n\t// join in harmony all the YAML documents back together\n\tcontent := strings.Join(documents, \"---\\n\")\n\n\tiowriter := out\n\t// @check if we are writing to a file rather than stdout\n\tif options.outputPath != \"\" {\n\t\tw, err := os.OpenFile(utils.ExpandPath(options.outputPath), os.O_RDWR|os.O_TRUNC|os.O_CREATE, 0o660)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"unable to open file: %s, error: %v\", options.outputPath, err)\n\t\t}\n\t\tdefer try.CloseFile(w)\n\t\tiowriter = w\n\t}\n\n\tif _, err := iowriter.Write([]byte(content)); err != nil {\n\t\treturn fmt.Errorf(\"unable to write template: %s\", err)\n\t}\n\n\treturn nil\n}\n\n// newTemplateContext is responsible for loading the --values and build a context for the template\nfunc newTemplateContext(files []string, values []string, stringValues []string) (map[string]interface{}, error) {\n\tcontext := make(map[string]interface{})\n\n\tfor _, x := range files {\n\t\tlist, err := expandFiles(utils.ExpandPath(x))\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\tfor _, j := range list {\n\t\t\tcontent, err := os.ReadFile(j)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"unable to configuration file: %s, error: %s\", j, err)","sourceCodeStart":208,"sourceCodeEnd":244,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/cmd/kops/toolbox_template.go#L208-L244","documentation":"After successfully opening the output file (or writing to stdout), RunToolBoxTemplate writes the rendered content with iowriter.Write. If the write fails, this error wraps the underlying write error. Rare for stdout, more plausible for files when disk is full or descriptors are bad.","triggerScenarios":"`kops toolbox template --out <file>` where the write syscall fails: disk full, I/O error, or the file handle becomes invalid during write.","commonSituations":"Full disk on CI runners; network filesystem issues; quota exceeded.","solutions":["Check free disk space (df -h) and clean up if full.","Verify the output filesystem is writable and healthy.","Write to stdout and redirect as a workaround to confirm the failure is storage-related."],"exampleFix":"// before\nkops toolbox template --out /mnt/full-disk/out.yaml\n// after\ndf -h /mnt/full-disk  # free space, then retry\nkops toolbox template --out /mnt/full-disk/out.yaml","handlingStrategy":"try-catch","validationCode":"if st, err := os.Stat(filepath.Dir(outPath)); err == nil && st.IsDir() { // ensure free space\n cmd := exec.Command(\"df\", \"-h\", filepath.Dir(outPath)); _ = cmd.Run() }","typeGuard":null,"tryCatchPattern":"err := run(\"kops\", \"toolbox\", \"template\", \"--out\", p)\nif err != nil && strings.Contains(err.Error(), \"unable to write template\") { check disk space / fs health before retrying }","preventionTips":["Monitor disk space on CI runners","Avoid writing rendered templates to network or read-only mounts","Fall back to stdout output when file writes are unreliable"],"tags":["cli","filesystem","file-io"],"backgroundTag":"file-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"}