|
4 | 4 | "bytes" |
5 | 5 | "fmt" |
6 | 6 | "os/exec" |
| 7 | + "strings" |
7 | 8 | "text/template" |
8 | 9 |
|
9 | 10 | "github.com/Azure/azure-container-networking/test/integration/swiftv2/helpers" |
@@ -130,29 +131,46 @@ type NodePoolInfo struct { |
130 | 131 | HighNicNodes []string |
131 | 132 | } |
132 | 133 |
|
133 | | -// GetNodesByNicCount categorizes nodes by NIC count (1 NIC vs 7+ NICs) |
| 134 | +// GetNodesByNicCount categorizes nodes by NIC count based on node pool labels |
134 | 135 | func GetNodesByNicCount(kubeconfig string) (NodePoolInfo, error) { |
135 | | - nodes, err := helpers.GetClusterNodes(kubeconfig) |
136 | | - if err != nil { |
137 | | - return NodePoolInfo{}, err |
138 | | - } |
139 | | - |
140 | 136 | nodeInfo := NodePoolInfo{ |
141 | 137 | LowNicNodes: []string{}, |
142 | 138 | HighNicNodes: []string{}, |
143 | 139 | } |
144 | 140 |
|
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 | + } |
154 | 154 | } |
155 | 155 |
|
| 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 | + |
156 | 174 | return nodeInfo, nil |
157 | 175 | } |
158 | 176 |
|
|
0 commit comments