Skip to content

Commit 2cd8998

Browse files
authored
[Feature] Additional Topology rules (#815)
1 parent d1acf1a commit 2cd8998

21 files changed

+298
-39
lines changed

pkg/apis/deployment/v1/conditions.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ const (
4242
ConditionTypeTerminated ConditionType = "Terminated"
4343
// ConditionTypeAutoUpgrade indicates that the member has to be started with `--database.auto-upgrade` once.
4444
ConditionTypeAutoUpgrade ConditionType = "AutoUpgrade"
45+
4546
// ConditionTypeCleanedOut indicates that the member (dbserver) has been cleaned out.
4647
// Always check in combination with ConditionTypeTerminated.
4748
ConditionTypeCleanedOut ConditionType = "CleanedOut"
@@ -51,16 +52,9 @@ const (
5152
ConditionTypeAgentRecoveryNeeded ConditionType = "AgentRecoveryNeeded"
5253
// ConditionTypePodSchedulingFailure indicates that one or more pods belonging to the deployment cannot be schedule.
5354
ConditionTypePodSchedulingFailure ConditionType = "PodSchedulingFailure"
54-
// ConditionTypeSecretsChanged indicates that the value of one of more secrets used by
55-
// the deployment have changed. Once that is the case, the operator will no longer
56-
// touch the deployment, until the original secrets have been restored.
57-
ConditionTypeSecretsChanged ConditionType = "SecretsChanged"
5855
// ConditionTypeMemberOfCluster indicates that the member is a known member of the ArangoDB cluster.
5956
ConditionTypeMemberOfCluster ConditionType = "MemberOfCluster"
60-
// ConditionTypeBootstrapCompleted indicates that the initial cluster bootstrap has been completed.
61-
ConditionTypeBootstrapCompleted ConditionType = "BootstrapCompleted"
62-
// ConditionTypeBootstrapSucceded indicates that the initial cluster bootstrap completed successfully.
63-
ConditionTypeBootstrapSucceded ConditionType = "BootstrapSucceded"
57+
6458
// ConditionTypeTerminating indicates that the member is terminating but not yet terminated.
6559
ConditionTypeTerminating ConditionType = "Terminating"
6660
// ConditionTypeTerminating indicates that the deployment is up to date.
@@ -69,20 +63,25 @@ const (
6963
ConditionTypeMarkedToRemove ConditionType = "MarkedToRemove"
7064
// ConditionTypeUpgradeFailed indicates that upgrade failed
7165
ConditionTypeUpgradeFailed ConditionType = "UpgradeFailed"
66+
7267
// ConditionTypeMaintenanceMode indicates that Maintenance is enabled
7368
ConditionTypeMaintenanceMode ConditionType = "MaintenanceMode"
69+
7470
// ConditionTypePendingRestart indicates that restart is required
7571
ConditionTypePendingRestart ConditionType = "PendingRestart"
7672
// ConditionTypeRestart indicates that restart will be started
7773
ConditionTypeRestart ConditionType = "Restart"
74+
7875
// ConditionTypePendingTLSRotation indicates that TLS rotation is pending
7976
ConditionTypePendingTLSRotation ConditionType = "PendingTLSRotation"
77+
8078
// ConditionTypePendingUpdate indicates that runtime update is pending
8179
ConditionTypePendingUpdate ConditionType = "PendingUpdate"
8280
// ConditionTypeUpdating indicates that runtime update is in progress
8381
ConditionTypeUpdating ConditionType = "Updating"
8482
// ConditionTypeUpdateFailed indicates that runtime update failed
8583
ConditionTypeUpdateFailed ConditionType = "UpdateFailed"
84+
8685
// ConditionTypeTopologyAware indicates that the member is deployed with TopologyAwareness.
8786
ConditionTypeTopologyAware ConditionType = "TopologyAware"
8887
)
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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 v1
22+
23+
const (
24+
// ConditionTypeSecretsChanged indicates that the value of one of more secrets used by
25+
// the deployment have changed. Once that is the case, the operator will no longer
26+
// touch the deployment, until the original secrets have been restored.
27+
ConditionTypeSecretsChanged ConditionType = "SecretsChanged"
28+
29+
// ConditionTypeBootstrapCompleted indicates that the initial cluster bootstrap has been completed.
30+
ConditionTypeBootstrapCompleted ConditionType = "BootstrapCompleted"
31+
// ConditionTypeBootstrapSucceded indicates that the initial cluster bootstrap completed successfully.
32+
ConditionTypeBootstrapSucceded ConditionType = "BootstrapSucceded"
33+
)

pkg/apis/deployment/v1/deployment_member_status_element.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,39 @@
2020

2121
package v1
2222

23+
import "sort"
24+
25+
type DeploymentStatusMemberElementsSortFunc func(a, b DeploymentStatusMemberElement) bool
26+
type DeploymentStatusMemberElementsCondFunc func(a DeploymentStatusMemberElement) bool
27+
2328
type DeploymentStatusMemberElements []DeploymentStatusMemberElement
2429

30+
func (d DeploymentStatusMemberElements) Filter(f DeploymentStatusMemberElementsCondFunc) DeploymentStatusMemberElements {
31+
var l DeploymentStatusMemberElements
32+
33+
for _, a := range d {
34+
if !f(a) {
35+
continue
36+
}
37+
38+
z := a.DeepCopy()
39+
40+
l = append(l, *z)
41+
}
42+
43+
return l
44+
}
45+
46+
func (d DeploymentStatusMemberElements) Sort(less DeploymentStatusMemberElementsSortFunc) DeploymentStatusMemberElements {
47+
n := d.DeepCopy()
48+
49+
sort.Slice(n, func(i, j int) bool {
50+
return less(n[i], n[j])
51+
})
52+
53+
return n
54+
}
55+
2556
// DeploymentStatusMemberElement holds one specific element with group and member status
2657
type DeploymentStatusMemberElement struct {
2758
Group ServerGroup `json:"group,omitempty"`

pkg/apis/deployment/v1/list.go

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,24 @@ func (l List) Contains(v string) bool {
3434
return false
3535
}
3636

37-
func (l List) Sort() {
38-
sort.Strings(l)
37+
func (l List) Sort() List {
38+
z := l.DeepCopy()
39+
sort.Strings(z)
40+
return z
41+
}
42+
43+
func (l List) Unique() List {
44+
var m List
45+
46+
for _, k := range l {
47+
if m.Contains(k) {
48+
continue
49+
}
50+
51+
m = m.Add(k)
52+
}
53+
54+
return m
3955
}
4056

4157
func (l List) Remove(values ...string) List {
@@ -53,3 +69,11 @@ func (l List) Remove(values ...string) List {
5369

5470
return m
5571
}
72+
func (l List) Add(values ...string) List {
73+
var m List
74+
75+
m = append(m, l...)
76+
m = append(m, values...)
77+
78+
return m
79+
}

pkg/apis/deployment/v1/plan.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ const (
175175
// Topology
176176
ActionTypeTopologyEnable ActionType = "TopologyEnable"
177177
ActionTypeTopologyDisable ActionType = "TopologyDisable"
178+
ActionTypeTopologyZonesUpdate ActionType = "TopologyZonesUpdate"
178179
ActionTypeTopologyMemberAssignment ActionType = "TopologyMemberAssignment"
179180
)
180181

pkg/apis/deployment/v1/topology_member_status.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ package v1
2323
import "k8s.io/apimachinery/pkg/types"
2424

2525
type TopologyMemberStatus struct {
26-
ID types.UID `json:"id"`
27-
Zone int `json:"rack"`
26+
ID types.UID `json:"id"`
27+
Zone int `json:"rack"`
28+
Label string `json:"label,omitempty"`
2829
}

pkg/apis/deployment/v1/topology_status.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,7 @@ func (t *TopologyStatus) RegisterTopologyLabel(zone int, label string) bool {
7272
return false
7373
}
7474

75-
t.Zones[zone].Labels = append(t.Zones[zone].Labels, label)
76-
t.Zones[zone].Labels.Sort()
75+
t.Zones[zone].Labels = t.Zones[zone].Labels.Add(label).Sort()
7776

7877
return true
7978
}
@@ -125,9 +124,7 @@ func (t *TopologyStatusZone) AddMember(group ServerGroup, id string) {
125124
t.Members = TopologyStatusZoneMembers{}
126125
}
127126

128-
t.Members[group.AsRoleAbbreviated()] = append(t.Members[group.AsRoleAbbreviated()], id)
129-
130-
t.Members[group.AsRoleAbbreviated()].Sort()
127+
t.Members[group.AsRoleAbbreviated()] = t.Members[group.AsRoleAbbreviated()].Add(id).Sort()
131128
}
132129

133130
func (t *TopologyStatusZone) RemoveMember(group ServerGroup, id string) bool {

pkg/apis/deployment/v2alpha1/conditions.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ const (
4242
ConditionTypeTerminated ConditionType = "Terminated"
4343
// ConditionTypeAutoUpgrade indicates that the member has to be started with `--database.auto-upgrade` once.
4444
ConditionTypeAutoUpgrade ConditionType = "AutoUpgrade"
45+
4546
// ConditionTypeCleanedOut indicates that the member (dbserver) has been cleaned out.
4647
// Always check in combination with ConditionTypeTerminated.
4748
ConditionTypeCleanedOut ConditionType = "CleanedOut"
@@ -51,16 +52,9 @@ const (
5152
ConditionTypeAgentRecoveryNeeded ConditionType = "AgentRecoveryNeeded"
5253
// ConditionTypePodSchedulingFailure indicates that one or more pods belonging to the deployment cannot be schedule.
5354
ConditionTypePodSchedulingFailure ConditionType = "PodSchedulingFailure"
54-
// ConditionTypeSecretsChanged indicates that the value of one of more secrets used by
55-
// the deployment have changed. Once that is the case, the operator will no longer
56-
// touch the deployment, until the original secrets have been restored.
57-
ConditionTypeSecretsChanged ConditionType = "SecretsChanged"
5855
// ConditionTypeMemberOfCluster indicates that the member is a known member of the ArangoDB cluster.
5956
ConditionTypeMemberOfCluster ConditionType = "MemberOfCluster"
60-
// ConditionTypeBootstrapCompleted indicates that the initial cluster bootstrap has been completed.
61-
ConditionTypeBootstrapCompleted ConditionType = "BootstrapCompleted"
62-
// ConditionTypeBootstrapSucceded indicates that the initial cluster bootstrap completed successfully.
63-
ConditionTypeBootstrapSucceded ConditionType = "BootstrapSucceded"
57+
6458
// ConditionTypeTerminating indicates that the member is terminating but not yet terminated.
6559
ConditionTypeTerminating ConditionType = "Terminating"
6660
// ConditionTypeTerminating indicates that the deployment is up to date.
@@ -69,20 +63,25 @@ const (
6963
ConditionTypeMarkedToRemove ConditionType = "MarkedToRemove"
7064
// ConditionTypeUpgradeFailed indicates that upgrade failed
7165
ConditionTypeUpgradeFailed ConditionType = "UpgradeFailed"
66+
7267
// ConditionTypeMaintenanceMode indicates that Maintenance is enabled
7368
ConditionTypeMaintenanceMode ConditionType = "MaintenanceMode"
69+
7470
// ConditionTypePendingRestart indicates that restart is required
7571
ConditionTypePendingRestart ConditionType = "PendingRestart"
7672
// ConditionTypeRestart indicates that restart will be started
7773
ConditionTypeRestart ConditionType = "Restart"
74+
7875
// ConditionTypePendingTLSRotation indicates that TLS rotation is pending
7976
ConditionTypePendingTLSRotation ConditionType = "PendingTLSRotation"
77+
8078
// ConditionTypePendingUpdate indicates that runtime update is pending
8179
ConditionTypePendingUpdate ConditionType = "PendingUpdate"
8280
// ConditionTypeUpdating indicates that runtime update is in progress
8381
ConditionTypeUpdating ConditionType = "Updating"
8482
// ConditionTypeUpdateFailed indicates that runtime update failed
8583
ConditionTypeUpdateFailed ConditionType = "UpdateFailed"
84+
8685
// ConditionTypeTopologyAware indicates that the member is deployed with TopologyAwareness.
8786
ConditionTypeTopologyAware ConditionType = "TopologyAware"
8887
)
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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 v2alpha1
22+
23+
const (
24+
// ConditionTypeSecretsChanged indicates that the value of one of more secrets used by
25+
// the deployment have changed. Once that is the case, the operator will no longer
26+
// touch the deployment, until the original secrets have been restored.
27+
ConditionTypeSecretsChanged ConditionType = "SecretsChanged"
28+
29+
// ConditionTypeBootstrapCompleted indicates that the initial cluster bootstrap has been completed.
30+
ConditionTypeBootstrapCompleted ConditionType = "BootstrapCompleted"
31+
// ConditionTypeBootstrapSucceded indicates that the initial cluster bootstrap completed successfully.
32+
ConditionTypeBootstrapSucceded ConditionType = "BootstrapSucceded"
33+
)

pkg/apis/deployment/v2alpha1/deployment_member_status_element.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,39 @@
2020

2121
package v2alpha1
2222

23+
import "sort"
24+
25+
type DeploymentStatusMemberElementsSortFunc func(a, b DeploymentStatusMemberElement) bool
26+
type DeploymentStatusMemberElementsCondFunc func(a DeploymentStatusMemberElement) bool
27+
2328
type DeploymentStatusMemberElements []DeploymentStatusMemberElement
2429

30+
func (d DeploymentStatusMemberElements) Filter(f DeploymentStatusMemberElementsCondFunc) DeploymentStatusMemberElements {
31+
var l DeploymentStatusMemberElements
32+
33+
for _, a := range d {
34+
if !f(a) {
35+
continue
36+
}
37+
38+
z := a.DeepCopy()
39+
40+
l = append(l, *z)
41+
}
42+
43+
return l
44+
}
45+
46+
func (d DeploymentStatusMemberElements) Sort(less DeploymentStatusMemberElementsSortFunc) DeploymentStatusMemberElements {
47+
n := d.DeepCopy()
48+
49+
sort.Slice(n, func(i, j int) bool {
50+
return less(n[i], n[j])
51+
})
52+
53+
return n
54+
}
55+
2556
// DeploymentStatusMemberElement holds one specific element with group and member status
2657
type DeploymentStatusMemberElement struct {
2758
Group ServerGroup `json:"group,omitempty"`

0 commit comments

Comments
 (0)