Skip to content

Commit

Permalink
Merge pull request #88 from arangodb/tests/modes
Browse files Browse the repository at this point in the history
Tests/modes
  • Loading branch information
ObiWahn authored Mar 29, 2018
2 parents ee02966 + 7ad2c22 commit 5cf25ee
Show file tree
Hide file tree
Showing 6 changed files with 134 additions and 2 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ endif
endif
MANIFESTPATHDEPLOYMENT := manifests/arango-deployment$(MANIFESTSUFFIX).yaml
MANIFESTPATHSTORAGE := manifests/arango-storage$(MANIFESTSUFFIX).yaml
MANIFESTPATHTEST := manifests/arango-test$(MANIFESTSUFFIX).yaml
ifndef DEPLOYMENTNAMESPACE
DEPLOYMENTNAMESPACE := default
endif
Expand Down Expand Up @@ -251,6 +252,7 @@ endif
kubectl apply -f manifests/crd.yaml
kubectl apply -f $(MANIFESTPATHSTORAGE)
kubectl apply -f $(MANIFESTPATHDEPLOYMENT)
kubectl apply -f $(MANIFESTPATHTEST)
$(ROOTDIR)/scripts/kube_create_storage.sh $(DEPLOYMENTNAMESPACE)
$(ROOTDIR)/scripts/kube_run_tests.sh $(DEPLOYMENTNAMESPACE) $(TESTIMAGE) "$(ENTERPRISEIMAGE)" $(TESTTIMEOUT) $(TESTLENGTHOPTIONS)
ifneq ($(DEPLOYMENTNAMESPACE), default)
Expand Down Expand Up @@ -312,6 +314,7 @@ minikube-start:

.PHONY: delete-operator
delete-operator:
kubectl delete -f $(MANIFESTPATHTEST) --ignore-not-found
kubectl delete -f $(MANIFESTPATHDEPLOYMENT) --ignore-not-found
kubectl delete -f $(MANIFESTPATHSTORAGE) --ignore-not-found

Expand All @@ -320,4 +323,5 @@ redeploy-operator: delete-operator manifests
kubectl apply -f manifests/crd.yaml
kubectl apply -f $(MANIFESTPATHSTORAGE)
kubectl apply -f $(MANIFESTPATHDEPLOYMENT)
kubectl apply -f $(MANIFESTPATHTEST)
kubectl get pods
3 changes: 2 additions & 1 deletion manifests/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
arango-deployment-dev.yaml
arango-storage-dev.yaml
arango-storage-dev.yaml
arango-test-dev.yaml
2 changes: 1 addition & 1 deletion manifests/templates/deployment/rbac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,4 @@ subjects:
name: {{ .Deployment.Operator.ServiceAccountName }}
namespace: {{ .Deployment.Operator.Namespace }}

{{- end -}}
{{- end -}}
31 changes: 31 additions & 0 deletions manifests/templates/test/rbac.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{{- if .RBAC -}}

## Cluster role granting access to resources needed by the integration tests.
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRole
metadata:
name: {{ .Test.RoleName }}
rules:
- apiGroups: [""]
resources: ["nodes"]
verbs: ["list"]

---

## Bind the cluster role granting access to ArangoLocalStorage resources
## to the default service account of the configured namespace.
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
name: {{ .Test.RoleBindingName }}
namespace: {{ .Test.Namespace }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: {{ .Test.RoleName }}
subjects:
- kind: ServiceAccount
name: {{ .Test.ServiceAccountName }}
namespace: {{ .Test.Namespace }}

{{- end -}}
85 changes: 85 additions & 0 deletions tests/environments_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
//
// 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 Jan Christoph Uhde <[email protected]>
//
package tests

import (
"fmt"
"strings"
"testing"

"github.com/dchest/uniuri"
"github.com/stretchr/testify/assert"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1alpha"
kubeArangoClient "github.com/arangodb/kube-arangodb/pkg/client"
"github.com/arangodb/kube-arangodb/pkg/util"
)

// Test if deployment comes up in production environment.
// LONG: The test ensures that the deployment fails if there are
// less nodes available than servers required.
func TestProduction(t *testing.T) {
longOrSkip(t)

mode := api.DeploymentModeCluster
engine := api.StorageEngineRocksDB

k8sNameSpace := getNamespace(t)
k8sClient := mustNewKubeClient(t)

nodeList, err := k8sClient.CoreV1().Nodes().List(metav1.ListOptions{})
if err != nil {
t.Fatalf("Unable to receive node list: %v", err)
}
numNodes := len(nodeList.Items)

deploymentClient := kubeArangoClient.MustNewInCluster()
deploymentTemplate := newDeployment(strings.Replace(fmt.Sprintf("tprod-%s-%s-%s", mode[:2], engine[:2], uniuri.NewLen(4)), ".", "", -1))
deploymentTemplate.Spec.Mode = api.NewMode(mode)
deploymentTemplate.Spec.StorageEngine = api.NewStorageEngine(engine)
deploymentTemplate.Spec.TLS = api.TLSSpec{}
deploymentTemplate.Spec.Environment = api.NewEnvironment(api.EnvironmentProduction)
deploymentTemplate.Spec.Image = util.NewString("arangodb/arangodb:3.3.4")
deploymentTemplate.Spec.DBServers.Count = util.NewInt(numNodes + 1)
deploymentTemplate.Spec.SetDefaults(deploymentTemplate.GetName()) // this must be last
assert.NoError(t, deploymentTemplate.Spec.Validate())

dbserverCount := *deploymentTemplate.Spec.DBServers.Count
if dbserverCount < 3 {
t.Fatalf("Not enough DBServers to run this test: server count %d", dbserverCount)
}

// Create deployment
_, err = deploymentClient.DatabaseV1alpha().ArangoDeployments(k8sNameSpace).Create(deploymentTemplate)
if err != nil {
// REVIEW - should the test already fail here
t.Fatalf("Create deployment failed: %v", err)
}

_, err = waitUntilDeployment(deploymentClient, deploymentTemplate.GetName(), k8sNameSpace, deploymentIsReady())
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))

// Cleanup
removeDeployment(deploymentClient, deploymentTemplate.GetName(), k8sNameSpace)
}
11 changes: 11 additions & 0 deletions tools/manifests/manifest_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ var (
"rbac.yaml",
"deployment.yaml",
}
testTemplateNames = []string{
"rbac.yaml",
}
)

func init() {
Expand All @@ -79,6 +82,7 @@ type TemplateOptions struct {
RBAC bool
Deployment ResourceOptions
Storage ResourceOptions
Test CommonOptions
}

type CommonOptions struct {
Expand Down Expand Up @@ -123,6 +127,7 @@ func main() {
templateNameSet := map[string][]string{
"deployment": deploymentTemplateNames,
"storage": storageTemplateNames,
"test": testTemplateNames,
}

// Process templates
Expand Down Expand Up @@ -160,6 +165,12 @@ func main() {
},
OperatorDeploymentName: "arango-storage-operator",
},
Test: CommonOptions{
Namespace: options.Namespace,
RoleName: "arango-operator-test",
RoleBindingName: "arango-operator-test",
ServiceAccountName: "default",
},
}
for group, templateNames := range templateNameSet {
output := &bytes.Buffer{}
Expand Down

0 comments on commit 5cf25ee

Please sign in to comment.