kubernetes/kops · error
error creating temp dir: %v
Error message
error creating temp dir: %v
What it means
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.
Source
Thrown at channels/pkg/channels/kubectlapplier.go:38
"context"
"fmt"
"os"
"os/exec"
"path"
"strings"
"k8s.io/klog/v2"
)
type KubectlApplier struct{}
// Apply calls kubectl apply to apply the manifest.
// We will likely in future change this to create things directly (or more likely embed this logic into kubectl itself)
func (*KubectlApplier) Apply(ctx context.Context, data []byte) error {
// We copy the manifest to a temp file because it is likely e.g. an s3 URL, which kubectl can't read
tmpDir, err := os.MkdirTemp("", "channel")
if err != nil {
return fmt.Errorf("error creating temp dir: %v", err)
}
defer func() {
if err := os.RemoveAll(tmpDir); err != nil {
klog.Warningf("error deleting temp dir %q: %v", tmpDir, err)
}
}()
localManifestFile := path.Join(tmpDir, "manifest.yaml")
if err := os.WriteFile(localManifestFile, data, 0o600); err != nil {
return fmt.Errorf("error writing temp file: %v", err)
}
// First do an apply. This may fail when removing things from lists/arrays and required fields are not removed.
{
_, err := execKubectl(ctx, "apply", "-f", localManifestFile, "--server-side", "--force-conflicts", "--field-manager=kops")
if err != nil {
klog.Errorf("failed to apply the manifest: %v", err)
}View on GitHub (pinned to 4c8573c808)
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.
Example fix
// before export TMPDIR=/nonexistent kops update cluster ... // after export TMPDIR=$(mktemp -d -t kops-tmp-XXXXXX) # or unset TMPDIR to use default /tmp kops update cluster ...
Defensive patterns
Strategy: validation
Validate before calling
tmp := os.TempDir()
if fi, err := os.Stat(tmp); err != nil || !fi.IsDir() {
return fmt.Errorf("TMPDIR %q not usable: %v", tmp, err)
}
probe, err := os.CreateTemp(tmp, "kops-probe-*")
if err != nil {
return fmt.Errorf("temp dir not writable: %w", err)
}
probe.Close(); os.Remove(probe.Name()) Type guard
func canCreateTempDir() bool {
d, err := os.MkdirTemp("", "channel-probe")
if err != nil { return false }
os.RemoveAll(d)
return true
} Try / catch
if err := applier.Apply(ctx, data); err != nil {
if strings.Contains(err.Error(), "error creating temp dir") {
return fmt.Errorf("fix TMPDIR/disk, then retry: %w", err)
}
return err
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: Container images with tiny or read-only /tmp; TMPDIR set to a non-existent or non-writable path; disk-full nodes running kops.
Related errors
- error writing temp file: %v
- error reading addons file %s: %v
- reading %q certificate: %v
- error reading user provided private key %q: %v
- reading encryption config %v: %v
AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05).
Data as JSON: /api/errors/9a4a409fb428f349.
Report an issue: GitHub.