Skip to content

Commit 63d0f01

Browse files
authored
[Bugfix] Allow nil architecture (#943)
1 parent 06ab2a8 commit 63d0f01

File tree

10 files changed

+40
-15
lines changed

10 files changed

+40
-15
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
- (Bugfix) Skip Replace operation on DBServer if they need to be scaled down
1616
- (Feature) Upgrade procedure steps
1717
- (Refactor) Remove API and Core cross-dependency
18+
- (Bugfix) Allow to have nil architecture (NPE fix)
1819

1920
## [1.2.8](https://github.com/arangodb/kube-arangodb/tree/1.2.8) (2022-02-24)
2021
- Do not check License V2 on Community images

pkg/apis/deployment/v1/architecture.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,14 @@ func (a ArangoDeploymentArchitectureType) Validate() error {
7272
}
7373
}
7474

75+
func (a *ArangoDeploymentArchitectureType) Default(def ArangoDeploymentArchitectureType) ArangoDeploymentArchitectureType {
76+
if a == nil {
77+
return def
78+
}
79+
80+
return *a
81+
}
82+
7583
func (a ArangoDeploymentArchitectureType) AsNodeSelectorRequirement() core.NodeSelectorTerm {
7684
return core.NodeSelectorTerm{
7785
MatchExpressions: []core.NodeSelectorRequirement{

pkg/apis/deployment/v2alpha1/architecture.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,14 @@ func (a ArangoDeploymentArchitectureType) Validate() error {
7272
}
7373
}
7474

75+
func (a *ArangoDeploymentArchitectureType) Default(def ArangoDeploymentArchitectureType) ArangoDeploymentArchitectureType {
76+
if a == nil {
77+
return def
78+
}
79+
80+
return *a
81+
}
82+
7583
func (a ArangoDeploymentArchitectureType) AsNodeSelectorRequirement() core.NodeSelectorTerm {
7684
return core.NodeSelectorTerm{
7785
MatchExpressions: []core.NodeSelectorRequirement{

pkg/deployment/images.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ func (i *ImageUpdatePod) GetNodeAffinity() *core.NodeAffinity {
357357
a := core.NodeAffinity{}
358358
arch := i.spec.Architecture.GetDefault()
359359

360-
pod.AppendArchSelector(&a, &arch)
360+
pod.AppendArchSelector(&a, arch)
361361

362362
pod.MergeNodeAffinity(&a, i.spec.ID.Get().NodeAffinity)
363363

pkg/deployment/member/phase_updates.go

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ const (
3232
recentTerminationsKeepPeriod = time.Minute * 30
3333
)
3434

35-
type phaseMapFunc func(obj meta.Object, group api.ServerGroup, action api.Action, m *api.MemberStatus)
35+
type phaseMapFunc func(obj meta.Object, spec api.DeploymentSpec, group api.ServerGroup, action api.Action, m *api.MemberStatus)
3636
type phaseMapTo map[api.MemberPhase]phaseMapFunc
3737
type phaseMap map[api.MemberPhase]phaseMapTo
3838

3939
type PhaseExecutor interface {
40-
Execute(obj meta.Object, group api.ServerGroup, m *api.MemberStatus, action api.Action, to api.MemberPhase) bool
40+
Execute(obj meta.Object, spec api.DeploymentSpec, group api.ServerGroup, m *api.MemberStatus, action api.Action, to api.MemberPhase) bool
4141
}
4242

4343
func GetPhaseExecutor() PhaseExecutor {
@@ -46,22 +46,30 @@ func GetPhaseExecutor() PhaseExecutor {
4646

4747
var phase = phaseMap{
4848
api.MemberPhaseNone: {
49-
api.MemberPhasePending: func(obj meta.Object, group api.ServerGroup, action api.Action, m *api.MemberStatus) {
49+
api.MemberPhasePending: func(obj meta.Object, spec api.DeploymentSpec, group api.ServerGroup, action api.Action, m *api.MemberStatus) {
5050
// Change member RID
5151
m.RID = uuid.NewUUID()
5252

5353
// Clean Pod details
5454
m.PodUID = ""
5555

56-
m.ClusterID = obj.GetUID()
56+
// Add ClusterID
57+
if m.ClusterID == "" {
58+
m.ClusterID = obj.GetUID()
59+
}
60+
61+
if m.Architecture == nil {
62+
d := spec.Architecture.GetDefault()
63+
m.Architecture = &d
64+
}
5765
},
5866
},
5967
api.MemberPhasePending: {
60-
api.MemberPhaseCreated: func(obj meta.Object, group api.ServerGroup, action api.Action, m *api.MemberStatus) {
68+
api.MemberPhaseCreated: func(obj meta.Object, spec api.DeploymentSpec, group api.ServerGroup, action api.Action, m *api.MemberStatus) {
6169
// Clean conditions
6270
removeMemberConditionsMapFunc(m)
6371
},
64-
api.MemberPhaseUpgrading: func(obj meta.Object, group api.ServerGroup, action api.Action, m *api.MemberStatus) {
72+
api.MemberPhaseUpgrading: func(obj meta.Object, spec api.DeploymentSpec, group api.ServerGroup, action api.Action, m *api.MemberStatus) {
6573
removeMemberConditionsMapFunc(m)
6674
},
6775
},
@@ -94,7 +102,7 @@ func removeMemberConditionsMapFunc(m *api.MemberStatus) {
94102
m.Upgrade = false
95103
}
96104

97-
func (p phaseMap) empty(obj meta.Object, group api.ServerGroup, action api.Action, m *api.MemberStatus) {
105+
func (p phaseMap) empty(obj meta.Object, spec api.DeploymentSpec, group api.ServerGroup, action api.Action, m *api.MemberStatus) {
98106

99107
}
100108

@@ -108,7 +116,7 @@ func (p phaseMap) getFunc(from, to api.MemberPhase) phaseMapFunc {
108116
return p.empty
109117
}
110118

111-
func (p phaseMap) Execute(obj meta.Object, group api.ServerGroup, m *api.MemberStatus, action api.Action, to api.MemberPhase) bool {
119+
func (p phaseMap) Execute(obj meta.Object, spec api.DeploymentSpec, group api.ServerGroup, m *api.MemberStatus, action api.Action, to api.MemberPhase) bool {
112120
from := m.Phase
113121

114122
if from == to {
@@ -119,7 +127,7 @@ func (p phaseMap) Execute(obj meta.Object, group api.ServerGroup, m *api.MemberS
119127

120128
m.Phase = to
121129

122-
f(obj, group, action, m)
130+
f(obj, spec, group, action, m)
123131

124132
return true
125133
}

pkg/deployment/pod/affinity.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func AppendPodAntiAffinityDefault(p interfaces.PodCreator, a *core.PodAntiAffini
5151
}
5252
}
5353

54-
func AppendArchSelector(a *core.NodeAffinity, arch *api.ArangoDeploymentArchitectureType) {
54+
func AppendArchSelector(a *core.NodeAffinity, arch api.ArangoDeploymentArchitectureType) {
5555
if a.RequiredDuringSchedulingIgnoredDuringExecution == nil {
5656
a.RequiredDuringSchedulingIgnoredDuringExecution = &core.NodeSelector{}
5757
}

pkg/deployment/reconcile/action_member_phase_update.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func (a *memberPhaseUpdateAction) Start(ctx context.Context) (bool, error) {
7272
return true, nil
7373
}
7474

75-
if member.GetPhaseExecutor().Execute(a.actionCtx.GetAPIObject(), a.action.Group, &m, a.action, p) {
75+
if member.GetPhaseExecutor().Execute(a.actionCtx.GetAPIObject(), a.actionCtx.GetSpec(), a.action.Group, &m, a.action, p) {
7676
if err := a.actionCtx.UpdateMember(ctx, m); err != nil {
7777
return false, errors.WithStack(err)
7878
}

pkg/deployment/resources/pod_creator.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ func (r *Resources) createPodForMember(ctx context.Context, cachedStatus inspect
554554
m.PodSpecVersion = template.PodSpecChecksum
555555
}
556556

557-
member.GetPhaseExecutor().Execute(r.context.GetAPIObject(), group, &m, api.Action{}, newPhase)
557+
member.GetPhaseExecutor().Execute(r.context.GetAPIObject(), spec, group, &m, api.Action{}, newPhase)
558558

559559
if top := status.Topology; top.Enabled() {
560560
if m.Topology != nil && m.Topology.ID == top.ID {

pkg/deployment/resources/pod_creator_arangod.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ func (m *MemberArangoDPod) GetPodAffinity() *core.PodAffinity {
332332
func (m *MemberArangoDPod) GetNodeAffinity() *core.NodeAffinity {
333333
a := core.NodeAffinity{}
334334

335-
pod.AppendArchSelector(&a, m.status.Architecture)
335+
pod.AppendArchSelector(&a, m.status.Architecture.Default(m.spec.Architecture.GetDefault()))
336336

337337
pod.MergeNodeAffinity(&a, m.groupSpec.NodeAffinity)
338338

pkg/deployment/resources/pod_creator_sync.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ func (m *MemberSyncPod) GetPodAffinity() *core.PodAffinity {
231231
func (m *MemberSyncPod) GetNodeAffinity() *core.NodeAffinity {
232232
a := core.NodeAffinity{}
233233

234-
pod.AppendArchSelector(&a, m.memberStatus.Architecture)
234+
pod.AppendArchSelector(&a, m.memberStatus.Architecture.Default(m.spec.Architecture.GetDefault()))
235235

236236
pod.MergeNodeAffinity(&a, m.groupSpec.NodeAffinity)
237237

0 commit comments

Comments
 (0)