From 7a7abec06ad122abeb23f90000a7a31b2bb0b255 Mon Sep 17 00:00:00 2001 From: Ewout Prangsma Date: Thu, 1 Mar 2018 09:30:44 +0100 Subject: [PATCH 1/3] Adding commandline generation tests --- pkg/deployment/pod_creator.go | 39 ++++++--- pkg/deployment/pod_creator_test.go | 135 +++++++++++++++++++++++++++++ 2 files changed, 163 insertions(+), 11 deletions(-) create mode 100644 pkg/deployment/pod_creator_test.go diff --git a/pkg/deployment/pod_creator.go b/pkg/deployment/pod_creator.go index 5a66e60ca..71420c33a 100644 --- a/pkg/deployment/pod_creator.go +++ b/pkg/deployment/pod_creator.go @@ -26,13 +26,16 @@ import ( "fmt" "net" "path/filepath" + "sort" "strconv" + "strings" api "github.com/arangodb/k8s-operator/pkg/apis/arangodb/v1alpha" "github.com/arangodb/k8s-operator/pkg/util/arangod" "github.com/arangodb/k8s-operator/pkg/util/constants" "github.com/arangodb/k8s-operator/pkg/util/k8sutil" "github.com/pkg/errors" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) type optionPair struct { @@ -40,8 +43,19 @@ type optionPair struct { 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) +} + // createArangodArgs creates command line arguments for an arangod server in the given group. -func (d *Deployment) createArangodArgs(apiObject *api.ArangoDeployment, group api.ServerGroup, spec api.ServerGroupSpec, agents api.MemberStatusList, id string) []string { +func createArangodArgs(apiObject metav1.Object, deplSpec api.DeploymentSpec, group api.ServerGroup, svrSpec api.ServerGroupSpec, agents api.MemberStatusList, id string) []string { options := make([]optionPair, 0, 64) // Endpoint @@ -56,7 +70,7 @@ func (d *Deployment) createArangodArgs(apiObject *api.ArangoDeployment, group ap ) // Authentication - if apiObject.Spec.IsAuthenticated() { + if deplSpec.IsAuthenticated() { // With authentication options = append(options, optionPair{"--server.authentication", "true"}, @@ -71,7 +85,7 @@ func (d *Deployment) createArangodArgs(apiObject *api.ArangoDeployment, group ap // Storage engine options = append(options, - optionPair{"--server.storage-engine", string(apiObject.Spec.StorageEngine)}, + optionPair{"--server.storage-engine", string(deplSpec.StorageEngine)}, ) // Logging @@ -94,7 +108,7 @@ func (d *Deployment) createArangodArgs(apiObject *api.ArangoDeployment, group ap }*/ // RocksDB - if apiObject.Spec.RocksDB.IsEncrypted() { + if deplSpec.RocksDB.IsEncrypted() { keyPath := filepath.Join(k8sutil.RocksDBEncryptionVolumeMountDir, "key") options = append(options, optionPair{"--rocksdb.encryption-keyfile", keyPath}, @@ -121,7 +135,7 @@ func (d *Deployment) createArangodArgs(apiObject *api.ArangoDeployment, group ap optionPair{"--cluster.my-id", id}, optionPair{"--agency.activate", "true"}, optionPair{"--agency.my-address", myTCPURL}, - optionPair{"--agency.size", strconv.Itoa(apiObject.Spec.Agents.Count)}, + optionPair{"--agency.size", strconv.Itoa(deplSpec.Agents.Count)}, optionPair{"--agency.supervision", "true"}, optionPair{"--foxx.queues", "false"}, optionPair{"--server.statistics", "false"}, @@ -162,7 +176,7 @@ func (d *Deployment) createArangodArgs(apiObject *api.ArangoDeployment, group ap optionPair{"--foxx.queues", "true"}, optionPair{"--server.statistics", "true"}, ) - if apiObject.Spec.Mode == api.DeploymentModeResilientSingle { + if deplSpec.Mode == api.DeploymentModeResilientSingle { addAgentEndpoints = true options = append(options, optionPair{"--replication.automatic-failover", "true"}, @@ -182,17 +196,20 @@ func (d *Deployment) createArangodArgs(apiObject *api.ArangoDeployment, group ap } } - args := make([]string, 0, len(options)+len(spec.Args)) + args := make([]string, 0, len(options)+len(svrSpec.Args)) + sort.Slice(options, func(i, j int) bool { + return options[i].CompareTo(options[j]) < 0 + }) for _, o := range options { args = append(args, o.Key+"="+o.Value) } - args = append(args, spec.Args...) + args = append(args, svrSpec.Args...) return args } // createArangoSyncArgs creates command line arguments for an arangosync server in the given group. -func (d *Deployment) createArangoSyncArgs(apiObject *api.ArangoDeployment, group api.ServerGroup, spec api.ServerGroupSpec, agents api.MemberStatusList, id string) []string { +func createArangoSyncArgs(apiObject *api.ArangoDeployment, group api.ServerGroup, spec api.ServerGroupSpec, agents api.MemberStatusList, id string) []string { // TODO return nil } @@ -291,7 +308,7 @@ func (d *Deployment) ensurePods(apiObject *api.ArangoDeployment) error { // Create pod role := group.AsRole() if group.IsArangod() { - args := d.createArangodArgs(apiObject, group, spec, d.status.Members.Agents, m.ID) + args := createArangodArgs(apiObject, apiObject.Spec, group, spec, d.status.Members.Agents, m.ID) env := make(map[string]k8sutil.EnvValue) livenessProbe, err := d.createLivenessProbe(apiObject, group) if err != nil { @@ -318,7 +335,7 @@ func (d *Deployment) ensurePods(apiObject *api.ArangoDeployment) error { return maskAny(err) } } else if group.IsArangosync() { - args := d.createArangoSyncArgs(apiObject, group, spec, d.status.Members.Agents, m.ID) + args := createArangoSyncArgs(apiObject, group, spec, d.status.Members.Agents, m.ID) env := make(map[string]k8sutil.EnvValue) livenessProbe, err := d.createLivenessProbe(apiObject, group) if err != nil { diff --git a/pkg/deployment/pod_creator_test.go b/pkg/deployment/pod_creator_test.go new file mode 100644 index 000000000..533fd7390 --- /dev/null +++ b/pkg/deployment/pod_creator_test.go @@ -0,0 +1,135 @@ +// +// DISCLAIMER +// +// Copyright 2018 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 Ewout Prangsma +// + +package deployment + +import ( + "testing" + + api "github.com/arangodb/k8s-operator/pkg/apis/arangodb/v1alpha" + "github.com/stretchr/testify/assert" +) + +// TestCreateArangodArgs tests createArangodArgs. +func TestCreateArangodArgsSingle(t *testing.T) { + // Default deployment + { + apiObject := &api.ArangoDeployment{ + Spec: api.DeploymentSpec{ + Mode: api.DeploymentModeSingle, + }, + } + apiObject.Spec.SetDefaults("test") + cmdline := createArangodArgs(apiObject, apiObject.Spec, api.ServerGroupSingle, apiObject.Spec.Single, nil, "id1") + assert.Equal(t, + []string{ + "--database.directory=/data", + "--foxx.queues=true", + "--log.level=INFO", + "--log.output=+", + "--server.authentication=true", + "--server.endpoint=tcp://[::]:8529", + "--server.jwt-secret=$(ARANGOD_JWT_SECRET)", + "--server.statistics=true", + "--server.storage-engine=mmfiles", + }, + cmdline, + ) + } + + // Default deployment with mmfiles + { + apiObject := &api.ArangoDeployment{ + Spec: api.DeploymentSpec{ + Mode: api.DeploymentModeSingle, + StorageEngine: api.StorageEngineMMFiles, + }, + } + apiObject.Spec.SetDefaults("test") + cmdline := createArangodArgs(apiObject, apiObject.Spec, api.ServerGroupSingle, apiObject.Spec.Single, nil, "id1") + assert.Equal(t, + []string{ + "--database.directory=/data", + "--foxx.queues=true", + "--log.level=INFO", + "--log.output=+", + "--server.authentication=true", + "--server.endpoint=tcp://[::]:8529", + "--server.jwt-secret=$(ARANGOD_JWT_SECRET)", + "--server.statistics=true", + "--server.storage-engine=mmfiles", + }, + cmdline, + ) + } + + // Default deployment with rocksdb + { + apiObject := &api.ArangoDeployment{ + Spec: api.DeploymentSpec{ + Mode: api.DeploymentModeSingle, + StorageEngine: api.StorageEngineRocksDB, + }, + } + apiObject.Spec.SetDefaults("test") + cmdline := createArangodArgs(apiObject, apiObject.Spec, api.ServerGroupSingle, apiObject.Spec.Single, nil, "id1") + assert.Equal(t, + []string{ + "--database.directory=/data", + "--foxx.queues=true", + "--log.level=INFO", + "--log.output=+", + "--server.authentication=true", + "--server.endpoint=tcp://[::]:8529", + "--server.jwt-secret=$(ARANGOD_JWT_SECRET)", + "--server.statistics=true", + "--server.storage-engine=rocksdb", + }, + cmdline, + ) + } + + // No authentication + { + apiObject := &api.ArangoDeployment{ + Spec: api.DeploymentSpec{ + Mode: api.DeploymentModeSingle, + }, + } + apiObject.Spec.Authentication.JWTSecretName = "None" + apiObject.Spec.SetDefaults("test") + cmdline := createArangodArgs(apiObject, apiObject.Spec, api.ServerGroupSingle, apiObject.Spec.Single, nil, "id1") + assert.Equal(t, + []string{ + "--database.directory=/data", + "--foxx.queues=true", + "--log.level=INFO", + "--log.output=+", + "--server.authentication=false", + "--server.endpoint=tcp://[::]:8529", + "--server.statistics=true", + "--server.storage-engine=mmfiles", + }, + cmdline, + ) + } +} From 3f4e820ba37a58a5161f37070b66fb3139da0191 Mon Sep 17 00:00:00 2001 From: Ewout Prangsma Date: Thu, 1 Mar 2018 10:33:41 +0100 Subject: [PATCH 2/3] Added command line argument tests --- pkg/deployment/pod_creator_agent_args_test.go | 161 ++++++++++++++++++ .../pod_creator_coordinator_args_test.go | 158 +++++++++++++++++ .../pod_creator_dbserver_args_test.go | 158 +++++++++++++++++ ...est.go => pod_creator_single_args_test.go} | 73 +++++++- 4 files changed, 549 insertions(+), 1 deletion(-) create mode 100644 pkg/deployment/pod_creator_agent_args_test.go create mode 100644 pkg/deployment/pod_creator_coordinator_args_test.go create mode 100644 pkg/deployment/pod_creator_dbserver_args_test.go rename pkg/deployment/{pod_creator_test.go => pod_creator_single_args_test.go} (63%) diff --git a/pkg/deployment/pod_creator_agent_args_test.go b/pkg/deployment/pod_creator_agent_args_test.go new file mode 100644 index 000000000..0d777dab4 --- /dev/null +++ b/pkg/deployment/pod_creator_agent_args_test.go @@ -0,0 +1,161 @@ +// +// DISCLAIMER +// +// Copyright 2018 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 Ewout Prangsma +// + +package deployment + +import ( + "testing" + + "github.com/stretchr/testify/assert" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + + api "github.com/arangodb/k8s-operator/pkg/apis/arangodb/v1alpha" +) + +// TestCreateArangodArgsAgent tests createArangodArgs for agent. +func TestCreateArangodArgsAgent(t *testing.T) { + // Default deployment + { + apiObject := &api.ArangoDeployment{ + ObjectMeta: metav1.ObjectMeta{ + Name: "name", + Namespace: "ns", + }, + Spec: api.DeploymentSpec{ + Mode: api.DeploymentModeCluster, + }, + } + apiObject.Spec.SetDefaults("test") + agents := api.MemberStatusList{ + api.MemberStatus{ID: "a1"}, + api.MemberStatus{ID: "a2"}, + api.MemberStatus{ID: "a3"}, + } + cmdline := createArangodArgs(apiObject, apiObject.Spec, api.ServerGroupAgents, apiObject.Spec.Agents, agents, "a1") + assert.Equal(t, + []string{ + "--agency.activate=true", + "--agency.endpoint=tcp://name-agent-a2.name-int.ns.svc:8529", + "--agency.endpoint=tcp://name-agent-a3.name-int.ns.svc:8529", + "--agency.my-address=tcp://name-agent-a1.name-int.ns.svc:8529", + "--agency.size=3", + "--agency.supervision=true", + "--cluster.my-id=a1", + "--database.directory=/data", + "--foxx.queues=false", + "--log.level=INFO", + "--log.output=+", + "--server.authentication=true", + "--server.endpoint=tcp://[::]:8529", + "--server.jwt-secret=$(ARANGOD_JWT_SECRET)", + "--server.statistics=false", + "--server.storage-engine=mmfiles", + }, + cmdline, + ) + } + + // No authentication + { + apiObject := &api.ArangoDeployment{ + ObjectMeta: metav1.ObjectMeta{ + Name: "name", + Namespace: "ns", + }, + Spec: api.DeploymentSpec{ + Mode: api.DeploymentModeCluster, + }, + } + apiObject.Spec.SetDefaults("test") + apiObject.Spec.Authentication.JWTSecretName = "None" + agents := api.MemberStatusList{ + api.MemberStatus{ID: "a1"}, + api.MemberStatus{ID: "a2"}, + api.MemberStatus{ID: "a3"}, + } + cmdline := createArangodArgs(apiObject, apiObject.Spec, api.ServerGroupAgents, apiObject.Spec.Agents, agents, "a1") + assert.Equal(t, + []string{ + "--agency.activate=true", + "--agency.endpoint=tcp://name-agent-a2.name-int.ns.svc:8529", + "--agency.endpoint=tcp://name-agent-a3.name-int.ns.svc:8529", + "--agency.my-address=tcp://name-agent-a1.name-int.ns.svc:8529", + "--agency.size=3", + "--agency.supervision=true", + "--cluster.my-id=a1", + "--database.directory=/data", + "--foxx.queues=false", + "--log.level=INFO", + "--log.output=+", + "--server.authentication=false", + "--server.endpoint=tcp://[::]:8529", + "--server.statistics=false", + "--server.storage-engine=mmfiles", + }, + cmdline, + ) + } + + // Custom args + { + apiObject := &api.ArangoDeployment{ + ObjectMeta: metav1.ObjectMeta{ + Name: "name", + Namespace: "ns", + }, + Spec: api.DeploymentSpec{ + Mode: api.DeploymentModeCluster, + }, + } + apiObject.Spec.SetDefaults("test") + apiObject.Spec.Agents.Args = []string{"--foo1", "--foo2"} + agents := api.MemberStatusList{ + api.MemberStatus{ID: "a1"}, + api.MemberStatus{ID: "a2"}, + api.MemberStatus{ID: "a3"}, + } + cmdline := createArangodArgs(apiObject, apiObject.Spec, api.ServerGroupAgents, apiObject.Spec.Agents, agents, "a1") + assert.Equal(t, + []string{ + "--agency.activate=true", + "--agency.endpoint=tcp://name-agent-a2.name-int.ns.svc:8529", + "--agency.endpoint=tcp://name-agent-a3.name-int.ns.svc:8529", + "--agency.my-address=tcp://name-agent-a1.name-int.ns.svc:8529", + "--agency.size=3", + "--agency.supervision=true", + "--cluster.my-id=a1", + "--database.directory=/data", + "--foxx.queues=false", + "--log.level=INFO", + "--log.output=+", + "--server.authentication=true", + "--server.endpoint=tcp://[::]:8529", + "--server.jwt-secret=$(ARANGOD_JWT_SECRET)", + "--server.statistics=false", + "--server.storage-engine=mmfiles", + "--foo1", + "--foo2", + }, + cmdline, + ) + } +} diff --git a/pkg/deployment/pod_creator_coordinator_args_test.go b/pkg/deployment/pod_creator_coordinator_args_test.go new file mode 100644 index 000000000..30d553de7 --- /dev/null +++ b/pkg/deployment/pod_creator_coordinator_args_test.go @@ -0,0 +1,158 @@ +// +// DISCLAIMER +// +// Copyright 2018 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 Ewout Prangsma +// + +package deployment + +import ( + "testing" + + "github.com/stretchr/testify/assert" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + + api "github.com/arangodb/k8s-operator/pkg/apis/arangodb/v1alpha" +) + +// TestCreateArangodArgsCoordinator tests createArangodArgs for coordinator. +func TestCreateArangodArgsCoordinator(t *testing.T) { + // Default deployment + { + apiObject := &api.ArangoDeployment{ + ObjectMeta: metav1.ObjectMeta{ + Name: "name", + Namespace: "ns", + }, + Spec: api.DeploymentSpec{ + Mode: api.DeploymentModeCluster, + }, + } + apiObject.Spec.SetDefaults("test") + agents := api.MemberStatusList{ + api.MemberStatus{ID: "a1"}, + api.MemberStatus{ID: "a2"}, + api.MemberStatus{ID: "a3"}, + } + cmdline := createArangodArgs(apiObject, apiObject.Spec, api.ServerGroupCoordinators, apiObject.Spec.Coordinators, agents, "id1") + assert.Equal(t, + []string{ + "--cluster.agency-endpoint=tcp://name-agent-a1.name-int.ns.svc:8529", + "--cluster.agency-endpoint=tcp://name-agent-a2.name-int.ns.svc:8529", + "--cluster.agency-endpoint=tcp://name-agent-a3.name-int.ns.svc:8529", + "--cluster.my-address=tcp://name-coordinator-id1.name-int.ns.svc:8529", + "--cluster.my-id=id1", + "--cluster.my-role=COORDINATOR", + "--database.directory=/data", + "--foxx.queues=true", + "--log.level=INFO", + "--log.output=+", + "--server.authentication=true", + "--server.endpoint=tcp://[::]:8529", + "--server.jwt-secret=$(ARANGOD_JWT_SECRET)", + "--server.statistics=true", + "--server.storage-engine=mmfiles", + }, + cmdline, + ) + } + + // No authentication + { + apiObject := &api.ArangoDeployment{ + ObjectMeta: metav1.ObjectMeta{ + Name: "name", + Namespace: "ns", + }, + Spec: api.DeploymentSpec{ + Mode: api.DeploymentModeCluster, + }, + } + apiObject.Spec.SetDefaults("test") + apiObject.Spec.Authentication.JWTSecretName = "None" + agents := api.MemberStatusList{ + api.MemberStatus{ID: "a1"}, + api.MemberStatus{ID: "a2"}, + api.MemberStatus{ID: "a3"}, + } + cmdline := createArangodArgs(apiObject, apiObject.Spec, api.ServerGroupCoordinators, apiObject.Spec.Coordinators, agents, "id1") + assert.Equal(t, + []string{ + "--cluster.agency-endpoint=tcp://name-agent-a1.name-int.ns.svc:8529", + "--cluster.agency-endpoint=tcp://name-agent-a2.name-int.ns.svc:8529", + "--cluster.agency-endpoint=tcp://name-agent-a3.name-int.ns.svc:8529", + "--cluster.my-address=tcp://name-coordinator-id1.name-int.ns.svc:8529", + "--cluster.my-id=id1", + "--cluster.my-role=COORDINATOR", + "--database.directory=/data", + "--foxx.queues=true", + "--log.level=INFO", + "--log.output=+", + "--server.authentication=false", + "--server.endpoint=tcp://[::]:8529", + "--server.statistics=true", + "--server.storage-engine=mmfiles", + }, + cmdline, + ) + } + + // Custom args + { + apiObject := &api.ArangoDeployment{ + ObjectMeta: metav1.ObjectMeta{ + Name: "name", + Namespace: "ns", + }, + Spec: api.DeploymentSpec{ + Mode: api.DeploymentModeCluster, + }, + } + apiObject.Spec.SetDefaults("test") + apiObject.Spec.Coordinators.Args = []string{"--foo1", "--foo2"} + agents := api.MemberStatusList{ + api.MemberStatus{ID: "a1"}, + api.MemberStatus{ID: "a2"}, + api.MemberStatus{ID: "a3"}, + } + cmdline := createArangodArgs(apiObject, apiObject.Spec, api.ServerGroupCoordinators, apiObject.Spec.Coordinators, agents, "id1") + assert.Equal(t, + []string{ + "--cluster.agency-endpoint=tcp://name-agent-a1.name-int.ns.svc:8529", + "--cluster.agency-endpoint=tcp://name-agent-a2.name-int.ns.svc:8529", + "--cluster.agency-endpoint=tcp://name-agent-a3.name-int.ns.svc:8529", + "--cluster.my-address=tcp://name-coordinator-id1.name-int.ns.svc:8529", + "--cluster.my-id=id1", + "--cluster.my-role=COORDINATOR", + "--database.directory=/data", + "--foxx.queues=true", + "--log.level=INFO", + "--log.output=+", + "--server.authentication=true", + "--server.endpoint=tcp://[::]:8529", + "--server.jwt-secret=$(ARANGOD_JWT_SECRET)", + "--server.statistics=true", + "--server.storage-engine=mmfiles", + "--foo1", + "--foo2", + }, + cmdline, + ) + } +} diff --git a/pkg/deployment/pod_creator_dbserver_args_test.go b/pkg/deployment/pod_creator_dbserver_args_test.go new file mode 100644 index 000000000..5ae94ccd4 --- /dev/null +++ b/pkg/deployment/pod_creator_dbserver_args_test.go @@ -0,0 +1,158 @@ +// +// DISCLAIMER +// +// Copyright 2018 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 Ewout Prangsma +// + +package deployment + +import ( + "testing" + + "github.com/stretchr/testify/assert" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + + api "github.com/arangodb/k8s-operator/pkg/apis/arangodb/v1alpha" +) + +// TestCreateArangodArgsDBServer tests createArangodArgs for dbserver. +func TestCreateArangodArgsDBServer(t *testing.T) { + // Default deployment + { + apiObject := &api.ArangoDeployment{ + ObjectMeta: metav1.ObjectMeta{ + Name: "name", + Namespace: "ns", + }, + Spec: api.DeploymentSpec{ + Mode: api.DeploymentModeCluster, + }, + } + apiObject.Spec.SetDefaults("test") + agents := api.MemberStatusList{ + api.MemberStatus{ID: "a1"}, + api.MemberStatus{ID: "a2"}, + api.MemberStatus{ID: "a3"}, + } + cmdline := createArangodArgs(apiObject, apiObject.Spec, api.ServerGroupDBServers, apiObject.Spec.DBServers, agents, "id1") + assert.Equal(t, + []string{ + "--cluster.agency-endpoint=tcp://name-agent-a1.name-int.ns.svc:8529", + "--cluster.agency-endpoint=tcp://name-agent-a2.name-int.ns.svc:8529", + "--cluster.agency-endpoint=tcp://name-agent-a3.name-int.ns.svc:8529", + "--cluster.my-address=tcp://name-dbserver-id1.name-int.ns.svc:8529", + "--cluster.my-id=id1", + "--cluster.my-role=PRIMARY", + "--database.directory=/data", + "--foxx.queues=false", + "--log.level=INFO", + "--log.output=+", + "--server.authentication=true", + "--server.endpoint=tcp://[::]:8529", + "--server.jwt-secret=$(ARANGOD_JWT_SECRET)", + "--server.statistics=true", + "--server.storage-engine=mmfiles", + }, + cmdline, + ) + } + + // No authentication + { + apiObject := &api.ArangoDeployment{ + ObjectMeta: metav1.ObjectMeta{ + Name: "name", + Namespace: "ns", + }, + Spec: api.DeploymentSpec{ + Mode: api.DeploymentModeCluster, + }, + } + apiObject.Spec.SetDefaults("test") + apiObject.Spec.Authentication.JWTSecretName = "None" + agents := api.MemberStatusList{ + api.MemberStatus{ID: "a1"}, + api.MemberStatus{ID: "a2"}, + api.MemberStatus{ID: "a3"}, + } + cmdline := createArangodArgs(apiObject, apiObject.Spec, api.ServerGroupDBServers, apiObject.Spec.DBServers, agents, "id1") + assert.Equal(t, + []string{ + "--cluster.agency-endpoint=tcp://name-agent-a1.name-int.ns.svc:8529", + "--cluster.agency-endpoint=tcp://name-agent-a2.name-int.ns.svc:8529", + "--cluster.agency-endpoint=tcp://name-agent-a3.name-int.ns.svc:8529", + "--cluster.my-address=tcp://name-dbserver-id1.name-int.ns.svc:8529", + "--cluster.my-id=id1", + "--cluster.my-role=PRIMARY", + "--database.directory=/data", + "--foxx.queues=false", + "--log.level=INFO", + "--log.output=+", + "--server.authentication=false", + "--server.endpoint=tcp://[::]:8529", + "--server.statistics=true", + "--server.storage-engine=mmfiles", + }, + cmdline, + ) + } + + // Custom args + { + apiObject := &api.ArangoDeployment{ + ObjectMeta: metav1.ObjectMeta{ + Name: "name", + Namespace: "ns", + }, + Spec: api.DeploymentSpec{ + Mode: api.DeploymentModeCluster, + }, + } + apiObject.Spec.SetDefaults("test") + apiObject.Spec.DBServers.Args = []string{"--foo1", "--foo2"} + agents := api.MemberStatusList{ + api.MemberStatus{ID: "a1"}, + api.MemberStatus{ID: "a2"}, + api.MemberStatus{ID: "a3"}, + } + cmdline := createArangodArgs(apiObject, apiObject.Spec, api.ServerGroupDBServers, apiObject.Spec.DBServers, agents, "id1") + assert.Equal(t, + []string{ + "--cluster.agency-endpoint=tcp://name-agent-a1.name-int.ns.svc:8529", + "--cluster.agency-endpoint=tcp://name-agent-a2.name-int.ns.svc:8529", + "--cluster.agency-endpoint=tcp://name-agent-a3.name-int.ns.svc:8529", + "--cluster.my-address=tcp://name-dbserver-id1.name-int.ns.svc:8529", + "--cluster.my-id=id1", + "--cluster.my-role=PRIMARY", + "--database.directory=/data", + "--foxx.queues=false", + "--log.level=INFO", + "--log.output=+", + "--server.authentication=true", + "--server.endpoint=tcp://[::]:8529", + "--server.jwt-secret=$(ARANGOD_JWT_SECRET)", + "--server.statistics=true", + "--server.storage-engine=mmfiles", + "--foo1", + "--foo2", + }, + cmdline, + ) + } +} diff --git a/pkg/deployment/pod_creator_test.go b/pkg/deployment/pod_creator_single_args_test.go similarity index 63% rename from pkg/deployment/pod_creator_test.go rename to pkg/deployment/pod_creator_single_args_test.go index 533fd7390..4681cfa30 100644 --- a/pkg/deployment/pod_creator_test.go +++ b/pkg/deployment/pod_creator_single_args_test.go @@ -25,11 +25,13 @@ package deployment import ( "testing" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + api "github.com/arangodb/k8s-operator/pkg/apis/arangodb/v1alpha" "github.com/stretchr/testify/assert" ) -// TestCreateArangodArgs tests createArangodArgs. +// TestCreateArangodArgsSingle tests createArangodArgs for single server. func TestCreateArangodArgsSingle(t *testing.T) { // Default deployment { @@ -132,4 +134,73 @@ func TestCreateArangodArgsSingle(t *testing.T) { cmdline, ) } + + // Custom args + { + apiObject := &api.ArangoDeployment{ + Spec: api.DeploymentSpec{ + Mode: api.DeploymentModeSingle, + }, + } + apiObject.Spec.Single.Args = []string{"--foo1", "--foo2"} + apiObject.Spec.SetDefaults("test") + cmdline := createArangodArgs(apiObject, apiObject.Spec, api.ServerGroupSingle, apiObject.Spec.Single, nil, "id1") + assert.Equal(t, + []string{ + "--database.directory=/data", + "--foxx.queues=true", + "--log.level=INFO", + "--log.output=+", + "--server.authentication=true", + "--server.endpoint=tcp://[::]:8529", + "--server.jwt-secret=$(ARANGOD_JWT_SECRET)", + "--server.statistics=true", + "--server.storage-engine=mmfiles", + "--foo1", + "--foo2", + }, + cmdline, + ) + } + + // Resilient single + { + apiObject := &api.ArangoDeployment{ + ObjectMeta: metav1.ObjectMeta{ + Name: "name", + Namespace: "ns", + }, + Spec: api.DeploymentSpec{ + Mode: api.DeploymentModeResilientSingle, + }, + } + apiObject.Spec.SetDefaults("test") + agents := api.MemberStatusList{ + api.MemberStatus{ID: "a1"}, + api.MemberStatus{ID: "a2"}, + api.MemberStatus{ID: "a3"}, + } + cmdline := createArangodArgs(apiObject, apiObject.Spec, api.ServerGroupSingle, apiObject.Spec.Single, agents, "id1") + assert.Equal(t, + []string{ + "--cluster.agency-endpoint=tcp://name-agent-a1.name-int.ns.svc:8529", + "--cluster.agency-endpoint=tcp://name-agent-a2.name-int.ns.svc:8529", + "--cluster.agency-endpoint=tcp://name-agent-a3.name-int.ns.svc:8529", + "--cluster.my-address=tcp://name-single-id1.name-int.ns.svc:8529", + "--cluster.my-id=id1", + "--cluster.my-role=SINGLE", + "--database.directory=/data", + "--foxx.queues=true", + "--log.level=INFO", + "--log.output=+", + "--replication.automatic-failover=true", + "--server.authentication=true", + "--server.endpoint=tcp://[::]:8529", + "--server.jwt-secret=$(ARANGOD_JWT_SECRET)", + "--server.statistics=true", + "--server.storage-engine=mmfiles", + }, + cmdline, + ) + } } From 2b53e7b3389110992ea680fceb7197692c3d4a8d Mon Sep 17 00:00:00 2001 From: Ewout Prangsma Date: Thu, 1 Mar 2018 10:54:09 +0100 Subject: [PATCH 3/3] Updated tests wrt changed default for storage engine --- Makefile | 3 +- pkg/deployment/pod_creator_agent_args_test.go | 7 ++-- .../pod_creator_coordinator_args_test.go | 7 ++-- .../pod_creator_dbserver_args_test.go | 7 ++-- .../pod_creator_single_args_test.go | 34 +++---------------- 5 files changed, 18 insertions(+), 40 deletions(-) diff --git a/Makefile b/Makefile index e17700402..f2617f04b 100644 --- a/Makefile +++ b/Makefile @@ -160,7 +160,8 @@ run-unit-tests: $(GOBUILDDIR) $(SOURCES) -w /usr/code/ \ golang:$(GOVERSION) \ go test -v \ - $(REPOPATH)/pkg/apis/arangodb/v1alpha + $(REPOPATH)/pkg/apis/arangodb/v1alpha \ + $(REPOPATH)/pkg/deployment $(TESTBIN): $(GOBUILDDIR) $(SOURCES) @mkdir -p $(BINDIR) diff --git a/pkg/deployment/pod_creator_agent_args_test.go b/pkg/deployment/pod_creator_agent_args_test.go index 0d777dab4..dace0e19d 100644 --- a/pkg/deployment/pod_creator_agent_args_test.go +++ b/pkg/deployment/pod_creator_agent_args_test.go @@ -68,13 +68,13 @@ func TestCreateArangodArgsAgent(t *testing.T) { "--server.endpoint=tcp://[::]:8529", "--server.jwt-secret=$(ARANGOD_JWT_SECRET)", "--server.statistics=false", - "--server.storage-engine=mmfiles", + "--server.storage-engine=rocksdb", }, cmdline, ) } - // No authentication + // No authentication, mmfiles { apiObject := &api.ArangoDeployment{ ObjectMeta: metav1.ObjectMeta{ @@ -87,6 +87,7 @@ func TestCreateArangodArgsAgent(t *testing.T) { } apiObject.Spec.SetDefaults("test") apiObject.Spec.Authentication.JWTSecretName = "None" + apiObject.Spec.StorageEngine = api.StorageEngineMMFiles agents := api.MemberStatusList{ api.MemberStatus{ID: "a1"}, api.MemberStatus{ID: "a2"}, @@ -151,7 +152,7 @@ func TestCreateArangodArgsAgent(t *testing.T) { "--server.endpoint=tcp://[::]:8529", "--server.jwt-secret=$(ARANGOD_JWT_SECRET)", "--server.statistics=false", - "--server.storage-engine=mmfiles", + "--server.storage-engine=rocksdb", "--foo1", "--foo2", }, diff --git a/pkg/deployment/pod_creator_coordinator_args_test.go b/pkg/deployment/pod_creator_coordinator_args_test.go index 30d553de7..d9cd5406e 100644 --- a/pkg/deployment/pod_creator_coordinator_args_test.go +++ b/pkg/deployment/pod_creator_coordinator_args_test.go @@ -67,7 +67,7 @@ func TestCreateArangodArgsCoordinator(t *testing.T) { "--server.endpoint=tcp://[::]:8529", "--server.jwt-secret=$(ARANGOD_JWT_SECRET)", "--server.statistics=true", - "--server.storage-engine=mmfiles", + "--server.storage-engine=rocksdb", }, cmdline, ) @@ -107,13 +107,13 @@ func TestCreateArangodArgsCoordinator(t *testing.T) { "--server.authentication=false", "--server.endpoint=tcp://[::]:8529", "--server.statistics=true", - "--server.storage-engine=mmfiles", + "--server.storage-engine=rocksdb", }, cmdline, ) } - // Custom args + // Custom args, RocksDB { apiObject := &api.ArangoDeployment{ ObjectMeta: metav1.ObjectMeta{ @@ -126,6 +126,7 @@ func TestCreateArangodArgsCoordinator(t *testing.T) { } apiObject.Spec.SetDefaults("test") apiObject.Spec.Coordinators.Args = []string{"--foo1", "--foo2"} + apiObject.Spec.StorageEngine = api.StorageEngineMMFiles agents := api.MemberStatusList{ api.MemberStatus{ID: "a1"}, api.MemberStatus{ID: "a2"}, diff --git a/pkg/deployment/pod_creator_dbserver_args_test.go b/pkg/deployment/pod_creator_dbserver_args_test.go index 5ae94ccd4..e8ca64f84 100644 --- a/pkg/deployment/pod_creator_dbserver_args_test.go +++ b/pkg/deployment/pod_creator_dbserver_args_test.go @@ -67,7 +67,7 @@ func TestCreateArangodArgsDBServer(t *testing.T) { "--server.endpoint=tcp://[::]:8529", "--server.jwt-secret=$(ARANGOD_JWT_SECRET)", "--server.statistics=true", - "--server.storage-engine=mmfiles", + "--server.storage-engine=rocksdb", }, cmdline, ) @@ -107,13 +107,13 @@ func TestCreateArangodArgsDBServer(t *testing.T) { "--server.authentication=false", "--server.endpoint=tcp://[::]:8529", "--server.statistics=true", - "--server.storage-engine=mmfiles", + "--server.storage-engine=rocksdb", }, cmdline, ) } - // Custom args + // Custom args, MMFiles { apiObject := &api.ArangoDeployment{ ObjectMeta: metav1.ObjectMeta{ @@ -125,6 +125,7 @@ func TestCreateArangodArgsDBServer(t *testing.T) { }, } apiObject.Spec.SetDefaults("test") + apiObject.Spec.StorageEngine = api.StorageEngineMMFiles apiObject.Spec.DBServers.Args = []string{"--foo1", "--foo2"} agents := api.MemberStatusList{ api.MemberStatus{ID: "a1"}, diff --git a/pkg/deployment/pod_creator_single_args_test.go b/pkg/deployment/pod_creator_single_args_test.go index 4681cfa30..a02b04ee0 100644 --- a/pkg/deployment/pod_creator_single_args_test.go +++ b/pkg/deployment/pod_creator_single_args_test.go @@ -52,7 +52,7 @@ func TestCreateArangodArgsSingle(t *testing.T) { "--server.endpoint=tcp://[::]:8529", "--server.jwt-secret=$(ARANGOD_JWT_SECRET)", "--server.statistics=true", - "--server.storage-engine=mmfiles", + "--server.storage-engine=rocksdb", }, cmdline, ) @@ -84,32 +84,6 @@ func TestCreateArangodArgsSingle(t *testing.T) { ) } - // Default deployment with rocksdb - { - apiObject := &api.ArangoDeployment{ - Spec: api.DeploymentSpec{ - Mode: api.DeploymentModeSingle, - StorageEngine: api.StorageEngineRocksDB, - }, - } - apiObject.Spec.SetDefaults("test") - cmdline := createArangodArgs(apiObject, apiObject.Spec, api.ServerGroupSingle, apiObject.Spec.Single, nil, "id1") - assert.Equal(t, - []string{ - "--database.directory=/data", - "--foxx.queues=true", - "--log.level=INFO", - "--log.output=+", - "--server.authentication=true", - "--server.endpoint=tcp://[::]:8529", - "--server.jwt-secret=$(ARANGOD_JWT_SECRET)", - "--server.statistics=true", - "--server.storage-engine=rocksdb", - }, - cmdline, - ) - } - // No authentication { apiObject := &api.ArangoDeployment{ @@ -129,7 +103,7 @@ func TestCreateArangodArgsSingle(t *testing.T) { "--server.authentication=false", "--server.endpoint=tcp://[::]:8529", "--server.statistics=true", - "--server.storage-engine=mmfiles", + "--server.storage-engine=rocksdb", }, cmdline, ) @@ -155,7 +129,7 @@ func TestCreateArangodArgsSingle(t *testing.T) { "--server.endpoint=tcp://[::]:8529", "--server.jwt-secret=$(ARANGOD_JWT_SECRET)", "--server.statistics=true", - "--server.storage-engine=mmfiles", + "--server.storage-engine=rocksdb", "--foo1", "--foo2", }, @@ -198,7 +172,7 @@ func TestCreateArangodArgsSingle(t *testing.T) { "--server.endpoint=tcp://[::]:8529", "--server.jwt-secret=$(ARANGOD_JWT_SECRET)", "--server.statistics=true", - "--server.storage-engine=mmfiles", + "--server.storage-engine=rocksdb", }, cmdline, )