mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-28 14:07:14 +00:00
remove deadcode in pkg/util/node
Signed-off-by: xin.li <xin.li@daocloud.io>
This commit is contained in:
parent
60c4c2b252
commit
b24804faf8
@ -17,17 +17,10 @@ limitations under the License.
|
|||||||
package node
|
package node
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"time"
|
|
||||||
|
|
||||||
"k8s.io/klog/v2"
|
|
||||||
|
|
||||||
v1 "k8s.io/api/core/v1"
|
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"
|
netutils "k8s.io/utils/net"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -103,46 +96,6 @@ func GetNodeHostIPs(node *v1.Node) ([]net.IP, error) {
|
|||||||
return nodeIPs, nil
|
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.
|
// IsNodeReady returns true if a node is ready; false otherwise.
|
||||||
func IsNodeReady(node *v1.Node) bool {
|
func IsNodeReady(node *v1.Node) bool {
|
||||||
for _, c := range node.Status.Conditions {
|
for _, c := range node.Status.Conditions {
|
||||||
|
@ -178,11 +178,7 @@ func TestGetNodeHostIPs(t *testing.T) {
|
|||||||
Status: v1.NodeStatus{Addresses: tc.addresses},
|
Status: v1.NodeStatus{Addresses: tc.addresses},
|
||||||
}
|
}
|
||||||
nodeIPs, err := GetNodeHostIPs(node)
|
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 err != nil {
|
||||||
if tc.expectIPs != nil {
|
if tc.expectIPs != nil {
|
||||||
t.Errorf("expected %v, got error (%v)", tc.expectIPs, err)
|
t.Errorf("expected %v, got error (%v)", tc.expectIPs, err)
|
||||||
@ -191,8 +187,6 @@ func TestGetNodeHostIPs(t *testing.T) {
|
|||||||
t.Errorf("expected error, got %v", nodeIPs)
|
t.Errorf("expected error, got %v", nodeIPs)
|
||||||
} else if !reflect.DeepEqual(nodeIPs, tc.expectIPs) {
|
} else if !reflect.DeepEqual(nodeIPs, tc.expectIPs) {
|
||||||
t.Errorf("expected %v, got %v", tc.expectIPs, nodeIPs)
|
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())
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user