Skip to content

Commit

Permalink
vsphere give more time to resolve addrs
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-deboer committed Mar 21, 2017
1 parent c58eb39 commit cc80e29
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 19 deletions.
7 changes: 3 additions & 4 deletions pkg/discovery/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,9 @@ func (d *Discovery) DiscoverEnvironment() (map[string]string, error) {
d.ClientPort, d.ServerScheme, d.ServerPort); err == nil {
for _, m := range members {
// have to cast here because of golang type-system--ugh!
if len(m.ClientURLs) > 0 && len(m.PeerURLs) > 0 {
expectedMembers = append(expectedMembers, etcd.Member(m))
} else if log.GetLevel() >= log.DebugLevel {
log.Debugf("Platform %s returned an invalid member which will be ignored: %#v", d.Platform, m)
expectedMembers = append(expectedMembers, etcd.Member(m))
if len(m.PeerURLs) == 0 {
log.Fatalf("Platform %s returned an invalid member which will be ignored: %#v", d.Platform, m)
}
}
} else {
Expand Down
36 changes: 21 additions & 15 deletions pkg/platform/vsphere/vsphere.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
const (
ActivePowerState = "poweredOn"
RoundTripperDefaultCount = 3
MaxWaitForVMAddresses = (time.Minute * 10)
)

var clientLock sync.Mutex
Expand Down Expand Up @@ -114,9 +115,12 @@ func (vs *VSphere) ExpectedMembers(
if err != nil {
return nil, err
}
for _, name := range names {
member := etcd.Member{Name: name, ClientURLs: []string{}, PeerURLs: []string{}}
for tries := 0; tries <= 10 && len(member.PeerURLs) == 0; tries++ {

timeout := time.Now().Add(MaxWaitForVMAddresses)
now := time.Now()
for len(members) < len(names) && now.Before(timeout) {
for _, name := range names {
member := etcd.Member{Name: name, ClientURLs: []string{}, PeerURLs: []string{}}
addrs, err := vs.getAddresses(name)
if err != nil {
return nil, err
Expand All @@ -129,20 +133,22 @@ func (vs *VSphere) ExpectedMembers(
member.ClientURLs = append(member.ClientURLs, fmt.Sprintf("%s://%s:%d", clientScheme, addr, clientPort))
member.PeerURLs = append(member.PeerURLs, fmt.Sprintf("%s://%s:%d", serverScheme, addr, serverPort))
}

if len(member.PeerURLs) > 0 {
if log.GetLevel() >= log.DebugLevel {
log.Debugf("ExpectedMembers: member: %#v", member)
}
} else {
sleepTime := (2 * time.Second)
if log.GetLevel() >= log.DebugLevel {
log.Debugf("%s has no addresses yet; sleeping for %s", name, sleepTime)
}
time.Sleep(sleepTime)
if len(member.ClientURLs) > 0 {
members = append(members, member)
}
}
if len(members) < len(names) {
sleepTime := (5 * time.Second)
if log.GetLevel() >= log.DebugLevel {
log.Debugf("Still waiting to resolve addresses for %d out of %d members; sleeping for %s",
len(members), (len(names) - len(members)), sleepTime)
}
time.Sleep(sleepTime)
now = time.Now().Add(time.Second)
if now.After(timeout) {
return nil, fmt.Errorf("Timed out waiting for %v to resolve addresses", names)
}
}
members = append(members, member)
}
return members, nil
}
Expand Down

0 comments on commit cc80e29

Please sign in to comment.