Skip to content

Commit abf9275

Browse files
committed
Merged in master
2 parents 3849a30 + efc9fa1 commit abf9275

11 files changed

+267
-44
lines changed

Jenkinsfile.groovy

+5-3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ pipeline {
2525
}
2626
agent any
2727
parameters {
28+
booleanParam(name: 'LONG', defaultValue: false, description: 'Execute long running tests')
2829
string(name: 'KUBECONFIG', defaultValue: '/home/jenkins/.kube/scw-183a3b', description: 'KUBECONFIG controls which k8s cluster is used', )
2930
string(name: 'TESTNAMESPACE', defaultValue: 'jenkins', description: 'TESTNAMESPACE sets the kubernetes namespace to ru tests in (this must be short!!)', )
3031
string(name: 'ENTERPRISEIMAGE', defaultValue: '', description: 'ENTERPRISEIMAGE sets the docker image used for enterprise tests)', )
@@ -48,11 +49,12 @@ pipeline {
4849
lock("${params.TESTNAMESPACE}-${env.GIT_COMMIT}") {
4950
withCredentials([string(credentialsId: 'ENTERPRISEIMAGE', variable: 'DEFAULTENTERPRISEIMAGE')]) {
5051
withEnv([
51-
"KUBECONFIG=${params.KUBECONFIG}",
52-
"TESTNAMESPACE=${params.TESTNAMESPACE}-${env.GIT_COMMIT}",
52+
"ENTERPRISEIMAGE=${params.ENTERPRISEIMAGE}",
5353
"IMAGETAG=${env.GIT_COMMIT}",
54+
"KUBECONFIG=${params.KUBECONFIG}",
55+
"LONG=${params.LONG ? 1 : 0}",
5456
"PUSHIMAGES=1",
55-
"ENTERPRISEIMAGE=${params.ENTERPRISEIMAGE}",
57+
"TESTNAMESPACE=${params.TESTNAMESPACE}-${env.GIT_COMMIT}",
5658
]) {
5759
sh "make run-tests"
5860
}

Makefile

+9-2
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ GHRELEASE := $(GOBUILDDIR)/bin/github-release
5454
ifndef TESTNAMESPACE
5555
TESTNAMESPACE := arangodb-operator-tests
5656
endif
57+
TESTLENGTHOPTIONS := -test.short
58+
TESTTIMEOUT := 20m
59+
ifeq ($(LONG), 1)
60+
TESTLENGTHOPTIONS :=
61+
TESTTIMEOUT := 40m
62+
endif
5763

5864
SOURCES := $(shell find $(SRCDIR) -name '*.go' -not -path './test/*')
5965

@@ -161,7 +167,8 @@ run-unit-tests: $(GOBUILDDIR) $(SOURCES)
161167
golang:$(GOVERSION) \
162168
go test -v \
163169
$(REPOPATH)/pkg/apis/arangodb/v1alpha \
164-
$(REPOPATH)/pkg/deployment
170+
$(REPOPATH)/pkg/deployment \
171+
$(REPOPATH)/pkg/util/k8sutil
165172

166173
$(TESTBIN): $(GOBUILDDIR) $(SOURCES)
167174
@mkdir -p $(BINDIR)
@@ -194,7 +201,7 @@ endif
194201
--env="ENTERPRISEIMAGE=$(ENTERPRISEIMAGE)" \
195202
--env="TEST_NAMESPACE=$(TESTNAMESPACE)" \
196203
-- \
197-
-test.v
204+
-test.v -test.timeout $(TESTTIMEOUT) $(TESTLENGTHOPTIONS)
198205
kubectl delete namespace $(TESTNAMESPACE) --ignore-not-found --now
199206

200207
cleanup-tests:

docs/user/custom_resource.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ This setting specifies the type of storage engine used for all servers
101101
in the cluster.
102102
Possible values are:
103103

104-
- `mmfiles` (default) To use the MMfiles storage engine.
105-
- `rocksdb` To use the RocksDB storage engine.
104+
- `mmfiles` To use the MMfiles storage engine.
105+
- `rocksdb` (default) To use the RocksDB storage engine.
106106

107107
This setting cannot be changed after the cluster has been created.
108108

pkg/apis/arangodb/v1alpha/deployment_spec.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func (s *DeploymentSpec) SetDefaults(deploymentName string) {
8282
s.Environment = EnvironmentDevelopment
8383
}
8484
if s.StorageEngine == "" {
85-
s.StorageEngine = StorageEngineMMFiles
85+
s.StorageEngine = StorageEngineRocksDB
8686
}
8787
if s.Image == "" && s.IsDevelopment() {
8888
s.Image = defaultImage

pkg/util/k8sutil/affinity_test.go

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
//
2+
// DISCLAIMER
3+
//
4+
// Copyright 2018 ArangoDB GmbH, Cologne, Germany
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
//
18+
// Copyright holder is ArangoDB GmbH, Cologne, Germany
19+
//
20+
// Author Ewout Prangsma
21+
//
22+
23+
package k8sutil
24+
25+
import (
26+
"testing"
27+
28+
"github.com/stretchr/testify/assert"
29+
"github.com/stretchr/testify/require"
30+
)
31+
32+
// TestCreateAffinity tests createAffinity
33+
func TestCreateAffinity(t *testing.T) {
34+
// Required
35+
a := createAffinity("test", "role", true, "")
36+
assert.Nil(t, a.PodAffinity)
37+
require.NotNil(t, a.PodAntiAffinity)
38+
require.Len(t, a.PodAntiAffinity.RequiredDuringSchedulingIgnoredDuringExecution, 1)
39+
assert.Len(t, a.PodAntiAffinity.PreferredDuringSchedulingIgnoredDuringExecution, 0)
40+
assert.Equal(t, "kubernetes.io/hostname", a.PodAntiAffinity.RequiredDuringSchedulingIgnoredDuringExecution[0].TopologyKey)
41+
require.NotNil(t, a.PodAntiAffinity.RequiredDuringSchedulingIgnoredDuringExecution[0].LabelSelector)
42+
assert.Equal(t, "test", a.PodAntiAffinity.RequiredDuringSchedulingIgnoredDuringExecution[0].LabelSelector.MatchLabels["arango_deployment"])
43+
assert.Equal(t, "arangodb", a.PodAntiAffinity.RequiredDuringSchedulingIgnoredDuringExecution[0].LabelSelector.MatchLabels["app"])
44+
assert.Equal(t, "role", a.PodAntiAffinity.RequiredDuringSchedulingIgnoredDuringExecution[0].LabelSelector.MatchLabels["role"])
45+
46+
// Require & affinity with role dbserver
47+
a = createAffinity("test", "role", true, "dbserver")
48+
require.NotNil(t, a.PodAffinity)
49+
require.Len(t, a.PodAffinity.RequiredDuringSchedulingIgnoredDuringExecution, 1)
50+
assert.Len(t, a.PodAffinity.PreferredDuringSchedulingIgnoredDuringExecution, 0)
51+
assert.Equal(t, "kubernetes.io/hostname", a.PodAffinity.RequiredDuringSchedulingIgnoredDuringExecution[0].TopologyKey)
52+
require.NotNil(t, a.PodAffinity.RequiredDuringSchedulingIgnoredDuringExecution[0].LabelSelector)
53+
assert.Equal(t, "test", a.PodAffinity.RequiredDuringSchedulingIgnoredDuringExecution[0].LabelSelector.MatchLabels["arango_deployment"])
54+
assert.Equal(t, "arangodb", a.PodAffinity.RequiredDuringSchedulingIgnoredDuringExecution[0].LabelSelector.MatchLabels["app"])
55+
assert.Equal(t, "dbserver", a.PodAffinity.RequiredDuringSchedulingIgnoredDuringExecution[0].LabelSelector.MatchLabels["role"])
56+
57+
require.NotNil(t, a.PodAntiAffinity)
58+
require.Len(t, a.PodAntiAffinity.RequiredDuringSchedulingIgnoredDuringExecution, 1)
59+
assert.Len(t, a.PodAntiAffinity.PreferredDuringSchedulingIgnoredDuringExecution, 0)
60+
assert.Equal(t, "kubernetes.io/hostname", a.PodAntiAffinity.RequiredDuringSchedulingIgnoredDuringExecution[0].TopologyKey)
61+
require.NotNil(t, a.PodAntiAffinity.RequiredDuringSchedulingIgnoredDuringExecution[0].LabelSelector)
62+
assert.Equal(t, "test", a.PodAntiAffinity.RequiredDuringSchedulingIgnoredDuringExecution[0].LabelSelector.MatchLabels["arango_deployment"])
63+
assert.Equal(t, "arangodb", a.PodAntiAffinity.RequiredDuringSchedulingIgnoredDuringExecution[0].LabelSelector.MatchLabels["app"])
64+
assert.Equal(t, "role", a.PodAntiAffinity.RequiredDuringSchedulingIgnoredDuringExecution[0].LabelSelector.MatchLabels["role"])
65+
66+
// Not Required
67+
a = createAffinity("test", "role", false, "")
68+
assert.Nil(t, a.PodAffinity)
69+
require.NotNil(t, a.PodAntiAffinity)
70+
assert.Len(t, a.PodAntiAffinity.RequiredDuringSchedulingIgnoredDuringExecution, 0)
71+
require.Len(t, a.PodAntiAffinity.PreferredDuringSchedulingIgnoredDuringExecution, 1)
72+
assert.Equal(t, "kubernetes.io/hostname", a.PodAntiAffinity.PreferredDuringSchedulingIgnoredDuringExecution[0].PodAffinityTerm.TopologyKey)
73+
require.NotNil(t, a.PodAntiAffinity.PreferredDuringSchedulingIgnoredDuringExecution[0].PodAffinityTerm.LabelSelector)
74+
assert.Equal(t, "test", a.PodAntiAffinity.PreferredDuringSchedulingIgnoredDuringExecution[0].PodAffinityTerm.LabelSelector.MatchLabels["arango_deployment"])
75+
assert.Equal(t, "arangodb", a.PodAntiAffinity.PreferredDuringSchedulingIgnoredDuringExecution[0].PodAffinityTerm.LabelSelector.MatchLabels["app"])
76+
assert.Equal(t, "role", a.PodAntiAffinity.PreferredDuringSchedulingIgnoredDuringExecution[0].PodAffinityTerm.LabelSelector.MatchLabels["role"])
77+
78+
// Not Required & affinity with role dbserver
79+
a = createAffinity("test", "role", false, "dbserver")
80+
require.NotNil(t, a.PodAffinity)
81+
require.Len(t, a.PodAffinity.PreferredDuringSchedulingIgnoredDuringExecution, 1)
82+
assert.Len(t, a.PodAffinity.RequiredDuringSchedulingIgnoredDuringExecution, 0)
83+
assert.Equal(t, "kubernetes.io/hostname", a.PodAffinity.PreferredDuringSchedulingIgnoredDuringExecution[0].PodAffinityTerm.TopologyKey)
84+
require.NotNil(t, a.PodAffinity.PreferredDuringSchedulingIgnoredDuringExecution[0].PodAffinityTerm.LabelSelector)
85+
assert.Equal(t, "test", a.PodAffinity.PreferredDuringSchedulingIgnoredDuringExecution[0].PodAffinityTerm.LabelSelector.MatchLabels["arango_deployment"])
86+
assert.Equal(t, "arangodb", a.PodAffinity.PreferredDuringSchedulingIgnoredDuringExecution[0].PodAffinityTerm.LabelSelector.MatchLabels["app"])
87+
assert.Equal(t, "dbserver", a.PodAffinity.PreferredDuringSchedulingIgnoredDuringExecution[0].PodAffinityTerm.LabelSelector.MatchLabels["role"])
88+
89+
require.NotNil(t, a.PodAntiAffinity)
90+
require.Len(t, a.PodAntiAffinity.PreferredDuringSchedulingIgnoredDuringExecution, 1)
91+
assert.Len(t, a.PodAntiAffinity.RequiredDuringSchedulingIgnoredDuringExecution, 0)
92+
assert.Equal(t, "kubernetes.io/hostname", a.PodAntiAffinity.PreferredDuringSchedulingIgnoredDuringExecution[0].PodAffinityTerm.TopologyKey)
93+
require.NotNil(t, a.PodAntiAffinity.PreferredDuringSchedulingIgnoredDuringExecution[0].PodAffinityTerm.LabelSelector)
94+
assert.Equal(t, "test", a.PodAntiAffinity.PreferredDuringSchedulingIgnoredDuringExecution[0].PodAffinityTerm.LabelSelector.MatchLabels["arango_deployment"])
95+
assert.Equal(t, "arangodb", a.PodAntiAffinity.PreferredDuringSchedulingIgnoredDuringExecution[0].PodAffinityTerm.LabelSelector.MatchLabels["app"])
96+
assert.Equal(t, "role", a.PodAntiAffinity.PreferredDuringSchedulingIgnoredDuringExecution[0].PodAffinityTerm.LabelSelector.MatchLabels["role"])
97+
}

tests/auth_test.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
// TestAuthenticationSingleDefaultSecret creating a single server
1818
// with default authentication (on) using a generated JWT secret.
1919
func TestAuthenticationSingleDefaultSecret(t *testing.T) {
20+
longOrSkip(t)
2021
c := client.MustNewInCluster()
2122
kubecli := mustNewKubeClient(t)
2223
ns := getNamespace(t)
@@ -63,6 +64,7 @@ func TestAuthenticationSingleDefaultSecret(t *testing.T) {
6364
// TestAuthenticationSingleCustomSecret creating a single server
6465
// with default authentication (on) using a user created JWT secret.
6566
func TestAuthenticationSingleCustomSecret(t *testing.T) {
67+
longOrSkip(t)
6668
c := client.MustNewInCluster()
6769
kubecli := mustNewKubeClient(t)
6870
ns := getNamespace(t)
@@ -113,6 +115,7 @@ func TestAuthenticationSingleCustomSecret(t *testing.T) {
113115
// TestAuthenticationNoneSingle creating a single server
114116
// with authentication set to `None`.
115117
func TestAuthenticationNoneSingle(t *testing.T) {
118+
longOrSkip(t)
116119
c := client.MustNewInCluster()
117120
kubecli := mustNewKubeClient(t)
118121
ns := getNamespace(t)
@@ -150,6 +153,7 @@ func TestAuthenticationNoneSingle(t *testing.T) {
150153
// TestAuthenticationClusterDefaultSecret creating a cluster
151154
// with default authentication (on) using a generated JWT secret.
152155
func TestAuthenticationClusterDefaultSecret(t *testing.T) {
156+
longOrSkip(t)
153157
c := client.MustNewInCluster()
154158
kubecli := mustNewKubeClient(t)
155159
ns := getNamespace(t)
@@ -196,6 +200,7 @@ func TestAuthenticationClusterDefaultSecret(t *testing.T) {
196200
// TestAuthenticationClusterCustomSecret creating a cluster
197201
// with default authentication (on) using a user created JWT secret.
198202
func TestAuthenticationClusterCustomSecret(t *testing.T) {
203+
longOrSkip(t)
199204
c := client.MustNewInCluster()
200205
kubecli := mustNewKubeClient(t)
201206
ns := getNamespace(t)
@@ -246,7 +251,7 @@ func TestAuthenticationClusterCustomSecret(t *testing.T) {
246251
// TestAuthenticationNoneCluster creating a cluster
247252
// with authentication set to `None`.
248253
func TestAuthenticationNoneCluster(t *testing.T) {
249-
// Do not allow to run this test in parallel, because it is already claiming a lot of resources.
254+
longOrSkip(t)
250255
c := client.MustNewInCluster()
251256
kubecli := mustNewKubeClient(t)
252257
ns := getNamespace(t)

tests/rocksdb_encryption_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
// TestRocksDBEncryptionSingle tests the creating of a single server deployment
1717
// with RocksDB & Encryption.
1818
func TestRocksDBEncryptionSingle(t *testing.T) {
19+
longOrSkip(t)
1920
image := getEnterpriseImageOrSkip(t)
2021
c := client.MustNewInCluster()
2122
kubecli := mustNewKubeClient(t)

tests/scale_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
// TestScaleCluster tests scaling up/down the number of DBServers & coordinators
1515
// of a cluster.
1616
func TestScaleCluster(t *testing.T) {
17+
longOrSkip(t)
1718
c := client.MustNewInCluster()
1819
kubecli := mustNewKubeClient(t)
1920
ns := getNamespace(t)

tests/simple_test.go

+136
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
package tests
2+
3+
import (
4+
"context"
5+
"testing"
6+
7+
"github.com/dchest/uniuri"
8+
"github.com/stretchr/testify/assert"
9+
10+
driver "github.com/arangodb/go-driver"
11+
api "github.com/arangodb/k8s-operator/pkg/apis/arangodb/v1alpha"
12+
"github.com/arangodb/k8s-operator/pkg/client"
13+
)
14+
15+
// TestSimpleSingle tests the creating of a single server deployment
16+
// with default settings.
17+
func TestSimpleSingle(t *testing.T) {
18+
c := client.MustNewInCluster()
19+
kubecli := mustNewKubeClient(t)
20+
ns := getNamespace(t)
21+
22+
// Prepare deployment config
23+
depl := newDeployment("test-sng-" + uniuri.NewLen(4))
24+
depl.Spec.Mode = api.DeploymentModeSingle
25+
26+
// Create deployment
27+
_, err := c.DatabaseV1alpha().ArangoDeployments(ns).Create(depl)
28+
if err != nil {
29+
t.Fatalf("Create deployment failed: %v", err)
30+
}
31+
// Prepare cleanup
32+
defer removeDeployment(c, depl.GetName(), ns)
33+
34+
// Wait for deployment to be ready
35+
apiObject, err := waitUntilDeployment(c, depl.GetName(), ns, deploymentHasState(api.DeploymentStateRunning))
36+
if err != nil {
37+
t.Errorf("Deployment not running in time: %v", err)
38+
}
39+
40+
// Create a database client
41+
ctx := context.Background()
42+
client := mustNewArangodDatabaseClient(ctx, kubecli, apiObject, t)
43+
44+
// Wait for single server available
45+
if err := waitUntilVersionUp(client); err != nil {
46+
t.Fatalf("Single server not running returning version in time: %v", err)
47+
}
48+
49+
// Check server role
50+
assert.NoError(t, client.SynchronizeEndpoints(ctx))
51+
role, err := client.ServerRole(ctx)
52+
assert.NoError(t, err)
53+
assert.Equal(t, driver.ServerRoleSingle, role)
54+
}
55+
56+
// TestSimpleResilientSingle tests the creating of a resilientsingle server deployment
57+
// with default settings.
58+
func TestSimpleResilientSingle(t *testing.T) {
59+
c := client.MustNewInCluster()
60+
kubecli := mustNewKubeClient(t)
61+
ns := getNamespace(t)
62+
63+
// Prepare deployment config
64+
depl := newDeployment("test-rs-" + uniuri.NewLen(4))
65+
depl.Spec.Mode = api.DeploymentModeResilientSingle
66+
67+
// Create deployment
68+
_, err := c.DatabaseV1alpha().ArangoDeployments(ns).Create(depl)
69+
if err != nil {
70+
t.Fatalf("Create deployment failed: %v", err)
71+
}
72+
// Prepare cleanup
73+
defer removeDeployment(c, depl.GetName(), ns)
74+
75+
// Wait for deployment to be ready
76+
apiObject, err := waitUntilDeployment(c, depl.GetName(), ns, deploymentHasState(api.DeploymentStateRunning))
77+
if err != nil {
78+
t.Errorf("Deployment not running in time: %v", err)
79+
}
80+
81+
// Create a database client
82+
ctx := context.Background()
83+
client := mustNewArangodDatabaseClient(ctx, kubecli, apiObject, t)
84+
85+
// Wait for single server available
86+
if err := waitUntilVersionUp(client); err != nil {
87+
t.Fatalf("ResilientSingle servers not running returning version in time: %v", err)
88+
}
89+
90+
// Check server role
91+
assert.NoError(t, client.SynchronizeEndpoints(ctx))
92+
role, err := client.ServerRole(ctx)
93+
assert.NoError(t, err)
94+
assert.Equal(t, driver.ServerRoleSingleActive, role)
95+
}
96+
97+
// TestSimpleCluster tests the creating of a cluster deployment
98+
// with default settings.
99+
func TestSimpleCluster(t *testing.T) {
100+
c := client.MustNewInCluster()
101+
kubecli := mustNewKubeClient(t)
102+
ns := getNamespace(t)
103+
104+
// Prepare deployment config
105+
depl := newDeployment("test-cls-" + uniuri.NewLen(4))
106+
depl.Spec.Mode = api.DeploymentModeCluster
107+
108+
// Create deployment
109+
_, err := c.DatabaseV1alpha().ArangoDeployments(ns).Create(depl)
110+
if err != nil {
111+
t.Fatalf("Create deployment failed: %v", err)
112+
}
113+
// Prepare cleanup
114+
defer removeDeployment(c, depl.GetName(), ns)
115+
116+
// Wait for deployment to be ready
117+
apiObject, err := waitUntilDeployment(c, depl.GetName(), ns, deploymentHasState(api.DeploymentStateRunning))
118+
if err != nil {
119+
t.Errorf("Deployment not running in time: %v", err)
120+
}
121+
122+
// Create a database client
123+
ctx := context.Background()
124+
client := mustNewArangodDatabaseClient(ctx, kubecli, apiObject, t)
125+
126+
// Wait for single server available
127+
if err := waitUntilVersionUp(client); err != nil {
128+
t.Fatalf("Cluster not running returning version in time: %v", err)
129+
}
130+
131+
// Check server role
132+
assert.NoError(t, client.SynchronizeEndpoints(ctx))
133+
role, err := client.ServerRole(ctx)
134+
assert.NoError(t, err)
135+
assert.Equal(t, driver.ServerRoleCoordinator, role)
136+
}

0 commit comments

Comments
 (0)