Skip to content

[Feature] Alternative Upgrade Order #1731

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
- (Improvement) Improve Metrics Handling
- (Feature) (Scheduler) Create Integration Profile
- (Feature) (Scheduler) Additional types
- (Feature) Alternative Upgrade Order Feature

## [1.2.42](https://github.com/arangodb/kube-arangodb/tree/1.2.42) (2024-07-23)
- (Maintenance) Go 1.22.4 & Kubernetes 1.29.6 libraries
Expand Down
11 changes: 11 additions & 0 deletions pkg/deployment/features/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ package features
func init() {
registerFeature(upgradeVersionCheck)
registerFeature(upgradeVersionCheckV2)
registerFeature(upgradeAlternativeOrder)
}

var upgradeVersionCheck Feature = &feature{
Expand All @@ -39,10 +40,20 @@ var upgradeVersionCheckV2 Feature = &feature{
enabledByDefault: false,
}

var upgradeAlternativeOrder Feature = &feature{
name: "upgrade-alternative-order",
description: "Changes order of the upgrade process - Coordinators are upgraded before DBServers",
enterpriseRequired: false,
enabledByDefault: false,
hidden: true,
}

func UpgradeVersionCheck() Feature {
return upgradeVersionCheck
}

func UpgradeVersionCheckV2() Feature {
return upgradeVersionCheckV2
}

func UpgradeAlternativeOrder() Feature { return upgradeAlternativeOrder }
11 changes: 11 additions & 0 deletions pkg/deployment/reconcile/plan_builder_rotate_upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,17 @@ var (
api.ServerGroupSyncWorkers,
api.ServerGroupGateways,
}

// alternativeUpgradeOrder contains execution order which enforce upgrade of Coordinators before DBServers
alternativeUpgradeOrder = []api.ServerGroup{
api.ServerGroupAgents,
api.ServerGroupSingle,
api.ServerGroupCoordinators,
api.ServerGroupDBServers,
api.ServerGroupSyncMasters,
api.ServerGroupSyncWorkers,
api.ServerGroupGateways,
}
)

// upgradeDecision is the result of an upgrade check.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// DISCLAIMER
//
// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany
// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -22,6 +22,7 @@ package reconcile

import (
api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
"github.com/arangodb/kube-arangodb/pkg/deployment/features"
"github.com/arangodb/kube-arangodb/pkg/deployment/rotation"
"github.com/arangodb/kube-arangodb/pkg/util"
)
Expand Down Expand Up @@ -62,7 +63,10 @@ func (r *Reconciler) createRotateOrUpgradeDecision(spec api.DeploymentSpec, stat
d := updateUpgradeDecisionMap{}

// Init phase
for _, m := range status.Members.AsList() {

upgradeOrder := util.BoolSwitch(features.UpgradeAlternativeOrder().Enabled(), alternativeUpgradeOrder, api.AllServerGroups)

for _, m := range status.Members.AsListInGroups(upgradeOrder...) {
d[m.Member.ID] = r.createRotateOrUpgradeDecisionMember(spec, status, context, m)
}

Expand Down
20 changes: 19 additions & 1 deletion pkg/deployment/reconcile/plan_builder_rotate_upgrade_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// DISCLAIMER
//
// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany
// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -31,6 +31,24 @@ import (
"github.com/arangodb/kube-arangodb/pkg/util"
)

func Test_EnsureGroupsContainsAll(t *testing.T) {
ensure := func(t *testing.T, groups ...api.ServerGroup) {
require.Equal(t, groups, util.UniqueList(groups))

for _, expected := range api.AllServerGroups {
t.Run(expected.AsRole(), func(t *testing.T) {
require.Contains(t, groups, expected)
})
}
}
t.Run("rotationByAnnotationOrder", func(t *testing.T) {
ensure(t, rotationByAnnotationOrder...)
})
t.Run("alternativeUpgradeOrder", func(t *testing.T) {
ensure(t, alternativeUpgradeOrder...)
})
}

func Test_RotateUpgrade_Condition(t *testing.T) {
type testCase struct {
status api.MemberStatus
Expand Down
22 changes: 22 additions & 0 deletions pkg/util/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,28 @@ func FormatList[A, B any](in []A, format func(A) B) []B {
return r
}

func ContainsList[A comparable](in []A, item A) bool {
for _, el := range in {
if el == item {
return true
}
}

return false
}

func UniqueList[A comparable](in []A) []A {
var r = make([]A, 0, len(in))

for _, el := range in {
if !ContainsList(r, el) {
r = append(r, el)
}
}

return r
}

func FormatListErr[A, B any](in []A, format func(A) (B, error)) ([]B, error) {
var r = make([]B, len(in))

Expand Down