Skip to content

Commit 85ac0a0

Browse files
author
Dan Larkin-York
committed
Moved client changes to test code.
1 parent 53738d6 commit 85ac0a0

File tree

3 files changed

+89
-64
lines changed

3 files changed

+89
-64
lines changed

pkg/util/arangod/client.go

Lines changed: 12 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ import (
3232
"time"
3333

3434
driver "github.com/arangodb/go-driver"
35-
vst "github.com/arangodb/go-driver/vst"
36-
vstProtocol "github.com/arangodb/go-driver/vst/protocol"
3735
"github.com/arangodb/go-driver/agency"
3836
"github.com/arangodb/go-driver/http"
3937
"github.com/arangodb/go-driver/jwt"
@@ -102,10 +100,10 @@ func CreateArangodClient(ctx context.Context, cli corev1.CoreV1Interface, apiObj
102100
}
103101

104102
// CreateArangodDatabaseClient creates a go-driver client for accessing the entire cluster (or single server).
105-
func CreateArangodDatabaseClient(ctx context.Context, cli corev1.CoreV1Interface, apiObject *api.ArangoDeployment, useVst ...bool) (driver.Client, error) {
103+
func CreateArangodDatabaseClient(ctx context.Context, cli corev1.CoreV1Interface, apiObject *api.ArangoDeployment) (driver.Client, error) {
106104
// Create connection
107105
dnsName := k8sutil.CreateDatabaseClientServiceDNSName(apiObject)
108-
c, err := createArangodClientForDNSName(ctx, cli, apiObject, dnsName, useVst...)
106+
c, err := createArangodClientForDNSName(ctx, cli, apiObject, dnsName)
109107
if err != nil {
110108
return nil, maskAny(err)
111109
}
@@ -157,36 +155,21 @@ func CreateArangodImageIDClient(ctx context.Context, deployment k8sutil.APIObjec
157155
}
158156

159157
// CreateArangodClientForDNSName creates a go-driver client for a given DNS name.
160-
func createArangodClientForDNSName(ctx context.Context, cli corev1.CoreV1Interface, apiObject *api.ArangoDeployment, dnsName string, useVst ...bool) (driver.Client, error) {
161-
config := driver.ClientConfig{}
162-
var conn driver.Connection
163-
if len(useVst) > 0 && useVst[0] {
164-
connConfig, err := createArangodVSTConfigForDNSNames(ctx, cli, apiObject, []string{dnsName})
165-
if err != nil {
166-
return nil, maskAny(err)
167-
}
168-
// TODO deal with TLS with proper CA checking
169-
conn, err = vst.NewConnection(connConfig)
170-
if err != nil {
171-
return nil, maskAny(err)
172-
}
173-
} else {
174-
connConfig, err := createArangodHTTPConfigForDNSNames(ctx, cli, apiObject, []string{dnsName})
175-
if err != nil {
176-
return nil, maskAny(err)
177-
}
178-
// TODO deal with TLS with proper CA checking
179-
conn, err = http.NewConnection(connConfig)
180-
if err != nil {
181-
return nil, maskAny(err)
182-
}
158+
func createArangodClientForDNSName(ctx context.Context, cli corev1.CoreV1Interface, apiObject *api.ArangoDeployment, dnsName string) (driver.Client, error) {
159+
connConfig, err := createArangodHTTPConfigForDNSNames(ctx, cli, apiObject, []string{dnsName})
160+
if err != nil {
161+
return nil, maskAny(err)
162+
}
163+
// TODO deal with TLS with proper CA checking
164+
conn, err := http.NewConnection(connConfig)
165+
if err != nil {
166+
return nil, maskAny(err)
183167
}
184168

185169
// Create client
186-
config = driver.ClientConfig{
170+
config := driver.ClientConfig{
187171
Connection: conn,
188172
}
189-
190173
auth, err := createArangodClientAuthentication(ctx, cli, apiObject)
191174
if err != nil {
192175
return nil, maskAny(err)
@@ -217,27 +200,6 @@ func createArangodHTTPConfigForDNSNames(ctx context.Context, cli corev1.CoreV1In
217200
return connConfig, nil
218201
}
219202

220-
// createArangodVSTConfigForDNSNames creates a go-driver VST connection config for a given DNS names.
221-
func createArangodVSTConfigForDNSNames(ctx context.Context, cli corev1.CoreV1Interface, apiObject *api.ArangoDeployment, dnsNames []string) (vst.ConnectionConfig, error) {
222-
scheme := "http"
223-
tlsConfig := &tls.Config{InsecureSkipVerify: true}
224-
if apiObject != nil && apiObject.Spec.IsSecure() {
225-
scheme = "https"
226-
tlsConfig = &tls.Config{}
227-
}
228-
transport := vstProtocol.TransportConfig{
229-
Version: vstProtocol.Version1_1,
230-
}
231-
connConfig := vst.ConnectionConfig{
232-
TLSConfig: tlsConfig,
233-
Transport: transport,
234-
}
235-
for _, dnsName := range dnsNames {
236-
connConfig.Endpoints = append(connConfig.Endpoints, scheme+"://"+net.JoinHostPort(dnsName, strconv.Itoa(k8sutil.ArangoPort)))
237-
}
238-
return connConfig, nil
239-
}
240-
241203
// createArangodClientAuthentication creates a go-driver authentication for the servers in the given deployment.
242204
func createArangodClientAuthentication(ctx context.Context, cli corev1.CoreV1Interface, apiObject *api.ArangoDeployment) (driver.Authentication, error) {
243205
if apiObject != nil && apiObject.Spec.IsAuthenticated() {

tests/load_balancer_test.go

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,6 @@ import (
3535
"github.com/arangodb/kube-arangodb/pkg/client"
3636
)
3737

38-
/*type queryTest struct {
39-
Query string
40-
BindVars map[string]interface{}
41-
ExpectSuccess bool
42-
ExpectedDocuments []interface{}
43-
DocumentType reflect.Type
44-
}
45-
46-
type ueryTestContext struct {
47-
Context context.Context
48-
ExpectCount bool
49-
}*/
50-
5138
func TestLoadBalancingCursorVST(t *testing.T) {
5239
// run with VST
5340
LoadBalancingCursorSubtest(t, true)
@@ -208,6 +195,10 @@ func LoadBalancingCursorSubtest(t *testing.T, useVst bool) {
208195
queryTestContext{driver.WithQueryCache(driver.WithQueryCount(driver.WithQueryBatchSize(nil, 2))), true},
209196
}
210197

198+
// keep track of whether at least one request was forwarded internally to the
199+
// correct coordinator behind the load balancer
200+
someRequestForwarded = false
201+
211202
// Run tests for every context alternative
212203
for _, qctx := range contexts {
213204
ctx := qctx.Context

tests/test_util.go

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ package tests
2424

2525
import (
2626
"context"
27+
"crypto/tls"
2728
"fmt"
2829
"net"
2930
"os"
@@ -39,9 +40,12 @@ import (
3940
"github.com/arangodb/arangosync/client"
4041
"github.com/arangodb/arangosync/tasks"
4142
driver "github.com/arangodb/go-driver"
43+
vst "github.com/arangodb/go-driver/vst"
44+
vstProtocol "github.com/arangodb/go-driver/vst/protocol"
4245
"github.com/pkg/errors"
4346
"github.com/rs/zerolog"
4447
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
48+
corev1 "k8s.io/client-go/kubernetes/typed/core/v1"
4549

4650
api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1alpha"
4751
"github.com/arangodb/kube-arangodb/pkg/generated/clientset/versioned"
@@ -60,6 +64,68 @@ var (
6064
showEnterpriseImageOnce sync.Once
6165
)
6266

67+
// CreateArangodClientForDNSName creates a go-driver client for a given DNS name.
68+
func createArangodVSTClientForDNSName(ctx context.Context, cli corev1.CoreV1Interface, apiObject *api.ArangoDeployment, dnsName string) (driver.Client, error) {
69+
config := driver.ClientConfig{}
70+
connConfig, err := createArangodVSTConfigForDNSNames(ctx, cli, apiObject, []string{dnsName})
71+
if err != nil {
72+
return nil, maskAny(err)
73+
}
74+
// TODO deal with TLS with proper CA checking
75+
conn, err := vst.NewConnection(connConfig)
76+
if err != nil {
77+
return nil, maskAny(err)
78+
}
79+
80+
// Create client
81+
config = driver.ClientConfig{
82+
Connection: conn,
83+
}
84+
85+
auth := driver.BasicAuthentication("root", "")
86+
if err != nil {
87+
return nil, maskAny(err)
88+
}
89+
config.Authentication = auth
90+
c, err := driver.NewClient(config)
91+
if err != nil {
92+
return nil, maskAny(err)
93+
}
94+
return c, nil
95+
}
96+
97+
// createArangodVSTConfigForDNSNames creates a go-driver VST connection config for a given DNS names.
98+
func createArangodVSTConfigForDNSNames(ctx context.Context, cli corev1.CoreV1Interface, apiObject *api.ArangoDeployment, dnsNames []string) (vst.ConnectionConfig, error) {
99+
scheme := "http"
100+
tlsConfig := &tls.Config{InsecureSkipVerify: true}
101+
if apiObject != nil && apiObject.Spec.IsSecure() {
102+
scheme = "https"
103+
tlsConfig = &tls.Config{}
104+
}
105+
transport := vstProtocol.TransportConfig{
106+
Version: vstProtocol.Version1_1,
107+
}
108+
connConfig := vst.ConnectionConfig{
109+
TLSConfig: tlsConfig,
110+
Transport: transport,
111+
}
112+
for _, dnsName := range dnsNames {
113+
connConfig.Endpoints = append(connConfig.Endpoints, scheme+"://"+net.JoinHostPort(dnsName, strconv.Itoa(k8sutil.ArangoPort)))
114+
}
115+
return connConfig, nil
116+
}
117+
118+
// CreateArangodDatabaseVSTClient creates a go-driver client for accessing the entire cluster (or single server) via VST
119+
func CreateArangodDatabaseVSTClient(ctx context.Context, cli corev1.CoreV1Interface, apiObject *api.ArangoDeployment) (driver.Client, error) {
120+
// Create connection
121+
dnsName := k8sutil.CreateDatabaseClientServiceDNSName(apiObject)
122+
c, err := createArangodVSTClientForDNSName(ctx, cli, apiObject, dnsName)
123+
if err != nil {
124+
return nil, maskAny(err)
125+
}
126+
return c, nil
127+
}
128+
63129
// longOrSkip checks the short test flag.
64130
// If short is set, the current test is skipped.
65131
// If not, this function returns as normal.
@@ -102,7 +168,13 @@ func mustNewKubeClient(t *testing.T) kubernetes.Interface {
102168
// mustNewArangodDatabaseClient creates a new database client,
103169
// failing the test on errors.
104170
func mustNewArangodDatabaseClient(ctx context.Context, kubecli kubernetes.Interface, apiObject *api.ArangoDeployment, t *testing.T, useVst ...bool) driver.Client {
105-
c, err := arangod.CreateArangodDatabaseClient(ctx, kubecli.CoreV1(), apiObject, useVst...)
171+
var c driver.Client
172+
var err error
173+
if len(useVst) > 0 && useVst[0] {
174+
c, err = CreateArangodDatabaseVSTClient(ctx, kubecli.CoreV1(), apiObject)
175+
} else {
176+
c, err = arangod.CreateArangodDatabaseClient(ctx, kubecli.CoreV1(), apiObject)
177+
}
106178
if err != nil {
107179
t.Fatalf("Failed to create arango database client: %v", err)
108180
}

0 commit comments

Comments
 (0)