Port https://github.com/rancher/rancher-ai-mcp/pull/99 - #7
Merged
Conversation
Signed-off-by: Kiefer Chang <kiefer.chang@suse.com>
bk201
force-pushed
the
port-rancher-ai-mcp-99
branch
from
July 29, 2026 06:29
74e562e to
5aedf0f
Compare
Yu-Jack
reviewed
Jul 29, 2026
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) | ||
| } | ||
| } |
There was a problem hiding this comment.
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
}
Collaborator
Author
There was a problem hiding this comment.
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) {
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.
Port rancher/rancher-ai-mcp#99