|
| 1 | +// |
| 2 | +// DISCLAIMER |
| 3 | +// |
| 4 | +// Copyright 2025 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 | + "time" |
| 26 | + |
| 27 | + api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1" |
| 28 | +) |
| 29 | + |
| 30 | +const ( |
| 31 | + DelayActionDuration = "delayActionDuration" |
| 32 | +) |
| 33 | + |
| 34 | +// newDelayAction creates a new Action that implements the given |
| 35 | +// planned Delay action. |
| 36 | +func newDelayAction(action api.Action, actionCtx ActionContext) Action { |
| 37 | + a := &actionDelay{} |
| 38 | + |
| 39 | + a.actionImpl = newActionImplDefRef(action, actionCtx) |
| 40 | + |
| 41 | + return a |
| 42 | +} |
| 43 | + |
| 44 | +// actionDelay implements an Delay. |
| 45 | +type actionDelay struct { |
| 46 | + // actionImpl implement timeout and member id functions |
| 47 | + actionImpl |
| 48 | +} |
| 49 | + |
| 50 | +// Start performs the start of the action. |
| 51 | +// Returns true if the action is completely finished, false in case |
| 52 | +// the start time needs to be recorded and a ready condition needs to be checked. |
| 53 | +func (a *actionDelay) Start(ctx context.Context) (bool, error) { |
| 54 | + return false, nil |
| 55 | +} |
| 56 | + |
| 57 | +func (a *actionDelay) CheckProgress(ctx context.Context) (bool, bool, error) { |
| 58 | + v, ok := a.action.Params[DelayActionDuration] |
| 59 | + if !ok { |
| 60 | + a.log.Str("key", DelayActionDuration).Warn("Param for the delay not defined") |
| 61 | + return true, false, nil |
| 62 | + } |
| 63 | + |
| 64 | + d, err := time.ParseDuration(v) |
| 65 | + if err != nil { |
| 66 | + a.log.Err(err).Str("value", v).Warn("Unable to parse duration") |
| 67 | + return true, false, nil |
| 68 | + } |
| 69 | + |
| 70 | + if v := a.action.StartTime; v != nil { |
| 71 | + if v.Time.Add(d).Before(time.Now()) { |
| 72 | + return true, false, nil |
| 73 | + } |
| 74 | + } |
| 75 | + |
| 76 | + return false, false, nil |
| 77 | +} |
0 commit comments