{"record":{"id":"cbb9d96d8cec6916","repo":"kubernetes/kops","slug":"kubernetespath-hash-not-supported","errorCode":null,"errorMessage":"KubernetesPath::Hash not supported","messagePattern":"KubernetesPath::Hash not supported","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"util/pkg/vfs/k8sfs.go","lineNumber":133,"sourceCode":"\nfunc (p *KubernetesPath) ReadDir() ([]Path, error) {\n\treturn nil, fmt.Errorf(\"KubernetesPath::ReadDir not supported\")\n}\n\nfunc (p *KubernetesPath) ReadTree(ctx context.Context) ([]Path, error) {\n\treturn nil, fmt.Errorf(\"KubernetesPath::ReadTree not supported\")\n}\n\nfunc (p *KubernetesPath) Base() string {\n\treturn path.Base(p.key)\n}\n\nfunc (p *KubernetesPath) PreferredHash() (*hashing.Hash, error) {\n\treturn p.Hash(hashing.HashAlgorithmMD5)\n}\n\nfunc (p *KubernetesPath) Hash(a hashing.HashAlgorithm) (*hashing.Hash, error) {\n\treturn nil, fmt.Errorf(\"KubernetesPath::Hash not supported\")\n}\n","sourceCodeStart":115,"sourceCodeEnd":135,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/util/pkg/vfs/k8sfs.go#L115-L135","documentation":"KubernetesPath represents a path inside the k8s API (e.g. via a ConfigMap-backed VFS), which stores opaque string objects. The VFS layer cannot compute a content hash for such paths, so Hash() unconditionally returns this error for every hash algorithm.","triggerScenarios":"Any call to KubernetesPath.Hash() — including the common indirect path where vfs path hashing is requested via PreferredHash(), which delegates to Hash(hashing.HashAlgorithmMD5).","commonSituations":"Code that hashes paths generically (e.g. comparing cluster spec files, caching by content hash) when the vfs path happens to be backed by the Kubernetes API server rather than S3/GCS/local storage.","solutions":["Avoid hashing KubernetesPath objects; check the concrete path type before calling Hash/PreferredHash and skip or handle unsupported backends","If you need content identity for k8s-backed data, read the file contents (ReadFile) and hash the bytes yourself","Report/fix upstream: implement Hash or change PreferredHash to return a sentinel like vfs.ErrHashNotSupported so callers can branch"],"exampleFix":"// before\nh, err := path.PreferredHash() // fails for k8s-backed paths\n// after\nif _, ok := path.(*vfs.KubernetesPath); ok {\n    data, err := path.ReadFile(ctx)\n    h := hashing.HashAlgorithmMD5.Hash(data)\n} else {\n    h, err = path.PreferredHash()\n}","handlingStrategy":"type-guard","validationCode":"func canHash(p vfs.Path) bool { _, ok := p.(*vfs.KubernetesPath); return !ok }","typeGuard":"func isKubernetesPath(p vfs.Path) (*vfs.KubernetesPath, bool) { kp, ok := p.(*vfs.KubernetesPath); return kp, ok }","tryCatchPattern":"h, err := p.PreferredHash()\nif err != nil {\n    if _, ok := p.(*vfs.KubernetesPath); ok { /* fall back to hashing ReadFile bytes */ }\n    return err\n}","preventionTips":["Type-check the vfs.Path concrete type before calling Hash/PreferredHash","Hash ReadFile bytes for k8s-backed paths instead of relying on VFS hashing","Treat Hash as an optional capability of the Path interface"],"tags":["vfs","kubernetes","unsupported-operation"],"backgroundTag":"operation-not-supported","analyzedSha":"4c8573c808a73d578c5eadc86d410646ea0b0d73","analyzedAt":"2026-09-05T04:13:19.212Z","contentChangedAt":"2026-09-05T04:13:19.212Z","schemaVersion":2},"datasetVersion":"2026-09-12T07:17:12.445Z"}