Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change update strategy #203

Merged
merged 8 commits into from
Nov 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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