refactor codebase:
- trailing whitespace in docs - reduce panic and return err - use log instead of fmt
This commit is contained in:
Родитель
0d27b61614
Коммит
e042578269
|
@ -14,7 +14,7 @@ For each reconciling cycle, we get P from k8s API. Comparing M and P, we have th
|
||||||
2. P’ consist of remaining pods of P
|
2. P’ consist of remaining pods of P
|
||||||
3. If P’ = M, the current state matches the membership state. GOTO Resize.
|
3. If P’ = M, the current state matches the membership state. GOTO Resize.
|
||||||
4. If len(P’) < len(M)/2 + 1, quorum lost. Go to recovery process (TODO).
|
4. If len(P’) < len(M)/2 + 1, quorum lost. Go to recovery process (TODO).
|
||||||
5. Remove one member that in M but does not in P's. GOTO Resize.
|
5. Remove one member that in M but does not in P's. GOTO Resize.
|
||||||
|
|
||||||
### Resize
|
### Resize
|
||||||
|
|
||||||
|
|
|
@ -121,7 +121,7 @@ func (c *Cluster) create(spec *Spec) {
|
||||||
panic(fmt.Sprintf("(TODO: we need to clean up already created ones.)\nError: %v", err))
|
panic(fmt.Sprintf("(TODO: we need to clean up already created ones.)\nError: %v", err))
|
||||||
}
|
}
|
||||||
c.idCounter++
|
c.idCounter++
|
||||||
fmt.Println("created cluster:", members)
|
log.Println("created cluster:", members)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Cluster) Update(spec *Spec) {
|
func (c *Cluster) Update(spec *Spec) {
|
||||||
|
|
|
@ -44,15 +44,15 @@ func (c *Cluster) reconcile(running etcdutil.MemberSet) error {
|
||||||
c.updateMembers(etcdcli)
|
c.updateMembers(etcdcli)
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Println("Running pods:", running)
|
log.Println("Running pods:\t", running)
|
||||||
log.Println("Expected membership:", c.members)
|
log.Println("Expected membership:\t", c.members)
|
||||||
|
|
||||||
unknownMembers := running.Diff(c.members)
|
unknownMembers := running.Diff(c.members)
|
||||||
if unknownMembers.Size() > 0 {
|
if unknownMembers.Size() > 0 {
|
||||||
log.Println("Removing unexpected pods:", unknownMembers)
|
log.Println("Removing unexpected pods:", unknownMembers)
|
||||||
for _, m := range unknownMembers {
|
for _, m := range unknownMembers {
|
||||||
if err := c.removePodAndService(m.Name); err != nil {
|
if err := c.removePodAndService(m.Name); err != nil {
|
||||||
panic(err)
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -63,11 +63,11 @@ func (c *Cluster) reconcile(running etcdutil.MemberSet) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if L.Size() < c.members.Size()/2+1 {
|
if L.Size() < c.members.Size()/2+1 {
|
||||||
fmt.Println("Disaster recovery")
|
log.Println("Disaster recovery")
|
||||||
return c.disasterRecovery()
|
return c.disasterRecovery()
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("Recovering one member")
|
log.Println("Recovering one member")
|
||||||
toRecover := c.members.Diff(L).PickOne()
|
toRecover := c.members.Diff(L).PickOne()
|
||||||
|
|
||||||
if err := c.removeMember(toRecover); err != nil {
|
if err := c.removeMember(toRecover); err != nil {
|
||||||
|
@ -101,7 +101,7 @@ func (c *Cluster) addOneMember() error {
|
||||||
newMember := &etcdutil.Member{Name: newMemberName}
|
newMember := &etcdutil.Member{Name: newMemberName}
|
||||||
resp, err := etcdcli.MemberAdd(context.TODO(), []string{newMember.PeerAddr()})
|
resp, err := etcdcli.MemberAdd(context.TODO(), []string{newMember.PeerAddr()})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
return err
|
||||||
}
|
}
|
||||||
newMember.ID = resp.Member.ID
|
newMember.ID = resp.Member.ID
|
||||||
c.members.Add(newMember)
|
c.members.Add(newMember)
|
||||||
|
|
Загрузка…
Ссылка в новой задаче