kubernetes/kops · error

error getting file status of %q: %v

Error message

error getting file status of %q: %v

What it means

os.Stat on the hosts file path failed before any mutation is applied; typically the file does not exist, or the path is unreadable due to permissions or a missing mount in the container/host context.

Source

Thrown at pkg/dns/hosts/hosts.go:116

	for _, record := range m.records {
		if record.Hostname == hostname {
			continue
		}
		newRecords = append(newRecords, record)
	}

	m.records = newRecords
}

// UpdateHostsFileWithRecords updates /etc/hosts by applying the given mutation function.
func UpdateHostsFileWithRecords(p string, mutator func(guarded []string) (*HostMap, error)) error {
	// For safety / sanity, we avoid concurrent updates from one process
	hostsFileMutex.Lock()
	defer hostsFileMutex.Unlock()

	stat, err := os.Stat(p)
	if err != nil {
		return fmt.Errorf("error getting file status of %q: %v", p, err)
	}

	data, err := os.ReadFile(p)
	if err != nil {
		return fmt.Errorf("error reading file %q: %v", p, err)
	}

	var guarded []string
	var out []string
	inGuardBlock := false
	for _, line := range strings.Split(string(data), "\n") {
		k := strings.TrimSpace(line)
		if k == GUARD_BEGIN {
			if inGuardBlock {
				klog.Warningf("/etc/hosts guard-block begin seen while in guard block; will ignore")
			}
			inGuardBlock = true
		}

View on GitHub (pinned to 4c8573c808)

Solutions

  1. Verify the hosts file path (e.g. /etc/hosts) exists in this context
  2. Check read permissions on the path
  3. Create the file with mode 0644 first if it legitimately does not exist
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at pkg/dns/hosts/hosts.go:116 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05). Data as JSON: /api/errors/4df8694afaf14801. Report an issue: GitHub.