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: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ require (
github.com/mattn/go-isatty v0.0.7 // indirect
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b // indirect
github.com/op/go-logging v0.0.0-20160315200505-970db520ece7 // indirect
github.com/pborman/uuid v1.2.0 // indirect
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
github.com/pkg/errors v0.8.1
github.com/prometheus/client_golang v1.0.0
Expand Down
40 changes: 40 additions & 0 deletions pkg/deployment/pod/args.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//
// 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
//
// Author Adam Janikowski
//

package pod

import (
"github.com/arangodb/go-driver"
deploymentApi "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
)

type Input struct {
Deployment deploymentApi.DeploymentSpec
GroupSpec deploymentApi.ServerGroupSpec
Group deploymentApi.ServerGroup
Version driver.Version
AutoUpgrade bool
}

type ArgumentsBuilder interface {
Create(i Input) []OptionPair
}
46 changes: 46 additions & 0 deletions pkg/deployment/pod/pair.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//
// 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
//
// Author Adam Janikowski
//

package pod

import "strings"

// OptionPair key value pair builder
type OptionPair struct {
Key string
Value string
}

// CompareTo returns -1 if o < other, 0 if o == other, 1 otherwise
func (o OptionPair) CompareTo(other OptionPair) int {
rc := strings.Compare(o.Key, other.Key)
if rc < 0 {
return -1
} else if rc > 0 {
return 1
}
return strings.Compare(o.Value, other.Value)
}

func NewOptionPair(pairs ...OptionPair) []OptionPair {
return pairs
}
46 changes: 46 additions & 0 deletions pkg/deployment/pod/upgrade.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//
// 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
//
// Author Adam Janikowski
//

package pod

import deploymentApi "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"

func AutoUpgrade() ArgumentsBuilder {
return autoUpgradeArgs{}
}

type autoUpgradeArgs struct{}

func (u autoUpgradeArgs) Create(i Input) []OptionPair {
if !i.AutoUpgrade {
return NewOptionPair()
}

if i.Version.CompareTo("3.6.0") >= 0 {
switch i.Group {
case deploymentApi.ServerGroupCoordinators:
return NewOptionPair(OptionPair{"--cluster.upgrade", "online"})
}
}

return NewOptionPair(OptionPair{"--database.auto-upgrade", "true"})
}
88 changes: 53 additions & 35 deletions pkg/deployment/reconcile/plan_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,24 @@ import (
api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
"github.com/arangodb/kube-arangodb/pkg/util"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil"
v1 "k8s.io/api/core/v1"
core "k8s.io/api/core/v1"
)

var _ PlanBuilderContext = &testContext{}

type testContext struct {
Pods []v1.Pod
Pods []core.Pod
ErrPods error
ArangoDeployment *api.ArangoDeployment
PVC *v1.PersistentVolumeClaim
PVC *core.PersistentVolumeClaim
PVCErr error
RecordedEvent *k8sutil.Event
}

func (c *testContext) GetAgencyData(ctx context.Context, i interface{}, keyParts ...string) error {
return nil
}

func (c *testContext) GetAPIObject() k8sutil.APIObject {
if c.ArangoDeployment == nil {
return &api.ArangoDeployment{}
Expand Down Expand Up @@ -108,13 +114,13 @@ func (c *testContext) RemovePodFinalizers(podName string) error {
panic("implement me")
}

func (c *testContext) GetOwnedPods() ([]v1.Pod, error) {
func (c *testContext) GetOwnedPods() ([]core.Pod, error) {
if c.ErrPods != nil {
return nil, c.ErrPods
}

if c.Pods == nil {
return make([]v1.Pod, 0), c.ErrPods
return make([]core.Pod, 0), c.ErrPods
}
return c.Pods, c.ErrPods
}
Expand Down Expand Up @@ -158,7 +164,7 @@ func (c *testContext) CreateEvent(evt *k8sutil.Event) {
}

// GetPvc gets a PVC by the given name, in the samespace of the deployment.
func (c *testContext) GetPvc(pvcName string) (*v1.PersistentVolumeClaim, error) {
func (c *testContext) GetPvc(pvcName string) (*core.PersistentVolumeClaim, error) {
return c.PVC, c.PVCErr
}

Expand All @@ -181,6 +187,22 @@ func (c *testContext) GetStatus() (api.DeploymentStatus, int32) {
return c.ArangoDeployment.Status, 0
}

func addAgentsToStatus(t *testing.T, status *api.DeploymentStatus, count int) {
for i := 0; i < count; i++ {
require.NoError(t, status.Members.Add(api.MemberStatus{
ID: fmt.Sprintf("AGNT-%d", i),
PodName: fmt.Sprintf("agnt-depl-xxx-%d", i),
Phase: api.MemberPhaseCreated,
Conditions: []api.Condition{
{
Type: api.ConditionTypeReady,
Status: core.ConditionTrue,
},
},
}, api.ServerGroupAgents))
}
}

// TestCreatePlanSingleScale creates a `single` deployment to test the creating of scaling plan.
func TestCreatePlanSingleScale(t *testing.T) {
c := &testContext{}
Expand Down Expand Up @@ -249,6 +271,8 @@ func TestCreatePlanActiveFailoverScale(t *testing.T) {

// Test with empty status
var status api.DeploymentStatus
addAgentsToStatus(t, &status, 3)

newPlan, changed := createPlan(log, depl, nil, spec, status, nil, c)
assert.True(t, changed)
require.Len(t, newPlan, 2)
Expand Down Expand Up @@ -314,6 +338,8 @@ func TestCreatePlanClusterScale(t *testing.T) {

// Test with empty status
var status api.DeploymentStatus
addAgentsToStatus(t, &status, 3)

newPlan, changed := createPlan(log, depl, nil, spec, status, nil, c)
assert.True(t, changed)
require.Len(t, newPlan, 6) // Adding 3 dbservers & 3 coordinators (note: agents do not scale now)
Expand Down Expand Up @@ -420,14 +446,6 @@ func TestCreatePlan(t *testing.T) {
ID: "3",
},
}
twoAgents := api.MemberStatusList{
{
ID: "1",
},
{
ID: "2",
},
}
threeDBServers := api.MemberStatusList{
{
ID: "1",
Expand Down Expand Up @@ -455,10 +473,10 @@ func TestCreatePlan(t *testing.T) {
Members: api.DeploymentStatusMembers{
DBServers: threeDBServers,
Coordinators: threeCoordinators,
Agents: twoAgents,
},
},
}
addAgentsToStatus(t, &deploymentTemplate.Status, 3)
deploymentTemplate.Spec.SetDefaults("createPlanTest")

testCases := []struct {
Expand Down Expand Up @@ -525,17 +543,17 @@ func TestCreatePlan(t *testing.T) {
Name: "Change Storage for DBServers",
context: &testContext{
ArangoDeployment: deploymentTemplate.DeepCopy(),
PVC: &v1.PersistentVolumeClaim{
Spec: v1.PersistentVolumeClaimSpec{
PVC: &core.PersistentVolumeClaim{
Spec: core.PersistentVolumeClaimSpec{
StorageClassName: util.NewString("oldStorage"),
},
},
},
Helper: func(ad *api.ArangoDeployment) {
ad.Spec.DBServers = api.ServerGroupSpec{
Count: util.NewInt(3),
VolumeClaimTemplate: &v1.PersistentVolumeClaim{
Spec: v1.PersistentVolumeClaimSpec{
VolumeClaimTemplate: &core.PersistentVolumeClaim{
Spec: core.PersistentVolumeClaimSpec{
StorageClassName: util.NewString("newStorage"),
},
},
Expand All @@ -558,8 +576,8 @@ func TestCreatePlan(t *testing.T) {
Name: "Change Storage for Agents with deprecated storage class name",
context: &testContext{
ArangoDeployment: deploymentTemplate.DeepCopy(),
PVC: &v1.PersistentVolumeClaim{
Spec: v1.PersistentVolumeClaimSpec{
PVC: &core.PersistentVolumeClaim{
Spec: core.PersistentVolumeClaimSpec{
StorageClassName: util.NewString("oldStorage"),
},
},
Expand All @@ -584,17 +602,17 @@ func TestCreatePlan(t *testing.T) {
Name: "Storage for Coordinators is not possible",
context: &testContext{
ArangoDeployment: deploymentTemplate.DeepCopy(),
PVC: &v1.PersistentVolumeClaim{
Spec: v1.PersistentVolumeClaimSpec{
PVC: &core.PersistentVolumeClaim{
Spec: core.PersistentVolumeClaimSpec{
StorageClassName: util.NewString("oldStorage"),
},
},
},
Helper: func(ad *api.ArangoDeployment) {
ad.Spec.Coordinators = api.ServerGroupSpec{
Count: util.NewInt(3),
VolumeClaimTemplate: &v1.PersistentVolumeClaim{
Spec: v1.PersistentVolumeClaimSpec{
VolumeClaimTemplate: &core.PersistentVolumeClaim{
Spec: core.PersistentVolumeClaimSpec{
StorageClassName: util.NewString("newStorage"),
},
},
Expand All @@ -605,7 +623,7 @@ func TestCreatePlan(t *testing.T) {
ExpectedPlan: []api.Action{},
ExpectedLog: "Storage class has changed - pod needs replacement",
ExpectedEvent: &k8sutil.Event{
Type: v1.EventTypeNormal,
Type: core.EventTypeNormal,
Reason: "Coordinator Member StorageClass Cannot Change",
Message: "Member 1 with role coordinator should use a different StorageClass, but is cannot because: Not supported",
},
Expand All @@ -614,15 +632,15 @@ func TestCreatePlan(t *testing.T) {
Name: "Create rotation plan",
context: &testContext{
ArangoDeployment: deploymentTemplate.DeepCopy(),
PVC: &v1.PersistentVolumeClaim{
Spec: v1.PersistentVolumeClaimSpec{
PVC: &core.PersistentVolumeClaim{
Spec: core.PersistentVolumeClaimSpec{
StorageClassName: util.NewString("oldStorage"),
},
Status: v1.PersistentVolumeClaimStatus{
Conditions: []v1.PersistentVolumeClaimCondition{
Status: core.PersistentVolumeClaimStatus{
Conditions: []core.PersistentVolumeClaimCondition{
{
Type: v1.PersistentVolumeClaimFileSystemResizePending,
Status: v1.ConditionTrue,
Type: core.PersistentVolumeClaimFileSystemResizePending,
Status: core.ConditionTrue,
},
},
},
Expand All @@ -631,8 +649,8 @@ func TestCreatePlan(t *testing.T) {
Helper: func(ad *api.ArangoDeployment) {
ad.Spec.Agents = api.ServerGroupSpec{
Count: util.NewInt(2),
VolumeClaimTemplate: &v1.PersistentVolumeClaim{
Spec: v1.PersistentVolumeClaimSpec{
VolumeClaimTemplate: &core.PersistentVolumeClaim{
Spec: core.PersistentVolumeClaimSpec{
StorageClassName: util.NewString("oldStorage"),
},
},
Expand Down Expand Up @@ -676,7 +694,7 @@ func TestCreatePlan(t *testing.T) {
ad.Status.Members.DBServers[0].Conditions = api.ConditionList{
{
Type: api.ConditionTypeCleanedOut,
Status: v1.ConditionTrue,
Status: core.ConditionTrue,
},
}
},
Expand Down
Loading