kubernetes/kops · error
error reading file %q: %v
Error message
error reading file %q: %v
What it means
`kops create -f` reads each input file via vfsContext.ReadFile (local path or URL). If the file cannot be read (missing file, bad URL, permission denied), the error is wrapped as "error reading file %q: %v".
Source
Thrown at cmd/kops/create.go:121
clusterName := ""
// var cSpec = false
var sb bytes.Buffer
fmt.Fprintf(&sb, "\n")
var addons kubemanifest.ObjectList
var clusters []*kopsapi.Cluster
for _, f := range c.Filenames {
var contents []byte
if f == "-" {
contents, err = ConsumeStdin()
if err != nil {
return err
}
} else {
contents, err = vfsContext.ReadFile(f)
if err != nil {
return fmt.Errorf("error reading file %q: %v", f, err)
}
}
// TODO: this does not support a JSON array
sections := text.SplitContentToSections(contents)
for _, section := range sections {
o, gvk, err := kopscodecs.Decode(section, nil)
if err != nil {
return fmt.Errorf("error parsing file %q: %v", f, err)
}
switch v := o.(type) {
case *kopsapi.Cluster:
cloud, err := cloudup.BuildCloud(v)
if err != nil {
return err
}
// Adding a PerformAssignments() call here as the user might be trying to useView on GitHub (pinned to 4c8573c808)
Solutions
- Verify the file path/URL is correct and the file exists (ls / curl the path)
- Run from the directory containing the manifest or use an absolute path
- Check file read permissions; add cloud credentials if using vfs URLs (s3://, gs://)
- If passing a directory, list individual files instead
Example fix
// before kops create -f ./cluser.yaml // after kops create -f ./cluster.yaml
Defensive patterns
Strategy: validation
Validate before calling
f := "./cluster.yaml"
if _, err := os.Stat(f); err != nil {
log.Fatalf("input file %q not readable: %v", f, err)
} Try / catch
if err := runCreate(); err != nil {
if strings.Contains(err.Error(), "error reading file") {
// surface path & cwd to the user before retrying
}
} Prevention
- Use absolute paths or run from the manifest's directory
- Pre-check file existence/permissions before invoking `kops create -f`
- Verify credentials before using s3://, gs://, or https:// input URLs
- Do not pass directories to -f
When it happens
Trigger: Running `kops create -f <path>` where the path does not exist, is misspelled, is unreadable (permissions), or an http(s)/s3 URL fails to fetch.
Common situations: Typos in the -f argument, running from the wrong working directory, forgetting the file is on a remote location not reachable without cloud credentials, or reading a directory instead of a file.
Understand the failure class
Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.
Related errors
- error reading SSH key file %q: %v
- error reading SSH public key files %q: %v
- error reading user provided cert %q: %v
- reading Cilium IPSec config %v: %v
- unable to open file: %s, error: %v
AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05).
Data as JSON: /api/errors/61ab83cafb6109c1.
Report an issue: GitHub.