Skip to content

Commit 5cf25ee

Browse files
authored
Merge pull request #88 from arangodb/tests/modes
Tests/modes
2 parents ee02966 + 7ad2c22 commit 5cf25ee

File tree

6 files changed

+134
-2
lines changed

6 files changed

+134
-2
lines changed

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ endif
5050
endif
5151
MANIFESTPATHDEPLOYMENT := manifests/arango-deployment$(MANIFESTSUFFIX).yaml
5252
MANIFESTPATHSTORAGE := manifests/arango-storage$(MANIFESTSUFFIX).yaml
53+
MANIFESTPATHTEST := manifests/arango-test$(MANIFESTSUFFIX).yaml
5354
ifndef DEPLOYMENTNAMESPACE
5455
DEPLOYMENTNAMESPACE := default
5556
endif
@@ -251,6 +252,7 @@ endif
251252
kubectl apply -f manifests/crd.yaml
252253
kubectl apply -f $(MANIFESTPATHSTORAGE)
253254
kubectl apply -f $(MANIFESTPATHDEPLOYMENT)
255+
kubectl apply -f $(MANIFESTPATHTEST)
254256
$(ROOTDIR)/scripts/kube_create_storage.sh $(DEPLOYMENTNAMESPACE)
255257
$(ROOTDIR)/scripts/kube_run_tests.sh $(DEPLOYMENTNAMESPACE) $(TESTIMAGE) "$(ENTERPRISEIMAGE)" $(TESTTIMEOUT) $(TESTLENGTHOPTIONS)
256258
ifneq ($(DEPLOYMENTNAMESPACE), default)
@@ -312,6 +314,7 @@ minikube-start:
312314

313315
.PHONY: delete-operator
314316
delete-operator:
317+
kubectl delete -f $(MANIFESTPATHTEST) --ignore-not-found
315318
kubectl delete -f $(MANIFESTPATHDEPLOYMENT) --ignore-not-found
316319
kubectl delete -f $(MANIFESTPATHSTORAGE) --ignore-not-found
317320

@@ -320,4 +323,5 @@ redeploy-operator: delete-operator manifests
320323
kubectl apply -f manifests/crd.yaml
321324
kubectl apply -f $(MANIFESTPATHSTORAGE)
322325
kubectl apply -f $(MANIFESTPATHDEPLOYMENT)
326+
kubectl apply -f $(MANIFESTPATHTEST)
323327
kubectl get pods

manifests/.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
arango-deployment-dev.yaml
2-
arango-storage-dev.yaml
2+
arango-storage-dev.yaml
3+
arango-test-dev.yaml

manifests/templates/deployment/rbac.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,4 @@ subjects:
6969
name: {{ .Deployment.Operator.ServiceAccountName }}
7070
namespace: {{ .Deployment.Operator.Namespace }}
7171

72-
{{- end -}}
72+
{{- end -}}

manifests/templates/test/rbac.yaml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{{- if .RBAC -}}
2+
3+
## Cluster role granting access to resources needed by the integration tests.
4+
apiVersion: rbac.authorization.k8s.io/v1beta1
5+
kind: ClusterRole
6+
metadata:
7+
name: {{ .Test.RoleName }}
8+
rules:
9+
- apiGroups: [""]
10+
resources: ["nodes"]
11+
verbs: ["list"]
12+
13+
---
14+
15+
## Bind the cluster role granting access to ArangoLocalStorage resources
16+
## to the default service account of the configured namespace.
17+
apiVersion: rbac.authorization.k8s.io/v1beta1
18+
kind: ClusterRoleBinding
19+
metadata:
20+
name: {{ .Test.RoleBindingName }}
21+
namespace: {{ .Test.Namespace }}
22+
roleRef:
23+
apiGroup: rbac.authorization.k8s.io
24+
kind: ClusterRole
25+
name: {{ .Test.RoleName }}
26+
subjects:
27+
- kind: ServiceAccount
28+
name: {{ .Test.ServiceAccountName }}
29+
namespace: {{ .Test.Namespace }}
30+
31+
{{- end -}}

