Skip to content

Commit effed19

Browse files
jwierzboajanikow
authored andcommitted
GT-134 Add annotation to change architecture (#1107)
1 parent 2a11165 commit effed19

25 files changed

+325
-26
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## [master](https://github.com/arangodb/kube-arangodb/tree/master) (N/A)
44
- (Feature) Add action progress
55
- (Feature) Ensure consistency during replication cancellation
6+
- (Feature) Add annotation to change architecture of a member
67

78
## [1.2.19](https://github.com/arangodb/kube-arangodb/tree/1.2.19) (2022-10-05)
89
- (Bugfix) Prevent changes when UID is wrong

docs/design/arch_change.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Member Architecture change
2+
3+
To change manually architecture of specific member, you can use annotation:
4+
```bash
5+
kubectl annotate pod arango-pod deployment.arangodb.com/arch=arm64
6+
```
7+
8+
It will add to the member status `ArchitectureMismatch` condition, e.g.:
9+
```yaml
10+
- lastTransitionTime: "2022-09-15T07:38:05Z"
11+
lastUpdateTime: "2022-09-15T07:38:05Z"
12+
reason: Member has a different architecture than the deployment
13+
status: "True"
14+
type: ArchitectureMismatch
15+
```
16+
17+
To provide requested arch changes for the member we need rotate it, so additional step is required:
18+
```bash
19+
`kubectl annotate pod arango-pod deployment.arangodb.com/rotate=true`
20+
```

docs/generated/actions.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
| SetCondition | 10m0s | Community & Enterprise | (Deprecated) Set deployment condition |
6161
| SetConditionV2 | 10m0s | Community & Enterprise | Set deployment condition |
6262
| SetCurrentImage | 6h0m0s | Community & Enterprise | Update deployment current image after image discovery |
63+
| SetCurrentMemberArch | 10m0s | Community & Enterprise | Set current member architecture |
6364
| SetMaintenanceCondition | 10m0s | Community & Enterprise | Update ArangoDB maintenance condition |
6465
| SetMemberCondition | 10m0s | Community & Enterprise | (Deprecated) Set member condition |
6566
| SetMemberConditionV2 | 10m0s | Community & Enterprise | Set member condition |
@@ -141,6 +142,7 @@ spec:
141142
SetCondition: 10m0s
142143
SetConditionV2: 10m0s
143144
SetCurrentImage: 6h0m0s
145+
SetCurrentMemberArch: 10m0s
144146
SetMaintenanceCondition: 10m0s
145147
SetMemberCondition: 10m0s
146148
SetMemberConditionV2: 10m0s

internal/actions.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ actions:
8484
enterprise: true
8585
description: Update certificate in SNI
8686
timeout: 10m
87+
SetCurrentMemberArch:
88+
description: Set current member architecture
89+
timeout: 10m
8790
SetCurrentImage:
8891
description: Update deployment current image after image discovery
8992
timeout: 6h

pkg/apis/deployment/annotations.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ package deployment
2323
const (
2424
ArangoDeploymentAnnotationPrefix = "deployment.arangodb.com"
2525
ArangoDeploymentPodMaintenanceAnnotation = ArangoDeploymentAnnotationPrefix + "/maintenance"
26+
ArangoDeploymentPodChangeArchAnnotation = ArangoDeploymentAnnotationPrefix + "/arch"
2627
ArangoDeploymentPodRotateAnnotation = ArangoDeploymentAnnotationPrefix + "/rotate"
2728
ArangoDeploymentPodReplaceAnnotation = ArangoDeploymentAnnotationPrefix + "/replace"
2829
ArangoDeploymentPodDeleteNow = ArangoDeploymentAnnotationPrefix + "/delete_now"

pkg/apis/deployment/v1/actions.generated.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ const (
137137
ActionSetConditionV2DefaultTimeout time.Duration = ActionsDefaultTimeout
138138
// ActionSetCurrentImageDefaultTimeout define default timeout for action ActionSetCurrentImage
139139
ActionSetCurrentImageDefaultTimeout time.Duration = 21600 * time.Second // 6h0m0s
140+
// ActionSetCurrentMemberArchDefaultTimeout define default timeout for action ActionSetCurrentMemberArch
141+
ActionSetCurrentMemberArchDefaultTimeout time.Duration = 600 * time.Second // 10m0s
140142
// ActionSetMaintenanceConditionDefaultTimeout define default timeout for action ActionSetMaintenanceCondition
141143
ActionSetMaintenanceConditionDefaultTimeout time.Duration = ActionsDefaultTimeout
142144
// ActionSetMemberConditionDefaultTimeout define default timeout for action ActionSetMemberCondition
@@ -286,6 +288,8 @@ const (
286288
ActionTypeSetConditionV2 ActionType = "SetConditionV2"
287289
// ActionTypeSetCurrentImage in scopes Normal. Update deployment current image after image discovery
288290
ActionTypeSetCurrentImage ActionType = "SetCurrentImage"
291+
// ActionTypeSetCurrentMemberArch in scopes Normal. Set current member architecture
292+
ActionTypeSetCurrentMemberArch ActionType = "SetCurrentMemberArch"
289293
// ActionTypeSetMaintenanceCondition in scopes Normal. Update ArangoDB maintenance condition
290294
ActionTypeSetMaintenanceCondition ActionType = "SetMaintenanceCondition"
291295
// ActionTypeSetMemberCondition in scopes High. (Deprecated) Set member condition
@@ -436,6 +440,8 @@ func ActionDefaultTimeout(in ActionType) time.Duration {
436440
return ActionSetConditionV2DefaultTimeout
437441
case ActionTypeSetCurrentImage:
438442
return ActionSetCurrentImageDefaultTimeout
443+
case ActionTypeSetCurrentMemberArch:
444+
return ActionSetCurrentMemberArchDefaultTimeout
439445
case ActionTypeSetMaintenanceCondition:
440446
return ActionSetMaintenanceConditionDefaultTimeout
441447
case ActionTypeSetMemberCondition:
@@ -589,6 +595,8 @@ func GetActionPriority(in ActionType) ActionPriority {
589595
return ActionPriorityHigh
590596
case ActionTypeSetCurrentImage:
591597
return ActionPriorityNormal
598+
case ActionTypeSetCurrentMemberArch:
599+
return ActionPriorityNormal
592600
case ActionTypeSetMaintenanceCondition:
593601
return ActionPriorityNormal
594602
case ActionTypeSetMemberCondition:

pkg/apis/deployment/v1/architecture.go

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,16 @@ func (a ArangoDeploymentArchitecture) Validate() error {
4949
return nil
5050
}
5151

52+
func (a ArangoDeploymentArchitecture) IsArchAllowed(arch ArangoDeploymentArchitectureType) bool {
53+
for id := range a {
54+
if a[id] == arch {
55+
return true
56+
}
57+
}
58+
59+
return false
60+
}
61+
5262
type ArangoDeploymentArchitectureType string
5363

5464
const (
@@ -93,7 +103,22 @@ func (a ArangoDeploymentArchitectureType) AsNodeSelectorRequirement() core.NodeS
93103
}
94104
}
95105

96-
func GetArchsFromNodeSelector(selectors []core.NodeSelectorTerm) map[ArangoDeploymentArchitectureType]bool {
106+
func (a ArangoDeploymentArchitectureType) IsArchMismatch(deploymentArch ArangoDeploymentArchitecture, memberArch *ArangoDeploymentArchitectureType) bool {
107+
if a.Validate() != nil {
108+
return false
109+
}
110+
111+
if deploymentArch.IsArchAllowed(a) {
112+
if memberArch == nil {
113+
return true
114+
} else if a != *memberArch {
115+
return true
116+
}
117+
}
118+
return false
119+
}
120+
121+
func GetAllArchFromNodeSelector(selectors []core.NodeSelectorTerm) map[ArangoDeploymentArchitectureType]bool {
97122
result := make(map[ArangoDeploymentArchitectureType]bool)
98123
for _, selector := range selectors {
99124
if selector.MatchExpressions != nil {

pkg/apis/deployment/v1/conditions.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ const (
7474
ConditionTypeScaleDownCandidate ConditionType = "ScaleDownCandidate"
7575
// ConditionTypeUpgradeFailed indicates that upgrade failed
7676
ConditionTypeUpgradeFailed ConditionType = "UpgradeFailed"
77+
// ConditionTypeArchitectureMismatch indicates that the member has a different architecture than the deployment.
78+
ConditionTypeArchitectureMismatch ConditionType = "ArchitectureMismatch"
7779

7880
// ConditionTypeMemberMaintenanceMode indicates that Maintenance is enabled on particular member
7981
ConditionTypeMemberMaintenanceMode ConditionType = "MemberMaintenanceMode"

pkg/apis/deployment/v1/plan.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ type Action struct {
9797
Locals PlanLocals `json:"locals,omitempty"`
9898
// ID reference of the task involved in this action (if any)
9999
TaskID types.UID `json:"taskID,omitempty"`
100+
// Architecture of the member involved in this action (if any)
101+
Architecture ArangoDeploymentArchitectureType `json:"arch,omitempty"`
100102
// Progress describes what is a status of the current action.
101103
Progress string `json:"progress,omitempty"`
102104
}
@@ -115,6 +117,7 @@ func (a Action) Equal(other Action) bool {
115117
equality.Semantic.DeepEqual(a.Params, other.Params) &&
116118
a.Locals.Equal(other.Locals) &&
117119
a.TaskID == other.TaskID &&
120+
a.Architecture == other.Architecture &&
118121
a.Progress == other.Progress
119122
}
120123

@@ -194,6 +197,12 @@ func (a Action) SetImage(image string) Action {
194197
return a
195198
}
196199

200+
// SetArch sets the Architecture field to the given value and returns the modified
201+
func (a Action) SetArch(arch ArangoDeploymentArchitectureType) Action {
202+
a.Architecture = arch
203+
return a
204+
}
205+
197206
// IsStarted returns true if the action has been started already.
198207
func (a Action) IsStarted() bool {
199208
return !a.StartTime.IsZero()

pkg/apis/deployment/v2alpha1/actions.generated.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ const (
137137
ActionSetConditionV2DefaultTimeout time.Duration = ActionsDefaultTimeout
138138
// ActionSetCurrentImageDefaultTimeout define default timeout for action ActionSetCurrentImage
139139
ActionSetCurrentImageDefaultTimeout time.Duration = 21600 * time.Second // 6h0m0s
140+
// ActionSetCurrentMemberArchDefaultTimeout define default timeout for action ActionSetCurrentMemberArch
141+
ActionSetCurrentMemberArchDefaultTimeout time.Duration = 600 * time.Second // 10m0s
140142
// ActionSetMaintenanceConditionDefaultTimeout define default timeout for action ActionSetMaintenanceCondition
141143
ActionSetMaintenanceConditionDefaultTimeout time.Duration = ActionsDefaultTimeout
142144
// ActionSetMemberConditionDefaultTimeout define default timeout for action ActionSetMemberCondition
@@ -286,6 +288,8 @@ const (
286288
ActionTypeSetConditionV2 ActionType = "SetConditionV2"
287289
// ActionTypeSetCurrentImage in scopes Normal. Update deployment current image after image discovery
288290
ActionTypeSetCurrentImage ActionType = "SetCurrentImage"
291+
// ActionTypeSetCurrentMemberArch in scopes Normal. Set current member architecture
292+
ActionTypeSetCurrentMemberArch ActionType = "SetCurrentMemberArch"
289293
// ActionTypeSetMaintenanceCondition in scopes Normal. Update ArangoDB maintenance condition
290294
ActionTypeSetMaintenanceCondition ActionType = "SetMaintenanceCondition"
291295
// ActionTypeSetMemberCondition in scopes High. (Deprecated) Set member condition
@@ -436,6 +440,8 @@ func ActionDefaultTimeout(in ActionType) time.Duration {
436440
return ActionSetConditionV2DefaultTimeout
437441
case ActionTypeSetCurrentImage:
438442
return ActionSetCurrentImageDefaultTimeout
443+
case ActionTypeSetCurrentMemberArch:
444+
return ActionSetCurrentMemberArchDefaultTimeout
439445
case ActionTypeSetMaintenanceCondition:
440446
return ActionSetMaintenanceConditionDefaultTimeout
441447
case ActionTypeSetMemberCondition:
@@ -589,6 +595,8 @@ func GetActionPriority(in ActionType) ActionPriority {
589595
return ActionPriorityHigh
590596
case ActionTypeSetCurrentImage:
591597
return ActionPriorityNormal
598+
case ActionTypeSetCurrentMemberArch:
599+
return ActionPriorityNormal
592600
case ActionTypeSetMaintenanceCondition:
593601
return ActionPriorityNormal
594602
case ActionTypeSetMemberCondition:

0 commit comments

Comments
 (0)