Skip to content

[SDK/CLI] Add self-serve cluster management - #165

Merged
anandj91 merged 11 commits into
mainfrom
sdk-cli-register-cluster
Nov 23, 2026
Merged

anandj91 merged 11 commits into
mainfrom
sdk-cli-register-cluster

Conversation

@anandj91

@anandj91 anandj91 commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Expose the platform's self-serve cluster endpoints so users can register, configure, list and delete their own clusters from the SDK or CLI instead of calling the API directly.

Register (POST /clusters)

  • SDK: CentMLClient.register_cluster(request: ClusterRegistrationRequest) returns a ClusterRegistrationResponse carrying the new cluster's id.
  • CLI: ccluster register-cluster takes --name, --storage-class, --server, --ca-cert (base64 PEM, as in a kubeconfig's certificate-authority-data), and optional --region and --cloud-provider (any case). If --bearer-token is omitted, it prompts for the token with hidden input so it stays out of shell history.

Update components (PUT /clusters/{id})

  • SDK: CentMLClient.update_cluster(cluster_id, request: dict) takes the request body, {"components": {name: chart values}}. It builds the request with UpdateClusterRequest.from_dict, because the generated constructors drop chart keys the typed models don't list (CentML/platform#4946), and reports its validation errors as ValueError. On top of that it rejects, without calling the API, the two mistakes from_dict accepts and the server would read as "not requested", uninstalling the component:
    • an unknown component name (e.g. ingress-nginx), which from_dict drops;
    • a component with no values (e.g. istio:), which is sent as null.
  • CLI: ccluster update-cluster CLUSTER_ID REQUEST_FILE, where the file is the same request body in YAML or JSON, so one file works with the API, the SDK and the CLI. It goes through the SDK's validation and reports problems as CLI errors.
  • Adds PyYAML as a dependency (types-PyYAML for dev).

List (GET /clusters)

  • SDK: the existing CentMLClient.get_clusters().
  • CLI: ccluster list-clusters prints the ID, name and region of each cluster the caller has access to.

Delete (DELETE /clusters/{id})

  • SDK: CentMLClient.delete_cluster(cluster_id).
  • CLI: ccluster delete-cluster CLUSTER_ID asks for confirmation first; --yes skips the prompt. For a cluster managed by ccluster, the server also uninstalls the components installed through it.

Examples: examples/sdk/register_cluster.py registers a cluster from environment variables. examples/sdk/update_cluster.py sets every component to its chart defaults on the cluster named by CLUSTER_ID. examples/sdk/delete_cluster.py deletes it. Listing is already covered by examples/sdk/get_clusters.py.

The README has a new "Managing your own clusters" section with the CLI commands, including installing the ccluster-ip operator first.

These endpoints are all already in the pinned platform-api-python-client==4.41.0. On the platform side, register, update and delete require dev features to be enabled and PERM_ADMIN_MANAGE_HARDWARE.

Validation:

  • python -m pytest tests -q: 151 passed. The CLI update tests run the SDK's real validation, with only the generated API mocked.
  • ./scripts/format.sh, ./scripts/lint.sh (10.00/10), ./scripts/typecheck.sh: passed.
  • Against dev (api.centml.org) with a real GKE cluster: register-cluster registered it, list-clusters lists it, and update-cluster installed the cluster-base components, after which the cluster's infra-plane operator reported Verified=True ("All 14 cluster_base components are installed and configured"). delete-cluster has not been run against a real cluster.

🤖 Generated with Claude Code

anandj91 and others added 2 commits November 23, 2026 13:08
Expose POST /clusters as CentMLClient.register_cluster and a
`register` CLI command so users can register their own cluster.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Expose PUT /clusters/{id} as CentMLClient.update_cluster and an
`update` CLI command that reads the components from a YAML or JSON file.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@anandj91 anandj91 changed the title [SDK/CLI] Add cluster registration [SDK/CLI] Add cluster registration and component updates Nov 23, 2026
anandj91 and others added 4 commits November 23, 2026 13:15
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@HanFa

HanFa commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Could we validate this change by exercising the lifecycle of a real cluster?

Copy link
Copy Markdown
Contributor

Two non-blocking structural nits:

  • CLI naming: Could we use ccluster register and ccluster update-components? register_cluster / update_cluster repeat the resource name and introduce underscores alongside commands such as pause, resume, and capacity. update-components also makes the scope of the update clearer.
  • Configuration parsing: Consider extracting YAML loading, component-name validation, and UpdateClusterRequest.from_dict(...) into one private helper returning the request. That would keep update_cluster() focused on invoking the API and reporting the result, give the generated-client workaround a clear home, and make malformed-input cases easier to test.

The thin SDK wrappers and separate register/update examples fit the existing structure. I don't think this PR needs a broader module split.

Add CentMLClient.delete_cluster, list_clusters and delete_cluster CLI
commands, and a delete_cluster example.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@anandj91 anandj91 changed the title [SDK/CLI] Add cluster registration and component updates [SDK/CLI] Add self-serve cluster management Nov 23, 2026
@V2arK

V2arK commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Ran it locally with platform-api-python-client==4.41.0. One thing I think should block, plus a few smaller ones.

1. An empty entry in the components file uninstalls that component. Say someone writes istio: meaning "istio with defaults":

final_stack: {}
istio:

yaml.safe_load turns that into {"istio": None}. It passes the unknown-name check, from_dict keeps the None, and apply_cluster_base_set on the server skips None. The operator then uninstalls istio, while the CLI still prints Updating components on cluster 7 and exits 0. The server can't catch this: the generated client also sends every component the file leaves out as null, so istio: and leaving istio out look the same on the wire. I think the client has to reject a None value with something like "use {} for the chart defaults".

2. The SDK path doesn't get the CLI's checks. CentMLClient.update_cluster(cluster_id, request) takes whatever request it's handed. An SDK user who builds it with the constructor loses podLabels (#4946), and a misspelled ingress-nginx gets dropped, so the server uninstalls ingress-nginx. +1 to Michael's helper idea, but I'd put it in the SDK (name check, null check, from_dict) so the CLI, the example and SDK users all go through it.

3. These commands 404 on prod today. register/update/delete sit behind require_dev_features_enabled, and enable_dev_features is "false" in iac/control-plane/api-k8s/Pulumi.prod.yaml. Right now a prod user sees Error: {"detail":"Not Found"}. Could we either hold the release until the flag is on, or say "dev only for now" in the --help text and docstrings?

4. +1 to HanFa on a real-cluster run. Every new test mocks the client, so #1 and the server-side ca_cert check never run. Dev has the flag on, so it should be doable there.

5. +1 to Michael on naming. The scariest part is that ccluster delete 7 deletes deployment 7 without asking, and it sits right next to ccluster delete_cluster 7.

Smaller things (non-blocking)
  • A non-string YAML key like 1: x gives a TypeError traceback. The PR body says the command doesn't produce tracebacks.
  • list_clusters doesn't show managed_by_ccluster, so you can't tell which clusters update/delete work on.
  • The delete prompt says it uninstalls components, but for a cluster that isn't managed by ccluster the server only soft-deletes the row.
  • --cloud-provider is case-sensitive; the server accepts AWS.
  • A --ca-cert-file option would save pasting base64.
  • The test value ca_cert="Y2E=" would get a 422 from the server.
  • The PR body says register_cluster returns the id; it returns ClusterRegistrationResponse.
  • examples/sdk/update_cluster.py resets every component to chart defaults, which is worth saying in the docstring.

@anandj91 anandj91 self-assigned this Nov 23, 2026

@HanFa HanFa left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

code change lgtm

anandj91 and others added 3 commits November 23, 2026 15:45
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The file now has the API's {"components": {...}} shape, in YAML or JSON,
so the same file works with the API and the CLI.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… command names

- CentMLClient.update_cluster takes the request body as a dict and rejects
  empty components (which would be uninstalled), unknown or non-string
  component names, and a missing or misspelled components key, before
  building the request with from_dict. The CLI and the example use it.
- Rename the cluster commands to register-cluster, update-cluster,
  list-clusters and delete-cluster.
- Accept --cloud-provider in any case; reword the delete prompt for clusters
  not managed by ccluster; use a PEM-shaped ca_cert in tests; note in the
  update example that it resets every component to its defaults.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@anandj91

Copy link
Copy Markdown
Contributor Author

Tested end to end on dev (api.centml.org) with a real GKE cluster, and it works:

  • register-cluster registered the cluster, and the control plane handed its domain to the cluster's infra-plane operator.
  • list-clusters lists it.
  • update-cluster installed the cluster-base components; the operator on the cluster then reported Verified=True ("All 14 cluster_base components are installed and configured").

…s it can't do

from_dict already rejects a missing or misspelled components key, a
non-mapping body and a missing final_stack. Keep only the two mistakes it
accepts and the server would read as an uninstall: an unknown component name
and a component with no values.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@anandj91

Copy link
Copy Markdown
Contributor Author

@michaelshin Thanks! Renamed to register-cluster / update-cluster / list-clusters / delete-cluster. Dashed per Click convention, but kept the resource name so they don't read as deployment commands next to ls/get/delete. The parsing now lives in one place, in the SDK: CentMLClient.update_cluster builds the request with from_dict and validates it, and the CLI just loads the file and reports errors.

@anandj91

Copy link
Copy Markdown
Contributor Author

@V2arK Thanks for the thorough run.

  1. Fixed: an empty component (istio:) is now rejected with "use {} for the chart defaults".
  2. Fixed: CentMLClient.update_cluster now takes the request body as a dict, builds it with from_dict and reports its errors, and also rejects unknown component names and empty components, the two mistakes from_dict lets through. The CLI and the example go through it.
  3. Prod: enable_dev_features is expected to be on in prod soon, so we're leaving the commands as is.
  4. Tested on dev with a real GKE cluster: register, list and update (operator reports Verified=True).
  5. Renamed to dashed *-cluster names; delete-cluster keeps its confirmation prompt.

Smaller: non-string keys, --cloud-provider case, the delete prompt wording, the test ca_cert and the PR body are fixed, and the update example now says it resets components to defaults. Left managed_by_ccluster out of list-clusters and skipped --ca-cert-file to keep this PR small.

@V2arK

V2arK commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

@anandj91 I tried to rerun with my agent, and it looks good now. LGTM :)

@anandj91
anandj91 merged commit 5f2bcc3 into main Nov 23, 2026
6 checks passed
@anandj91
anandj91 deleted the sdk-cli-register-cluster branch November 23, 2026 21:16
@atokayev atokayev mentioned this pull request Nov 25, 2026
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.

4 participants