feat(bootstrap): read the instance ID from a command #33

Merged
mikluko merged 2 commits from instance-id-command into main 2026-11-28 21:59:55 +00:00
Owner

NetActuate has no metadata service: the ID is only in the NoCloud seed, which cloud-init query reads. bootstrap.Config.InstanceIDCommand is set in place of InstanceIDURL; the generated join runs it as sh -c from a single-quoted word and refuses an empty result, as it does for the URL read.

Zone stays URL-only: no provider needs it from a command yet.

🤖 Generated with Claude Code

NetActuate has no metadata service: the ID is only in the NoCloud seed, which `cloud-init query` reads. `bootstrap.Config.InstanceIDCommand` is set in place of `InstanceIDURL`; the generated join runs it as `sh -c` from a single-quoted word and refuses an empty result, as it does for the URL read. Zone stays URL-only: no provider needs it from a command yet. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
feat(bootstrap): read the instance ID from a command
All checks were successful
CI / verify (pull_request) Has been skipped
CI / changelog (pull_request) Successful in 1s
Vulnerabilities / govulncheck-1 (pull_request) Successful in 11s
Vulnerabilities / govulncheck (pull_request) Successful in 0s
CI / check (pull_request) Successful in 1m2s
CI / ci (pull_request) Successful in 0s
f3783286a9
NetActuate has no metadata service: the ID is only in the NoCloud seed,
which cloud-init query reads. The command runs under sh -c from a single-
quoted word, so it cannot break the join script, and gets the same
empty-value check as the URL read.

Assisted-By: Claude <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Author
Owner

Review (provider-exoscale session): green. bootstrap tests pass at the PR head; existing goldens untouched, metadataRead's message renders as before.

Non-blocking:

  • The 'command failed' case passes through the empty-output check rather than the exit status. sh -c of a pipeline reports only the last stage (no pipefail in dash), so for the NetActuate example, a failing cloud-init becomes an empty sed output. Worth one doc clause on InstanceIDCommand: the command's exit status is its last stage's. Also, sed passes an ID that doesn't match the pattern through unchanged; that's NetActuate's to guard, not kit's.
  • The value is checked only for non-blank, so an ID with inner or trailing spaces reaches --provider-id unquoted inside kubelet_args. Consider a case pattern that refuses whitespace in instance_id (and zone) before the join.
Review (provider-exoscale session): green. bootstrap tests pass at the PR head; existing goldens untouched, metadataRead's message renders as before. Non-blocking: - The 'command failed' case passes through the empty-output check rather than the exit status. sh -c of a pipeline reports only the last stage (no pipefail in dash), so for the NetActuate example, a failing cloud-init becomes an empty sed output. Worth one doc clause on InstanceIDCommand: the command's exit status is its last stage's. Also, sed passes an ID that doesn't match the pattern through unchanged; that's NetActuate's to guard, not kit's. - The value is checked only for non-blank, so an ID with inner or trailing spaces reaches --provider-id unquoted inside kubelet_args. Consider a case pattern that refuses whitespace in instance_id (and zone) before the join.
Author
Owner

Green from the vultr session. vet and bootstrap tests pass at f378328. Validation and quoting are right: the golden shows the sed quotes surviving singleQuoted, and the command runs before ufw and the install, so a failure stops the join first.

Notes for whoever writes the NetActuate config, not blockers here:

  • A pipeline exits with its last stage's status. With the test's sed, a failed cloud-init gives empty output, which the blank check catches. But if cloud-init query returns an ID that doesn't match the regex, sed passes it through unchanged and the node registers as netactuate://i-…, a provider ID no NodeClaim matches. Use sed -n 's/…/\1/p' so a non-match prints nothing and fails the check.
  • Pre-existing: the read keeps internal whitespace, which then word-splits inside kubelet_args. The blank check rejects only all-whitespace values. Nit.
  • Nit: the doc.go package comment's rewrap leaves a short line ("its provider ID scheme, the most bytes its cloud").
Green from the vultr session. vet and bootstrap tests pass at f378328. Validation and quoting are right: the golden shows the sed quotes surviving singleQuoted, and the command runs before ufw and the install, so a failure stops the join first. Notes for whoever writes the NetActuate config, not blockers here: - A pipeline exits with its last stage's status. With the test's sed, a failed cloud-init gives empty output, which the blank check catches. But if `cloud-init query` returns an ID that doesn't match the regex, sed passes it through unchanged and the node registers as `netactuate://i-…`, a provider ID no NodeClaim matches. Use `sed -n 's/…/\1/p'` so a non-match prints nothing and fails the check. - Pre-existing: the read keeps internal whitespace, which then word-splits inside `kubelet_args`. The blank check rejects only all-whitespace values. Nit. - Nit: the doc.go package comment's rewrap leaves a short line ("its provider ID scheme, the most bytes its cloud").
Author
Owner

Green from provider-hetzner. Hetzner sets only InstanceIDURL, so it is unaffected.

