Skip to content

cli/cluster: add --use_public_api to nsc create#1869

Draft
annervisser wants to merge 1 commit into
mainfrom
nsc-create-use-public-api
Draft

cli/cluster: add --use_public_api to nsc create#1869
annervisser wants to merge 1 commit into
mainfrom
nsc-create-use-public-api

Conversation

@annervisser

Copy link
Copy Markdown
Member

Start moving nsc create onto the public compute API.

Adds a hidden --use_public_api flag (default false) with a --no_use_public_api counterpart, so the default can be flipped in a single line later. When enabled, nsc create creates the instance through the public compute ReservationService.ReserveInstance API (waiting for the reservation to be fulfilled and the instance to become ready) instead of the legacy private InstanceService (api.CreateAndWaitCluster).

This reuses the logic that was implemented for the (now-dropped) nsc reservation create command — see #1868.

Clean split for trivial legacy removal

The public path is fully self-contained in create_publicapi.go. Removing the legacy path later means deleting the else/fall-through in NewCreateCmd and promoting the public branch; the shared output helpers stay.

Correctness safeguards

  • The reservation deadline never outlives the client-side wait, and a reservation we stop waiting for is cancelled best-effort, so we never leave an untracked instance.
  • --use_public_api requires a positive --wait_timeout (the reservation flow is async and must wait for an instance).
  • Explicitly-set nsc create flags the public path does not map yet (--unique_tag, --available_secrets, --internal_extra, --experimental*) are rejected rather than silently dropped. Remove entries from publicAPIUnsupportedFlags as mappings are added.

Shared behavior

Output and side-effect files are shared between both paths via the extracted writeInstanceOutputFiles and printInstanceCreated helpers; the JSON/plain output is byte-for-byte identical to legacy nsc create.

Verification

  • build + go vet clean; hidden flags absent from --help; mutual-exclusivity, unsupported-flag, and wait_timeout=0 guards all error correctly.
  • Live nsc create --use_public_api (plain and -o json) created ready instances with output identical to legacy nsc create; both destroyed.

Amp-Thread-ID: https://ampcode.com/threads/T-019f1880-ac56-7349-b5df-36566f7fc069

Add a hidden --use_public_api flag (default false) to `nsc create`, with a
--no_use_public_api counterpart, so the default can later be flipped in one
line. When enabled, the instance is created through the public compute
ReservationService.ReserveInstance API instead of the legacy private
InstanceService (api.CreateAndWaitCluster).

The public path is kept self-contained in create_publicapi.go so removing the
legacy path later is trivial:
- createInstanceViaPublicAPI reserves an instance, waits for the reservation to
  be fulfilled and the instance to become ready, and returns the same result as
  the legacy path.
- the reservation deadline never outlives the client wait, and a reservation we
  stop waiting for is cancelled best-effort, so we never leave an untracked
  instance.
- explicitly-set create flags the public path does not map yet are rejected
  rather than silently dropped.
- machine_type accepts the full [os/arch:]<cpu>x<mem> form, with the legacy
  mac/silicon alias for macos/arm64.

Output and side-effect files are shared between both paths via the extracted
writeInstanceOutputFiles and printInstanceCreated helpers.

Co-authored-by: Amp <amp@ampcode.com>
Amp-Thread-ID: https://ampcode.com/threads/T-019f1880-ac56-7349-b5df-36566f7fc069
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.

1 participant