node-lookup: auto-qualify short node names to .main.unkin.net #19

Merged
benvin merged 1 commits from benvin/node-lookup-shortname into main 2026-08-15 14:50:36 +10:00
Member

Short -n node names silently returned nothing: node-lookup -R -n ausyd1nxvm2120 found nothing while -n ausyd1nxvm2120.main.unkin.net worked, because the PuppetDB certname filter needs a FQDN. This auto-qualifies a dotless name before the lookup.

Changes

  • Add qualifyNode() pure helper: a dotless name gets .<domain> appended; a name already containing a dot (any domain, incl. *.k8s.syd1.au.unkin.net) is left unchanged; a single trailing dot is stripped first; empty input is preserved (same "no node" behavior as today).
  • Apply normalization to the -n value and to stdin-sourced node names in run(), so both entry points behave consistently.
  • Make the domain configurable: config key domain, NODE_LOOKUP_DOMAIN env var, and --domain flag, all defaulting to main.unkin.net.
  • Surface domain in config show / config init output and document the new env var/flag/behavior in AGENTS.md.
  • Add table-driven qualifyNode tests (short name appended, FQDN unchanged, multi-label other-domain FQDN unchanged, trailing-dot handling, empty input, custom domain) and a NODE_LOOKUP_DOMAIN env-override test.

Companion tools pburl/pblastreport take already-qualified hostnames (typically piped from node-lookup) via puppet.ReadHosts and do not share the -n code path, so they are intentionally left out to keep this PR atomic.

Validation

  • gofmt -l . clean, go vet ./... clean
  • go test -race ./... pass
  • make build builds all three binaries
Short `-n` node names silently returned nothing: `node-lookup -R -n ausyd1nxvm2120` found nothing while `-n ausyd1nxvm2120.main.unkin.net` worked, because the PuppetDB `certname` filter needs a FQDN. This auto-qualifies a dotless name before the lookup. ## Changes - Add `qualifyNode()` pure helper: a dotless name gets `.<domain>` appended; a name already containing a dot (any domain, incl. `*.k8s.syd1.au.unkin.net`) is left unchanged; a single trailing dot is stripped first; empty input is preserved (same "no node" behavior as today). - Apply normalization to the `-n` value and to stdin-sourced node names in `run()`, so both entry points behave consistently. - Make the domain configurable: config key `domain`, `NODE_LOOKUP_DOMAIN` env var, and `--domain` flag, all defaulting to `main.unkin.net`. - Surface `domain` in `config show` / `config init` output and document the new env var/flag/behavior in AGENTS.md. - Add table-driven `qualifyNode` tests (short name appended, FQDN unchanged, multi-label other-domain FQDN unchanged, trailing-dot handling, empty input, custom domain) and a `NODE_LOOKUP_DOMAIN` env-override test. Companion tools `pburl`/`pblastreport` take already-qualified hostnames (typically piped from `node-lookup`) via `puppet.ReadHosts` and do not share the `-n` code path, so they are intentionally left out to keep this PR atomic. ## Validation - `gofmt -l .` clean, `go vet ./...` clean - `go test -race ./...` pass - `make build` builds all three binaries
unkin-agent added 1 commit 2026-08-15 13:49:19 +10:00
node-lookup: auto-qualify short node names to .main.unkin.net
ci/woodpecker/pr/build Pipeline was successful
ci/woodpecker/pr/test Pipeline was successful
ci/woodpecker/pr/pre-commit Pipeline was successful
807d3df71c
Short -n node names (no dot) now silently returned nothing because the
PuppetDB certname filter needs a FQDN. Auto-qualify a dotless name to
<name>.<domain> (domain defaults to main.unkin.net) before the query.

- Add qualifyNode() pure helper: dotless names get .<domain> appended;
  names already containing a dot (any domain) are left unchanged; a single
  trailing dot is stripped; empty input is preserved.
- Apply it to the -n value and to stdin-sourced node names in run().
- Make the domain configurable via config key domain, NODE_LOOKUP_DOMAIN
  env var, and --domain flag (default main.unkin.net).
- Surface domain in config show / config init and document in AGENTS.md.
- Add table-driven qualifyNode tests and a domain env-override test.
benvin merged commit 35edc9c547 into main 2026-08-15 14:50:36 +10:00
benvin deleted branch benvin/node-lookup-shortname 2026-08-15 14:50:36 +10:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: unkin/node-lookup#19