Use the modern API to import clusters#184
Open
moio wants to merge 1 commit into
Open
Conversation
This creates management cluster objects from the Kubernetes API instead of driving browser-like usage of Norman API to create provisioning clusters. This also generalizes a bit the kubectl.Wait and Get methods to support the new workflow.
There was a problem hiding this comment.
Pull request overview
This PR updates the downstream-cluster import workflow to create Rancher management Cluster objects via the Kubernetes API (kubectl) rather than simulating UI/Norman API calls, and adjusts the kubectl helpers to support the new flow.
Changes:
- Removed k6-based Norman/API “imported cluster” creation and its env-driven loop.
- Generalized kubectl wait helper to accept arbitrary
--forconditions and updated call sites accordingly. - Added a kubectl
Getconvenience for raw string output and added a newkubectl create -fpath to create management clusters.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| k6/rancher/rancher_utils.js | Removes the old Norman/UI-like imported cluster creation helper. |
| k6/rancher/rancher_setup.js | Drops imported-cluster creation loop/env var usage; keeps only login/logout. |
| internal/kubectl/kubectl.go | Adds Create, generalizes WaitFor... to WaitFor, and extends Get to support *string outputs. |
| cmd/dartboard/subcommands/deploy.go | Switches cluster import bootstrap to creating management clusters via kubectl and updates wait/get logic to match. |
Comments suppressed due to low confidence (2)
cmd/dartboard/subcommands/deploy.go:709
- The error wrapping here uses
%e, which is for floats; this will render as%!e(...)and also won't wrap the underlying error. Use%w(or%vif not wrapping) and consider updating the message to match the operation (kubectl createvs "applying").
if err := kubectl.Create(upstream.Kubeconfig, yamlFile.Name()); err != nil {
return fmt.Errorf("applying imported clusters YAML: %e", err)
}
cmd/dartboard/subcommands/deploy.go:733
clusterIDparsing is fragile:kubectl get -o jsonpathcan return empty output (no match) or multiple/whitespace-separated results.strings.Split(*out, " ")[0]can yield an empty ID; trim/field-split the output and explicitly error if no cluster ID is found (or retry until the created Cluster appears).
jsonPath := fmt.Sprintf(".items[?(@.spec.displayName==\"%s\")].metadata.name", name)
out := new(string)
if err = kubectl.Get(upstream.Kubeconfig, "clusters.management.cattle.io", "", "", jsonPath, out); err != nil {
return
}
clusterID = strings.Split(*out, " ")[0]
err = kubectl.WaitFor(upstream.Kubeconfig, "clusterregistrationtokens.management.cattle.io", "default-token", clusterID, "create", 1)
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| return Exec(kubePath, log.Writer(), "apply", "-f", filePath) | ||
| } | ||
|
|
||
| func Create(kubePath string, filePath string) interface{} { |
| yamlFile, err := os.CreateTemp("", "dartboard-imported-clusters-*.yaml") | ||
| if err != nil { | ||
| return fmt.Errorf("creating temp file for imported clusters: %w", err) | ||
| } |
git-ival
requested changes
May 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This creates management cluster objects from the Kubernetes API instead of driving browser-like usage of Norman API to create provisioning clusters.
This also generalizes a bit the kubectl.Wait and Get methods to support the new workflow.