Skip to content

Commit fd86e4e

Browse files
authored
Merge pull request #94 from arangodb/prepull-enterprise-image
Added helper to prepull arangodb (enterprise) image. This allows the normal tests to have decent timeouts while prevent a timeout caused by a long during image pull.
2 parents 82a6550 + 49ba607 commit fd86e4e

File tree

3 files changed

+108
-0
lines changed

3 files changed

+108
-0
lines changed

manifests/templates/test/rbac.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ rules:
99
- apiGroups: [""]
1010
resources: ["nodes"]
1111
verbs: ["list"]
12+
- apiGroups: ["apps"]
13+
resources: ["daemonsets"]
14+
verbs: ["*"]
1215

1316
---
1417

tests/prepull_image_util.go

+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
//
2+
// DISCLAIMER
3+
//
4+
// Copyright 2018 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+
//
22+
23+
package tests
24+
25+
import (
26+
"crypto/sha1"
27+
"fmt"
28+
"strings"
29+
"time"
30+
31+
"github.com/dchest/uniuri"
32+
appsv1 "k8s.io/api/apps/v1"
33+
corev1 "k8s.io/api/core/v1"
34+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
35+
"k8s.io/client-go/kubernetes"
36+
37+
"github.com/arangodb/kube-arangodb/pkg/util/retry"
38+
)
39+
40+
// prepullImage runs a daemonset that pulls a given ArangoDB image on all nodes.
41+
func prepullArangoImage(cli kubernetes.Interface, image, namespace string) error {
42+
name := "prepuller-" + strings.ToLower(uniuri.NewLen(4))
43+
dsLabels := map[string]string{
44+
"app": "prepuller",
45+
"image-hash": fmt.Sprintf("%0x", sha1.Sum([]byte(image)))[:10],
46+
}
47+
ds := &appsv1.DaemonSet{
48+
ObjectMeta: metav1.ObjectMeta{
49+
Name: name,
50+
Labels: dsLabels,
51+
},
52+
Spec: appsv1.DaemonSetSpec{
53+
Selector: &metav1.LabelSelector{
54+
MatchLabels: dsLabels,
55+
},
56+
Template: corev1.PodTemplateSpec{
57+
ObjectMeta: metav1.ObjectMeta{
58+
Labels: dsLabels,
59+
},
60+
Spec: corev1.PodSpec{
61+
Containers: []corev1.Container{
62+
corev1.Container{
63+
Name: "arango",
64+
Image: image,
65+
Env: []corev1.EnvVar{
66+
corev1.EnvVar{
67+
Name: "ARANGO_NO_AUTH",
68+
Value: "1",
69+
},
70+
},
71+
},
72+
},
73+
},
74+
},
75+
},
76+
}
77+
// Create DS
78+
if _, err := cli.AppsV1().DaemonSets(namespace).Create(ds); err != nil {
79+
return maskAny(err)
80+
}
81+
// Cleanup on exit
82+
defer func() {
83+
cli.AppsV1().DaemonSets(namespace).Delete(name, &metav1.DeleteOptions{})
84+
}()
85+
// Now wait for it to be ready
86+
op := func() error {
87+
current, err := cli.AppsV1().DaemonSets(namespace).Get(name, metav1.GetOptions{})
88+
if err != nil {
89+
return maskAny(err)
90+
}
91+
if current.Status.DesiredNumberScheduled > current.Status.NumberReady {
92+
return maskAny(fmt.Errorf("Expected %d pods to be ready, got %d", current.Status.DesiredNumberScheduled, current.Status.NumberReady))
93+
}
94+
return nil
95+
}
96+
if err := retry.Retry(op, time.Hour); err != nil {
97+
return maskAny(err)
98+
}
99+
return nil
100+
}

tests/rocksdb_encryption_test.go

+5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import (
66
"strings"
77
"testing"
88

9+
"github.com/stretchr/testify/assert"
10+
911
"github.com/dchest/uniuri"
1012

1113
api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1alpha"
@@ -23,6 +25,9 @@ func TestRocksDBEncryptionSingle(t *testing.T) {
2325
kubecli := mustNewKubeClient(t)
2426
ns := getNamespace(t)
2527

28+
// Prepull enterprise images
29+
assert.NoError(t, prepullArangoImage(kubecli, image, ns))
30+
2631
// Prepare deployment config
2732
depl := newDeployment("test-rocksdb-enc-sng-" + uniuri.NewLen(4))
2833
depl.Spec.Mode = api.NewMode(api.DeploymentModeSingle)

0 commit comments

Comments
 (0)