Skip to content

k6: switch imported cluster creation to Rancher v3 management API#183

Draft
moio with Copilot wants to merge 5 commits into
mainfrom
copilot/update-imported-cluster-api
Draft

k6: switch imported cluster creation to Rancher v3 management API#183
moio with Copilot wants to merge 5 commits into
mainfrom
copilot/update-imported-cluster-api

Conversation

Copilot AI commented May 8, 2026

Copy link
Copy Markdown
Contributor

Imported cluster creation in k6/rancher/rancher_utils.js was still using POST /v1/provisioning.cattle.io.clusters. This updates the flow to use the Rancher 2.11+ recommended management endpoint (/v3/clusters) and aligns request/lookup behavior with v3 responses.

  • API migration (create path)

    • Replaced imported cluster create call:
      • from POST /v1/provisioning.cattle.io.clusters
      • to POST /v3/clusters
    • Updated payload shape from provisioning-style resource to v3 management cluster payload.
  • Status handling for existing clusters

    • Kept non-fatal duplicate handling, now tolerant of version-specific duplicate responses (409 and 422) in addition to successful creation (201).
  • Post-create verification on v3

    • Removed provisioning cluster lookup by namespace/name.
    • Added v3 verification flow:
      • if create response includes cluster id, query GET /v3/clusters/{id}
      • otherwise query GET /v3/clusters and match by name/displayName variants.
    • Added clearer error diagnostics for parse failures and failed lookup responses.
response = http.post(
  `${baseUrl}/v3/clusters`,
  JSON.stringify({ "type": "cluster", "name": name }),
  {
    headers: {
      accept: 'application/json',
      'content-type': 'application/json',
    },
    cookies: cookies,
  }
)

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • get.helm.sh
    • Triggering command: /usr/bin/curl curl --output helm-v4.1.3-linux-amd64.tar.gz --location --fail REDACTED (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

In k6/rancher/rancher_utils.js, the createImportedCluster function currently uses POST /v1/provisioning.cattle.io.clusters to create imported clusters. As of Rancher 2.11, the best practice is to use the v3 management cluster API instead (see rancher/dashboard#13151).

Changes needed:

  1. Switch the cluster creation POST from POST /v1/provisioning.cattle.io.clusters to POST /v3/clusters (the v3 management cluster endpoint). The payload format for v3 is different — it should look something like:

    {
      "type": "cluster",
      "name": "<name>",
      "dockerRootDir": "/var/lib/docker",
      "enableClusterAlerting": false,
      "enableClusterMonitoring": false
    }

    Adjust as needed for a minimal imported cluster creation via the v3 API.

  2. Switch the cluster query after creation from GET /v1/provisioning.cattle.io.clusters/fleet-default/<name> to the corresponding v3 endpoint GET /v3/clusters (filtered by name) or simply check the creation response.

  3. Remove all the spurious surrounding GET calls that were added to mimic browser behavior but are not functionally relevant. Specifically, remove these unnecessary GET requests:

    • GET /v1/catalog.cattle.io.clusterrepos
    • GET /v1/management.cattle.io.kontainerdrivers
    • GET /v1/catalog.cattle.io.clusterrepos/rancher-charts?link=index
    • GET /v1/catalog.cattle.io.clusterrepos/rancher-partner-charts?link=index
    • GET /v1/catalog.cattle.io.clusterrepos/rancher-rke2-charts?link=index
    • GET /v3/clusterroletemplatebindings
    • GET /v1/management.cattle.io.roletemplates
    • GET /v1/cluster.x-k8s.io.machinedeployments
    • GET /v1/rke.cattle.io.etcdsnapshots
    • GET /v1/management.cattle.io.nodetemplates
    • GET /v1/management.cattle.io.clustertemplates
    • GET /v1/management.cattle.io.clustertemplaterevisions
  4. Keep the user preferences setup at the top of the function (getCurrentUserId, getUserPreferences, setUserPreferences) as those are still relevant.

  5. After making changes, run make verify-all to ensure all checks pass.

The file to modify is k6/rancher/rancher_utils.js.

The following is the prior conversation context from the user's chat exploration (may be truncated):

User: createImportedCluster still uses provisioning.cattle.io.cluster to define imported clusters, but the best practice as of 2.11 is to use the management cluster object, per @rancher/dashboard/issues/13151 . Open a PR to update that and also remove all the spurious surrounding get calls in the method, which were added to exactly mimic the browser's behavior at that time but are not relevant any longer. Make sure you run a "Test Deploy - Full Environment" to prove your changes are OK.

Assistant: I've started the coding agent to create a PR that will:

  1. Switch cluster creation from POST /v1/provisioning.cattle.io.clusters to the POST /v3/clusters management cluster API
  2. Update the post-creation cluster query to use the v3 endpoint
  3. Remove all the spurious GET calls (clusterrepos, kontainerdrivers, chart indexes, machinedeployments, etcdsnapshots, nodetemplates, clustertemplates, etc.) that were only there to mimic old browser behavior

The agent is working on this now — you'll receive a PR for review shortly. The make verify-all check will be run to validate the changes.

This pull request was created from Copilot chat.

Copilot AI changed the title [WIP] Update createImportedCluster to use v3 management cluster API k6: switch imported cluster creation to Rancher v3 management API May 8, 2026
Copilot finished work on behalf of moio May 8, 2026 06:43
Copilot AI requested a review from moio May 8, 2026 06:43
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