|
| 1 | +// |
| 2 | +// DISCLAIMER |
| 3 | +// |
| 4 | +// Copyright 2022 ArangoDB GmbH, Cologne, Germany |
| 5 | +// |
| 6 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | +// you may not use this file except in compliance with the License. |
| 8 | +// You may obtain a copy of the License at |
| 9 | +// |
| 10 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +// |
| 12 | +// Unless required by applicable law or agreed to in writing, software |
| 13 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | +// See the License for the specific language governing permissions and |
| 16 | +// limitations under the License. |
| 17 | +// |
| 18 | +// Copyright holder is ArangoDB GmbH, Cologne, Germany |
| 19 | +// |
| 20 | + |
| 21 | +package reconcile |
| 22 | + |
| 23 | +import ( |
| 24 | + "context" |
| 25 | + |
| 26 | + api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1" |
| 27 | + "github.com/arangodb/kube-arangodb/pkg/util/errors" |
| 28 | +) |
| 29 | + |
| 30 | +// newWaitForMemberReadyAction creates a new Action that implements the given |
| 31 | +// planned WaitForMemberReady action. |
| 32 | +func newWaitForMemberReadyAction(action api.Action, actionCtx ActionContext) Action { |
| 33 | + a := &actionWaitForMemberReady{} |
| 34 | + |
| 35 | + a.actionImpl = newActionImplDefRef(action, actionCtx) |
| 36 | + |
| 37 | + return a |
| 38 | +} |
| 39 | + |
| 40 | +// actionWaitForMemberReady implements an WaitForMemberReady. |
| 41 | +type actionWaitForMemberReady struct { |
| 42 | + // actionImpl implement timeout and member id functions |
| 43 | + actionImpl |
| 44 | +} |
| 45 | + |
| 46 | +// Start performs the start of the action. |
| 47 | +// Returns true if the action is completely finished, false in case |
| 48 | +// the start time needs to be recorded and a ready condition needs to be checked. |
| 49 | +func (a *actionWaitForMemberReady) Start(ctx context.Context) (bool, error) { |
| 50 | + ready, _, err := a.CheckProgress(ctx) |
| 51 | + if err != nil { |
| 52 | + return false, errors.WithStack(err) |
| 53 | + } |
| 54 | + return ready, nil |
| 55 | +} |
| 56 | + |
| 57 | +// CheckProgress checks the progress of the action. |
| 58 | +// Returns true if the action is completely finished, false otherwise. |
| 59 | +func (a *actionWaitForMemberReady) CheckProgress(ctx context.Context) (bool, bool, error) { |
| 60 | + member, ok := a.actionCtx.GetMemberStatusByID(a.MemberID()) |
| 61 | + if !ok || member.Phase == api.MemberPhaseFailed { |
| 62 | + a.log.Debug("Member in failed phase") |
| 63 | + return true, false, nil |
| 64 | + } |
| 65 | + |
| 66 | + return member.Conditions.IsTrue(api.ConditionTypeReady), false, nil |
| 67 | +} |
0 commit comments