Skip to content

Commit 69f08e1

Browse files
authored
[Feature] Core containers (#871)
1 parent 9a00f40 commit 69f08e1

19 files changed

+678
-136
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
- Add debug mode (Golang DLV)
1010
- License V2 for ArangoDB 3.9.0+
1111
- Add ArangoClusterSynchronization v1 API
12+
- Add core containers names to follow their terminations
1213

1314
## [1.2.6](https://github.com/arangodb/kube-arangodb/tree/1.2.6) (2021-12-15)
1415
- Add ArangoBackup backoff functionality

pkg/apis/deployment/v1/deployment_spec.go

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
//
1818
// Copyright holder is ArangoDB GmbH, Cologne, Germany
1919
//
20-
// Author Ewout Prangsma
21-
//
2220

2321
package v1
2422

@@ -28,11 +26,12 @@ import (
2826
"fmt"
2927
"reflect"
3028

31-
"github.com/arangodb/kube-arangodb/pkg/util/errors"
29+
core "k8s.io/api/core/v1"
3230

31+
"github.com/arangodb/kube-arangodb/pkg/backup/utils"
3332
"github.com/arangodb/kube-arangodb/pkg/util"
34-
35-
core "k8s.io/api/core/v1"
33+
"github.com/arangodb/kube-arangodb/pkg/util/errors"
34+
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil"
3635
)
3736

3837
var (
@@ -537,3 +536,19 @@ func (s DeploymentSpec) Checksum() (string, error) {
537536

538537
return fmt.Sprintf("%0x", sha256.Sum256(data)), nil
539538
}
539+
540+
// GetCoreContainers returns all containers' names which must running in the pod for the given group of servers.
541+
func (s DeploymentSpec) GetCoreContainers(group ServerGroup) utils.StringList {
542+
groupSpec := s.GetServerGroupSpec(group)
543+
if len(groupSpec.SidecarCoreNames) == 0 {
544+
return utils.StringList{k8sutil.ServerContainerName}
545+
}
546+
547+
result := make(utils.StringList, 0, len(groupSpec.SidecarCoreNames)+1)
548+
if !utils.StringList(groupSpec.SidecarCoreNames).Has(k8sutil.ServerContainerName) {
549+
result = append(result, k8sutil.ServerContainerName)
550+
}
551+
result = append(result, groupSpec.SidecarCoreNames...)
552+
553+
return result
554+
}

pkg/apis/deployment/v1/deployment_spec_test.go

Lines changed: 80 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@
1717
//
1818
// Copyright holder is ArangoDB GmbH, Cologne, Germany
1919
//
20-
// Author Ewout Prangsma
21-
//
2220

2321
package v1
2422

2523
import (
2624
"testing"
2725

28-
"github.com/arangodb/kube-arangodb/pkg/util"
2926
"github.com/stretchr/testify/assert"
3027
v1 "k8s.io/api/core/v1"
28+
29+
"github.com/arangodb/kube-arangodb/pkg/backup/utils"
30+
"github.com/arangodb/kube-arangodb/pkg/util"
3131
)
3232

3333
func TestDeploymentSpecValidate(t *testing.T) {
@@ -122,3 +122,80 @@ func TestDeploymentSpecResetImmutableFields(t *testing.T) {
122122
assert.Equal(t, test.Expected, test.Target)
123123
}
124124
}
125+
126+
func TestDeploymentSpec_GetCoreContainers(t *testing.T) {
127+
type fields struct {
128+
Single ServerGroupSpec
129+
Agents ServerGroupSpec
130+
DBServers ServerGroupSpec
131+
Coordinators ServerGroupSpec
132+
SyncMasters ServerGroupSpec
133+
SyncWorkers ServerGroupSpec
134+
}
135+
136+
type args struct {
137+
group ServerGroup
138+
}
139+
140+
tests := map[string]struct {
141+
fields fields
142+
args args
143+
want utils.StringList
144+
}{
145+
"one sidecar container": {
146+
fields: fields{
147+
DBServers: ServerGroupSpec{
148+
SidecarCoreNames: []string{"other"},
149+
},
150+
},
151+
args: args{
152+
group: ServerGroupDBServers,
153+
},
154+
want: utils.StringList{"server", "other"},
155+
},
156+
"one predefined container and one sidecar container": {
157+
fields: fields{
158+
DBServers: ServerGroupSpec{
159+
SidecarCoreNames: []string{"server", "other"},
160+
},
161+
},
162+
args: args{
163+
group: ServerGroupDBServers,
164+
},
165+
want: utils.StringList{"server", "other"},
166+
},
167+
"zero core containers": {
168+
fields: fields{
169+
DBServers: ServerGroupSpec{
170+
SidecarCoreNames: nil,
171+
},
172+
},
173+
args: args{
174+
group: ServerGroupDBServers,
175+
},
176+
want: utils.StringList{"server"},
177+
},
178+
"two non-core containers": {
179+
fields: fields{
180+
DBServers: ServerGroupSpec{
181+
SidecarCoreNames: []string{"other1", "other2"},
182+
},
183+
},
184+
args: args{
185+
group: ServerGroupDBServers,
186+
},
187+
want: utils.StringList{"server", "other1", "other2"},
188+
},
189+
}
190+
for testName, test := range tests {
191+
t.Run(testName, func(t *testing.T) {
192+
s := DeploymentSpec{
193+
DBServers: test.fields.DBServers,
194+
}
195+
196+
got := s.GetCoreContainers(test.args.group)
197+
assert.Equal(t, test.want, got)
198+
199+
})
200+
}
201+
}

pkg/apis/deployment/v1/deployment_status_members.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,8 @@ func (ds DeploymentStatusMembers) ForServerGroup(cb func(group ServerGroup, list
128128
}
129129

130130
// MemberStatusByPodName returns a reference to the element in the given set of lists that has the given pod name.
131-
// If no such element exists, nil is returned.
131+
// Returns member status and group which the pod belong to.
132+
// If no such element exists, false is returned.
132133
func (ds DeploymentStatusMembers) MemberStatusByPodName(podName string) (MemberStatus, ServerGroup, bool) {
133134
if result, found := ds.Single.ElementByPodName(podName); found {
134135
return result, ServerGroupSingle, true

pkg/apis/deployment/v1/server_group_spec.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@ type ServerGroupSpec struct {
126126
Affinity *core.PodAffinity `json:"affinity,omitempty"`
127127
// NodeAffinity specified additional nodeAffinity settings in ArangoDB Pod definitions
128128
NodeAffinity *core.NodeAffinity `json:"nodeAffinity,omitempty"`
129+
// SidecarCoreNames is a list of sidecar containers which must run in the pod.
130+
// Some names (e.g.: "server", "worker") are reserved, and they don't have any impact.
131+
SidecarCoreNames []string `json:"sidecarCoreNames,omitempty"`
129132
// Sidecars specifies a list of additional containers to be started
130133
Sidecars []core.Container `json:"sidecars,omitempty"`
131134
// SecurityContext specifies security context for group

pkg/apis/deployment/v1/zz_generated.deepcopy.go

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/apis/deployment/v2alpha1/deployment_spec.go

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
//
1818
// Copyright holder is ArangoDB GmbH, Cologne, Germany
1919
//
20-
// Author Ewout Prangsma
21-
//
2220

2321
package v2alpha1
2422

@@ -28,11 +26,12 @@ import (
2826
"fmt"
2927
"reflect"
3028

31-
"github.com/arangodb/kube-arangodb/pkg/util/errors"
29+
core "k8s.io/api/core/v1"
3230

31+
"github.com/arangodb/kube-arangodb/pkg/backup/utils"
3332
"github.com/arangodb/kube-arangodb/pkg/util"
34-
35-
core "k8s.io/api/core/v1"
33+
"github.com/arangodb/kube-arangodb/pkg/util/errors"
34+
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil"
3635
)
3736

3837
var (
@@ -537,3 +536,19 @@ func (s DeploymentSpec) Checksum() (string, error) {
537536

538537
return fmt.Sprintf("%0x", sha256.Sum256(data)), nil
539538
}
539+
540+
// GetCoreContainers returns all containers' names which must running in the pod for the given group of servers.
541+
func (s DeploymentSpec) GetCoreContainers(group ServerGroup) utils.StringList {
542+
groupSpec := s.GetServerGroupSpec(group)
543+
if len(groupSpec.SidecarCoreNames) == 0 {
544+
return utils.StringList{k8sutil.ServerContainerName}
545+
}
546+
547+
result := make(utils.StringList, 0, len(groupSpec.SidecarCoreNames)+1)
548+
if !utils.StringList(groupSpec.SidecarCoreNames).Has(k8sutil.ServerContainerName) {
549+
result = append(result, k8sutil.ServerContainerName)
550+
}
551+
result = append(result, groupSpec.SidecarCoreNames...)
552+
553+
return result
554+
}

pkg/apis/deployment/v2alpha1/deployment_spec_test.go

Lines changed: 80 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@
1717
//
1818
// Copyright holder is ArangoDB GmbH, Cologne, Germany
1919
//
20-
// Author Ewout Prangsma
21-
//
2220

2321
package v2alpha1
2422

2523
import (
2624
"testing"
2725

28-
"github.com/arangodb/kube-arangodb/pkg/util"
2926
"github.com/stretchr/testify/assert"
3027
v1 "k8s.io/api/core/v1"
28+
29+
"github.com/arangodb/kube-arangodb/pkg/backup/utils"
30+
"github.com/arangodb/kube-arangodb/pkg/util"
3131
)
3232

3333
func TestDeploymentSpecValidate(t *testing.T) {
@@ -122,3 +122,80 @@ func TestDeploymentSpecResetImmutableFields(t *testing.T) {
122122
assert.Equal(t, test.Expected, test.Target)
123123
}
124124
}
125+
126+
func TestDeploymentSpec_GetCoreContainers(t *testing.T) {
127+
type fields struct {
128+
Single ServerGroupSpec
129+
Agents ServerGroupSpec
130+
DBServers ServerGroupSpec
131+
Coordinators ServerGroupSpec
132+
SyncMasters ServerGroupSpec
133+
SyncWorkers ServerGroupSpec
134+
}
135+
136+
type args struct {
137+
group ServerGroup
138+
}
139+
140+
tests := map[string]struct {
141+
fields fields
142+
args args
143+
want utils.StringList
144+
}{
145+
"one sidecar container": {
146+
fields: fields{
147+
DBServers: ServerGroupSpec{
148+
SidecarCoreNames: []string{"other"},
149+
},
150+
},
151+
args: args{
152+
group: ServerGroupDBServers,
153+
},
154+
want: utils.StringList{"server", "other"},
155+
},
156+
"one predefined container and one sidecar container": {
157+
fields: fields{
158+
DBServers: ServerGroupSpec{
159+
SidecarCoreNames: []string{"server", "other"},
160+
},
161+
},
162+
args: args{
163+
group: ServerGroupDBServers,
164+
},
165+
want: utils.StringList{"server", "other"},
166+
},
167+
"zero core containers": {
168+
fields: fields{
169+
DBServers: ServerGroupSpec{
170+
SidecarCoreNames: nil,
171+
},
172+
},
173+
args: args{
174+
group: ServerGroupDBServers,
175+
},
176+
want: utils.StringList{"server"},
177+
},
178+
"two non-core containers": {
179+
fields: fields{
180+
DBServers: ServerGroupSpec{
181+
SidecarCoreNames: []string{"other1", "other2"},
182+
},
183+
},
184+
args: args{
185+
group: ServerGroupDBServers,
186+
},
187+
want: utils.StringList{"server", "other1", "other2"},
188+
},
189+
}
190+
for testName, test := range tests {
191+
t.Run(testName, func(t *testing.T) {
192+
s := DeploymentSpec{
193+
DBServers: test.fields.DBServers,
194+
}
195+
196+
got := s.GetCoreContainers(test.args.group)
197+
assert.Equal(t, test.want, got)
198+
199+
})
200+
}
201+
}

pkg/apis/deployment/v2alpha1/deployment_status_members.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,8 @@ func (ds DeploymentStatusMembers) ForServerGroup(cb func(group ServerGroup, list
128128
}
129129

130130
// MemberStatusByPodName returns a reference to the element in the given set of lists that has the given pod name.
131-
// If no such element exists, nil is returned.
131+
// Returns member status and group which the pod belong to.
132+
// If no such element exists, false is returned.
132133
func (ds DeploymentStatusMembers) MemberStatusByPodName(podName string) (MemberStatus, ServerGroup, bool) {
133134
if result, found := ds.Single.ElementByPodName(podName); found {
134135
return result, ServerGroupSingle, true

pkg/apis/deployment/v2alpha1/server_group_spec.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@ type ServerGroupSpec struct {
126126
Affinity *core.PodAffinity `json:"affinity,omitempty"`
127127
// NodeAffinity specified additional nodeAffinity settings in ArangoDB Pod definitions
128128
NodeAffinity *core.NodeAffinity `json:"nodeAffinity,omitempty"`
129+
// SidecarCoreNames is a list of sidecar containers which must run in the pod.
130+
// Some names (e.g.: "server", "worker") are reserved, and they don't have any impact.
131+
SidecarCoreNames []string `json:"sidecarCoreNames,omitempty"`
129132
// Sidecars specifies a list of additional containers to be started
130133
Sidecars []core.Container `json:"sidecars,omitempty"`
131134
// SecurityContext specifies security context for group

0 commit comments

Comments
 (0)