Skip to content

feat: add onctl import and a static provider for unmanaged hosts - #936

Merged
cdalar merged 8 commits into
mainfrom
feat/import-static-hosts
Jun 24, 2026
Merged

cdalar merged 8 commits into
mainfrom
feat/import-static-hosts

Conversation

@cdalar

@cdalar cdalar commented Jun 24, 2026

Copy link
Copy Markdown
Owner

Summary

  • Adds onctl import NAME --ip IP [--user USER] [--port PORT] [--key PATH], which registers an existing server onctl didn't create into a local imported.yaml inventory.
  • Adds a new static pseudo cloud provider (pkg/cloud/static.go) that serves ls/ssh/destroy from that inventory instead of a cloud API. destroy only removes the local record — it never touches the real machine, since onctl has no lifecycle API for it.
  • Motivating case: Hetzner auction/dedicated servers (hetzner.com/sb) are provisioned via Hetzner's Robot API, a different product from Hetzner Cloud — they can never appear through the existing hetzner provider no matter what labels are set. This also covers any other unmanaged/bare-metal host.

Usage:

onctl import myauctionbox --ip 1.2.3.4 --user root --key ~/.ssh/auction_key
onctl --provider static ls
onctl --provider static ssh myauctionbox

Test plan

  • go build ./..., go vet ./..., go test ./... all pass
  • New unit tests: pkg/cloud/static_test.go (load/save round-trip, GetByName not-found, destroy removes only the named entry, unsupported ops error) and cmd/import_test.go (flag registration, import writes/updates inventory)
  • Manual end-to-end smoke test against a real local sshd: import → --provider static ls shows the host → --provider static ssh ... -- echo actually connects and runs a command → destroy removes it from ls while the real machine stays reachable directly

cdalar added 6 commits June 23, 2026 11:02
…single onctl.yaml

- Bind generic --type/--location/--username create flags + new --project
  to the corresponding gcp.* viper keys (matching hetzner/aws treatment).
- Add GCloudDefaultProject() helper (best-effort gcloud fallback).
- resolveGCPProject() after ReadConfig to replace the <project-id> placeholder
  from gcloud when available (keeps onctl.yaml usable without manual edit).
- Extend flag existence/bind tests and add TestResolveGCPProject.
- No change to single onctl.yaml requirement or loading; CLI flags now
  correctly override gcp settings the same as for other providers.

Ports the useful parts of feat/gcp-zero-yaml-flags onto post-single-yaml main.
… gcp)

Brings --type, --project etc. bindings and gcloud fallback for gcp, consistent with aws/hetzner.
See feat/gcp-integration for details.
…--resource-group for azure

- Register --subscription-id/--resource-group as root persistent flags (needed for resolve on ls/destroy/ssh etc) + locally on create for help/bind.
- Bind generic + azure.* keys.
- Add AzureCLISubscriptionID / AzureCLIDefaultResourceGroup + runAzCLI helpers (with fix for query).
- resolveAzureIdentifiers() after load to replace placeholders from az CLI.
- Extend tests (flags exist, bind cases, resolve test).
- Consistent with gcp and the earlier aws/hetzner work on top of single onctl.yaml.

Adapts feat/azure-zero-yaml-flags + follow-up fix.
Completes wiring for azure (subscription, resource group, type etc) so it matches other providers under the single onctl.yaml setup.
# Conflicts:
#	cmd/create.go
#	cmd/flags_defaults_test.go
#	cmd/root.go
Lets onctl manage servers it didn't create (e.g. Hetzner auction/dedicated
boxes, which live on the Robot API and can never show up via the Cloud API
provider) by registering name/IP/user/key into a local imported.yaml. The
new `static` pseudo-provider serves ssh/ls/destroy from that file; destroy
only forgets the host locally since onctl has no lifecycle API for it.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: deac239272

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread pkg/cloud/static.go Resolved
Comment thread pkg/cloud/static.go Resolved
Comment thread pkg/cloud/static.go Resolved
@codecov

codecov Bot commented Jun 24, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 57.64706% with 72 lines in your changes missing coverage. Please review.
✅ Project coverage is 24.03%. Comparing base (457c0e4) to head (16849c2).

Files with missing lines Patch % Lines
pkg/cloud/static.go 59.78% 31 Missing and 6 partials ⚠️
cmd/ssh.go 0.00% 17 Missing ⚠️
cmd/import.go 81.81% 4 Missing and 4 partials ⚠️
cmd/root.go 0.00% 6 Missing ⚠️
cmd/common.go 63.63% 3 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #936      +/-   ##
==========================================
+ Coverage   22.69%   24.03%   +1.33%     
==========================================
  Files          42       44       +2     
  Lines        4247     4402     +155     
==========================================
+ Hits          964     1058      +94     
- Misses       3161     3213      +52     
- Partials      122      131       +9     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

claude and others added 2 commits June 24, 2026 20:38
- cmd/ssh.go: a plain `onctl --provider static ssh NAME` no longer
  requires a global ssh.privateKey default or forces port 22 — it
  now lets static.SSHInto fall back to the per-host key/port saved
  by `onctl import` unless --key/--port were explicitly passed.
- pkg/cloud/static.go: serialize Destroy's load-modify-save of
  imported.yaml so `destroy all`'s one-goroutine-per-VM fan-out
  can't race and clobber concurrent writes.

Addresses Codex review comments on PR #936.
@cdalar
cdalar merged commit 57a69e3 into main Jun 24, 2026
15 checks passed
@cdalar
cdalar deleted the feat/import-static-hosts branch August 19, 2026 13:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

⌂ 换网址