當前位置: 首頁>>代碼示例>>Golang>>正文


Golang node.GetNodeHostIP函數代碼示例

本文整理匯總了Golang中k8s/io/kubernetes/pkg/util/node.GetNodeHostIP函數的典型用法代碼示例。如果您正苦於以下問題:Golang GetNodeHostIP函數的具體用法?Golang GetNodeHostIP怎麽用?Golang GetNodeHostIP使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了GetNodeHostIP函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: getClusterNodesIP

// getClusterNodesIP returns the IP address of each node in the kubernetes cluster
func getClusterNodesIP(kubeClient *unversioned.Client, nodeSelector string) (clusterNodes []string) {
	listOpts := api.ListOptions{}

	if nodeSelector != "" {
		label, err := labels.Parse(nodeSelector)
		if err != nil {
			glog.Fatalf("'%v' is not a valid selector: %v", nodeSelector, err)
		}
		listOpts.LabelSelector = label
	}

	nodes, err := kubeClient.Nodes().List(listOpts)
	if err != nil {
		glog.Fatalf("Error getting running nodes: %v", err)
	}

	for _, nodo := range nodes.Items {
		nodeIP, err := node.GetNodeHostIP(&nodo)
		if err == nil {
			clusterNodes = append(clusterNodes, nodeIP.String())
		}
	}
	sort.Strings(clusterNodes)

	return
}
開發者ID:upmc-enterprises,項目名稱:contrib,代碼行數:27,代碼來源:utils.go

示例2: getHostIPAnyWay

// getHostIPAnyway attempts to return the host IP from kubelet's nodeInfo, or the initialNodeStatus
func (kl *Kubelet) getHostIPAnyWay() (net.IP, error) {
	node, err := kl.getNodeAnyWay()
	if err != nil {
		return nil, err
	}
	return nodeutil.GetNodeHostIP(node)
}
開發者ID:invenfantasy,項目名稱:kubernetes,代碼行數:8,代碼來源:kubelet_getters.go

示例3: GetHostIP

// Returns host IP or nil in case of error.
func (kl *Kubelet) GetHostIP() (net.IP, error) {
	node, err := kl.GetNode()
	if err != nil {
		return nil, fmt.Errorf("cannot get node: %v", err)
	}
	return nodeutil.GetNodeHostIP(node)
}
開發者ID:invenfantasy,項目名稱:kubernetes,代碼行數:8,代碼來源:kubelet_getters.go

示例4: ResourceLocation

// ResourceLocation returns an URL and transport which one can use to send traffic for the specified node.
func ResourceLocation(getter ResourceGetter, connection client.ConnectionInfoGetter, proxyTransport http.RoundTripper, ctx api.Context, id string) (*url.URL, http.RoundTripper, error) {
	schemeReq, name, portReq, valid := util.SplitSchemeNamePort(id)
	if !valid {
		return nil, nil, errors.NewBadRequest(fmt.Sprintf("invalid node request %q", id))
	}

	nodeObj, err := getter.Get(ctx, name)
	if err != nil {
		return nil, nil, err
	}
	node := nodeObj.(*api.Node)
	hostIP, err := nodeutil.GetNodeHostIP(node)
	if err != nil {
		return nil, nil, err
	}
	host := hostIP.String()

	if portReq == "" || strconv.Itoa(ports.KubeletPort) == portReq {
		// Ignore requested scheme, use scheme provided by GetConnectionInfo
		scheme, port, kubeletTransport, err := connection.GetConnectionInfo(host)
		if err != nil {
			return nil, nil, err
		}
		return &url.URL{
				Scheme: scheme,
				Host: net.JoinHostPort(
					host,
					strconv.FormatUint(uint64(port), 10),
				),
			},
			kubeletTransport,
			nil
	}
	return &url.URL{Scheme: schemeReq, Host: net.JoinHostPort(host, portReq)}, proxyTransport, nil
}
開發者ID:robbfoster-taulia,項目名稱:kubernetes,代碼行數:36,代碼來源:strategy.go

示例5: GetConnectionInfo

func (r *REST) GetConnectionInfo(ctx api.Context, nodeName types.NodeName) (string, string, uint, http.RoundTripper, error) {
	scheme, port, transport, err := r.connection.GetRawConnectionInfo(ctx, nodeName)
	if err != nil {
		return "", "", 0, nil, err
	}

	// We probably shouldn't care about context when looking for Node object.
	obj, err := r.Get(ctx, string(nodeName))
	if err != nil {
		return "", "", 0, nil, err
	}
	node, ok := obj.(*api.Node)
	if !ok {
		return "", "", 0, nil, fmt.Errorf("Unexpected object type: %#v", node)
	}

	hostIP, err := nodeutil.GetNodeHostIP(node)
	if err != nil {
		return "", "", 0, nil, err
	}
	host := hostIP.String()

	daemonPort := int(node.Status.DaemonEndpoints.KubeletEndpoint.Port)
	if daemonPort > 0 {
		return scheme, host, uint(daemonPort), transport, nil
	}
	return scheme, host, port, transport, nil
}
開發者ID:vikaschoudhary16,項目名稱:kubernetes,代碼行數:28,代碼來源:etcd.go