tests/environments_test.go

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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 Jan Christoph Uhde <jan@uhdejc.com>
21+
//
22+
package tests
23+
24+
import (
25+
"fmt"
26+
"strings"
27+
"testing"
28+
29+
"github.com/dchest/uniuri"
30+
"github.com/stretchr/testify/assert"
31+
32+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
33+
34+
api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1alpha"
35+
kubeArangoClient "github.com/arangodb/kube-arangodb/pkg/client"
36+
"github.com/arangodb/kube-arangodb/pkg/util"
37+
)
38+
39+
// Test if deployment comes up in production environment.
40+
// LONG: The test ensures that the deployment fails if there are
41+
// less nodes available than servers required.
42+
func TestProduction(t *testing.T) {
43+
longOrSkip(t)
44+
45+
mode := api.DeploymentModeCluster
46+
engine := api.StorageEngineRocksDB
47+
48+
k8sNameSpace := getNamespace(t)
49+
k8sClient := mustNewKubeClient(t)
50+
51+
nodeList, err := k8sClient.CoreV1().Nodes().List(metav1.ListOptions{})
52+
if err != nil {
53+
t.Fatalf("Unable to receive node list: %v", err)
54+
}
55+
numNodes := len(nodeList.Items)
56+
57+
deploymentClient := kubeArangoClient.MustNewInCluster()
58+
deploymentTemplate := newDeployment(strings.Replace(fmt.Sprintf("tprod-%s-%s-%s", mode[:2], engine[:2], uniuri.NewLen(4)), ".", "", -1))
59+
deploymentTemplate.Spec.Mode = api.NewMode(mode)
60+
deploymentTemplate.Spec.StorageEngine = api.NewStorageEngine(engine)
61+
deploymentTemplate.Spec.TLS = api.TLSSpec{}
62+
deploymentTemplate.Spec.Environment = api.NewEnvironment(api.EnvironmentProduction)
63+
deploymentTemplate.Spec.Image = util.NewString("arangodb/arangodb:3.3.4")
64+
deploymentTemplate.Spec.DBServers.Count = util.NewInt(numNodes + 1)
65+
deploymentTemplate.Spec.SetDefaults(deploymentTemplate.GetName()) // this must be last
66+
assert.NoError(t, deploymentTemplate.Spec.Validate())
67+
68+
dbserverCount := *deploymentTemplate.Spec.DBServers.Count
69+
if dbserverCount < 3 {
70+
t.Fatalf("Not enough DBServers to run this test: server count %d", dbserverCount)
71+
}
72+
73+
// Create deployment
74+
_, err = deploymentClient.DatabaseV1alpha().ArangoDeployments(k8sNameSpace).Create(deploymentTemplate)
75+
if err != nil {
76+
// REVIEW - should the test already fail here
77+
t.Fatalf("Create deployment failed: %v", err)
78+
}
79+
80+
_, err = waitUntilDeployment(deploymentClient, deploymentTemplate.GetName(), k8sNameSpace, deploymentIsReady())
81+
assert.Error(t, err, fmt.Sprintf("Deployment is up and running when it should not! There are not enough nodes(%d) for all DBServers(%d) in production modes.", numNodes, dbserverCount))
82+
83+
// Cleanup
84+
removeDeployment(deploymentClient, deploymentTemplate.GetName(), k8sNameSpace)
85+
}

tools/manifests/manifest_builder.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ var (
5757
"rbac.yaml",
5858
"deployment.yaml",
5959
}
60+
testTemplateNames = []string{
61+
"rbac.yaml",
62+
}
6063
)
6164

6265
func init() {
@@ -79,6 +82,7 @@ type TemplateOptions struct {
7982
RBAC bool
8083
Deployment ResourceOptions
8184
Storage ResourceOptions
85+
Test CommonOptions
8286
}
8387

8488
type CommonOptions struct {
@@ -123,6 +127,7 @@ func main() {
123127
templateNameSet := map[string][]string{
124128
"deployment": deploymentTemplateNames,
125129
"storage": storageTemplateNames,
130+
"test": testTemplateNames,
126131
}
127132

128133
// Process templates
@@ -160,6 +165,12 @@ func main() {
160165
},
161166
OperatorDeploymentName: "arango-storage-operator",
162167
},
168+
Test: CommonOptions{
169+
Namespace: options.Namespace,
170+
RoleName: "arango-operator-test",
171+
RoleBindingName: "arango-operator-test",
172+
ServiceAccountName: "default",
173+
},
163174
}
164175
for group, templateNames := range templateNameSet {
165176
output := &bytes.Buffer{}

0 commit comments

Comments
 (0)