Skip to content

Commit

Permalink
etcdService.go: add error checks for host parsing in service watch
Browse files Browse the repository at this point in the history
Signed-off-by: Erik Hollensbe <erik+github@hollensbe.org>
  • Loading branch information
erikh committed Mar 2, 2016
1 parent 5011dbe commit ca6060e
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions etcdService.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,17 +165,30 @@ func (self *etcdPlugin) WatchService(name string,

// handle messages from watch service
go func() {
restart:
for {
select {
case watchResp := <-watchCh:
log.Debugf("Received event %#v\n Node: %#v", watchResp, watchResp.Node)

// derive service info from key
srvKey := strings.TrimPrefix(watchResp.Node.Key, "/contiv.io/service/")
srvName := strings.Split(srvKey, "/")[0]
hostInfo := strings.Split(srvKey, "/")[1]
hostAddr := strings.Split(hostInfo, ":")[0]
portNum, _ := strconv.Atoi(strings.Split(hostInfo, ":")[1])
parts := strings.Split(srvKey, "/")
if len(parts) < 2 {
log.Warnf("Recieved event for key %q, could not parse service key", srvKey)
goto restart
}

srvName := parts[0]
hostAddr := parts[1]

parts = strings.Split(hostAddr, ":")
if len(parts) != 2 {
log.Warnf("Recieved event for key %q, could not parse hostinfo", srvKey)
goto restart
}

portNum, _ := strconv.Atoi(parts[1])

// Build service info
srvInfo := ServiceInfo{
Expand Down

0 comments on commit ca6060e

Please sign in to comment.