-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathcontroller_test.go
109 lines (91 loc) · 2.98 KB
/
controller_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
package storage_test
import (
"context"
"fmt"
"path/filepath"
"testing"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/manager"
testobjects "github.com/ydb-platform/ydb-kubernetes-operator/e2e/tests/test-objects"
"github.com/ydb-platform/ydb-kubernetes-operator/internal/controllers/storage"
"github.com/ydb-platform/ydb-kubernetes-operator/internal/test"
)
var (
k8sClient client.Client
ctx context.Context
)
func TestAPIs(t *testing.T) {
RegisterFailHandler(Fail)
test.SetupK8STestManager(&ctx, &k8sClient, func(mgr *manager.Manager) []test.Reconciler {
return []test.Reconciler{
&storage.Reconciler{
Client: k8sClient,
Scheme: (*mgr).GetScheme(),
},
}
})
RunSpecs(t, "Storage controller medium tests suite")
}
var _ = Describe("Storage controller medium tests", func() {
var namespace corev1.Namespace
BeforeEach(func() {
namespace = corev1.Namespace{
ObjectMeta: metav1.ObjectMeta{
Name: testobjects.YdbNamespace,
},
}
Expect(k8sClient.Create(ctx, &namespace)).Should(Succeed())
})
AfterEach(func() {
Expect(k8sClient.Delete(ctx, &namespace)).Should(Succeed())
})
It("Check volume has been propagated to pods", func() {
storageSample := testobjects.DefaultStorage(filepath.Join("..", "..", "..", "e2e", "tests", "data", "storage-block-4-2-config.yaml"))
tmpFilesDir := "/tmp/mounted_volume"
testVolumeName := "sample-volume"
testVolumeMountPath := fmt.Sprintf("%v/volume", tmpFilesDir)
HostPathDirectoryType := corev1.HostPathDirectory
storageSample.Spec.Volumes = append(storageSample.Spec.Volumes, &corev1.Volume{
Name: testVolumeName,
VolumeSource: corev1.VolumeSource{
HostPath: &corev1.HostPathVolumeSource{
Path: testVolumeMountPath,
Type: &HostPathDirectoryType,
},
},
})
Expect(k8sClient.Create(ctx, storageSample)).Should(Succeed())
storageStatefulSets := appsv1.StatefulSetList{}
Eventually(func() bool {
Expect(k8sClient.List(ctx, &storageStatefulSets, client.InNamespace(
testobjects.YdbNamespace,
))).Should(Succeed())
foundStatefulSet := false
for _, statefulSet := range storageStatefulSets.Items {
if statefulSet.Name == testobjects.StorageName {
foundStatefulSet = true
break
}
}
return foundStatefulSet
}, test.Timeout, test.Interval).Should(BeTrue())
storageSS := storageStatefulSets.Items[0]
volumes := storageSS.Spec.Template.Spec.Volumes
// Pod Template always has `ydb-config` mounted as a volume, plus in
// this test it also has our test volume. So two in total:
Expect(len(volumes)).To(Equal(1 + 1))
foundVolume := false
for _, volume := range volumes {
if volume.Name == testVolumeName {
foundVolume = true
Expect(volume.VolumeSource.HostPath.Path).To(Equal(testVolumeMountPath))
}
}
Expect(foundVolume).To(BeTrue())
})
})