From 27ae597d4ff87fc76caed8fe554cc19fe949e44f Mon Sep 17 00:00:00 2001 From: CMGS Date: Thu, 13 Sep 2018 15:47:04 +0800 Subject: [PATCH] support unix sock when add node --- VERSION | 2 +- store/etcd/node.go | 27 +++++++++++---------------- types/node.go | 25 +++++++++++++++---------- 3 files changed, 27 insertions(+), 27 deletions(-) diff --git a/VERSION b/VERSION index 5bb5d92f2..37132a8df 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -18.9.12 +18.9.13 diff --git a/store/etcd/node.go b/store/etcd/node.go index 28fd99a99..04e73a575 100644 --- a/store/etcd/node.go +++ b/store/etcd/node.go @@ -5,8 +5,6 @@ import ( "encoding/json" "fmt" "io/ioutil" - "net" - "net/url" "strconv" "strings" @@ -125,18 +123,15 @@ func (k *Krypton) deleteNode(ctx context.Context, podname, nodename, endpoint st key := fmt.Sprintf(nodePrefixKey, podname, nodename) k.etcd.Delete(ctx, key, &etcdclient.DeleteOptions{Recursive: true}) k.etcd.Delete(ctx, fmt.Sprintf(nodePodKey, nodename), &etcdclient.DeleteOptions{}) - u, err := url.Parse(endpoint) - if err != nil { - log.Errorf("[deleteNode] Bad endpoint: %s", endpoint) - return - } - host, _, err := net.SplitHostPort(u.Host) - if err != nil { - log.Errorf("[deleteNode] Bad addr: %s", u.Host) - return + if strings.HasPrefix(endpoint, nodeTCPPrefixKey) { + host, err := types.GetEndpointHost(endpoint) + if err != nil { + log.Errorf("[deleteNode] Bad endpoint: %s", endpoint) + return + } + _cache.delete(host) } - _cache.delete(host) log.Debugf("[deleteNode] Node (%s, %s, %s) deleted", podname, nodename, endpoint) } @@ -300,12 +295,12 @@ func (k *Krypton) UpdateNodeResource(ctx context.Context, podname, nodename stri } func (k *Krypton) makeDockerClient(ctx context.Context, podname, nodename, endpoint string, force bool) (*engineapi.Client, error) { - u, err := url.Parse(endpoint) - if err != nil { - return nil, err + // if unix just connect it + if strings.HasPrefix(endpoint, nodeSockPrefixKey) { + return makeRawClient(endpoint, k.config.Docker.APIVersion) } - host, _, err := net.SplitHostPort(u.Host) + host, err := types.GetEndpointHost(endpoint) if err != nil { return nil, err } diff --git a/types/node.go b/types/node.go index b83c8b784..1d87012a5 100644 --- a/types/node.go +++ b/types/node.go @@ -81,16 +81,7 @@ func (n *Node) Info(ctx context.Context) (enginetypes.Info, error) { // get IP for node // will not return error func (n *Node) GetIP() string { - u, err := url.Parse(n.Endpoint) - if err != nil { - return "" - } - - host, _, err := net.SplitHostPort(u.Host) - if err != nil { - return "" - } - + host, _ := GetEndpointHost(n.Endpoint) return host } @@ -105,3 +96,17 @@ type NodeInfo struct { Deploy int // 最终部署几个 // 其他需要 filter 的字段 } + +// GetEndpointHost get host from endpoint +func GetEndpointHost(endpoint string) (string, error) { + u, err := url.Parse(endpoint) + if err != nil { + return "", err + } + + host, _, err := net.SplitHostPort(u.Host) + if err != nil { + return "", err + } + return host, nil +}