From 507e1b5c3865d4edda99d835d4af149ac0451edf Mon Sep 17 00:00:00 2001 From: Julio Chana Date: Mon, 25 Mar 2019 12:09:12 +0100 Subject: [PATCH] Always mark the failovers as ok or error Signed-off-by: Julio Chana --- operator/redisfailover/checker.go | 4 ---- operator/redisfailover/handler.go | 9 ++++++++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/operator/redisfailover/checker.go b/operator/redisfailover/checker.go index db248df64..54e0df41c 100644 --- a/operator/redisfailover/checker.go +++ b/operator/redisfailover/checker.go @@ -53,7 +53,6 @@ func (r *RedisFailoverHandler) CheckAndHeal(rf *redisfailoverv1alpha2.RedisFailo r.logger.Debugf("time %.f more than expected. Not even one master, fixing...", minTime.Round(time.Second).Seconds()) // We can consider there's an error if err2 := r.rfHealer.SetOldestAsMaster(rf); err2 != nil { - r.mClient.SetClusterError(rf.Namespace, rf.Name) return err2 } } else { @@ -64,7 +63,6 @@ func (r *RedisFailoverHandler) CheckAndHeal(rf *redisfailoverv1alpha2.RedisFailo case 1: break default: - r.mClient.SetClusterError(rf.Namespace, rf.Name) return errors.New("More than one master, fix manually") } @@ -97,7 +95,6 @@ func (r *RedisFailoverHandler) CheckAndHeal(rf *redisfailoverv1alpha2.RedisFailo if err := r.rfChecker.CheckSentinelMonitor(sip, master); err != nil { r.logger.Debug("Sentinel is not monitoring the correct master") if err := r.rfHealer.NewSentinelMonitor(sip, master, rf); err != nil { - r.mClient.SetClusterError(rf.Namespace, rf.Name) return err } } @@ -123,6 +120,5 @@ func (r *RedisFailoverHandler) CheckAndHeal(rf *redisfailoverv1alpha2.RedisFailo return err } } - r.mClient.SetClusterOK(rf.Namespace, rf.Name) return nil } diff --git a/operator/redisfailover/handler.go b/operator/redisfailover/handler.go index cf0329b30..c3b1055a4 100644 --- a/operator/redisfailover/handler.go +++ b/operator/redisfailover/handler.go @@ -76,10 +76,17 @@ func (r *RedisFailoverHandler) Add(_ context.Context, obj runtime.Object) error labels := r.mergeLabels(rf) if err := r.Ensure(rf, labels, oRefs); err != nil { + r.mClient.SetClusterError(rf.Namespace, rf.Name) + return err + } + + if err := r.CheckAndHeal(rf); err != nil { + r.mClient.SetClusterError(rf.Namespace, rf.Name) return err } - return r.CheckAndHeal(rf) + r.mClient.SetClusterOK(rf.Namespace, rf.Name) + return nil } // Delete handles the deletion of a RF.