-
Notifications
You must be signed in to change notification settings - Fork 6
feat: add support for NVLink domain discovery in NetQ provider #180
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| /* | ||
| * Copyright 2025 NVIDIA CORPORATION | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package netq | ||
|
|
||
| import ( | ||
| "context" | ||
| "encoding/base64" | ||
| "encoding/json" | ||
| "fmt" | ||
| "net/http" | ||
|
|
||
| "k8s.io/klog/v2" | ||
|
|
||
| "github.com/NVIDIA/topograph/internal/httperr" | ||
| "github.com/NVIDIA/topograph/internal/httpreq" | ||
| "github.com/NVIDIA/topograph/pkg/topology" | ||
| ) | ||
|
|
||
| const ( | ||
| ComputeURL = "nmx/v1/compute-nodes" | ||
| ) | ||
|
|
||
| type ComputeNode struct { | ||
| Id string `json:"ID"` | ||
| Name string `json:"Name"` | ||
| DomainUUID string `json:"DomainUUID"` | ||
| } | ||
|
|
||
| func (p *Provider) getNvlDomains(ctx context.Context) (topology.DomainMap, *httperr.Error) { | ||
| url, headers, httpErr := p.getComputeUrl() | ||
| if httpErr != nil { | ||
| return nil, httpErr | ||
| } | ||
|
|
||
| klog.V(4).Infof("Fetching %s", url) | ||
| f := getRequestFunc(ctx, "GET", url, headers, nil) | ||
| _, data, err := httpreq.DoRequest(f, true) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| return parseComputeNodes(data) | ||
| } | ||
|
|
||
| func (p *Provider) getComputeUrl() (string, map[string]string, *httperr.Error) { | ||
| auth := p.cred.user + ":" + p.cred.passwd | ||
| authHeader := "Basic " + base64.StdEncoding.EncodeToString([]byte(auth)) | ||
| headers := map[string]string{"Authorization": authHeader} | ||
|
|
||
| url, err := httpreq.GetURL(p.params.ApiURL, nil, ComputeURL) | ||
| return url, headers, err | ||
| } | ||
|
|
||
| func parseComputeNodes(data []byte) (topology.DomainMap, *httperr.Error) { | ||
| var computeNodes []ComputeNode | ||
| err := json.Unmarshal(data, &computeNodes) | ||
| if err != nil { | ||
| return nil, httperr.NewError(http.StatusBadGateway, fmt.Sprintf("nmx output read failed: %v", err)) | ||
| } | ||
|
|
||
| domainMap := topology.NewDomainMap() | ||
| for _, node := range computeNodes { | ||
| klog.V(4).Infof("Add NVL domain %q for node %q", node.DomainUUID, node.Name) | ||
| domainMap.AddHost(node.DomainUUID, node.Name, node.Name) | ||
| } | ||
|
|
||
| return domainMap, nil | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| /* | ||
| * Copyright 2025 NVIDIA CORPORATION | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package netq | ||
|
|
||
| import ( | ||
| "os" | ||
| "testing" | ||
|
|
||
| "github.com/NVIDIA/topograph/pkg/topology" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestGetComputeUrl(t *testing.T) { | ||
| p := &Provider{ | ||
| params: &ProviderParams{}, | ||
| cred: &Credentials{user: "user", passwd: "passwd"}, | ||
| } | ||
|
|
||
| testCases := []struct { | ||
| name string | ||
| serverURL string | ||
| headers map[string]string | ||
| computeUrl string | ||
| err string | ||
| }{ | ||
| { | ||
| name: "Case 1: invalid URL", | ||
| serverURL: `:///server`, | ||
| err: `parse ":///server": missing protocol scheme`, | ||
| }, | ||
| { | ||
| name: "Case 2: valid input", | ||
| serverURL: `https://server.com`, | ||
| headers: map[string]string{"Authorization": "Basic dXNlcjpwYXNzd2Q="}, | ||
| computeUrl: `https://server.com/nmx/v1/compute-nodes`, | ||
| }, | ||
| } | ||
|
|
||
| for _, tc := range testCases { | ||
| t.Run(tc.name, func(t *testing.T) { | ||
| p.params.ApiURL = tc.serverURL | ||
| url, headers, err := p.getComputeUrl() | ||
| if len(tc.err) != 0 { | ||
| require.NotNil(t, err) | ||
| require.EqualError(t, err, tc.err) | ||
| } else { | ||
| require.Nil(t, err) | ||
| require.Equal(t, tc.computeUrl, url) | ||
| require.Equal(t, tc.headers, headers) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestParseComputeNodes(t *testing.T) { | ||
| data, err := os.ReadFile("../../../tests/output/netq/computeNodes.json") | ||
| require.NoError(t, err) | ||
|
|
||
| domains, err := parseComputeNodes(data) | ||
| require.Nil(t, err) | ||
|
|
||
| expected := topology.NewDomainMap() | ||
| expected.AddHost("3fbfc98b-7f95-4749-ab11-bd351a2aab3e", "node1", "node1") | ||
| expected.AddHost("3fbfc98b-7f95-4749-ab11-bd351a2aab3e", "node2", "node2") | ||
|
|
||
| require.Equal(t, expected, domains) | ||
| } | ||
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| [ | ||
| { | ||
| "CreatedAt": "2025-11-04T16:45:16.482Z", | ||
| "Description": "Test", | ||
| "DomainUUID": "3fbfc98b-7f95-4749-ab11-bd351a2aab3e", | ||
| "GpuIDList": [ | ||
| "690a2d9cc5e905fa41a87cdc", | ||
| "690a2d9cc5e905fa41a87cdd", | ||
| "690a2d9cc5e905fa41a87cde", | ||
| "690a2d9cc5e905fa41a87cdf" | ||
| ], | ||
| "Health": "HEALTHY", | ||
| "ID": "690a2d9cc5e905fa41a87d79", | ||
| "LocationInfo": { | ||
| "ChassisID": 1, | ||
| "ChassisSerialNumber": "1825024170029", | ||
| "HostID": 1, | ||
| "SlotID": 5, | ||
| "TrayIndex": 4 | ||
| }, | ||
| "Name": "node1", | ||
| "UpdatedAt": "2025-11-05T18:37:47.155Z" | ||
| }, | ||
| { | ||
| "CreatedAt": "2025-11-04T16:45:16.482Z", | ||
| "Description": "", | ||
| "DomainUUID": "3fbfc98b-7f95-4749-ab11-bd351a2aab3e", | ||
| "GpuIDList": [ | ||
| "690a2d9cc5e905fa41a87ce0", | ||
| "690a2d9cc5e905fa41a87ce2", | ||
| "690a2d9cc5e905fa41a87ce3", | ||
| "690a2d9cc5e905fa41a87ce1" | ||
| ], | ||
| "Health": "HEALTHY", | ||
| "ID": "690a2d9cc5e905fa41a87d7a", | ||
| "LocationInfo": { | ||
| "ChassisID": 1, | ||
| "ChassisSerialNumber": "1825024170029", | ||
| "HostID": 1, | ||
| "SlotID": 22, | ||
| "TrayIndex": 12 | ||
| }, | ||
| "Name": "node2", | ||
| "UpdatedAt": "2025-11-05T18:37:47.155Z" | ||
| } | ||
| ] |
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.
Uh oh!
There was an error while loading. Please reload this page.