|
| 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 | +} |
0 commit comments