2222package tests
2323
2424import (
25- "context"
2625 "fmt"
2726 "strings"
2827 "testing"
2928
3029 "github.com/dchest/uniuri"
3130 "github.com/stretchr/testify/assert"
3231
33- meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
32+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3433
3534 api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1alpha"
3635 kubeArangoClient "github.com/arangodb/kube-arangodb/pkg/client"
3736 "github.com/arangodb/kube-arangodb/pkg/util"
3837)
3938
40- // test if deployment comes up in production mode if there are enough nodes and fails if there are too few
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.
4142func TestProduction (t * testing.T ) {
4243 longOrSkip (t )
4344
@@ -46,14 +47,21 @@ func TestProduction(t *testing.T) {
4647
4748 k8sNameSpace := getNamespace (t )
4849 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+
4957 deploymentClient := kubeArangoClient .MustNewInCluster ()
5058 deploymentTemplate := newDeployment (strings .Replace (fmt .Sprintf ("tprod-%s-%s-%s" , mode [:2 ], engine [:2 ], uniuri .NewLen (4 )), "." , "" , - 1 ))
5159 deploymentTemplate .Spec .Mode = api .NewMode (mode )
5260 deploymentTemplate .Spec .StorageEngine = api .NewStorageEngine (engine )
53- deploymentTemplate .Spec .TLS = api.TLSSpec {} // should auto-generate cert
61+ deploymentTemplate .Spec .TLS = api.TLSSpec {}
5462 deploymentTemplate .Spec .Environment = api .NewEnvironment (api .EnvironmentProduction )
5563 deploymentTemplate .Spec .Image = util .NewString ("arangodb/arangodb:3.3.4" )
56- deploymentTemplate .Spec .DBServers .Count = util .NewInt (4 )
64+ deploymentTemplate .Spec .DBServers .Count = util .NewInt (numNodes + 1 )
5765 deploymentTemplate .Spec .SetDefaults (deploymentTemplate .GetName ()) // this must be last
5866 assert .NoError (t , deploymentTemplate .Spec .Validate ())
5967
@@ -62,42 +70,15 @@ func TestProduction(t *testing.T) {
6270 t .Fatalf ("Not enough DBServers to run this test: server count %d" , dbserverCount )
6371 }
6472
65- options := meta_v1.ListOptions {}
66- nodeList , err := k8sClient .CoreV1 ().Nodes ().List (options )
67- if err != nil {
68- t .Fatalf ("Unable to receive node list: %v" , err )
69- }
70-
71- numNodes := len (nodeList .Items )
72- failExpected := false
73-
74- if numNodes < dbserverCount {
75- failExpected = true
76- }
77-
7873 // Create deployment
7974 _ , err = deploymentClient .DatabaseV1alpha ().ArangoDeployments (k8sNameSpace ).Create (deploymentTemplate )
8075 if err != nil {
76+ // REVIEW - should the test already fail here
8177 t .Fatalf ("Create deployment failed: %v" , err )
8278 }
8379
84- deployment , err := waitUntilDeployment (deploymentClient , deploymentTemplate .GetName (), k8sNameSpace , deploymentIsReady ())
85- if failExpected {
86- if err == nil {
87- t .Fatalf ("Deployment is up and running when it should not! There are not enough nodes(%d) for all DBServers(%d) in production modes." , numNodes , dbserverCount )
88- }
89- } else {
90- if err != nil {
91- t .Fatalf ("Deployment not running in time: %v" , err )
92- }
93- // Create a database client
94- ctx := context .Background ()
95- DBClient := mustNewArangodDatabaseClient (ctx , k8sClient , deployment , t )
96-
97- if err := waitUntilArangoDeploymentHealthy (deployment , DBClient , k8sClient , "" ); err != nil {
98- t .Fatalf ("Deployment not healthy in time: %v" , err )
99- }
100- }
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 ))
10182
10283 // Cleanup
10384 removeDeployment (deploymentClient , deploymentTemplate .GetName (), k8sNameSpace )
0 commit comments