@@ -23,9 +23,14 @@ package tests
2323
2424import (
2525 "context"
26+ "fmt"
2627 "testing"
2728
2829 "github.com/dchest/uniuri"
30+ "github.com/stretchr/testify/assert"
31+ "github.com/stretchr/testify/require"
32+
33+ driver "github.com/arangodb/go-driver"
2934
3035 api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1alpha"
3136 kubeArangoClient "github.com/arangodb/kube-arangodb/pkg/client"
@@ -77,27 +82,102 @@ func deploymentSubTest(t *testing.T, mode api.DeploymentMode, engine api.Storage
7782 deploymentTemplate .Spec .SetDefaults (deploymentTemplate .GetName ()) // this must be last
7883
7984 // Create deployment
80- deployment , err := deploymentClient .DatabaseV1alpha ().ArangoDeployments (k8sNameSpace ).Create (deploymentTemplate )
81- if err != nil {
82- t .Fatalf ("Create deployment failed: %v" , err )
83- }
85+ _ , err := deploymentClient .DatabaseV1alpha ().ArangoDeployments (k8sNameSpace ).Create (deploymentTemplate )
86+ require .NoError (t , err , fmt .Sprintf ("Create deployment failed: %v" , err ))
8487
8588 // Wait for deployment to be ready
86- deployment , err = waitUntilDeployment (deploymentClient , deploymentTemplate .GetName (), k8sNameSpace , deploymentIsReady ())
87- if err != nil {
88- t .Fatalf ("Deployment not running in time: %v" , err )
89- }
89+ deployment , err := waitUntilDeployment (deploymentClient , deploymentTemplate .GetName (), k8sNameSpace , deploymentIsReady ())
90+ require .NoError (t , err , fmt .Sprintf ("Deployment not running in time: %v" , err ))
9091
9192 // Create a database client
9293 ctx := context .Background ()
9394 DBClient := mustNewArangodDatabaseClient (ctx , k8sClient , deployment , t )
94-
95- if err := waitUntilArangoDeploymentHealthy (deployment , DBClient , k8sClient , "" ); err != nil {
96- t .Fatalf ("Deployment not healthy in time: %v" , err )
97- }
95+ require .NoError (t , waitUntilArangoDeploymentHealthy (deployment , DBClient , k8sClient , "" ), fmt .Sprintf ("Deployment not healthy in time: %v" , err ))
9896
9997 // Cleanup
10098 removeDeployment (deploymentClient , deploymentTemplate .GetName (), k8sNameSpace )
10199
102100 return nil
103101}
102+
103+ // test a setup containing multiple deployments
104+ func TestMultiDeployment (t * testing.T ) {
105+ longOrSkip (t )
106+
107+ k8sNameSpace := getNamespace (t )
108+ k8sClient := mustNewKubeClient (t )
109+ deploymentClient := kubeArangoClient .MustNewInCluster ()
110+
111+ // Prepare deployment configurations
112+ deploymentTemplate1 := newDeployment ("test-multidep1-1-" + uniuri .NewLen (4 ))
113+ deploymentTemplate1 .Spec .Mode = api .NewMode (api .DeploymentModeCluster )
114+ deploymentTemplate1 .Spec .StorageEngine = api .NewStorageEngine (api .StorageEngineRocksDB )
115+ deploymentTemplate1 .Spec .TLS = api.TLSSpec {} // should auto-generate cert
116+ deploymentTemplate1 .Spec .SetDefaults (deploymentTemplate1 .GetName ()) // this must be last
117+
118+ deploymentTemplate2 := newDeployment ("test-multidep1-2-" + uniuri .NewLen (4 ))
119+ deploymentTemplate2 .Spec .Mode = api .NewMode (api .DeploymentModeSingle )
120+ deploymentTemplate2 .Spec .StorageEngine = api .NewStorageEngine (api .StorageEngineMMFiles )
121+ deploymentTemplate2 .Spec .TLS = api.TLSSpec {} // should auto-generate cert
122+ deploymentTemplate2 .Spec .SetDefaults (deploymentTemplate2 .GetName ()) // this must be last
123+
124+ // Create deployments
125+ _ , err := deploymentClient .DatabaseV1alpha ().ArangoDeployments (k8sNameSpace ).Create (deploymentTemplate1 )
126+ require .NoError (t , err , fmt .Sprintf ("Deployment creation failed: %v" , err ))
127+
128+ _ , err = deploymentClient .DatabaseV1alpha ().ArangoDeployments (k8sNameSpace ).Create (deploymentTemplate2 )
129+ require .NoError (t , err , fmt .Sprintf ("Deployment creation failed: %v" , err ))
130+
131+ // Wait for deployments to be ready
132+ deployment1 , err := waitUntilDeployment (deploymentClient , deploymentTemplate1 .GetName (), k8sNameSpace , deploymentIsReady ())
133+ require .NoError (t , err , fmt .Sprintf ("Deployment not running in time: %v" , err ))
134+
135+ deployment2 , err := waitUntilDeployment (deploymentClient , deploymentTemplate2 .GetName (), k8sNameSpace , deploymentIsReady ())
136+ require .NoError (t , err , fmt .Sprintf ("Deployment not running in time: %v" , err ))
137+
138+ require .True (t , deployment1 != nil && deployment2 != nil , "deployment is nil" )
139+
140+ // Create a database clients
141+ ctx := context .Background ()
142+ DBClient1 := mustNewArangodDatabaseClient (ctx , k8sClient , deployment1 , t )
143+ require .NoError (t , waitUntilArangoDeploymentHealthy (deployment1 , DBClient1 , k8sClient , "" ), fmt .Sprintf ("Deployment not healthy in time: %v" , err ))
144+ DBClient2 := mustNewArangodDatabaseClient (ctx , k8sClient , deployment2 , t )
145+ require .NoError (t , waitUntilArangoDeploymentHealthy (deployment1 , DBClient1 , k8sClient , "" ), fmt .Sprintf ("Deployment not healthy in time: %v" , err ))
146+
147+ // Test if we are able to create a collections in both deployments.
148+ db1 , err := DBClient1 .Database (ctx , "_system" )
149+ require .NoError (t , err , "failed to get database" )
150+ _ , err = db1 .CreateCollection (ctx , "col1" , nil )
151+ require .NoError (t , err , "failed to create collection" )
152+
153+ db2 , err := DBClient2 .Database (ctx , "_system" )
154+ require .NoError (t , err , "failed to get database" )
155+ _ , err = db2 .CreateCollection (ctx , "col2" , nil )
156+ require .NoError (t , err , "failed to create collection" )
157+
158+ // The newly created collections must be (only) visible in the deployment
159+ // that it was created in. The following lines ensure this behavior.
160+ collections1 , err := db1 .Collections (ctx )
161+ require .NoError (t , err , "failed to get collections" )
162+ collections2 , err := db2 .Collections (ctx )
163+ require .NoError (t , err , "failed to get collections" )
164+
165+ assert .True (t , containsCollection (collections1 , "col1" ), "collection missing" )
166+ assert .True (t , containsCollection (collections2 , "col2" ), "collection missing" )
167+ assert .False (t , containsCollection (collections1 , "col2" ), "collection must not be in this deployment" )
168+ assert .False (t , containsCollection (collections2 , "col1" ), "collection must not be in this deployment" )
169+
170+ // Cleanup
171+ removeDeployment (deploymentClient , deploymentTemplate1 .GetName (), k8sNameSpace )
172+ removeDeployment (deploymentClient , deploymentTemplate2 .GetName (), k8sNameSpace )
173+
174+ }
175+
176+ func containsCollection (colls []driver.Collection , name string ) bool {
177+ for _ , col := range colls {
178+ if name == col .Name () {
179+ return true
180+ }
181+ }
182+ return false
183+ }
0 commit comments