Skip to content

k8s WK8102 prints [object Object] for a manifest whose metadata.name is not a string #5110

Closed

Description

@lex00

chant audit reads a template file that holds name: {{name}} as a Kubernetes manifest. YAML parses {{name}} as a flow mapping whose key is another mapping, so metadata.name is an object. WK8102 then reports Namespace "[object Object]" has no metadata.labels, and the finding's entity in the JSON report is the object {"[object Object]": null} where the report model expects a string. The file on kubernetes/k8s.io is infra/gcp/bash/namespaces/namespace.yml, a template a shell script fills in.

Reproduce

Run with chant 0.124.95 from npm.

tree/namespace.yml:

apiVersion: v1
kind: Namespace
metadata:
  name: {{name}}
chant audit tree --format json --tier all --fail-on none -o out.json

The report holds one finding: checkId WK8102, entity {"[object Object]": null}, message starting Namespace "[object Object]" has no metadata.labels.

Expected

A document whose metadata.name is not a string is not read as a named object. The audit skips it with a notice naming the file (a template placeholder is the common cause), or reports it under the file with no entity. Every finding's entity in the JSON report is a string or absent. No message prints [object Object].

Where

lexicons/k8s/src/lint/post-synth/wk8102.ts (manifest.metadata.name ?? manifest.kind, with no type check; it is the only post-synth rule in the k8s lexicon with that fallback). The same unchecked cast is in parseDocument in lexicons/k8s/src/import/parser.ts (metadata.name as string | undefined).

Found while reading kubernetes/k8s.io offline, for #5067. Tracked on #5105.

Metadata

Metadata

Assignees

No one assigned

    Labels

    epic:estate-read

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions