cilium/cilium · critical

%s is a file which is not a directory

Error message

%s is a file which is not a directory

What it means

If `os.Stat(cgroupRoot)` succeeds but shows the path is a regular file rather than a directory, cilium cannot mount cgroup2 there and fails with this error.

Source

Thrown at pkg/cgroups/cgroups_linux.go:28

	"golang.org/x/sys/unix"

	"github.com/cilium/cilium/pkg/mountinfo"
)

// mountCgroup mounts the Cgroup v2 filesystem into the desired cgroupRoot directory.
func mountCgroup() error {
	cgroupRootStat, err := os.Stat(cgroupRoot)
	if err != nil {
		if os.IsNotExist(err) {
			if err := os.MkdirAll(cgroupRoot, 0755); err != nil {
				return fmt.Errorf("Unable to create cgroup mount directory: %w", err)
			}
		} else {
			return fmt.Errorf("Failed to stat the mount path %s: %w", cgroupRoot, err)
		}
	} else if !cgroupRootStat.IsDir() {
		return fmt.Errorf("%s is a file which is not a directory", cgroupRoot)
	}

	if err := unix.Mount("none", cgroupRoot, "cgroup2", 0, ""); err != nil {
		return fmt.Errorf("failed to mount %s: %w", cgroupRoot, err)
	}

	return nil
}

// checkOrMountCustomLocation tries to check or mount the cgroup filesystem in the
// given path.
func cgrpCheckOrMountLocation(cgroupRoot string) error {
	setCgroupRoot(cgroupRoot)

	// Check whether the custom location has a mount.
	mounted, cgroupInstance, err := mountinfo.IsMountFS(mountinfo.FilesystemTypeCgroup2, cgroupRoot)
	if err != nil {
		return err

View on GitHub (pinned to ac7b90affa)

Solutions

  1. Remove or rename the file: `rm /run/cilium/cgroupv2` (verify it's not needed), then let cilium recreate it
  2. Fix the Kubernetes volume `type` to `DirectoryOrCreate`
  3. Point `--cgroup-root` at a proper empty directory

Example fix

# before
ls -la /run/cilium/cgroupv2   # -rw-r--r-- file
# after
rm /run/cilium/cgroupv2
mkdir -p /run/cilium/cgroupv2
Defensive patterns

Strategy: validation

Validate before calling

const cgroupRoot = "/run/cilium/cgroupv2"
if fi, err := os.Stat(cgroupRoot); err == nil && !fi.IsDir() {
    return fmt.Errorf("%s exists but is not a directory; remove it", cgroupRoot)
}

Try / catch

if err := cgroups.Init(cgroupRoot); err != nil {
    if strings.Contains(err.Error(), "is a file which is not a directory") {
        os.Remove(cgroupRoot) // careful: only if stale
        return cgroups.Init(cgroupRoot)
    }
    return err
}

Prevention

When it happens

Trigger: `cgrpCheckOrMountLocation` -> `mountCgroup` when a file already exists at the configured cgroup-root path (e.g. a stale bind-mounted file, a leftover from a bad provisioner, or someone created the path with `touch`).

Common situations: Kubernetes hostPath volumes created with `type: File`; leftover artifacts after failed upgrades; manual misconfiguration of --cgroup-root.

Related errors


AI-assisted analysis of cilium/cilium@ac7b90affa (2026-08-31). Data as JSON: /api/errors/7779e021b9fe1726. Report an issue: GitHub.