Skip to content

Commit 79d3c99

Browse files
committed
Add a test.
1 parent c8d017f commit 79d3c99

File tree

1 file changed

+111
-0
lines changed

1 file changed

+111
-0
lines changed
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
//
2+
// DISCLAIMER
3+
//
4+
// Copyright 2019 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 Ewout Prangsma
21+
// Author Max Neunhoeffer
22+
//
23+
24+
package tests
25+
26+
import (
27+
"context"
28+
"testing"
29+
"time"
30+
31+
"github.com/dchest/uniuri"
32+
33+
api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1alpha"
34+
"github.com/arangodb/kube-arangodb/pkg/client"
35+
"github.com/arangodb/kube-arangodb/pkg/util"
36+
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil"
37+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
38+
)
39+
40+
// tests cursor forwarding with load-balanced conn., specify a source range
41+
func TestLoadBalancingSourceRanges(t *testing.T) {
42+
longOrSkip(t)
43+
44+
c := client.MustNewInCluster()
45+
kubecli := mustNewKubeClient(t)
46+
ns := getNamespace(t)
47+
48+
// Prepare deployment config
49+
namePrefix := "test-lb-src-ranges-"
50+
depl := newDeployment(namePrefix + uniuri.NewLen(4))
51+
depl.Spec.Mode = api.NewMode(api.DeploymentModeCluster)
52+
depl.Spec.Image = util.NewString("arangodb/arangodb:latest")
53+
depl.Spec.ExternalAccess.LoadBalancerSourceRanges = append(depl.Spec.ExternalAccess.LoadBalancerSourceRanges, "1.2.3.0/24", "0.0.0.0/0")
54+
55+
// Create deployment
56+
_, err := c.DatabaseV1alpha().ArangoDeployments(ns).Create(depl)
57+
if err != nil {
58+
t.Fatalf("Create deployment failed: %v", err)
59+
}
60+
// Prepare cleanup
61+
defer removeDeployment(c, depl.GetName(), ns)
62+
63+
// Wait for deployment to be ready
64+
apiObject, err := waitUntilDeployment(c, depl.GetName(), ns, deploymentIsReady())
65+
if err != nil {
66+
t.Fatalf("Deployment not running in time: %v", err)
67+
}
68+
69+
// Create a database client
70+
ctx := context.Background()
71+
clOpts := &DatabaseClientOptions{
72+
UseVST: false,
73+
ShortTimeout: true,
74+
}
75+
client := mustNewArangodDatabaseClient(ctx, kubecli, apiObject, t, clOpts)
76+
77+
// Wait for cluster to be available
78+
if err := waitUntilVersionUp(client, nil); err != nil {
79+
t.Fatalf("Cluster not running returning version in time: %v", err)
80+
}
81+
82+
// Now let's use the k8s api to check if the source ranges are present in
83+
// the external service spec:
84+
svcs := k8sutil.NewServiceCache(kubecli.CoreV1().Services(ns))
85+
eaServiceName := k8sutil.CreateDatabaseExternalAccessServiceName(depl.GetName())
86+
// Just in case, give the service some time to appear, it should usually
87+
// be there already, when the deployment is ready, however, we have had
88+
// unstable tests in the past
89+
counter := 0
90+
for counter < 60 {
91+
if svc, err := svcs.Get(eaServiceName, metav1.GetOptions{}); err == nil {
92+
spec := svc.Spec
93+
ranges := spec.LoadBalancerSourceRanges
94+
if len(ranges) != 2 {
95+
t.Errorf("LoadBalancerSourceRanges do not have length 2: %v", ranges)
96+
} else {
97+
if ranges[0] != "1.2.3.0/24" {
98+
t.Errorf("Expecting first LoadBalancerSourceRange to be \"1.2.3.0/24\", but ranges are: %v", ranges)
99+
}
100+
if ranges[1] != "0.0.0.0/0" {
101+
t.Errorf("Expecting second LoadBalancerSourceRange to be \"0.0.0.0/0\", but ranges are: %v", ranges)
102+
}
103+
}
104+
return
105+
}
106+
t.Logf("Service %s cannot be found, waiting for some time...", eaServiceName)
107+
time.Sleep(time.Second)
108+
counter += 1
109+
}
110+
t.Fatalf("Could not find service %s within 60 seconds, giving up.", eaServiceName)
111+
}

0 commit comments

Comments
 (0)