Skip to content

Commit 177a186

Browse files
fix: use grep -w for exact IP matching in cluster node configuration (#757)
When configuring cluster nodes, the grep command used to find node names by private IP would match IP prefixes as substrings (e.g., 10.0.1.8 matching 10.0.1.81), concatenating multiple node names with a newline. This caused kubectl to fail with "nodes not found" for the combined string. Add -w flag to grep for word-boundary matching, ensuring each IP matches only its exact occurrence in kubectl output. Fixes #756 Signed-off-by: Carlos Eduardo Arango Gutierrez <eduardoa@nvidia.com>
1 parent 2f61797 commit 177a186

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

pkg/provisioner/cluster.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ func (cp *ClusterProvisioner) configureNodes(firstCP NodeInfo, nodes []NodeInfo)
514514
fmt.Fprintf(&script, "echo 'Configuring control-plane node with IP %s...'\n", node.PrivateIP)
515515

516516
// Get the actual node name from private IP
517-
fmt.Fprintf(&script, "CP_NODE=$(sudo -E kubectl get nodes -o wide --no-headers | grep '%s' | awk '{print $1}')\n", node.PrivateIP)
517+
fmt.Fprintf(&script, "CP_NODE=$(sudo -E kubectl get nodes -o wide --no-headers | grep -w '%s' | awk '{print $1}')\n", node.PrivateIP)
518518
script.WriteString("if [ -n \"$CP_NODE\" ]; then\n")
519519

520520
// Apply control-plane labels
@@ -547,7 +547,7 @@ func (cp *ClusterProvisioner) configureNodes(firstCP NodeInfo, nodes []NodeInfo)
547547
fmt.Fprintf(&script, "echo 'Configuring worker node with IP %s...'\n", node.PrivateIP)
548548

549549
// Get the actual node name from private IP
550-
fmt.Fprintf(&script, "WORKER_NODE=$(sudo -E kubectl get nodes -o wide --no-headers | grep '%s' | awk '{print $1}')\n", node.PrivateIP)
550+
fmt.Fprintf(&script, "WORKER_NODE=$(sudo -E kubectl get nodes -o wide --no-headers | grep -w '%s' | awk '{print $1}')\n", node.PrivateIP)
551551
script.WriteString("if [ -n \"$WORKER_NODE\" ]; then\n")
552552

553553
// Apply worker role label

0 commit comments

Comments
 (0)