Skip to content

Port https://github.com/rancher/rancher-ai-mcp/pull/99 - #7

Merged
bk201 merged 1 commit into
harvester:mainfrom
bk201:port-rancher-ai-mcp-99
Jul 29, 2026
Merged

Port https://github.com/rancher/rancher-ai-mcp/pull/99#7
bk201 merged 1 commit into
harvester:mainfrom
bk201:port-rancher-ai-mcp-99

Conversation

@bk201

@bk201 bk201 commented Jul 29, 2026

Copy link
Copy Markdown
Collaborator

Signed-off-by: Kiefer Chang <kiefer.chang@suse.com>
@bk201
bk201 force-pushed the port-rancher-ai-mcp-99 branch from 74e562e to 5aedf0f Compare July 29, 2026 06:29
@bk201
bk201 requested a review from Yu-Jack July 29, 2026 06:29
Comment thread pkg/client/client.go
Comment on lines +62 to +69
if envURL := os.Getenv("RANCHER_URL"); envURL != "" {
rancherURL = envURL
} else {
rancherURL, err = fetchRancherURL()
if err != nil {
return nil, fmt.Errorf("fetching internal-server-url from rancher: %w", err)
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

we can combine these into a single function like:

func fetchRancherURL() (string, error) {
    if url := os.Getenv("RANCHER_URL"); url != "" {
        return url, nil
    }

	cfg, err := rest.InClusterConfig()
	if err != nil {
		return "", fmt.Errorf("creating in-cluster config: %w", err)
	}

	dynClient, err := dynamic.NewForConfig(cfg)
	if err != nil {
		return "", fmt.Errorf("creating dynamic client: %w", err)
	}

	gvr := schema.GroupVersionResource{
		Group:    "management.cattle.io",
		Version:  "v3",
		Resource: "settings",
	}

	obj, err := dynClient.Resource(gvr).Get(context.Background(), "internal-server-url", metav1.GetOptions{})
	if err != nil {
		return "", fmt.Errorf("getting internal-server-url setting: %w", err)
	}

	value, _, err := unstructured.NestedString(obj.Object, "value")
	return value, err
}

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Thanks, Jack. I'd like to keep it as it is. The function from the writer is meant to only fetch the URL from the internal-server-url setting. So it totally makes sense to separate the overriding of the env variable here.

// fetchRancherURL fetches the Rancher server URL from the internal-server-url Setting
// resource via the Kubernetes API using in-cluster config.
func fetchRancherURL() (string, error) {

@Yu-Jack Yu-Jack 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.

Others LGTM.

@bk201
bk201 merged commit c306ab0 into harvester:main Jul 29, 2026
2 checks passed
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