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 @@ -5,6 +5,7 @@
- Add "Short Names" feature
- Switch ArangoDB Image Discovery process from Headless Service to Pod IP
- Fix PVC Resize for Single servers
- Add Topology support

## [1.2.3](https://github.com/arangodb/kube-arangodb/tree/1.2.3) (2021-09-24)
- Update UBI Image to 8.4
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ require (
github.com/arangodb/go-driver v0.0.0-20210621075908-e7a6fa0cbd18
github.com/arangodb/go-upgrade-rules v0.0.0-20180809110947-031b4774ff21
github.com/cenkalti/backoff v2.2.1+incompatible
github.com/coreos/go-semver v0.3.0
github.com/coreos/go-semver v0.3.0 // indirect
github.com/dchest/uniuri v0.0.0-20160212164326-8902c56451e9
github.com/evanphx/json-patch v4.9.0+incompatible
github.com/ghodss/yaml v1.0.0
Expand All @@ -43,7 +43,7 @@ require (
github.com/jessevdk/go-assets v0.0.0-20160921144138-4f4301a06e15
github.com/jessevdk/go-assets-builder v0.0.0-20130903091706-b8483521738f // indirect
github.com/jessevdk/go-flags v1.4.0 // indirect
github.com/json-iterator/go v1.1.11
github.com/json-iterator/go v1.1.11 // indirect
github.com/julienschmidt/httprouter v1.3.0
github.com/kevinburke/rest v0.0.0-20210222204520-f7a2e216372f // indirect
github.com/magiconair/properties v1.8.0
Expand All @@ -62,7 +62,7 @@ require (
github.com/ugorji/go/codec v1.2.6 // indirect
github.com/voxelbrain/goptions v0.0.0-20180630082107-58cddc247ea2 // indirect
github.com/zenazn/goji v0.9.0 // indirect
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4 // indirect
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c
golang.org/x/tools v0.1.1-0.20210504181558-0bb7e5c47b1a // indirect
google.golang.org/protobuf v1.27.1 // indirect
Expand Down
2 changes: 2 additions & 0 deletions pkg/apis/deployment/v1/conditions.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ const (
ConditionTypeUpdating ConditionType = "Updating"
// ConditionTypeUpdateFailed indicates that runtime update failed
ConditionTypeUpdateFailed ConditionType = "UpdateFailed"
// ConditionTypeTopologyAware indicates that the member is deployed with TopologyAwareness.
ConditionTypeTopologyAware ConditionType = "TopologyAware"
)

// Condition represents one current condition of a deployment or deployment member.
Expand Down
3 changes: 3 additions & 0 deletions pkg/apis/deployment/v1/deployment_spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ type DeploymentSpec struct {

// CommunicationMethod define communication method used in deployment
CommunicationMethod *DeploymentCommunicationMethod `json:"communicationMethod,omitempty"`

// Topology define topology adjustment details, Enterprise only
Topology *TopologySpec `json:"topology,omitempty"`
}

// GetAllowMemberRecreation returns member recreation policy based on group and settings
Expand Down
2 changes: 2 additions & 0 deletions pkg/apis/deployment/v1/deployment_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ type DeploymentStatus struct {

// Agency keeps information about agency
Agency *DeploymentStatusAgencyInfo `json:"agency,omitempty"`

Topology *TopologyStatus `json:"topology,omitempty"`
}

// Equal checks for equality
Expand Down
55 changes: 55 additions & 0 deletions pkg/apis/deployment/v1/list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
//
// DISCLAIMER
//
// Copyright 2020 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.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Copyright holder is ArangoDB GmbH, Cologne, Germany
//

package v1

import "sort"

type List []string

func (l List) Contains(v string) bool {
for _, z := range l {
if z == v {
return true
}
}

return false
}

func (l List) Sort() {
sort.Strings(l)
}

func (l List) Remove(values ...string) List {
var m List

toRemove := List(values)

for _, v := range l {
if toRemove.Contains(v) {
continue
}

m = append(m, v)
}

return m
}
6 changes: 6 additions & 0 deletions pkg/apis/deployment/v1/member_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ type MemberStatus struct {
// ID holds the unique ID of the member.
// This id is also used within the ArangoDB cluster to identify this server.
ID string `json:"id"`
// UID holds the unique UID of the member.
// UID is created once member run in AddMember action.
UID types.UID `json:"uid,omitempty"`
// RID holds the ID of the member run.
// Value is updated in Pending Phase.
RID types.UID `json:"rid,omitempty"`
Expand Down Expand Up @@ -80,11 +83,14 @@ type MemberStatus struct {
Upgrade bool `json:"upgrade,omitempty"`
// Endpoint definition how member should be reachable
Endpoint *string `json:"endpoint,omitempty"`
// Topology define topology member status assignment
Topology *TopologyMemberStatus `json:"topology,omitempty"`
}

// Equal checks for equality
func (s MemberStatus) Equal(other MemberStatus) bool {
return s.ID == other.ID &&
s.UID == other.UID &&
s.RID == other.RID &&
s.Phase == other.Phase &&
util.TimeCompareEqual(s.CreatedAt, other.CreatedAt) &&
Expand Down
18 changes: 17 additions & 1 deletion pkg/apis/deployment/v1/member_status_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,12 @@ func (l *MemberStatusList) removeByID(id string) error {
return errors.WithStack(errors.Wrapf(NotFoundError, "Member '%s' is not a member", id))
}

type MemberToRemoveSelector func(m MemberStatusList) (string, error)

// SelectMemberToRemove selects a member from the given list that should
// be removed in a scale down action.
// Returns an error if the list is empty.
func (l MemberStatusList) SelectMemberToRemove() (MemberStatus, error) {
func (l MemberStatusList) SelectMemberToRemove(selectors ...MemberToRemoveSelector) (MemberStatus, error) {
if len(l) > 0 {
// Try to find member with phase to be removed
for _, m := range l {
Expand All @@ -165,6 +167,20 @@ func (l MemberStatusList) SelectMemberToRemove() (MemberStatus, error) {
return m, nil
}
}

// Run conditional picker
for _, selector := range selectors {
if m, err := selector(l); err != nil {
return MemberStatus{}, err
} else if m != "" {
if member, ok := l.ElementByID(m); ok {
return member, nil
} else {
return MemberStatus{}, errors.Newf("Unable to find member with id %s", m)
}
}
}

// Pick a random member that is in created state
perm := rand.Perm(len(l))
for _, idx := range perm {
Expand Down
47 changes: 47 additions & 0 deletions pkg/apis/deployment/v1/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,11 @@ const (
ActionTypeRuntimeContainerImageUpdate ActionType = "RuntimeContainerImageUpdate"
// ActionTypeRuntimeContainerArgsLogLevelUpdate updates the container's executor arguments.
ActionTypeRuntimeContainerArgsLogLevelUpdate ActionType = "RuntimeContainerArgsLogLevelUpdate"

// Topology
ActionTypeTopologyEnable ActionType = "TopologyEnable"
ActionTypeTopologyDisable ActionType = "TopologyDisable"
ActionTypeTopologyMemberAssignment ActionType = "TopologyMemberAssignment"
)

const (
Expand Down Expand Up @@ -346,3 +351,45 @@ func (p Plan) Wrap(before, after Action) Plan {

return n
}

// AfterFirst adds actions when condition will return false
func (p Plan) AfterFirst(condition func(a Action) bool, actions ...Action) Plan {
var r Plan
c := p
for {
if len(c) == 0 {
break
}

if !condition(c[0]) {
r = append(r, actions...)

r = append(r, c...)

break
}

r = append(r, c[0])

if len(c) == 1 {
break
}

c = c[1:]
}

return r
}

// Filter filter list of the actions
func (p Plan) Filter(condition func(a Action) bool) Plan {
var r Plan

for _, a := range p {
if condition(a) {
r = append(r, a)
}
}

return r
}
28 changes: 28 additions & 0 deletions pkg/apis/deployment/v1/topology_member_status.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//
// DISCLAIMER
//
// Copyright 2020 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.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Copyright holder is ArangoDB GmbH, Cologne, Germany
//

package v1

import "k8s.io/apimachinery/pkg/types"

type TopologyMemberStatus struct {
ID types.UID `json:"id"`
Zone int `json:"rack"`
}
53 changes: 53 additions & 0 deletions pkg/apis/deployment/v1/topology_spec.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//
// DISCLAIMER
//
// Copyright 2020 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.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Copyright holder is ArangoDB GmbH, Cologne, Germany
//

package v1

const DefaultTopologySpecLabel = "topology.kubernetes.io/zone"

type TopologySpec struct {
Enabled bool `json:"enabled,omitempty"`
Zones int `json:"zones,omitempty"`
Label *string `json:"label,omitempty"`
}

func (t *TopologySpec) IsEnabled() bool {
if t == nil {
return false
}

return t.Enabled && t.Zones > 0
}

func (t *TopologySpec) GetZones() int {
if t == nil {
return 0
}

return t.Zones
}

func (t *TopologySpec) GetLabel() string {
if t == nil || t.Label == nil {
return DefaultTopologySpecLabel
}

return *t.Label
}
Loading