Skip to content

Commit 9f0e5c5

Browse files
authored
[Feature] Alternative Upgrade Order (#1731)
1 parent 459462b commit 9f0e5c5

File tree

6 files changed

+70
-3
lines changed

6 files changed

+70
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
- (Improvement) Improve Metrics Handling
3636
- (Feature) (Scheduler) Create Integration Profile
3737
- (Feature) (Scheduler) Additional types
38+
- (Feature) Alternative Upgrade Order Feature
3839

3940
## [1.2.42](https://github.com/arangodb/kube-arangodb/tree/1.2.42) (2024-07-23)
4041
- (Maintenance) Go 1.22.4 & Kubernetes 1.29.6 libraries

pkg/deployment/features/upgrade.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ package features
2323
func init() {
2424
registerFeature(upgradeVersionCheck)
2525
registerFeature(upgradeVersionCheckV2)
26+
registerFeature(upgradeAlternativeOrder)
2627
}
2728

2829
var upgradeVersionCheck Feature = &feature{
@@ -39,10 +40,20 @@ var upgradeVersionCheckV2 Feature = &feature{
3940
enabledByDefault: false,
4041
}
4142

43+
var upgradeAlternativeOrder Feature = &feature{
44+
name: "upgrade-alternative-order",
45+
description: "Changes order of the upgrade process - Coordinators are upgraded before DBServers",
46+
enterpriseRequired: false,
47+
enabledByDefault: false,
48+
hidden: true,
49+
}
50+
4251
func UpgradeVersionCheck() Feature {
4352
return upgradeVersionCheck
4453
}
4554

4655
func UpgradeVersionCheckV2() Feature {
4756
return upgradeVersionCheckV2
4857
}
58+
59+
func UpgradeAlternativeOrder() Feature { return upgradeAlternativeOrder }

pkg/deployment/reconcile/plan_builder_rotate_upgrade.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,17 @@ var (
5151
api.ServerGroupSyncWorkers,
5252
api.ServerGroupGateways,
5353
}
54+
55+
// alternativeUpgradeOrder contains execution order which enforce upgrade of Coordinators before DBServers
56+
alternativeUpgradeOrder = []api.ServerGroup{
57+
api.ServerGroupAgents,
58+
api.ServerGroupSingle,
59+
api.ServerGroupCoordinators,
60+
api.ServerGroupDBServers,
61+
api.ServerGroupSyncMasters,
62+
api.ServerGroupSyncWorkers,
63+
api.ServerGroupGateways,
64+
}
5465
)
5566

5667
// upgradeDecision is the result of an upgrade check.

pkg/deployment/reconcile/plan_builder_rotate_upgrade_decision.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// DISCLAIMER
33
//
4-
// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany
4+
// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany
55
//
66
// Licensed under the Apache License, Version 2.0 (the "License");
77
// you may not use this file except in compliance with the License.
@@ -22,6 +22,7 @@ package reconcile
2222

2323
import (
2424
api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
25+
"github.com/arangodb/kube-arangodb/pkg/deployment/features"
2526
"github.com/arangodb/kube-arangodb/pkg/deployment/rotation"
2627
"github.com/arangodb/kube-arangodb/pkg/util"
2728
)
@@ -62,7 +63,10 @@ func (r *Reconciler) createRotateOrUpgradeDecision(spec api.DeploymentSpec, stat
6263
d := updateUpgradeDecisionMap{}
6364

6465
// Init phase
65-
for _, m := range status.Members.AsList() {
66+
67+
upgradeOrder := util.BoolSwitch(features.UpgradeAlternativeOrder().Enabled(), alternativeUpgradeOrder, api.AllServerGroups)
68+
69+
for _, m := range status.Members.AsListInGroups(upgradeOrder...) {
6670
d[m.Member.ID] = r.createRotateOrUpgradeDecisionMember(spec, status, context, m)
6771
}
6872

pkg/deployment/reconcile/plan_builder_rotate_upgrade_test.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// DISCLAIMER
33
//
4-
// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany
4+
// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany
55
//
66
// Licensed under the Apache License, Version 2.0 (the "License");
77
// you may not use this file except in compliance with the License.
@@ -31,6 +31,24 @@ import (
3131
"github.com/arangodb/kube-arangodb/pkg/util"
3232
)
3333

34+
func Test_EnsureGroupsContainsAll(t *testing.T) {
35+
ensure := func(t *testing.T, groups ...api.ServerGroup) {
36+
require.Equal(t, groups, util.UniqueList(groups))
37+
38+
for _, expected := range api.AllServerGroups {
39+
t.Run(expected.AsRole(), func(t *testing.T) {
40+
require.Contains(t, groups, expected)
41+
})
42+
}
43+
}
44+
t.Run("rotationByAnnotationOrder", func(t *testing.T) {
45+
ensure(t, rotationByAnnotationOrder...)
46+
})
47+
t.Run("alternativeUpgradeOrder", func(t *testing.T) {
48+
ensure(t, alternativeUpgradeOrder...)
49+
})
50+
}
51+
3452
func Test_RotateUpgrade_Condition(t *testing.T) {
3553
type testCase struct {
3654
status api.MemberStatus

pkg/util/list.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,28 @@ func FormatList[A, B any](in []A, format func(A) B) []B {
112112
return r
113113
}
114114

115+
func ContainsList[A comparable](in []A, item A) bool {
116+
for _, el := range in {
117+
if el == item {
118+
return true
119+
}
120+
}
121+
122+
return false
123+
}
124+
125+
func UniqueList[A comparable](in []A) []A {
126+
var r = make([]A, 0, len(in))
127+
128+
for _, el := range in {
129+
if !ContainsList(r, el) {
130+
r = append(r, el)
131+
}
132+
}
133+
134+
return r
135+
}
136+
115137
func FormatListErr[A, B any](in []A, format func(A) (B, error)) ([]B, error) {
116138
var r = make([]B, len(in))
117139

0 commit comments

Comments
 (0)