Skip to content

Commit 29b979d

Browse files
authored
[Feature] Propagation modes (#779)
1 parent f62fdf2 commit 29b979d

19 files changed

+378
-107
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- Add Ephemeral Volumes for apps feature
88
- Check if the DB server is cleaned out.
99
- Render Pod Template in ArangoMember Spec and Status
10+
- Add Pod PropagationModes
1011

1112
## [1.2.1](https://github.com/arangodb/kube-arangodb/tree/1.2.1) (2021-07-28)
1213
- Fix ArangoMember race with multiple ArangoDeployments within single namespace

pkg/apis/deployment/v1/conditions.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ const (
7373
ConditionTypeMaintenanceMode ConditionType = "MaintenanceMode"
7474
// ConditionTypePendingRestart indicates that restart is required
7575
ConditionTypePendingRestart ConditionType = "PendingRestart"
76+
// ConditionTypeRestart indicates that restart will be started
77+
ConditionTypeRestart ConditionType = "Restart"
7678
// ConditionTypePendingTLSRotation indicates that TLS rotation is pending
7779
ConditionTypePendingTLSRotation ConditionType = "PendingTLSRotation"
7880
)
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
//
2+
// DISCLAIMER
3+
//
4+
// Copyright 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+
// Author Adam Janikowski
21+
//
22+
23+
package v1
24+
25+
type DeploymentMemberPropagationMode string
26+
27+
func (d *DeploymentMemberPropagationMode) Get() DeploymentMemberPropagationMode {
28+
if d == nil {
29+
return DeploymentMemberPropagationModeDefault
30+
}
31+
32+
return *d
33+
}
34+
35+
func (d DeploymentMemberPropagationMode) New() *DeploymentMemberPropagationMode {
36+
return &d
37+
}
38+
39+
func (d DeploymentMemberPropagationMode) String() string {
40+
return string(d)
41+
}
42+
43+
func (d *DeploymentMemberPropagationMode) Equal(b *DeploymentMemberPropagationMode) bool {
44+
if d == nil && b == nil {
45+
return true
46+
}
47+
48+
if d == nil || b == nil {
49+
return false
50+
}
51+
52+
return *d == *b
53+
}
54+
55+
const (
56+
// DeploymentMemberPropagationModeDefault Define default propagation mode
57+
DeploymentMemberPropagationModeDefault = DeploymentMemberPropagationModeAlways
58+
// DeploymentMemberPropagationModeAlways define mode which restart member whenever change in pod is discovered
59+
DeploymentMemberPropagationModeAlways DeploymentMemberPropagationMode = "always"
60+
// DeploymentMemberPropagationModeOnRestart propagate member spec whenever pod is restarted. Do not restart member by default
61+
DeploymentMemberPropagationModeOnRestart DeploymentMemberPropagationMode = "on-restart"
62+
)

pkg/apis/deployment/v1/deployment_spec.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ type DeploymentSpec struct {
149149
SyncMasters ServerGroupSpec `json:"syncmasters"`
150150
SyncWorkers ServerGroupSpec `json:"syncworkers"`
151151

152+
MemberPropagationMode *DeploymentMemberPropagationMode `json:"memberPropagationMode,omitempty"`
153+
152154
Chaos ChaosSpec `json:"chaos"`
153155

154156
Recovery *ArangoDeploymentRecoverySpec `json:"recovery,omitempty"`

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

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

pkg/apis/deployment/v2alpha1/conditions.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ const (
7373
ConditionTypeMaintenanceMode ConditionType = "MaintenanceMode"
7474
// ConditionTypePendingRestart indicates that restart is required
7575
ConditionTypePendingRestart ConditionType = "PendingRestart"
76+
// ConditionTypeRestart indicates that restart will be started
77+
ConditionTypeRestart ConditionType = "Restart"
7678
// ConditionTypePendingTLSRotation indicates that TLS rotation is pending
7779
ConditionTypePendingTLSRotation ConditionType = "PendingTLSRotation"
7880
)
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
//
2+
// DISCLAIMER
3+
//
4+
// Copyright 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+
// Author Adam Janikowski
21+
//
22+
23+
package v2alpha1
24+
25+
type DeploymentMemberPropagationMode string
26+
27+
func (d *DeploymentMemberPropagationMode) Get() DeploymentMemberPropagationMode {
28+
if d == nil {
29+
return DeploymentMemberPropagationModeDefault
30+
}
31+
32+
return *d
33+
}
34+
35+
func (d DeploymentMemberPropagationMode) New() *DeploymentMemberPropagationMode {
36+
return &d
37+
}
38+
39+
func (d DeploymentMemberPropagationMode) String() string {
40+
return string(d)
41+
}
42+
43+
func (d *DeploymentMemberPropagationMode) Equal(b *DeploymentMemberPropagationMode) bool {
44+
if d == nil && b == nil {
45+
return true
46+
}
47+
48+
if d == nil || b == nil {
49+
return false
50+
}
51+
52+
return *d == *b
53+
}
54+
55+
const (
56+
// DeploymentMemberPropagationModeDefault Define default propagation mode
57+
DeploymentMemberPropagationModeDefault = DeploymentMemberPropagationModeAlways
58+
// DeploymentMemberPropagationModeAlways define mode which restart member whenever change in pod is discovered
59+
DeploymentMemberPropagationModeAlways DeploymentMemberPropagationMode = "always"
60+
// DeploymentMemberPropagationModeOnRestart propagate member spec whenever pod is restarted. Do not restart member by default
61+
DeploymentMemberPropagationModeOnRestart DeploymentMemberPropagationMode = "on-restart"
62+
)

pkg/apis/deployment/v2alpha1/deployment_spec.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ type DeploymentSpec struct {
149149
SyncMasters ServerGroupSpec `json:"syncmasters"`
150150
SyncWorkers ServerGroupSpec `json:"syncworkers"`
151151

152+
MemberPropagationMode *DeploymentMemberPropagationMode `json:"memberPropagationMode,omitempty"`
153+
152154
Chaos ChaosSpec `json:"chaos"`
153155

154156
Recovery *ArangoDeploymentRecoverySpec `json:"recovery,omitempty"`

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

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

pkg/deployment/deployment_inspector.go

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -303,15 +303,17 @@ func (d *Deployment) inspectDeploymentWithError(ctx context.Context, lastInterva
303303

304304
return minInspectionInterval, nil
305305
} else if status.AppliedVersion == checksum {
306-
if !d.apiObject.Status.IsPlanEmpty() && status.Conditions.IsTrue(api.ConditionTypeUpToDate) {
307-
if err = d.updateCondition(ctx, api.ConditionTypeUpToDate, false, "Plan is not empty", "There are pending operations in plan"); err != nil {
306+
isUpToDate, reason := d.isUpToDateStatus()
307+
308+
if !isUpToDate && status.Conditions.IsTrue(api.ConditionTypeUpToDate) {
309+
if err = d.updateCondition(ctx, api.ConditionTypeUpToDate, false, reason, "There are pending operations in plan or members are in restart process"); err != nil {
308310
return minInspectionInterval, errors.Wrapf(err, "Unable to update UpToDate condition")
309311
}
310312

311313
return minInspectionInterval, nil
312314
}
313315

314-
if d.apiObject.Status.IsPlanEmpty() && !status.Conditions.IsTrue(api.ConditionTypeUpToDate) {
316+
if isUpToDate && !status.Conditions.IsTrue(api.ConditionTypeUpToDate) {
315317
if err = d.updateCondition(ctx, api.ConditionTypeUpToDate, true, "Spec is Up To Date", "Spec is Up To Date"); err != nil {
316318
return minInspectionInterval, errors.Wrapf(err, "Unable to update UpToDate condition")
317319
}
@@ -349,6 +351,26 @@ func (d *Deployment) inspectDeploymentWithError(ctx context.Context, lastInterva
349351
return
350352
}
351353

354+
func (d *Deployment) isUpToDateStatus() (upToDate bool, reason string) {
355+
if !d.apiObject.Status.IsPlanEmpty() {
356+
return false, "Plan is not empty"
357+
}
358+
359+
upToDate = true
360+
361+
d.apiObject.Status.Members.ForeachServerGroup(func(group api.ServerGroup, list api.MemberStatusList) error {
362+
for _, member := range list {
363+
if member.Conditions.IsTrue(api.ConditionTypeRestart) || member.Conditions.IsTrue(api.ConditionTypePendingRestart) {
364+
upToDate = false
365+
reason = "Pending restarts on members"
366+
}
367+
}
368+
return nil
369+
})
370+
371+
return
372+
}
373+
352374
func (d *Deployment) refreshMaintenanceTTL(ctx context.Context) {
353375
if d.apiObject.Spec.Mode.Get() == api.DeploymentModeSingle {
354376
return

0 commit comments

Comments
 (0)