Skip to content

Commit

Permalink
fix for proxy case w/ no local master
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-deboer committed Mar 21, 2017
1 parent ce50d97 commit 090d133
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions pkg/discovery/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func (d *Discovery) DiscoverEnvironment() (map[string]string, error) {
sort.Slice(expectedMembers, func(i, j int) bool { return expectedMembers[i].Name < expectedMembers[j].Name })

localMaster := findMemberByName(expectedMembers, p.LocalInstanceName())
membersAPI, currentMembers, err := d.resolveMembersAndAPI(expectedMembers, *localMaster)
membersAPI, currentMembers, err := d.resolveMembersAndAPI(expectedMembers, localMaster)

environment := map[string]string{}
environment["ETCD_NAME"] = p.LocalInstanceName()
Expand All @@ -115,7 +115,7 @@ func (d *Discovery) DiscoverEnvironment() (map[string]string, error) {
log.Infof("Joining existing cluster as a master")
// TODO: what if we encounter a state where not of the expected masters are
// members of the current cluster?
if err := d.joinExistingCluster(membersAPI, expectedMembers, *localMaster); err != nil {
if err := d.joinExistingCluster(membersAPI, expectedMembers, localMaster); err != nil {
log.Fatal(err)
}
environment["ETCD_INITIAL_CLUSTER_STATE"] = "existing"
Expand Down Expand Up @@ -212,7 +212,7 @@ func (d *Discovery) evictBadPeers(membersAPI etcd.MembersAPI, expectedMembers []
}

func (d *Discovery) joinExistingCluster(membersAPI etcd.MembersAPI,
expectedMembers []etcd.Member, localMember etcd.Member) error {
expectedMembers []etcd.Member, localMember *etcd.Member) error {

msg := "Joining existing cluster: "
for tries := 0; tries < d.MaxTries; tries++ {
Expand Down Expand Up @@ -240,7 +240,7 @@ func (d *Discovery) joinExistingCluster(membersAPI etcd.MembersAPI,
return nil
}

func (d *Discovery) resolveMembersAndAPI(expectedMembers []etcd.Member, localMember etcd.Member) (etcd.MembersAPI, []etcd.Member, error) {
func (d *Discovery) resolveMembersAndAPI(expectedMembers []etcd.Member, localMember *etcd.Member) (etcd.MembersAPI, []etcd.Member, error) {

ctx := context.Background()
var currentMembers []etcd.Member
Expand All @@ -250,7 +250,7 @@ func (d *Discovery) resolveMembersAndAPI(expectedMembers []etcd.Member, localMem
for _, member := range expectedMembers {
// don't attempt self connection; afterall, this is intended as a pre-cursor
// to the actual etcd service on the local host
if member.PeerURLs[0] != localMember.PeerURLs[0] {
if localMember != nil && member.PeerURLs[0] != localMember.PeerURLs[0] {
cfg := etcd.Config{
Endpoints: member.ClientURLs,
Transport: etcd.DefaultTransport,
Expand Down Expand Up @@ -279,7 +279,6 @@ func (d *Discovery) resolveMembersAndAPI(expectedMembers []etcd.Member, localMem
log.Debugf("Actual cluster members: %#v", currentMembers)
}
return membersAPI, currentMembers, nil
break
}
}
if len(currentMembers) == 0 {
Expand Down

0 comments on commit 090d133

Please sign in to comment.