示例6: GetHostIP

// Returns host IP or nil in case of error.
func (nm *realNodeManager) GetHostIP() (net.IP, error) {
	if nm.client == nil {
		return nil, errors.New("unable to get node entry because apiserver client is nil")
	}
	node, err := nm.GetNode()
	if err != nil {
		return nil, fmt.Errorf("cannot get node: %v", err)
	}
	return nodeutil.GetNodeHostIP(node)
}
開發者ID:liuhewei,項目名稱:kubernetes,代碼行數:11,代碼來源:node_manager.go

示例7: getNodeIP

func getNodeIP(client clientset.Interface, hostname string) net.IP {
	var nodeIP net.IP
	node, err := client.Core().Nodes().Get(hostname)
	if err != nil {
		glog.Warningf("Failed to retrieve node info: %v", err)
		return nil
	}
	nodeIP, err = nodeutil.GetNodeHostIP(node)
	if err != nil {
		glog.Warningf("Failed to retrieve node IP: %v", err)
		return nil
	}
	return nodeIP
}
開發者ID:jumpkick,項目名稱:kubernetes,代碼行數:14,代碼來源:server.go

示例8: getNodeIP

// getNodeIP is copied from the upstream proxy config to retrieve the IP of a node.
func getNodeIP(client *kclient.Client, hostname string) net.IP {
	var nodeIP net.IP
	node, err := client.Nodes().Get(hostname)
	if err != nil {
		glog.Warningf("Failed to retrieve node info: %v", err)
		return nil
	}
	nodeIP, err = utilnode.GetNodeHostIP(node)
	if err != nil {
		glog.Warningf("Failed to retrieve node IP: %v", err)
		return nil
	}
	return nodeIP
}
開發者ID:pweil-,項目名稱:origin,代碼行數:15,代碼來源:node.go

示例9: getClusterNodesIP

// getClusterNodesIP returns the IP address of each node in the kubernetes cluster
func getClusterNodesIP(kubeClient *unversioned.Client) (clusterNodes []string) {
	nodes, err := kubeClient.Nodes().List(api.ListOptions{})
	if err != nil {
		glog.Fatalf("Error getting running nodes: %v", err)
	}

	for _, nodo := range nodes.Items {
		nodeIP, err := node.GetNodeHostIP(&nodo)
		if err == nil {
			clusterNodes = append(clusterNodes, nodeIP.String())
		}
	}
	sort.Strings(clusterNodes)

	return
}
開發者ID:remoe,項目名稱:contrib,代碼行數:17,代碼來源:utils.go

示例10: ResourceLocation

// ResourceLocation returns an URL and transport which one can use to send traffic for the specified node.
func ResourceLocation(getter ResourceGetter, connection client.ConnectionInfoGetter, proxyTransport http.RoundTripper, ctx api.Context, id string) (*url.URL, http.RoundTripper, error) {
	schemeReq, name, portReq, valid := utilnet.SplitSchemeNamePort(id)
	if !valid {
		return nil, nil, errors.NewBadRequest(fmt.Sprintf("invalid node request %q", id))
	}

	nodeObj, err := getter.Get(ctx, name)
	if err != nil {
		return nil, nil, err
	}
	node := nodeObj.(*api.Node)
	hostIP, err := nodeutil.GetNodeHostIP(node)
	if err != nil {
		return nil, nil, err
	}
	host := hostIP.String()

	// We check if we want to get a default Kubelet's transport. It happens if either:
	// - no port is specified in request (Kubelet's port is default),
	// - we're using Port stored as a DaemonEndpoint and requested port is a Kubelet's port stored in the DaemonEndpoint,
	// - there's no information in the API about DaemonEnpoint (legacy cluster) and requested port is equal to ports.KubeletPort (cluster-wide config)
	kubeletPort := node.Status.DaemonEndpoints.KubeletEndpoint.Port
	if kubeletPort == 0 {
		kubeletPort = ports.KubeletPort
	}
	if portReq == "" || strconv.Itoa(int(kubeletPort)) == portReq {
		scheme, port, kubeletTransport, err := connection.GetConnectionInfo(ctx, node.Name)
		if err != nil {
			return nil, nil, err
		}
		return &url.URL{
				Scheme: scheme,
				Host: net.JoinHostPort(
					host,
					strconv.FormatUint(uint64(port), 10),
				),
			},
			kubeletTransport,
			nil
	}
	return &url.URL{Scheme: schemeReq, Host: net.JoinHostPort(host, portReq)}, proxyTransport, nil
}
開發者ID:ncdc,項目名稱:kubernetes,代碼行數:43,代碼來源:strategy.go


注:本文中的k8s/io/kubernetes/pkg/util/node.GetNodeHostIP函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。