Skip to content

Commit

Permalink
support unix sock when add node
Browse files Browse the repository at this point in the history
  • Loading branch information
CMGS committed Sep 13, 2018
1 parent db43e00 commit 27ae597
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 27 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
18.9.12
18.9.13
27 changes: 11 additions & 16 deletions store/etcd/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import (
"encoding/json"
"fmt"
"io/ioutil"
"net"
"net/url"
"strconv"
"strings"

Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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
}
Expand Down
25 changes: 15 additions & 10 deletions types/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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
}

0 comments on commit 27ae597

Please sign in to comment.