{"record":{"id":"1e73c59a533d30ad","repo":"kubernetes/kops","slug":"error-getting-relative-path-for-s","errorCode":null,"errorMessage":"error getting relative path for %s","messagePattern":"error getting relative path for (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/templates/templates.go","lineNumber":74,"sourceCode":"func (t *Templates) loadFrom(ctx context.Context, base vfs.Path) error {\n\tfiles, err := base.ReadTree(ctx)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error reading from %s\", base)\n\t}\n\n\tfor _, f := range files {\n\t\tcontents, err := f.ReadFile(ctx)\n\t\tif err != nil {\n\t\t\tif os.IsNotExist(err) {\n\t\t\t\t// This is just an annoyance of gobindata - we can't tell the difference between files & directories.  Ignore.\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\treturn fmt.Errorf(\"error reading %s: %v\", f, err)\n\t\t}\n\n\t\tkey, err := vfs.RelativePath(base, f)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"error getting relative path for %s\", f)\n\t\t}\n\n\t\tisTemplate := strings.HasSuffix(key, \".template\")\n\t\tkey = strings.TrimSuffix(key, \".template\")\n\t\tklog.V(6).Infof(\"loading resource %q\", key)\n\t\tt.resources[key] = fi.NewBytesResource(contents)\n\t\tt.isTemplate[key] = isTemplate\n\t}\n\treturn nil\n}\n","sourceCodeStart":56,"sourceCodeEnd":85,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/pkg/templates/templates.go#L56-L85","documentation":"For each file read, loadFrom computes its path relative to the template base directory via vfs.RelativePath to derive the template key. If RelativePath fails (the file is not actually under the base path), the layout is inconsistent and loading aborts with this error.","triggerScenarios":"vfs.RelativePath(base, f) returns an error because the VFS entry f cannot be expressed as a child of the base path — e.g. mixed VFS backends, symlinks escaping the base, or an unusual path construction.","commonSituations":"Mounting/overlapping VFS paths (a base directory that is an ancestor/sibling mismatch), custom model directories with symlinks pointing outside the base, or backend-specific path quirks in S3/GCS prefixes.","solutions":["Ensure the template base directory is a plain directory containing the templates directly (no symlinks escaping it)","Use a single consistent VFS backend for base and its contents","Check for duplicate/overlapping --model or path configuration","If it persists, inspect vfs.RelativePath's inputs by logging base and f at higher verbosity"],"exampleFix":"// before\nln -s /home/me/extra-templates ~/.kops/models/mymodel/extra  # escapes base\n// after\ncp -rL /home/me/extra-templates ~/.kops/models/mymodel/extra # copy contents inside base","handlingStrategy":"validation","validationCode":"// Ensure the file lives under base before adding it\nrel, err := vfs.RelativePath(base, f)\nif err != nil {\n\tklog.Warningf(\"skipping %s: not under %s\", f, base)\n}","typeGuard":"func isUnderBase(base, f vfs.Path) bool {\n\t_, err := vfs.RelativePath(base, f)\n\treturn err == nil\n}","tryCatchPattern":null,"preventionTips":["Keep template dirs plain directories without symlinks escaping the base","Use one VFS backend consistently for base and contents","Avoid overlapping/ambiguous path prefixes in model configuration"],"tags":["vfs","templates","path"],"backgroundTag":"vfs-relative-path-failed","analyzedSha":"4c8573c808a73d578c5eadc86d410646ea0b0d73","analyzedAt":"2026-09-05T04:13:19.212Z","contentChangedAt":"2026-09-05T04:13:19.212Z","schemaVersion":2},"datasetVersion":"2026-09-12T12:17:11.808Z"}