From e5e39b41f7cec78bd0df26bf1473bbb6fad511fa Mon Sep 17 00:00:00 2001 From: Ewout Prangsma Date: Thu, 14 Jun 2018 15:37:26 +0200 Subject: [PATCH] Fixed all-member-ready check --- .../v1alpha/deployment_status_members.go | 28 +++++++++++-------- .../deployment/v1alpha/member_status_list.go | 16 +++++++++++ pkg/deployment/resources/pod_inspector.go | 3 +- 3 files changed, 35 insertions(+), 12 deletions(-) diff --git a/pkg/apis/deployment/v1alpha/deployment_status_members.go b/pkg/apis/deployment/v1alpha/deployment_status_members.go index 28edb0e18..9a39e9ae5 100644 --- a/pkg/apis/deployment/v1alpha/deployment_status_members.go +++ b/pkg/apis/deployment/v1alpha/deployment_status_members.go @@ -23,8 +23,6 @@ package v1alpha import ( - "fmt" - "github.com/pkg/errors" ) @@ -214,16 +212,24 @@ func (ds *DeploymentStatusMembers) RemoveByID(id string, group ServerGroup) erro } // AllMembersReady returns true when all members are in the Ready state. -func (ds DeploymentStatusMembers) AllMembersReady() bool { - if err := ds.ForeachServerGroup(func(group ServerGroup, list MemberStatusList) error { - for _, x := range list { - if !x.Conditions.IsTrue(ConditionTypeReady) { - return fmt.Errorf("not ready") - } +func (ds DeploymentStatusMembers) AllMembersReady(mode DeploymentMode, syncEnabled bool) bool { + syncReady := func() bool { + if syncEnabled { + return ds.SyncMasters.AllMembersReady() && ds.SyncWorkers.AllMembersReady() } - return nil - }); err != nil { + return true + } + switch mode { + case DeploymentModeSingle: + return ds.Single.MembersReady() > 0 + case DeploymentModeActiveFailover: + return ds.Agents.AllMembersReady() && ds.Single.MembersReady() > 0 + case DeploymentModeCluster: + return ds.Agents.AllMembersReady() && + ds.DBServers.AllMembersReady() && + ds.Coordinators.AllMembersReady() && + syncReady() + default: return false } - return true } diff --git a/pkg/apis/deployment/v1alpha/member_status_list.go b/pkg/apis/deployment/v1alpha/member_status_list.go index 6d8280b20..bc8ca9f21 100644 --- a/pkg/apis/deployment/v1alpha/member_status_list.go +++ b/pkg/apis/deployment/v1alpha/member_status_list.go @@ -134,3 +134,19 @@ func (l MemberStatusList) SelectMemberToRemove() (MemberStatus, error) { } return MemberStatus{}, maskAny(errors.Wrap(NotFoundError, "No member available for removal")) } + +// MembersReady returns the number of members that are in the Ready state. +func (l MemberStatusList) MembersReady() int { + readyCount := 0 + for _, x := range l { + if x.Conditions.IsTrue(ConditionTypeReady) { + readyCount++ + } + } + return readyCount +} + +// AllMembersReady returns the true if all members are in the Ready state. +func (l MemberStatusList) AllMembersReady() bool { + return len(l) == l.MembersReady() +} diff --git a/pkg/deployment/resources/pod_inspector.go b/pkg/deployment/resources/pod_inspector.go index 8ac76142c..1ccaecc6d 100644 --- a/pkg/deployment/resources/pod_inspector.go +++ b/pkg/deployment/resources/pod_inspector.go @@ -217,7 +217,8 @@ func (r *Resources) InspectPods(ctx context.Context) error { }) // Update overall conditions - allMembersReady := status.Members.AllMembersReady() + spec := r.context.GetSpec() + allMembersReady := status.Members.AllMembersReady(spec.GetMode(), spec.Sync.IsEnabled()) status.Conditions.Update(api.ConditionTypeReady, allMembersReady, "", "") // Update conditions