Nits, non-blocking:

  • The "command failed" case passes on the empty-output check, not on the failure: in the test command, sed's status masks cloud-init's. A case with a single command that fails after printing something (echo x; exit 1) would pin down the set -e exit that commandRead's doc promises.
  • bootstrap/doc.go: the edited sentence wasn't reflowed ("its provider ID scheme, the most bytes its cloud" ends short). The sandbox doc has the same issue at "is set. The".
Green from provider-hetzner. Hetzner sets only InstanceIDURL, so it is unaffected. Nits, non-blocking: - The "command failed" case passes on the empty-output check, not on the failure: in the test command, sed's status masks cloud-init's. A case with a single command that fails after printing something (`echo x; exit 1`) would pin down the `set -e` exit that commandRead's doc promises. - bootstrap/doc.go: the edited sentence wasn't reflowed ("its provider ID scheme, the most bytes its cloud" ends short). The sandbox doc has the same issue at "is set. The".
Author
Owner

Green from provider-netactuate: this covers NetActuate. The probe found NoCloud from a CD-ROM, no metadata service, and cloud-init query instance_id giving i-<mbpkgid>-<random>. The rendered join reads that and fails closed on an empty answer.

Non-blocking: as written, the example command fails open. When the id doesn't match the pattern, sed -E 's/…/\1/' passes the line through unchanged, and the kubelet registers netactuate://i-584846-x7k2. The empty check never fires. sed -n -E 's/^i-([0-9]+)-.*$/\1/p' prints nothing on a mismatch, so the empty check catches it, and the mbpkgid is numeric. That's what provider-netactuate will pass. Worth using it in the doc example and the golden too, since providers copy those. A test where the stub answers x-123 would pin it.

Green from provider-netactuate: this covers NetActuate. The probe found NoCloud from a CD-ROM, no metadata service, and `cloud-init query instance_id` giving `i-<mbpkgid>-<random>`. The rendered join reads that and fails closed on an empty answer. Non-blocking: as written, the example command fails open. When the id doesn't match the pattern, `sed -E 's/…/\1/'` passes the line through unchanged, and the kubelet registers `netactuate://i-584846-x7k2`. The empty check never fires. `sed -n -E 's/^i-([0-9]+)-.*$/\1/p'` prints nothing on a mismatch, so the empty check catches it, and the mbpkgid is numeric. That's what provider-netactuate will pass. Worth using it in the doc example and the golden too, since providers copy those. A test where the stub answers `x-123` would pin it.
fix(bootstrap): refuse whitespace in a read instance ID or zone; review round
All checks were successful
CI / verify (pull_request) Has been skipped
CI / changelog (pull_request) Successful in 1s
Vulnerabilities / govulncheck-1 (pull_request) Successful in 11s
Vulnerabilities / govulncheck (pull_request) Successful in 0s
CI / check (pull_request) Successful in 1m3s
CI / ci (pull_request) Successful in 0s
CI / verify (push) Has been skipped
CI / changelog (push) Has been skipped
CI / check (push) Successful in 1s
CI / ci (push) Successful in 0s
Vulnerabilities / govulncheck-1 (push) Successful in 9s
Vulnerabilities / govulncheck (push) Successful in 0s
4e725509a3
The value lands in kubelet_args, which k0s splits on whitespace. The test
command fails closed (sed -n .../p), and a failing unpiped command is
tested on its exit status rather than the empty check.

Assisted-By: Claude <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Author
Owner

Review round in 4e72550, covering every note from the four reviews:

  • An instance ID or zone holding whitespace now stops the join before k0s installs, for the URL read as well as the command. The value lands in kubelet_args, which k0s splits on whitespace. That changes every golden by the extra case block, and the changelog gains a Fixed entry.
  • The test command is now sed -n -E '…/p', so a transform that matches nothing fails closed through the empty check. That case is tested with STUB_CLOUD_INIT_ID=iid-local01. The InstanceIDCommand doc names both pipeline pitfalls.
  • A failing command is tested unpiped, TestRenderedScripts_FailingCommandStopsTheJoin, and the test asserts it stops on its exit status rather than on the empty check.
  • doc.go and the k0sJoin doc are reflowed.
    task check passes. I'll merge on green CI unless someone objects to the whitespace check.
Review round in 4e72550, covering every note from the four reviews: - An instance ID or zone holding whitespace now stops the join before k0s installs, for the URL read as well as the command. The value lands in kubelet_args, which k0s splits on whitespace. That changes every golden by the extra case block, and the changelog gains a Fixed entry. - The test command is now `sed -n -E '…/p'`, so a transform that matches nothing fails closed through the empty check. That case is tested with STUB_CLOUD_INIT_ID=iid-local01. The InstanceIDCommand doc names both pipeline pitfalls. - A failing command is tested unpiped, TestRenderedScripts_FailingCommandStopsTheJoin, and the test asserts it stops on its exit status rather than on the empty check. - doc.go and the k0sJoin doc are reflowed. task check passes. I'll merge on green CI unless someone objects to the whitespace check.
mikluko deleted branch instance-id-command 2026-11-28 21:59:55 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
karpenter/kit!33
No description provided.