Skip to content

Commit

Permalink
Merge pull request kubernetes#126621 from my-git9/node-deadcode-remove
Browse files Browse the repository at this point in the history
Remove deadcode in pkg/util/node
  • Loading branch information
k8s-ci-robot authored Nov 8, 2024
2 parents da215bf + b24804f commit 4695244
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 53 deletions.
47 changes: 0 additions & 47 deletions pkg/util/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,10 @@ limitations under the License.
package node

import (
"context"
"fmt"
"net"
"time"

"k8s.io/klog/v2"

v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/wait"
clientset "k8s.io/client-go/kubernetes"
netutils "k8s.io/utils/net"
)

Expand Down Expand Up @@ -103,46 +96,6 @@ func GetNodeHostIPs(node *v1.Node) ([]net.IP, error) {
return nodeIPs, nil
}

// GetNodeHostIP returns the provided node's "primary" IP; see GetNodeHostIPs for more details
func GetNodeHostIP(node *v1.Node) (net.IP, error) {
ips, err := GetNodeHostIPs(node)
if err != nil {
return nil, err
}
// GetNodeHostIPs always returns at least one IP if it didn't return an error
return ips[0], nil
}

// GetNodeIP returns an IP (as with GetNodeHostIP) for the node with the provided name.
// If required, it will wait for the node to be created.
func GetNodeIP(client clientset.Interface, name string) net.IP {
var nodeIP net.IP
backoff := wait.Backoff{
Steps: 6,
Duration: 1 * time.Second,
Factor: 2.0,
Jitter: 0.2,
}

err := wait.ExponentialBackoff(backoff, func() (bool, error) {
node, err := client.CoreV1().Nodes().Get(context.TODO(), name, metav1.GetOptions{})
if err != nil {
klog.Errorf("Failed to retrieve node info: %v", err)
return false, nil
}
nodeIP, err = GetNodeHostIP(node)
if err != nil {
klog.Errorf("Failed to retrieve node IP: %v", err)
return false, err
}
return true, nil
})
if err == nil {
klog.Infof("Successfully retrieved node IP: %v", nodeIP)
}
return nodeIP
}

// IsNodeReady returns true if a node is ready; false otherwise.
func IsNodeReady(node *v1.Node) bool {
for _, c := range node.Status.Conditions {
Expand Down
6 changes: 0 additions & 6 deletions pkg/util/node/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,7 @@ func TestGetNodeHostIPs(t *testing.T) {
Status: v1.NodeStatus{Addresses: tc.addresses},
}
nodeIPs, err := GetNodeHostIPs(node)
nodeIP, err2 := GetNodeHostIP(node)

if (err == nil && err2 != nil) || (err != nil && err2 == nil) {
t.Errorf("GetNodeHostIPs() returned error=%q but GetNodeHostIP() returned error=%q", err, err2)
}
if err != nil {
if tc.expectIPs != nil {
t.Errorf("expected %v, got error (%v)", tc.expectIPs, err)
Expand All @@ -191,8 +187,6 @@ func TestGetNodeHostIPs(t *testing.T) {
t.Errorf("expected error, got %v", nodeIPs)
} else if !reflect.DeepEqual(nodeIPs, tc.expectIPs) {
t.Errorf("expected %v, got %v", tc.expectIPs, nodeIPs)
} else if !nodeIP.Equal(nodeIPs[0]) {
t.Errorf("GetNodeHostIP did not return same primary (%s) as GetNodeHostIPs (%s)", nodeIP.String(), nodeIPs[0].String())
}
})
}
Expand Down

0 comments on commit 4695244

Please sign in to comment.