-
Notifications
You must be signed in to change notification settings - Fork 73
/
scale_test.go
154 lines (129 loc) · 4.82 KB
/
scale_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
package tests
import (
"context"
"testing"
"github.com/dchest/uniuri"
driver "github.com/arangodb/go-driver"
api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1alpha"
"github.com/arangodb/kube-arangodb/pkg/client"
)
// TestScaleCluster tests scaling up/down the number of DBServers & coordinators
// of a cluster.
func TestScaleClusterNonTLS(t *testing.T) {
longOrSkip(t)
c := client.MustNewInCluster()
kubecli := mustNewKubeClient(t)
ns := getNamespace(t)
// Prepare deployment config
depl := newDeployment("test-scale-non-tls" + uniuri.NewLen(4))
depl.Spec.Mode = api.DeploymentModeCluster
depl.Spec.TLS = api.TLSSpec{"None", nil, 50}
depl.Spec.SetDefaults(depl.GetName()) // this must be last
// Create deployment
apiObject, err := c.DatabaseV1alpha().ArangoDeployments(ns).Create(depl)
if err != nil {
t.Fatalf("Create deployment failed: %v", err)
}
// Wait for deployment to be ready
if _, err := waitUntilDeployment(c, depl.GetName(), ns, deploymentHasState(api.DeploymentStateRunning)); err != nil {
t.Fatalf("Deployment not running in time: %v", err)
}
// Create a database client
ctx := context.Background()
client := mustNewArangodDatabaseClient(ctx, kubecli, apiObject, t)
// Wait for cluster to be completely ready
if err := waitUntilClusterHealth(client, func(h driver.ClusterHealth) error {
return clusterHealthEqualsSpec(h, apiObject.Spec)
}); err != nil {
t.Fatalf("Cluster not running in expected health in time: %v", err)
}
// Add 2 DBServers, 1 coordinator
updated, err := updateDeployment(c, depl.GetName(), ns, func(spec *api.DeploymentSpec) {
spec.DBServers.Count = 5
spec.Coordinators.Count = 4
})
if err != nil {
t.Fatalf("Failed to update deployment: %v", err)
}
// Wait for cluster to reach new size
if err := waitUntilClusterHealth(client, func(h driver.ClusterHealth) error {
return clusterHealthEqualsSpec(h, updated.Spec)
}); err != nil {
t.Fatalf("Cluster not running, after scale-up, in expected health in time: %v", err)
}
// Remove 3 DBServers, 2 coordinator
updated, err = updateDeployment(c, depl.GetName(), ns, func(spec *api.DeploymentSpec) {
spec.DBServers.Count = 3
spec.Coordinators.Count = 2
})
if err != nil {
t.Fatalf("Failed to update deployment: %v", err)
}
// Wait for cluster to reach new size
if err := waitUntilClusterHealth(client, func(h driver.ClusterHealth) error {
return clusterHealthEqualsSpec(h, updated.Spec)
}); err != nil {
t.Fatalf("Cluster not running, after scale-down, in expected health in time: %v", err)
}
// Cleanup
removeDeployment(c, depl.GetName(), ns)
}
func TestScaleClusterTLS(t *testing.T) {
longOrSkip(t)
c := client.MustNewInCluster()
kubecli := mustNewKubeClient(t)
ns := getNamespace(t)
// Prepare deployment config
depl := newDeployment("test-scale-tls" + uniuri.NewLen(4))
depl.Spec.Mode = api.DeploymentModeCluster
depl.Spec.TLS = api.TLSSpec{} // should auto-generate cert
depl.Spec.SetDefaults(depl.GetName()) // this must be last
// Create deployment
apiObject, err := c.DatabaseV1alpha().ArangoDeployments(ns).Create(depl)
if err != nil {
t.Fatalf("Create deployment failed: %v", err)
}
// Wait for deployment to be ready
if _, err := waitUntilDeployment(c, depl.GetName(), ns, deploymentHasState(api.DeploymentStateRunning)); err != nil {
t.Fatalf("Deployment not running in time: %v", err)
}
// Create a database client
ctx := context.Background()
client := mustNewArangodDatabaseClient(ctx, kubecli, apiObject, t)
// Wait for cluster to be completely ready
if err := waitUntilClusterHealth(client, func(h driver.ClusterHealth) error {
return clusterHealthEqualsSpec(h, apiObject.Spec)
}); err != nil {
t.Fatalf("Cluster not running in expected health in time: %v", err)
}
// Add 2 DBServers, 1 coordinator
updated, err := updateDeployment(c, depl.GetName(), ns, func(spec *api.DeploymentSpec) {
spec.DBServers.Count = 5
spec.Coordinators.Count = 4
})
if err != nil {
t.Fatalf("Failed to update deployment: %v", err)
}
// Wait for cluster to reach new size
if err := waitUntilClusterHealth(client, func(h driver.ClusterHealth) error {
return clusterHealthEqualsSpec(h, updated.Spec)
}); err != nil {
t.Fatalf("Cluster not running, after scale-up, in expected health in time: %v", err)
}
// Remove 3 DBServers, 2 coordinator
updated, err = updateDeployment(c, depl.GetName(), ns, func(spec *api.DeploymentSpec) {
spec.DBServers.Count = 3
spec.Coordinators.Count = 2
})
if err != nil {
t.Fatalf("Failed to update deployment: %v", err)
}
// Wait for cluster to reach new size
if err := waitUntilClusterHealth(client, func(h driver.ClusterHealth) error {
return clusterHealthEqualsSpec(h, updated.Spec)
}); err != nil {
t.Fatalf("Cluster not running, after scale-down, in expected health in time: %v", err)
}
// Cleanup
removeDeployment(c, depl.GetName(), ns)
}