Skip to content

Commit 4615188

Browse files
authored
[Feature] Agent recreation and agency info (#790)
1 parent 13f3e2a commit 4615188

15 files changed

+426
-42
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
- Update UBI Image to 8.4
55
- Fix ArangoSync Liveness Prove
66
- Allow runtime update of Sidecar images
7+
- Allow Agent recreation with preserved IDs
78

89
## [1.2.2](https://github.com/arangodb/kube-arangodb/tree/1.2.2) (2021-09-09)
910
- Update 'github.com/arangodb/arangosync-client' dependency to v0.7.0

pkg/apis/deployment/v1/deployment_status.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ type DeploymentStatus struct {
7878

7979
// ForceStatusReload if set to true forces a reload of the status from the custom resource.
8080
ForceStatusReload *bool `json:"force-status-reload,omitempty"`
81+
82+
// Agency keeps information about agency
83+
Agency *DeploymentStatusAgencyInfo `json:"agency,omitempty"`
8184
}
8285

8386
// Equal checks for equality
@@ -95,7 +98,8 @@ func (ds *DeploymentStatus) Equal(other DeploymentStatus) bool {
9598
ds.Conditions.Equal(other.Conditions) &&
9699
ds.Plan.Equal(other.Plan) &&
97100
ds.AcceptedSpec.Equal(other.AcceptedSpec) &&
98-
ds.SecretHashes.Equal(other.SecretHashes)
101+
ds.SecretHashes.Equal(other.SecretHashes) &&
102+
ds.Agency.Equal(other.Agency)
99103
}
100104

101105
// IsForceReload returns true if ForceStatusReload is set to true
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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+
21+
package v1
22+
23+
import (
24+
"sort"
25+
"strings"
26+
)
27+
28+
type DeploymentStatusAgencySize int
29+
30+
func (d *DeploymentStatusAgencySize) Equal(b *DeploymentStatusAgencySize) bool {
31+
if d == nil && b == nil {
32+
return true
33+
}
34+
35+
if d == nil || b == nil {
36+
return true
37+
}
38+
39+
return *d == *b
40+
}
41+
42+
type DeploymentStatusAgencyIDs []string
43+
44+
func (d DeploymentStatusAgencyIDs) Sort() {
45+
sort.Slice(d, func(i, j int) bool {
46+
return strings.Compare(d[i], d[j]) > 0
47+
})
48+
}
49+
50+
func (d DeploymentStatusAgencyIDs) Equal(b DeploymentStatusAgencyIDs) bool {
51+
if len(d) != len(b) {
52+
return false
53+
}
54+
55+
for id := range d {
56+
if d[id] != b[id] {
57+
return false
58+
}
59+
}
60+
61+
return true
62+
}
63+
64+
type DeploymentStatusAgencyInfo struct {
65+
Size *DeploymentStatusAgencySize `json:"size,omitempty"`
66+
IDs DeploymentStatusAgencyIDs `json:"ids,omitempty"`
67+
}
68+
69+
func (d *DeploymentStatusAgencyInfo) Equal(b *DeploymentStatusAgencyInfo) bool {
70+
if d == nil && b == nil {
71+
return true
72+
}
73+
74+
if d == nil || b == nil {
75+
return true
76+
}
77+
78+
return d.IDs.Equal(b.IDs) && d.Size.Equal(b.Size)
79+
}

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

Lines changed: 51 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/deployment_status.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ type DeploymentStatus struct {
7878

7979
// ForceStatusReload if set to true forces a reload of the status from the custom resource.
8080
ForceStatusReload *bool `json:"force-status-reload,omitempty"`
81+
82+
// Agency keeps information about agency
83+
Agency *DeploymentStatusAgencyInfo `json:"agency,omitempty"`
8184
}
8285

8386
// Equal checks for equality
@@ -95,7 +98,8 @@ func (ds *DeploymentStatus) Equal(other DeploymentStatus) bool {
9598
ds.Conditions.Equal(other.Conditions) &&
9699
ds.Plan.Equal(other.Plan) &&
97100
ds.AcceptedSpec.Equal(other.AcceptedSpec) &&
98-
ds.SecretHashes.Equal(other.SecretHashes)
101+
ds.SecretHashes.Equal(other.SecretHashes) &&
102+
ds.Agency.Equal(other.Agency)
99103
}
100104

101105
// IsForceReload returns true if ForceStatusReload is set to true
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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+
21+
package v2alpha1
22+
23+
import (
24+
"sort"
25+
"strings"
26+
)
27+
28+
type DeploymentStatusAgencySize int
29+
30+
func (d *DeploymentStatusAgencySize) Equal(b *DeploymentStatusAgencySize) bool {
31+
if d == nil && b == nil {
32+
return true
33+
}
34+
35+
if d == nil || b == nil {
36+
return true
37+
}
38+
39+
return *d == *b
40+
}
41+
42+
type DeploymentStatusAgencyIDs []string
43+
44+
func (d DeploymentStatusAgencyIDs) Sort() {
45+
sort.Slice(d, func(i, j int) bool {
46+
return strings.Compare(d[i], d[j]) > 0
47+
})
48+
}
49+
50+
func (d DeploymentStatusAgencyIDs) Equal(b DeploymentStatusAgencyIDs) bool {
51+
if len(d) != len(b) {
52+
return false
53+
}
54+
55+
for id := range d {
56+
if d[id] != b[id] {
57+
return false
58+
}
59+
}
60+
61+
return true
62+
}
63+
64+
type DeploymentStatusAgencyInfo struct {
65+
Size *DeploymentStatusAgencySize `json:"size,omitempty"`
66+
IDs DeploymentStatusAgencyIDs `json:"ids,omitempty"`
67+
}
68+
69+
func (d *DeploymentStatusAgencyInfo) Equal(b *DeploymentStatusAgencyInfo) bool {
70+
if d == nil && b == nil {
71+
return true
72+
}
73+
74+
if d == nil || b == nil {
75+
return true
76+
}
77+
78+
return d.IDs.Equal(b.IDs) && d.Size.Equal(b.Size)
79+
}

pkg/apis/deployment/v2alpha1/plan.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func (a ActionType) String() string {
4949
// Priority returns plan priority
5050
func (a ActionType) Priority() ActionPriority {
5151
switch a {
52-
case ActionTypeMemberPhaseUpdate, ActionTypeMemberRIDUpdate, ActionTypeSetMemberCondition:
52+
case ActionTypeMemberPhaseUpdate, ActionTypeMemberRIDUpdate, ActionTypeSetMemberCondition, ActionTypeBootstrapSetAgencyInfo:
5353
return ActionPriorityHigh
5454
default:
5555
return ActionPriorityNormal
@@ -165,6 +165,8 @@ const (
165165
ActionTypeArangoMemberUpdatePodSpec ActionType = "ArangoMemberUpdatePodSpec"
166166
// ActionTypeArangoMemberUpdatePodStatus updates pod spec
167167
ActionTypeArangoMemberUpdatePodStatus ActionType = "ArangoMemberUpdatePodStatus"
168+
// ActionTypeBootstrapSetAgencyInfo set agency info into state
169+
ActionTypeBootstrapSetAgencyInfo ActionType = "BootstrapSetAgencyInfo"
168170

169171
// Runtime Updates
170172
// ActionTypeRuntimeContainerImageUpdate updates container image in runtime

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

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

pkg/deployment/deployment.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,11 @@ func (d *Deployment) send(ev *deploymentEvent) {
262262
func (d *Deployment) run() {
263263
log := d.deps.Log
264264

265+
// Create agency mapping
266+
if err := d.createAgencyMapping(context.TODO()); err != nil {
267+
d.CreateEvent(k8sutil.NewErrorEvent("Failed to create agency mapping members", err, d.GetAPIObject()))
268+
}
269+
265270
if d.GetPhase() == api.DeploymentPhaseNone {
266271
// Create service monitor
267272
if d.haveServiceMonitorCRD {

0 commit comments

Comments
 (0)