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 @@ -9,6 +9,7 @@
- Add debug mode (Golang DLV)
- License V2 for ArangoDB 3.9.0+
- Add ArangoClusterSynchronization v1 API
- Add core containers names to follow their terminations

## [1.2.6](https://github.com/arangodb/kube-arangodb/tree/1.2.6) (2021-12-15)
- Add ArangoBackup backoff functionality
Expand Down
25 changes: 20 additions & 5 deletions pkg/apis/deployment/v1/deployment_spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
//
// Copyright holder is ArangoDB GmbH, Cologne, Germany
//
// Author Ewout Prangsma
//

package v1

Expand All @@ -28,11 +26,12 @@ import (
"fmt"
"reflect"

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

"github.com/arangodb/kube-arangodb/pkg/backup/utils"
"github.com/arangodb/kube-arangodb/pkg/util"

core "k8s.io/api/core/v1"
"github.com/arangodb/kube-arangodb/pkg/util/errors"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil"
)

var (
Expand Down Expand Up @@ -537,3 +536,19 @@ func (s DeploymentSpec) Checksum() (string, error) {

return fmt.Sprintf("%0x", sha256.Sum256(data)), nil
}

// GetCoreContainers returns all containers' names which must running in the pod for the given group of servers.
func (s DeploymentSpec) GetCoreContainers(group ServerGroup) utils.StringList {
groupSpec := s.GetServerGroupSpec(group)
if len(groupSpec.SidecarCoreNames) == 0 {
return utils.StringList{k8sutil.ServerContainerName}
}

result := make(utils.StringList, 0, len(groupSpec.SidecarCoreNames)+1)
if !utils.StringList(groupSpec.SidecarCoreNames).Has(k8sutil.ServerContainerName) {
result = append(result, k8sutil.ServerContainerName)
}
result = append(result, groupSpec.SidecarCoreNames...)

return result
}
83 changes: 80 additions & 3 deletions pkg/apis/deployment/v1/deployment_spec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@
//
// Copyright holder is ArangoDB GmbH, Cologne, Germany
//
// Author Ewout Prangsma
//

package v1

import (
"testing"

"github.com/arangodb/kube-arangodb/pkg/util"
"github.com/stretchr/testify/assert"
v1 "k8s.io/api/core/v1"

"github.com/arangodb/kube-arangodb/pkg/backup/utils"
"github.com/arangodb/kube-arangodb/pkg/util"
)

func TestDeploymentSpecValidate(t *testing.T) {
Expand Down Expand Up @@ -122,3 +122,80 @@ func TestDeploymentSpecResetImmutableFields(t *testing.T) {
assert.Equal(t, test.Expected, test.Target)
}
}

func TestDeploymentSpec_GetCoreContainers(t *testing.T) {
type fields struct {
Single ServerGroupSpec
Agents ServerGroupSpec
DBServers ServerGroupSpec
Coordinators ServerGroupSpec
SyncMasters ServerGroupSpec
SyncWorkers ServerGroupSpec
}

type args struct {
group ServerGroup
}

tests := map[string]struct {
fields fields
args args
want utils.StringList
}{
"one sidecar container": {
fields: fields{
DBServers: ServerGroupSpec{
SidecarCoreNames: []string{"other"},
},
},
args: args{
group: ServerGroupDBServers,
},
want: utils.StringList{"server", "other"},
},
"one predefined container and one sidecar container": {
fields: fields{
DBServers: ServerGroupSpec{
SidecarCoreNames: []string{"server", "other"},
},
},
args: args{
group: ServerGroupDBServers,
},
want: utils.StringList{"server", "other"},
},
"zero core containers": {
fields: fields{
DBServers: ServerGroupSpec{
SidecarCoreNames: nil,
},
},
args: args{
group: ServerGroupDBServers,
},
want: utils.StringList{"server"},
},
"two non-core containers": {
fields: fields{
DBServers: ServerGroupSpec{
SidecarCoreNames: []string{"other1", "other2"},
},
},
args: args{
group: ServerGroupDBServers,
},
want: utils.StringList{"server", "other1", "other2"},
},
}
for testName, test := range tests {
t.Run(testName, func(t *testing.T) {
s := DeploymentSpec{
DBServers: test.fields.DBServers,
}

got := s.GetCoreContainers(test.args.group)
assert.Equal(t, test.want, got)

})
}
}
3 changes: 2 additions & 1 deletion pkg/apis/deployment/v1/deployment_status_members.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ func (ds DeploymentStatusMembers) ForServerGroup(cb func(group ServerGroup, list
}

// MemberStatusByPodName returns a reference to the element in the given set of lists that has the given pod name.
// If no such element exists, nil is returned.
// Returns member status and group which the pod belong to.
// If no such element exists, false is returned.
func (ds DeploymentStatusMembers) MemberStatusByPodName(podName string) (MemberStatus, ServerGroup, bool) {
if result, found := ds.Single.ElementByPodName(podName); found {
return result, ServerGroupSingle, true
Expand Down
3 changes: 3 additions & 0 deletions pkg/apis/deployment/v1/server_group_spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ type ServerGroupSpec struct {
Affinity *core.PodAffinity `json:"affinity,omitempty"`
// NodeAffinity specified additional nodeAffinity settings in ArangoDB Pod definitions
NodeAffinity *core.NodeAffinity `json:"nodeAffinity,omitempty"`
// SidecarCoreNames is a list of sidecar containers which must run in the pod.
// Some names (e.g.: "server", "worker") are reserved, and they don't have any impact.
SidecarCoreNames []string `json:"sidecarCoreNames,omitempty"`
// Sidecars specifies a list of additional containers to be started
Sidecars []core.Container `json:"sidecars,omitempty"`
// SecurityContext specifies security context for group
Expand Down
5 changes: 5 additions & 0 deletions pkg/apis/deployment/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 20 additions & 5 deletions pkg/apis/deployment/v2alpha1/deployment_spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
//
// Copyright holder is ArangoDB GmbH, Cologne, Germany
//
// Author Ewout Prangsma
//

package v2alpha1

Expand All @@ -28,11 +26,12 @@ import (
"fmt"
"reflect"

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

"github.com/arangodb/kube-arangodb/pkg/backup/utils"
"github.com/arangodb/kube-arangodb/pkg/util"

core "k8s.io/api/core/v1"
"github.com/arangodb/kube-arangodb/pkg/util/errors"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil"
)

var (
Expand Down Expand Up @@ -537,3 +536,19 @@ func (s DeploymentSpec) Checksum() (string, error) {

return fmt.Sprintf("%0x", sha256.Sum256(data)), nil
}

// GetCoreContainers returns all containers' names which must running in the pod for the given group of servers.
func (s DeploymentSpec) GetCoreContainers(group ServerGroup) utils.StringList {
groupSpec := s.GetServerGroupSpec(group)
if len(groupSpec.SidecarCoreNames) == 0 {
return utils.StringList{k8sutil.ServerContainerName}
}

result := make(utils.StringList, 0, len(groupSpec.SidecarCoreNames)+1)
if !utils.StringList(groupSpec.SidecarCoreNames).Has(k8sutil.ServerContainerName) {
result = append(result, k8sutil.ServerContainerName)
}
result = append(result, groupSpec.SidecarCoreNames...)

return result
}
83 changes: 80 additions & 3 deletions pkg/apis/deployment/v2alpha1/deployment_spec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@
//
// Copyright holder is ArangoDB GmbH, Cologne, Germany
//
// Author Ewout Prangsma
//

package v2alpha1

import (
"testing"

"github.com/arangodb/kube-arangodb/pkg/util"
"github.com/stretchr/testify/assert"
v1 "k8s.io/api/core/v1"

"github.com/arangodb/kube-arangodb/pkg/backup/utils"
"github.com/arangodb/kube-arangodb/pkg/util"
)

func TestDeploymentSpecValidate(t *testing.T) {
Expand Down Expand Up @@ -122,3 +122,80 @@ func TestDeploymentSpecResetImmutableFields(t *testing.T) {
assert.Equal(t, test.Expected, test.Target)
}
}

func TestDeploymentSpec_GetCoreContainers(t *testing.T) {
type fields struct {
Single ServerGroupSpec
Agents ServerGroupSpec
DBServers ServerGroupSpec
Coordinators ServerGroupSpec
SyncMasters ServerGroupSpec
SyncWorkers ServerGroupSpec
}

type args struct {
group ServerGroup
}

tests := map[string]struct {
fields fields
args args
want utils.StringList
}{
"one sidecar container": {
fields: fields{
DBServers: ServerGroupSpec{
SidecarCoreNames: []string{"other"},
},
},
args: args{
group: ServerGroupDBServers,
},
want: utils.StringList{"server", "other"},
},
"one predefined container and one sidecar container": {
fields: fields{
DBServers: ServerGroupSpec{
SidecarCoreNames: []string{"server", "other"},
},
},
args: args{
group: ServerGroupDBServers,
},
want: utils.StringList{"server", "other"},
},
"zero core containers": {
fields: fields{
DBServers: ServerGroupSpec{
SidecarCoreNames: nil,
},
},
args: args{
group: ServerGroupDBServers,
},
want: utils.StringList{"server"},
},
"two non-core containers": {
fields: fields{
DBServers: ServerGroupSpec{
SidecarCoreNames: []string{"other1", "other2"},
},
},
args: args{
group: ServerGroupDBServers,
},
want: utils.StringList{"server", "other1", "other2"},
},
}
for testName, test := range tests {
t.Run(testName, func(t *testing.T) {
s := DeploymentSpec{
DBServers: test.fields.DBServers,
}

got := s.GetCoreContainers(test.args.group)
assert.Equal(t, test.want, got)

})
}
}
3 changes: 2 additions & 1 deletion pkg/apis/deployment/v2alpha1/deployment_status_members.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ func (ds DeploymentStatusMembers) ForServerGroup(cb func(group ServerGroup, list
}

// MemberStatusByPodName returns a reference to the element in the given set of lists that has the given pod name.
// If no such element exists, nil is returned.
// Returns member status and group which the pod belong to.
// If no such element exists, false is returned.
func (ds DeploymentStatusMembers) MemberStatusByPodName(podName string) (MemberStatus, ServerGroup, bool) {
if result, found := ds.Single.ElementByPodName(podName); found {
return result, ServerGroupSingle, true
Expand Down
3 changes: 3 additions & 0 deletions pkg/apis/deployment/v2alpha1/server_group_spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ type ServerGroupSpec struct {
Affinity *core.PodAffinity `json:"affinity,omitempty"`
// NodeAffinity specified additional nodeAffinity settings in ArangoDB Pod definitions
NodeAffinity *core.NodeAffinity `json:"nodeAffinity,omitempty"`
// SidecarCoreNames is a list of sidecar containers which must run in the pod.
// Some names (e.g.: "server", "worker") are reserved, and they don't have any impact.
SidecarCoreNames []string `json:"sidecarCoreNames,omitempty"`
// Sidecars specifies a list of additional containers to be started
Sidecars []core.Container `json:"sidecars,omitempty"`
// SecurityContext specifies security context for group
Expand Down
5 changes: 5 additions & 0 deletions pkg/apis/deployment/v2alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions pkg/deployment/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,18 @@ import (
"strings"
"time"

"github.com/arangodb/kube-arangodb/pkg/util/globals"

"github.com/rs/zerolog"
core "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
"github.com/arangodb/kube-arangodb/pkg/backup/utils"
"github.com/arangodb/kube-arangodb/pkg/deployment/pod"
"github.com/arangodb/kube-arangodb/pkg/deployment/resources"
"github.com/arangodb/kube-arangodb/pkg/util/arangod"
"github.com/arangodb/kube-arangodb/pkg/util/constants"
"github.com/arangodb/kube-arangodb/pkg/util/errors"
"github.com/arangodb/kube-arangodb/pkg/util/globals"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil"
inspectorInterface "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/interfaces"
Expand Down Expand Up @@ -141,7 +141,7 @@ func (ib *imagesBuilder) fetchArangoDBImageIDAndVersion(ctx context.Context, cac
pod, err := ib.Context.GetCachedStatus().PodReadInterface().Get(ctxChild, podName, metav1.GetOptions{})
if err == nil {
// Pod found
if k8sutil.IsPodFailed(pod) {
if k8sutil.IsPodFailed(pod, utils.StringList{k8sutil.ServerContainerName}) {
// Wait some time before deleting the pod
if time.Now().After(pod.GetCreationTimestamp().Add(30 * time.Second)) {
err := globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error {
Expand Down
Loading