|
| 1 | +// |
| 2 | +// DISCLAIMER |
| 3 | +// |
| 4 | +// Copyright 2020 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 | +// Author Adam Janikowski |
| 21 | +// |
| 22 | + |
| 23 | +package reconcile |
| 24 | + |
| 25 | +import ( |
| 26 | + "context" |
| 27 | + |
| 28 | + "github.com/arangodb/kube-arangodb/pkg/util" |
| 29 | + |
| 30 | + "github.com/rs/zerolog" |
| 31 | + |
| 32 | + api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1" |
| 33 | +) |
| 34 | + |
| 35 | +func init() { |
| 36 | + registerAction(api.ActionTypeWaitForMemberInSync, newWaitForMemberInSync) |
| 37 | +} |
| 38 | + |
| 39 | +// newWaitForMemberUpAction creates a new Action that implements the given |
| 40 | +// planned WaitForShardInSync action. |
| 41 | +func newWaitForMemberInSync(log zerolog.Logger, action api.Action, actionCtx ActionContext) Action { |
| 42 | + a := &actionWaitForMemberInSync{} |
| 43 | + |
| 44 | + a.actionImpl = newActionImplDefRef(log, action, actionCtx, waitForMemberUpTimeout) |
| 45 | + |
| 46 | + return a |
| 47 | +} |
| 48 | + |
| 49 | +// actionWaitForMemberInSync implements an WaitForShardInSync. |
| 50 | +type actionWaitForMemberInSync struct { |
| 51 | + // actionImpl implement timeout and member id functions |
| 52 | + actionImpl |
| 53 | +} |
| 54 | + |
| 55 | +// Start performs the start of the action. |
| 56 | +// Returns true if the action is completely finished, false in case |
| 57 | +// the start time needs to be recorded and a ready condition needs to be checked. |
| 58 | +func (a *actionWaitForMemberInSync) Start(ctx context.Context) (bool, error) { |
| 59 | + ready, _, err := a.CheckProgress(ctx) |
| 60 | + return ready, err |
| 61 | +} |
| 62 | + |
| 63 | +// CheckProgress checks the progress of the action. |
| 64 | +// Returns true if the action is completely finished, false otherwise. |
| 65 | +func (a *actionWaitForMemberInSync) CheckProgress(ctx context.Context) (bool, bool, error) { |
| 66 | + ready, err := a.check(ctx) |
| 67 | + if err != nil { |
| 68 | + return false, false, err |
| 69 | + } |
| 70 | + |
| 71 | + return ready, false, nil |
| 72 | +} |
| 73 | + |
| 74 | +func (a *actionWaitForMemberInSync) check(ctx context.Context) (bool, error) { |
| 75 | + spec := a.actionCtx.GetSpec() |
| 76 | + |
| 77 | + groupSpec := spec.GetServerGroupSpec(a.action.Group) |
| 78 | + |
| 79 | + if !util.BoolOrDefault(groupSpec.ExtendedRotationCheck, false) { |
| 80 | + return true, nil |
| 81 | + } |
| 82 | + |
| 83 | + switch spec.Mode.Get() { |
| 84 | + case api.DeploymentModeCluster: |
| 85 | + return a.checkCluster(ctx, spec, groupSpec) |
| 86 | + default: |
| 87 | + return true, nil |
| 88 | + } |
| 89 | +} |
| 90 | + |
| 91 | +func (a *actionWaitForMemberInSync) checkCluster(ctx context.Context, spec api.DeploymentSpec, groupSpec api.ServerGroupSpec) (bool, error) { |
| 92 | + if !a.actionCtx.GetShardSyncStatus() { |
| 93 | + a.log.Info().Str("mode", "cluster").Msgf("Shards are not in sync") |
| 94 | + return false, nil |
| 95 | + } |
| 96 | + |
| 97 | + return true, nil |
| 98 | +} |
0 commit comments