reuse func getNodeIP

This commit is contained in:
Weibin Lin
2018-10-08 16:39:31 +08:00
parent a34123d9c3
commit 0d57ec2938
5 changed files with 21 additions and 38 deletions

View File

@@ -24,6 +24,8 @@ import (
"strings"
"time"
"github.com/golang/glog"
"k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
@@ -91,6 +93,22 @@ func GetNodeHostIP(node *v1.Node) (net.IP, error) {
return nil, fmt.Errorf("host IP unknown; known addresses: %v", addresses)
}
// GetNodeIP returns the ip of node with the provided hostname
func GetNodeIP(client clientset.Interface, hostname string) net.IP {
var nodeIP net.IP
node, err := client.CoreV1().Nodes().Get(hostname, metav1.GetOptions{})
if err != nil {
glog.Warningf("Failed to retrieve node info: %v", err)
return nil
}
nodeIP, err = GetNodeHostIP(node)
if err != nil {
glog.Warningf("Failed to retrieve node IP: %v", err)
return nil
}
return nodeIP
}
// GetZoneKey is a helper function that builds a string identifier that is unique per failure-zone;
// it returns empty-string for no zone.
func GetZoneKey(node *v1.Node) string {