Skip to content

Commit efb5d3f

Browse files
authored
TG-158 [Feature] Operator Wait command (#825)
* TG-158 [Feature] Operator Wait command * TG-158 [Feature] Add missing licence * MacOS adjustments
1 parent 1c17ea1 commit efb5d3f

File tree

4 files changed

+113
-0
lines changed

4 files changed

+113
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- Drop support for ArangoDB <= 3.5 (versions already EOL)
66
- Add new admin commands to fetch agency dump and agency state
77
- Add Graceful shutdown as finalizer (supports kubectl delete)
8+
- Add Watch to Lifecycle command
89

910
## [1.2.4](https://github.com/arangodb/kube-arangodb/tree/1.2.4) (2021-10-22)
1011
- Replace `beta.kubernetes.io/arch` Pod label with `kubernetes.io/arch` using Silent Rotation

docs/design/maintenance.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
# Maintenance
22

3+
## Development on MacOS
4+
5+
This repo requires GNU command line tools instead BSD one (which are by default available on Mac).
6+
7+
Please add following to your `~/bashrc` or `~/.zshrc` file (it requires Hombebrew to be installed):
8+
9+
```shell
10+
HOMEBREW_PREFIX=$(brew --prefix)
11+
for d in ${HOMEBREW_PREFIX}/opt/*/libexec/gnubin; do export PATH=$d:$PATH; done
12+
```
13+
314
## ArangoDeployment
415

516
Maintenance on ArangoDeployment can be enabled using annotation.

lifecycle.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ func init() {
9191
cmdLifecycle.AddCommand(cmdLifecyclePreStop)
9292
cmdLifecycle.AddCommand(cmdLifecycleCopy)
9393
cmdLifecycle.AddCommand(cmdLifecycleProbe)
94+
cmdLifecycle.AddCommand(cmdLifecycleWait)
9495

9596
cmdLifecycleCopy.Flags().StringVar(&lifecycleCopyOptions.TargetDir, "target", "", "Target directory to copy the executable to")
9697
}

lifecycle_wait.go

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
//
2+
// DISCLAIMER
3+
//
4+
// Copyright 2016-2021 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 main
22+
23+
import (
24+
"context"
25+
"fmt"
26+
"os"
27+
"time"
28+
29+
v1 "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
30+
"github.com/arangodb/kube-arangodb/pkg/util"
31+
"github.com/arangodb/kube-arangodb/pkg/util/constants"
32+
33+
"github.com/spf13/cobra"
34+
)
35+
36+
const (
37+
ArgDeploymentWatchTimeout = "watch-timeout"
38+
WatchDefaultTimeout = time.Minute * 5
39+
WatchCheckInterval = time.Second * 5
40+
)
41+
42+
var (
43+
cmdLifecycleWait = &cobra.Command{
44+
Use: "wait",
45+
Short: "Wait for specific ArangoDeployment",
46+
Long: "Wait for ArangoDeployment till it will reach UpToDate condition",
47+
Run: cmdLifecycleWaitCheck,
48+
}
49+
)
50+
51+
func init() {
52+
var deploymentName string
53+
var watchTimeout time.Duration
54+
55+
cmdLifecycleWait.Flags().StringVarP(&deploymentName, ArgDeploymentName, "d", "",
56+
"Name of ArangoDeployment to watch - necessary when more than one deployment exist within one namespace")
57+
cmdLifecycleWait.Flags().DurationVarP(&watchTimeout, ArgDeploymentWatchTimeout, "t", WatchDefaultTimeout,
58+
"Watch timeout")
59+
}
60+
61+
func cmdLifecycleWaitCheck(cmd *cobra.Command, _ []string) {
62+
ctx := util.CreateSignalContext(context.Background())
63+
64+
deploymentName, err := cmd.Flags().GetString(ArgDeploymentName)
65+
if err != nil {
66+
cliLog.Fatal().Err(err).Msg(fmt.Sprintf("error parsing argument: %s", ArgDeploymentName))
67+
}
68+
watchTimeout, err := cmd.Flags().GetDuration(ArgDeploymentWatchTimeout)
69+
if err != nil {
70+
cliLog.Fatal().Err(err).Msg(fmt.Sprintf("error parsing argument: %s", ArgDeploymentWatchTimeout))
71+
}
72+
73+
for {
74+
d, err := getDeployment(ctx, os.Getenv(constants.EnvOperatorPodNamespace), deploymentName)
75+
if err != nil {
76+
cliLog.Fatal().Err(err).Msg(fmt.Sprintf("error getting ArangoDeployment: %s", d.Name))
77+
}
78+
79+
isUpToDate, err := d.IsUpToDate()
80+
if err != nil {
81+
cliLog.Err(err).Msg(fmt.Sprintf("error checking Status for ArangoDeployment: %s", d.Name))
82+
}
83+
84+
if isUpToDate {
85+
cliLog.Info().Msg(fmt.Sprintf("ArangoDeployment: %s is %s", d.Name, v1.ConditionTypeUpToDate))
86+
return
87+
}
88+
89+
select {
90+
case <-ctx.Done():
91+
return
92+
case <-time.After(WatchCheckInterval):
93+
cliLog.Info().Msg(fmt.Sprintf("ArangoDeployment: %s is not ready yet. Waiting...", d.Name))
94+
continue
95+
case <-time.After(watchTimeout):
96+
cliLog.Error().Msg(fmt.Sprintf("ArangoDeployment: %s is not %s yet - operation timed out!", d.Name, v1.ConditionTypeUpToDate))
97+
return
98+
}
99+
}
100+
}

0 commit comments

Comments
 (0)