kubernetes/kops · error
unable to read snippet: %s, error: %s
Error message
unable to read snippet: %s, error: %s
What it means
Returned by RunToolBoxTemplate when os.ReadFile fails on a snippet file that expandFiles successfully discovered. The glob expanded to a file list, but reading one of the individual files failed — typically a race (file deleted between listing and read), a permission error on the file itself, or a broken symlink.
Source
Thrown at cmd/kops/toolbox_template.go:162
for _, x := range options.templatePath {
list, err := expandFiles(utils.ExpandPath(x))
if err != nil {
return fmt.Errorf("unable to expand the template: %s, error: %s", x, err)
}
templates = append(templates, list...)
}
snippets := make(map[string]string)
for _, x := range options.snippetsPath {
list, err := expandFiles(utils.ExpandPath(x))
if err != nil {
return fmt.Errorf("unable to expand the snippets: %s, error: %s", x, err)
}
for _, j := range list {
content, err := os.ReadFile(j)
if err != nil {
return fmt.Errorf("unable to read snippet: %s, error: %s", j, err)
}
snippets[path.Base(j)] = string(content)
}
}
channel, err := kopsapi.LoadChannel(f.VFSContext(), options.channel)
if err != nil {
return fmt.Errorf("error loading channel %q: %v", options.channel, err)
}
// @step: render each of the templates, splitting on the documents
r := templater.NewTemplater(channel)
var documents []string
for _, x := range templates {
content, err := os.ReadFile(x)
if err != nil {
return fmt.Errorf("unable to read template: %s, error: %s", x, err)
}View on GitHub (pinned to 4c8573c808)
Solutions
- Check permissions on the specific file named in the error (ls -l) and grant read access (chmod/chown)
- Verify the file exists and is a regular file, not a broken symlink: ls -lL <file>
- Re-run after ensuring no concurrent process deletes files in the snippets directory
- If files are on a network/EFS mount, verify the mount is healthy and remount if needed
Example fix
// before -rw------- snippet.yaml (owned by another user) // after chmod a+r ./snippets/snippet.yaml kops toolbox template --template-path ./templates --snippets-path ./snippets --values values.yaml
Defensive patterns
Strategy: try-catch
Validate before calling
matches, _ := filepath.Glob(snippetDir)
for _, f := range matches {
if fi, err := os.Stat(f); err != nil || fi.IsDir() || fi.Mode().Perm()&0o400 == 0 {
return fmt.Errorf("snippet %s unreadable", f)
}
} Try / catch
if _, err := os.ReadFile(snippetFile); err != nil {
if errors.Is(err, os.ErrPermission) {
return fmt.Errorf("fix permissions on %s: %w", snippetFile, err)
}
if errors.Is(err, os.ErrNotExist) {
return fmt.Errorf("snippet %s disappeared or is a broken symlink", snippetFile)
}
return err
} Prevention
- Keep snippet files world-readable (0644) in shared directories
- Avoid concurrent cleanup jobs touching the snippets directory during renders
- Replace dangling symlinks with real files or fix their targets
When it happens
Trigger: A snippet file listed by expandFiles is unreadable: permissions deny read for the kops user, the file was removed between glob expansion and ReadFile (CI cleanup, tmp dir), the entry is a dangling symlink, or it's a directory-ish entry without read access.
Common situations: Snippet files with restrictive modes (e.g. 0600 owned by another user) inside a shared snippets dir; snippets on a network mount that dropped out; CI pipelines cleaning up generated snippets mid-run; symlinked snippet dirs pointing to a removed location.
Related errors
- unable to expand the snippets: %s, error: %s
- unable to read template: %s, error: %s
- creating directory %q: %w
- creating file %q: %w
- error creating output directory %q: %v
AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05).
Data as JSON: /api/errors/9c89a53204d722c7.
Report an issue: GitHub.