{"record":{"id":"9a4a409fb428f349","repo":"kubernetes/kops","slug":"error-creating-temp-dir-v","errorCode":null,"errorMessage":"error creating temp dir: %v","messagePattern":"error creating temp dir: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"channels/pkg/channels/kubectlapplier.go","lineNumber":38,"sourceCode":"\t\"context\"\n\t\"fmt\"\n\t\"os\"\n\t\"os/exec\"\n\t\"path\"\n\t\"strings\"\n\n\t\"k8s.io/klog/v2\"\n)\n\ntype KubectlApplier struct{}\n\n// Apply calls kubectl apply to apply the manifest.\n// We will likely in future change this to create things directly (or more likely embed this logic into kubectl itself)\nfunc (*KubectlApplier) Apply(ctx context.Context, data []byte) error {\n\t// We copy the manifest to a temp file because it is likely e.g. an s3 URL, which kubectl can't read\n\ttmpDir, err := os.MkdirTemp(\"\", \"channel\")\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error creating temp dir: %v\", err)\n\t}\n\n\tdefer func() {\n\t\tif err := os.RemoveAll(tmpDir); err != nil {\n\t\t\tklog.Warningf(\"error deleting temp dir %q: %v\", tmpDir, err)\n\t\t}\n\t}()\n\n\tlocalManifestFile := path.Join(tmpDir, \"manifest.yaml\")\n\tif err := os.WriteFile(localManifestFile, data, 0o600); err != nil {\n\t\treturn fmt.Errorf(\"error writing temp file: %v\", err)\n\t}\n\t// First do an apply. This may fail when removing things from lists/arrays and required fields are not removed.\n\t{\n\t\t_, err := execKubectl(ctx, \"apply\", \"-f\", localManifestFile, \"--server-side\", \"--force-conflicts\", \"--field-manager=kops\")\n\t\tif err != nil {\n\t\t\tklog.Errorf(\"failed to apply the manifest: %v\", err)\n\t\t}","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/channels/pkg/channels/kubectlapplier.go#L20-L56","documentation":"KubectlApplier.Apply shells out to kubectl and must first write the manifest to a temporary directory because the input may be an s3 URL that kubectl cannot read directly. If os.MkdirTemp fails to create the temp dir, this error is returned. It almost always indicates an OS-level filesystem/environment problem, not a cluster issue.","triggerScenarios":"os.MkdirTemp(\"\", \"channel\") failing due to a full or read-only filesystem, a bad TMPDIR environment variable, or exhausted inodes/permissions on the temp directory.","commonSituations":"Container images with tiny or read-only /tmp; TMPDIR set to a non-existent or non-writable path; disk-full nodes running kops.","solutions":["Check TMPDIR points to a writable, existing directory; unset or fix it if wrong.","Verify disk space and inodes on the temp filesystem (df -h /tmp, df -i /tmp).","Ensure the process user has write permission to the temp location.","Run in an environment with a writable /tmp (fix the container spec if needed).","Read the wrapped %v error (e.g. 'no space left on device' vs 'permission denied') to target the fix."],"exampleFix":"// before\nexport TMPDIR=/nonexistent\nkops update cluster ...\n// after\nexport TMPDIR=$(mktemp -d -t kops-tmp-XXXXXX) # or unset TMPDIR to use default /tmp\nkops update cluster ...","handlingStrategy":"validation","validationCode":"tmp := os.TempDir()\nif fi, err := os.Stat(tmp); err != nil || !fi.IsDir() {\n    return fmt.Errorf(\"TMPDIR %q not usable: %v\", tmp, err)\n}\nprobe, err := os.CreateTemp(tmp, \"kops-probe-*\")\nif err != nil {\n    return fmt.Errorf(\"temp dir not writable: %w\", err)\n}\nprobe.Close(); os.Remove(probe.Name())","typeGuard":"func canCreateTempDir() bool {\n    d, err := os.MkdirTemp(\"\", \"channel-probe\")\n    if err != nil { return false }\n    os.RemoveAll(d)\n    return true\n}","tryCatchPattern":"if err := applier.Apply(ctx, data); err != nil {\n    if strings.Contains(err.Error(), \"error creating temp dir\") {\n        return fmt.Errorf(\"fix TMPDIR/disk, then retry: %w\", err)\n    }\n    return err\n}","preventionTips":["Keep TMPDIR set to an existing, writable directory.","Monitor disk space/inodes on nodes running kops.","Ensure containers have a writable /tmp.","Read the wrapped errno (ENOSPC vs EACCES) before acting."],"tags":["filesystem","temp-dir","environment","os"],"backgroundTag":"temp-dir-creation-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"}