Skip to content

Commit

Permalink
Merge pull request #203 from spotahome/change-update-policy
Browse files Browse the repository at this point in the history
change update strategy
  • Loading branch information
chusAlvarez authored Nov 28, 2019
2 parents 3862be6 + 694251f commit 2659077
Show file tree
Hide file tree
Showing 11 changed files with 791 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

107 changes: 107 additions & 0 deletions mocks/operator/redisfailover/service/RedisFailoverCheck.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions mocks/operator/redisfailover/service/RedisFailoverHeal.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions mocks/service/redis/Client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

61 changes: 61 additions & 0 deletions operator/redisfailover/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,62 @@ const (
timeToPrepare = 2 * time.Minute
)

//UpdateRedisesPods if the running version of pods are equal to the statefulset one
func (r *RedisFailoverHandler) UpdateRedisesPods(rf *redisfailoverv1.RedisFailover) error {
redises, err := r.rfChecker.GetRedisesIPs(rf)
if err != nil {
return err
}

masterIP, err := r.rfChecker.GetMasterIP(rf)
// No perform updates when nodes are syncing, still not connected, etc.
for _, rp := range redises {
if rp != masterIP {
ready, err := r.rfChecker.CheckRedisSlavesReady(rp, rf)
if err != nil {
return err
}
if !ready {
return nil
}
}
}

ssUR, err := r.rfChecker.GetStatefulSetUpdateRevision(rf)
if err != nil {
return err
}

redisesPods, err := r.rfChecker.GetRedisesSlavesPods(rf)
if err != nil {
return err
}

// Update stale pods with slave role
for _, pod := range redisesPods {
revision, err := r.rfChecker.GetRedisRevisionHash(pod, rf)
if err != nil {
return err
}
if revision != ssUR {
//Delete pod and wait next round to check if the new one is synced
r.rfHealer.DeletePod(pod, rf)
return nil
}
}

// Update stale pod with role master
master, err := r.rfChecker.GetRedisesMasterPod(rf)

masterRevision, err := r.rfChecker.GetRedisRevisionHash(master, rf)
if masterRevision != ssUR {
r.rfHealer.DeletePod(master, rf)
return nil
}

return nil
}

func (r *RedisFailoverHandler) CheckAndHeal(rf *redisfailoverv1.RedisFailover) error {
// Number of redis is equal as the set on the RF spec
// Number of sentinel is equal as the set on the RF spec
Expand Down Expand Up @@ -87,6 +143,11 @@ func (r *RedisFailoverHandler) CheckAndHeal(rf *redisfailoverv1.RedisFailover) e
}
}

err = r.UpdateRedisesPods(rf)
if err != nil {
return err
}

sentinels, err := r.rfChecker.GetSentinelsIPs(rf)
if err != nil {
return err
Expand Down
Loading

0 comments on commit 2659077

Please sign in to comment.