|
| 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 Ewout Prangsma |
| 21 | +// |
| 22 | + |
| 23 | +package reconcile |
| 24 | + |
| 25 | +import ( |
| 26 | + "context" |
| 27 | + |
| 28 | + api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1" |
| 29 | + "github.com/rs/zerolog" |
| 30 | +) |
| 31 | + |
| 32 | +func init() { |
| 33 | + registerAction(api.ActionTypeMarkToRemoveMember, newMarkToRemoveMemberAction) |
| 34 | +} |
| 35 | + |
| 36 | +func newMarkToRemoveMemberAction(log zerolog.Logger, action api.Action, actionCtx ActionContext) Action { |
| 37 | + a := &actionMarkToRemove{} |
| 38 | + |
| 39 | + a.actionImpl = newActionImplDefRef(log, action, actionCtx, addMemberTimeout) |
| 40 | + |
| 41 | + return a |
| 42 | +} |
| 43 | + |
| 44 | +type actionMarkToRemove struct { |
| 45 | + // actionImpl implement timeout and member id functions |
| 46 | + actionImpl |
| 47 | + |
| 48 | + // actionEmptyCheckProgress implement check progress with empty implementation |
| 49 | + actionEmptyCheckProgress |
| 50 | +} |
| 51 | + |
| 52 | +func (a *actionMarkToRemove) Start(ctx context.Context) (bool, error) { |
| 53 | + if a.action.Group != api.ServerGroupDBServers { |
| 54 | + return true, nil |
| 55 | + } |
| 56 | + |
| 57 | + return true, a.actionCtx.WithStatusUpdate(func(s *api.DeploymentStatus) bool { |
| 58 | + member, group, ok := s.Members.ElementByID(a.action.MemberID) |
| 59 | + if !ok { |
| 60 | + return false |
| 61 | + } |
| 62 | + |
| 63 | + if group != a.action.Group { |
| 64 | + return false |
| 65 | + } |
| 66 | + |
| 67 | + if !member.Conditions.Update(api.ConditionTypeMarkedToRemove, true, "Member marked to be removed", "") { |
| 68 | + return false |
| 69 | + } |
| 70 | + |
| 71 | + if err := s.Members.Update(member, group); err != nil { |
| 72 | + a.log.Warn().Err(err).Str("Member", member.ID).Msgf("Unable to update member") |
| 73 | + return false |
| 74 | + } |
| 75 | + |
| 76 | + return true |
| 77 | + }) |
| 78 | +} |
0 commit comments