Skip to content

Commit 7c119c7

Browse files
committed
[Feature] Agency DBServer Discovery
1 parent f78877b commit 7c119c7

8 files changed

+50
-18
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
- (Feature) (Platform) CLI
1010
- (Bugfix) Fix Condition name
1111
- (Bugfix) Add missing ArangoDeployment ExternalAccess Managed Type definition
12+
- (Feature) Agency DBServer Discovery
1213

1314
## [1.2.44](https://github.com/arangodb/kube-arangodb/tree/1.2.44) (2025-02-03)
1415
- (Maintenance) Kubernetes 1.31.1 libraries

pkg/deployment/agency/state/state.go

+13-6
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020

2121
package state
2222

23-
import "github.com/arangodb/go-driver"
24-
2523
type Root struct {
2624
Arango State `json:"arango"`
2725
ArangoDB DB `json:"arangodb,omitempty"`
@@ -53,12 +51,14 @@ type Current struct {
5351
Collections CurrentCollections `json:"Collections"`
5452

5553
// ServersKnown stores information about ArangoDB servers.
56-
ServersKnown map[driver.ServerID]ServerKnown `json:"ServersKnown,omitempty"`
54+
ServersKnown ServerMap[ServerKnown] `json:"ServersKnown,omitempty"`
5755
}
5856

5957
type Plan struct {
60-
Collections PlanCollections `json:"Collections"`
61-
Databases PlanDatabases `json:"Databases,omitempty"`
58+
Collections PlanCollections `json:"Collections"`
59+
Databases PlanDatabases `json:"Databases,omitempty"`
60+
DBServers ServerMap[string] `json:"DBServers,omitempty"`
61+
Coordinators ServerMap[string] `json:"Coordinators,omitempty"`
6262
}
6363

6464
type Supervision struct {
@@ -69,6 +69,13 @@ type ShardCountDetails struct {
6969
Leader, Follower int
7070
}
7171

72+
type ServerMap[T any] map[Server]T
73+
74+
func (s ServerMap[T]) Exists(server Server) bool {
75+
_, ok := s[server]
76+
return ok
77+
}
78+
7279
func (s ShardCountDetails) Count() int {
7380
return s.Leader + s.Follower
7481
}
@@ -445,7 +452,7 @@ func (s State) GetCollectionDatabaseByID(id string) (string, bool) {
445452

446453
// GetRebootID returns reboot ID for a given server ID.
447454
// returns false when a server ID does not exist in cache.
448-
func (s State) GetRebootID(id driver.ServerID) (int, bool) {
455+
func (s State) GetRebootID(id Server) (int, bool) {
449456
if v, ok := s.Current.ServersKnown[id]; ok {
450457
return v.RebootID, true
451458
}

pkg/deployment/agency/state/state_test.go

+6
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ var (
7070
"3.9": agencyDump39,
7171
"3.9-satellite": agencyDump39Satellite,
7272
"3.9-hotbackup": agencyDump39HotBackup,
73+
"3.10": agencyDump310,
7374
}
7475
)
7576

@@ -87,6 +88,11 @@ func Test_Unmarshal_MultiVersion(t *testing.T) {
8788
}
8889
})
8990

91+
t.Run("Ensure member discovery", func(t *testing.T) {
92+
require.NotEmpty(t, s.Agency.Arango.Plan.DBServers)
93+
require.NotEmpty(t, s.Agency.Arango.Plan.Coordinators)
94+
})
95+
9096
t.Run("Ensure distributeShardsLike", func(t *testing.T) {
9197
collections, ok := s.Agency.Arango.Plan.Collections["_system"]
9298
require.True(t, ok)

pkg/deployment/reconcile/action_enforce_resign_leadership.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// DISCLAIMER
33
//
4-
// Copyright 2023 ArangoDB GmbH, Cologne, Germany
4+
// Copyright 2023-2025 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.
@@ -98,7 +98,7 @@ func (a *actionEnforceResignLeadership) CheckProgress(ctx context.Context) (bool
9898
a.log.Warn("Maintenance is enabled, skipping action")
9999
// We are done, action cannot be handled on maintenance mode
100100
return true, false, nil
101-
} else if isServerRebooted(a.log, a.action, agencyState, driver.ServerID(m.ID)) {
101+
} else if hasServerRebooted(a.log, a.action, agencyState, state.Server(m.ID)) {
102102
return true, false, nil
103103
}
104104

pkg/deployment/reconcile/action_resign_leadership.go

+2-2
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-2025 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.
@@ -131,7 +131,7 @@ func (a *actionResignLeadership) CheckProgress(ctx context.Context) (bool, bool,
131131
return false, false, errors.WithStack(err)
132132
}
133133
return true, false, nil
134-
} else if isServerRebooted(a.log, a.action, agencyState, driver.ServerID(m.ID)) {
134+
} else if hasServerRebooted(a.log, a.action, agencyState, state.Server(m.ID)) {
135135
return true, false, nil
136136
}
137137

pkg/deployment/reconcile/action_resign_leadership_utils.go

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// DISCLAIMER
33
//
4-
// Copyright 2023 ArangoDB GmbH, Cologne, Germany
4+
// Copyright 2023-2025 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.
@@ -23,8 +23,6 @@ package reconcile
2323
import (
2424
"strconv"
2525

26-
"github.com/arangodb/go-driver"
27-
2826
api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
2927
"github.com/arangodb/kube-arangodb/pkg/deployment/agency/state"
3028
"github.com/arangodb/kube-arangodb/pkg/deployment/features"
@@ -38,8 +36,8 @@ func getResignLeadershipActionType() api.ActionType {
3836
return api.ActionTypeResignLeadership
3937
}
4038

41-
// isServerRebooted returns true when a given server ID was rebooted during resignation of leadership.
42-
func isServerRebooted(log logging.Logger, action api.Action, agencyState state.State, serverID driver.ServerID) bool {
39+
// hasServerRebooted returns true when a given server ID was rebooted during resignation of leadership.
40+
func hasServerRebooted(log logging.Logger, action api.Action, agencyState state.State, serverID state.Server) bool {
4341
rebootID, ok := agencyState.GetRebootID(serverID)
4442
if !ok {
4543
return false

pkg/deployment/reconcile/action_wait_for_member_ready.go

+21-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// DISCLAIMER
33
//
4-
// Copyright 2022 ArangoDB GmbH, Cologne, Germany
4+
// Copyright 2022-2025 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.
@@ -24,6 +24,7 @@ import (
2424
"context"
2525

2626
api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
27+
"github.com/arangodb/kube-arangodb/pkg/deployment/agency/state"
2728
"github.com/arangodb/kube-arangodb/pkg/util/errors"
2829
)
2930

@@ -67,5 +68,24 @@ func (a *actionWaitForMemberReady) CheckProgress(ctx context.Context) (bool, boo
6768
return true, false, nil
6869
}
6970

71+
cache, ok := a.actionCtx.GetAgencyCache()
72+
if !ok {
73+
a.log.Debug("AgencyCache is not ready")
74+
return false, false, nil
75+
}
76+
77+
switch a.action.Group {
78+
case api.ServerGroupDBServers:
79+
if !cache.Plan.DBServers.Exists(state.Server(member.ID)) {
80+
a.log.Debug("DBServer not yet present")
81+
return false, false, nil
82+
}
83+
case api.ServerGroupCoordinators:
84+
if !cache.Plan.Coordinators.Exists(state.Server(member.ID)) {
85+
a.log.Debug("Coordinator not yet present")
86+
return false, false, nil
87+
}
88+
}
89+
7090
return member.Conditions.IsTrue(api.ConditionTypeReady), false, nil
7191
}

pkg/deployment/reconcile/plan_builder_rotate_upgrade.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ func (r *Reconciler) createUpdatePlanInternal(apiObject k8sutil.APIObject, spec
196196
}
197197

198198
if m.Member.Conditions.IsTrue(api.ConditionTypeRestart) {
199-
return r.createRotateMemberPlan(m.Member, m.Group, spec, "Restart flag present", util.CheckConditionalP1Nil(agencyCache.GetRebootID, driver.ServerID(m.Member.ID))), false
199+
return r.createRotateMemberPlan(m.Member, m.Group, spec, "Restart flag present", util.CheckConditionalP1Nil(agencyCache.GetRebootID, state.Server(m.Member.ID))), false
200200
}
201201

202202
arangoMember, ok := context.ACS().CurrentClusterCache().ArangoMember().V1().GetSimple(m.Member.ArangoMemberName(apiObject.GetName(), m.Group))
@@ -560,7 +560,7 @@ func (r *Reconciler) createUpgradeMemberPlan(member api.MemberStatus,
560560
Str("action", string(upgradeAction)).
561561
Info("Creating upgrade plan")
562562

563-
plan := createRotateMemberPlanWithAction(member, group, upgradeAction, spec, reason, util.CheckConditionalP1Nil(agencyCache.GetRebootID, driver.ServerID(member.ID)))
563+
plan := createRotateMemberPlanWithAction(member, group, upgradeAction, spec, reason, util.CheckConditionalP1Nil(agencyCache.GetRebootID, state.Server(member.ID)))
564564

565565
if member.Image == nil || member.Image.Image != spec.GetImage() {
566566
plan = plan.Before(actions.NewAction(api.ActionTypeSetMemberCurrentImage, group, member, reason).SetImage(spec.GetImage()))

0 commit comments

Comments
 (0)