Skip to content

Commit 9b5f145

Browse files
authored
[Feature] Add Maintenance Mode support (#623)
1 parent 7a8be98 commit 9b5f145

26 files changed

+619
-64
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Change Log
22

33
## [master](https://github.com/arangodb/kube-arangodb/tree/master) (N/A)
4+
- Add Operator Maintenance Management feature
45

56
## [1.0.6](https://github.com/arangodb/kube-arangodb/tree/1.0.6) (2020-08-19)
67
- Add Operator Namespaced mode (Alpha)

README.md

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -60,25 +60,26 @@ covers individual newer features separately.
6060

6161
Feature-wise production readiness table:
6262

63-
| Feature | Operator Version | ArangoDB Version | ArangoDB Edition | State | Enabled | Flag | Remarks |
64-
|---------------------------------|------------------|------------------|-----------------------|------------|---------|------------------------------------------|--------------------------------------------------------------------------|
65-
| Pod Disruption Budgets | 0.3.10 | Any | Community, Enterprise | Alpha | True | N/A | N/A |
66-
| Pod Disruption Budgets | 0.3.11 | Any | Community, Enterprise | Production | True | N/A | N/A |
67-
| Volume Resizing | 0.3.10 | Any | Community, Enterprise | Alpha | True | N/A | N/A |
68-
| Volume Resizing | 0.3.11 | Any | Community, Enterprise | Production | True | N/A | N/A |
69-
| Disabling of liveness probes | 0.3.10 | Any | Community, Enterprise | Alpha | True | N/A | N/A |
70-
| Disabling of liveness probes | 0.3.11 | Any | Community, Enterprise | Production | True | N/A | N/A |
71-
| Volume Claim Templates | 0.3.11 | Any | Community, Enterprise | Alpha | True | N/A | N/A |
72-
| Volume Claim Templates | 1.0.0 | Any | Community, Enterprise | Production | True | N/A | N/A |
73-
| Prometheus Metrics Exporter | 0.3.11 | Any | Community, Enterprise | Alpha | True | N/A | Prometheus required |
74-
| Prometheus Metrics Exporter | 1.0.0 | Any | Community, Enterprise | Production | True | N/A | Prometheus required |
75-
| Sidecar Containers | 0.3.11 | Any | Community, Enterprise | Alpha | True | N/A | N/A |
76-
| Sidecar Containers | 1.0.0 | Any | Community, Enterprise | Production | True | N/A | N/A |
77-
| Operator Single Mode | 1.0.4 | Any | Community, Enterprise | Production | False | --mode.single | Only 1 instance of Operator allowed in namespace when feature is enabled |
78-
| TLS SNI Support | 1.0.3 | >= 3.7.0 | Enterprise | Production | True | --deployment.feature.tls-sni | N/A |
79-
| TLS Runtime Rotation Support | 1.0.4 | > 3.7.0 | Enterprise | Alpha | False | --deployment.feature.tls-rotation | N/A |
80-
| JWT Rotation Support | 1.0.4 | > 3.7.0 | Enterprise | Alpha | False | --deployment.feature.jwt-rotation | N/A |
81-
| Encryption Key Rotation Support | 1.0.4 | > 3.7.0 | Enterprise | Alpha | False | --deployment.feature.encryption-rotation | N/A |
63+
| Feature | Operator Version | ArangoDB Version | ArangoDB Edition | State | Enabled | Flag | Remarks |
64+
|-----------------------------------------|------------------|------------------|-----------------------|------------|---------|------------------------------------------|--------------------------------------------------------------------------|
65+
| Pod Disruption Budgets | 0.3.10 | Any | Community, Enterprise | Alpha | True | N/A | N/A |
66+
| Pod Disruption Budgets | 0.3.11 | Any | Community, Enterprise | Production | True | N/A | N/A |
67+
| Volume Resizing | 0.3.10 | Any | Community, Enterprise | Alpha | True | N/A | N/A |
68+
| Volume Resizing | 0.3.11 | Any | Community, Enterprise | Production | True | N/A | N/A |
69+
| Disabling of liveness probes | 0.3.10 | Any | Community, Enterprise | Alpha | True | N/A | N/A |
70+
| Disabling of liveness probes | 0.3.11 | Any | Community, Enterprise | Production | True | N/A | N/A |
71+
| Volume Claim Templates | 0.3.11 | Any | Community, Enterprise | Alpha | True | N/A | N/A |
72+
| Volume Claim Templates | 1.0.0 | Any | Community, Enterprise | Production | True | N/A | N/A |
73+
| Prometheus Metrics Exporter | 0.3.11 | Any | Community, Enterprise | Alpha | True | N/A | Prometheus required |
74+
| Prometheus Metrics Exporter | 1.0.0 | Any | Community, Enterprise | Production | True | N/A | Prometheus required |
75+
| Sidecar Containers | 0.3.11 | Any | Community, Enterprise | Alpha | True | N/A | N/A |
76+
| Sidecar Containers | 1.0.0 | Any | Community, Enterprise | Production | True | N/A | N/A |
77+
| Operator Single Mode | 1.0.4 | Any | Community, Enterprise | Production | False | --mode.single | Only 1 instance of Operator allowed in namespace when feature is enabled |
78+
| TLS SNI Support | 1.0.3 | >= 3.7.0 | Enterprise | Production | True | --deployment.feature.tls-sni | N/A |
79+
| TLS Runtime Rotation Support | 1.0.4 | > 3.7.0 | Enterprise | Alpha | False | --deployment.feature.tls-rotation | N/A |
80+
| JWT Rotation Support | 1.0.4 | > 3.7.0 | Enterprise | Alpha | False | --deployment.feature.jwt-rotation | N/A |
81+
| Encryption Key Rotation Support | 1.0.4 | > 3.7.0 | Enterprise | Alpha | False | --deployment.feature.encryption-rotation | N/A |
82+
| Operator Maintenance Management Support | 1.0.7 | >= 3.5.0 | Community, Enterprise | Alpha | False | --deployment.feature.maintenance | N/A |
8283

8384
## Release notes for 0.3.16
8485

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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 v1
24+
25+
type DatabaseSpec struct {
26+
Maintenance *bool `json:"maintenance,omitempty"`
27+
}
28+
29+
func (m *DatabaseSpec) GetMaintenance() bool {
30+
if m == nil || m.Maintenance == nil {
31+
return false
32+
}
33+
34+
return *m.Maintenance
35+
}

pkg/apis/deployment/v1/deployment_spec.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ type DeploymentSpec struct {
9595

9696
ID *ServerIDGroupSpec `json:"id,omitempty"`
9797

98+
Database *DatabaseSpec `json:"database,omitempty"`
99+
98100
Single ServerGroupSpec `json:"single"`
99101
Agents ServerGroupSpec `json:"agents"`
100102
DBServers ServerGroupSpec `json:"dbservers"`
@@ -295,6 +297,9 @@ func (s *DeploymentSpec) SetDefaultsFrom(source DeploymentSpec) {
295297
if s.AllowUnsafeUpgrade == nil {
296298
s.AllowUnsafeUpgrade = util.NewBoolOrNil(source.AllowUnsafeUpgrade)
297299
}
300+
if s.Database == nil {
301+
s.Database = source.Database.DeepCopy()
302+
}
298303

299304
s.License.SetDefaultsFrom(source.License)
300305
s.ExternalAccess.SetDefaultsFrom(source.ExternalAccess)

pkg/apis/deployment/v1/plan.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,10 @@ const (
119119
ActionTypeJWTPropagated ActionType = "JWTPropagated"
120120
// ActionTypeClusterMemberCleanup removes member from cluster
121121
ActionTypeClusterMemberCleanup ActionType = "ClusterMemberCleanup"
122+
// ActionTypeEnableMaintenance enables maintenance on cluster.
123+
ActionTypeEnableMaintenance ActionType = "EnableMaintenance"
124+
// ActionTypeEnableMaintenance disables maintenance on cluster.
125+
ActionTypeDisableMaintenance ActionType = "DisableMaintenance"
122126
)
123127

124128
const (

pkg/apis/deployment/v1/zz_generated.deepcopy.go

Lines changed: 26 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/deployment/agency/agency.go

Lines changed: 18 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -22,41 +22,25 @@
2222

2323
package agency
2424

25-
type ArangoPlanDatabases map[string]ArangoPlanCollections
26-
27-
func (a ArangoPlanDatabases) IsDBServerInDatabases(name string) bool {
28-
for _, collections := range a {
29-
if collections.IsDBServerInCollections(name) {
30-
return true
31-
}
32-
}
33-
return false
34-
}
35-
36-
type ArangoPlanCollections map[string]ArangoPlanCollection
37-
38-
func (a ArangoPlanCollections) IsDBServerInCollections(name string) bool {
39-
for _, collection := range a {
40-
if collection.IsDBServerInShards(name) {
41-
return true
25+
import (
26+
"context"
27+
28+
"github.com/arangodb/go-driver/agency"
29+
"github.com/pkg/errors"
30+
)
31+
32+
type Fetcher func(ctx context.Context, i interface{}, keyParts ...string) error
33+
34+
func NewFetcher(a agency.Agency) Fetcher {
35+
return func(ctx context.Context, i interface{}, keyParts ...string) error {
36+
if err := a.ReadKey(ctx, []string{
37+
ArangoKey,
38+
PlanKey,
39+
PlanCollectionsKey,
40+
}, i); err != nil {
41+
return errors.WithStack(err)
4242
}
43-
}
44-
return false
45-
}
46-
47-
type ArangoPlanCollection struct {
48-
Shards ArangoPlanShard `json:"shards"`
49-
}
5043

51-
func (a ArangoPlanCollection) IsDBServerInShards(name string) bool {
52-
for _, dbservers := range a.Shards {
53-
for _, dbserver := range dbservers {
54-
if dbserver == name {
55-
return true
56-
}
57-
}
44+
return nil
5845
}
59-
return false
6046
}
61-
62-
type ArangoPlanShard map[string][]string

pkg/deployment/agency/database.go

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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 agency
24+
25+
import (
26+
"context"
27+
28+
"github.com/pkg/errors"
29+
)
30+
31+
func GetAgencyCollections(ctx context.Context, f Fetcher) (*ArangoPlanDatabases, error) {
32+
ret := &ArangoPlanDatabases{}
33+
34+
if err := f(ctx, ret, ArangoKey, PlanKey, PlanCollectionsKey); err != nil {
35+
return nil, errors.WithStack(err)
36+
}
37+
38+
return ret, nil
39+
}
40+
41+
type ArangoPlanDatabases map[string]ArangoPlanCollections
42+
43+
func (a ArangoPlanDatabases) IsDBServerInDatabases(name string) bool {
44+
for _, collections := range a {
45+
if collections.IsDBServerInCollections(name) {
46+
return true
47+
}
48+
}
49+
return false
50+
}
51+
52+
type ArangoPlanCollections map[string]ArangoPlanCollection
53+
54+
func (a ArangoPlanCollections) IsDBServerInCollections(name string) bool {
55+
for _, collection := range a {
56+
if collection.IsDBServerInShards(name) {
57+
return true
58+
}
59+
}
60+
return false
61+
}
62+
63+
type ArangoPlanCollection struct {
64+
Shards ArangoPlanShard `json:"shards"`
65+
}
66+
67+
func (a ArangoPlanCollection) IsDBServerInShards(name string) bool {
68+
for _, dbservers := range a.Shards {
69+
for _, dbserver := range dbservers {
70+
if dbserver == name {
71+
return true
72+
}
73+
}
74+
}
75+
return false
76+
}
77+
78+
type ArangoPlanShard map[string][]string
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
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 agency
24+
25+
import (
26+
"context"
27+
"net/http"
28+
29+
"github.com/arangodb/go-driver"
30+
)
31+
32+
type Maintenance struct {
33+
Result string `json:"result"`
34+
}
35+
36+
func (m Maintenance) Enabled() bool {
37+
return m.Result == "Maintenance"
38+
}
39+
40+
func GetMaintenanceMode(ctx context.Context, client driver.Client) (Maintenance, error) {
41+
conn := client.Connection()
42+
r, err := conn.NewRequest(http.MethodGet, "/_admin/cluster/maintenance")
43+
if err != nil {
44+
return Maintenance{}, err
45+
}
46+
47+
resp, err := conn.Do(ctx, r)
48+
if err != nil {
49+
return Maintenance{}, err
50+
}
51+
52+
if err := resp.CheckStatus(http.StatusOK); err != nil {
53+
return Maintenance{}, err
54+
}
55+
56+
var m Maintenance
57+
58+
if err := resp.ParseBody("", &m); err != nil {
59+
return Maintenance{}, err
60+
}
61+
62+
return m, nil
63+
}
64+
65+
func SetMaintenanceMode(ctx context.Context, client driver.Client, enabled bool) error {
66+
data := "on"
67+
if !enabled {
68+
data = "off"
69+
}
70+
71+
conn := client.Connection()
72+
r, err := conn.NewRequest(http.MethodPut, "/_admin/cluster/maintenance")
73+
if err != nil {
74+
return err
75+
}
76+
77+
if _, err := r.SetBody(data); err != nil {
78+
return err
79+
}
80+
81+
resp, err := conn.Do(ctx, r)
82+
if err != nil {
83+
return err
84+
}
85+
86+
if err := resp.CheckStatus(http.StatusOK); err != nil {
87+
return err
88+
}
89+
90+
return nil
91+
}

pkg/deployment/features/encryption.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
//
1818
// Copyright holder is ArangoDB GmbH, Cologne, Germany
1919
//
20+
// Author Adam Janikowski
21+
//
2022

2123
package features
2224

0 commit comments

Comments
 (0)