Skip to content

Commit 39b2063

Browse files
author
sivakami
committed
Fetch nodes with nic count.
1 parent 84c5944 commit 39b2063

File tree

1 file changed

+33
-15
lines changed

1 file changed

+33
-15
lines changed

test/integration/swiftv2/longRunningCluster/datapath.go

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"bytes"
55
"fmt"
66
"os/exec"
7+
"strings"
78
"text/template"
89

910
"github.com/Azure/azure-container-networking/test/integration/swiftv2/helpers"
@@ -130,29 +131,46 @@ type NodePoolInfo struct {
130131
HighNicNodes []string
131132
}
132133

133-
// GetNodesByNicCount categorizes nodes by NIC count (1 NIC vs 7+ NICs)
134+
// GetNodesByNicCount categorizes nodes by NIC count based on node pool labels
134135
func GetNodesByNicCount(kubeconfig string) (NodePoolInfo, error) {
135-
nodes, err := helpers.GetClusterNodes(kubeconfig)
136-
if err != nil {
137-
return NodePoolInfo{}, err
138-
}
139-
140136
nodeInfo := NodePoolInfo{
141137
LowNicNodes: []string{},
142138
HighNicNodes: []string{},
143139
}
144140

145-
// In a real implementation, you'd query node labels or annotations
146-
// For now, we'll assume first 2 nodes are low-NIC, last 2 are high-NIC
147-
// You can enhance this by checking actual node labels like "agentpool"
148-
if len(nodes) >= 4 {
149-
nodeInfo.LowNicNodes = nodes[:2]
150-
nodeInfo.HighNicNodes = nodes[2:]
151-
} else if len(nodes) >= 2 {
152-
nodeInfo.LowNicNodes = nodes[:1]
153-
nodeInfo.HighNicNodes = nodes[1:]
141+
// Get nodes from default node pool (low-NIC nodes)
142+
cmd := exec.Command("kubectl", "--kubeconfig", kubeconfig, "get", "nodes",
143+
"-l", "agentpool!=nplinux", "-o", "name")
144+
out, err := cmd.CombinedOutput()
145+
if err != nil {
146+
return NodePoolInfo{}, fmt.Errorf("failed to get default pool nodes: %w\nOutput: %s", err, string(out))
147+
}
148+
149+
lines := strings.Split(strings.TrimSpace(string(out)), "\n")
150+
for _, line := range lines {
151+
if strings.HasPrefix(line, "node/") {
152+
nodeInfo.LowNicNodes = append(nodeInfo.LowNicNodes, strings.TrimPrefix(line, "node/"))
153+
}
154154
}
155155

156+
// Get nodes from nplinux node pool (high-NIC nodes)
157+
cmd = exec.Command("kubectl", "--kubeconfig", kubeconfig, "get", "nodes",
158+
"-l", "agentpool=nplinux", "-o", "name")
159+
out, err = cmd.CombinedOutput()
160+
if err != nil {
161+
return NodePoolInfo{}, fmt.Errorf("failed to get nplinux pool nodes: %w\nOutput: %s", err, string(out))
162+
}
163+
164+
lines = strings.Split(strings.TrimSpace(string(out)), "\n")
165+
for _, line := range lines {
166+
if line != "" && strings.HasPrefix(line, "node/") {
167+
nodeInfo.HighNicNodes = append(nodeInfo.HighNicNodes, strings.TrimPrefix(line, "node/"))
168+
}
169+
}
170+
171+
fmt.Printf("Found %d low-NIC nodes (default pool) and %d high-NIC nodes (nplinux pool)\n",
172+
len(nodeInfo.LowNicNodes), len(nodeInfo.HighNicNodes))
173+
156174
return nodeInfo, nil
157175
}
158176

0 commit comments

Comments
 (0)