Skip to content
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 @@ -15,6 +15,7 @@
- (Bugfix) Skip Replace operation on DBServer if they need to be scaled down
- (Feature) Upgrade procedure steps
- (Refactor) Remove API and Core cross-dependency
- (Bugfix) Allow to have nil architecture (NPE fix)

## [1.2.8](https://github.com/arangodb/kube-arangodb/tree/1.2.8) (2022-02-24)
- Do not check License V2 on Community images
Expand Down
8 changes: 8 additions & 0 deletions pkg/apis/deployment/v1/architecture.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ func (a ArangoDeploymentArchitectureType) Validate() error {
}
}

func (a *ArangoDeploymentArchitectureType) Default(def ArangoDeploymentArchitectureType) ArangoDeploymentArchitectureType {
if a == nil {
return def
}

return *a
}

func (a ArangoDeploymentArchitectureType) AsNodeSelectorRequirement() core.NodeSelectorTerm {
return core.NodeSelectorTerm{
MatchExpressions: []core.NodeSelectorRequirement{
Expand Down
8 changes: 8 additions & 0 deletions pkg/apis/deployment/v2alpha1/architecture.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ func (a ArangoDeploymentArchitectureType) Validate() error {
}
}

func (a *ArangoDeploymentArchitectureType) Default(def ArangoDeploymentArchitectureType) ArangoDeploymentArchitectureType {
if a == nil {
return def
}

return *a
}

func (a ArangoDeploymentArchitectureType) AsNodeSelectorRequirement() core.NodeSelectorTerm {
return core.NodeSelectorTerm{
MatchExpressions: []core.NodeSelectorRequirement{
Expand Down
2 changes: 1 addition & 1 deletion pkg/deployment/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ func (i *ImageUpdatePod) GetNodeAffinity() *core.NodeAffinity {
a := core.NodeAffinity{}
arch := i.spec.Architecture.GetDefault()

pod.AppendArchSelector(&a, &arch)
pod.AppendArchSelector(&a, arch)

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

Expand Down
26 changes: 17 additions & 9 deletions pkg/deployment/member/phase_updates.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ const (
recentTerminationsKeepPeriod = time.Minute * 30
)

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

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

func GetPhaseExecutor() PhaseExecutor {
Expand All @@ -46,22 +46,30 @@ func GetPhaseExecutor() PhaseExecutor {

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

// Clean Pod details
m.PodUID = ""

m.ClusterID = obj.GetUID()
// Add ClusterID
if m.ClusterID == "" {
m.ClusterID = obj.GetUID()
}

if m.Architecture == nil {
d := spec.Architecture.GetDefault()
m.Architecture = &d
}
},
},
api.MemberPhasePending: {
api.MemberPhaseCreated: func(obj meta.Object, group api.ServerGroup, action api.Action, m *api.MemberStatus) {
api.MemberPhaseCreated: func(obj meta.Object, spec api.DeploymentSpec, group api.ServerGroup, action api.Action, m *api.MemberStatus) {
// Clean conditions
removeMemberConditionsMapFunc(m)
},
api.MemberPhaseUpgrading: func(obj meta.Object, group api.ServerGroup, action api.Action, m *api.MemberStatus) {
api.MemberPhaseUpgrading: func(obj meta.Object, spec api.DeploymentSpec, group api.ServerGroup, action api.Action, m *api.MemberStatus) {
removeMemberConditionsMapFunc(m)
},
},
Expand Down Expand Up @@ -94,7 +102,7 @@ func removeMemberConditionsMapFunc(m *api.MemberStatus) {
m.Upgrade = false
}

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

}

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

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

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

m.Phase = to

f(obj, group, action, m)
f(obj, spec, group, action, m)

return true
}
2 changes: 1 addition & 1 deletion pkg/deployment/pod/affinity.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func AppendPodAntiAffinityDefault(p interfaces.PodCreator, a *core.PodAntiAffini
}
}

func AppendArchSelector(a *core.NodeAffinity, arch *api.ArangoDeploymentArchitectureType) {
func AppendArchSelector(a *core.NodeAffinity, arch api.ArangoDeploymentArchitectureType) {
if a.RequiredDuringSchedulingIgnoredDuringExecution == nil {
a.RequiredDuringSchedulingIgnoredDuringExecution = &core.NodeSelector{}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/deployment/reconcile/action_member_phase_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (a *memberPhaseUpdateAction) Start(ctx context.Context) (bool, error) {
return true, nil
}

if member.GetPhaseExecutor().Execute(a.actionCtx.GetAPIObject(), a.action.Group, &m, a.action, p) {
if member.GetPhaseExecutor().Execute(a.actionCtx.GetAPIObject(), a.actionCtx.GetSpec(), a.action.Group, &m, a.action, p) {
if err := a.actionCtx.UpdateMember(ctx, m); err != nil {
return false, errors.WithStack(err)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/deployment/resources/pod_creator.go
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ func (r *Resources) createPodForMember(ctx context.Context, cachedStatus inspect
m.PodSpecVersion = template.PodSpecChecksum
}

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

if top := status.Topology; top.Enabled() {
if m.Topology != nil && m.Topology.ID == top.ID {
Expand Down
2 changes: 1 addition & 1 deletion pkg/deployment/resources/pod_creator_arangod.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ func (m *MemberArangoDPod) GetPodAffinity() *core.PodAffinity {
func (m *MemberArangoDPod) GetNodeAffinity() *core.NodeAffinity {
a := core.NodeAffinity{}

pod.AppendArchSelector(&a, m.status.Architecture)
pod.AppendArchSelector(&a, m.status.Architecture.Default(m.spec.Architecture.GetDefault()))

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

Expand Down
2 changes: 1 addition & 1 deletion pkg/deployment/resources/pod_creator_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ func (m *MemberSyncPod) GetPodAffinity() *core.PodAffinity {
func (m *MemberSyncPod) GetNodeAffinity() *core.NodeAffinity {
a := core.NodeAffinity{}

pod.AppendArchSelector(&a, m.memberStatus.Architecture)
pod.AppendArchSelector(&a, m.memberStatus.Architecture.Default(m.spec.Architecture.GetDefault()))

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

Expand Down