forked from kubernetes/kubernetes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
in_tree.go
1564 lines (1333 loc) · 43.5 KB
/
in_tree.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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Copyright 2018 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
* This file defines various in-tree volume test drivers for TestSuites.
*
* There are two ways, how to prepare test drivers:
* 1) With containerized server (NFS, Ceph, Gluster, iSCSI, ...)
* It creates a server pod which defines one volume for the tests.
* These tests work only when privileged containers are allowed, exporting
* various filesystems (NFS, GlusterFS, ...) usually needs some mounting or
* other privileged magic in the server pod.
*
* Note that the server containers are for testing purposes only and should not
* be used in production.
*
* 2) With server or cloud provider outside of Kubernetes (Cinder, GCE, AWS, Azure, ...)
* Appropriate server or cloud provider must exist somewhere outside
* the tested Kubernetes cluster. CreateVolume will create a new volume to be
* used in the TestSuites for inlineVolume or DynamicPV tests.
*/
package drivers
import (
"fmt"
"math/rand"
"os/exec"
"strings"
"time"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"k8s.io/api/core/v1"
rbacv1beta1 "k8s.io/api/rbac/v1beta1"
storagev1 "k8s.io/api/storage/v1"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/apiserver/pkg/authentication/serviceaccount"
kubeletapis "k8s.io/kubernetes/pkg/kubelet/apis"
"k8s.io/kubernetes/test/e2e/framework"
"k8s.io/kubernetes/test/e2e/storage/testpatterns"
"k8s.io/kubernetes/test/e2e/storage/utils"
vspheretest "k8s.io/kubernetes/test/e2e/storage/vsphere"
imageutils "k8s.io/kubernetes/test/utils/image"
)
// NFS
type nfsDriver struct {
externalProvisionerPod *v1.Pod
externalPluginName string
driverInfo DriverInfo
}
type nfsTestResource struct {
serverIP string
serverPod *v1.Pod
}
var _ TestDriver = &nfsDriver{}
var _ PreprovisionedVolumeTestDriver = &nfsDriver{}
var _ InlineVolumeTestDriver = &nfsDriver{}
var _ PreprovisionedPVTestDriver = &nfsDriver{}
var _ DynamicPVTestDriver = &nfsDriver{}
// InitNFSDriver returns nfsDriver that implements TestDriver interface
func InitNFSDriver() TestDriver {
return &nfsDriver{
driverInfo: DriverInfo{
Name: "nfs",
MaxFileSize: testpatterns.FileSizeLarge,
SupportedFsType: sets.NewString(
"", // Default fsType
),
SupportedMountOption: sets.NewString("proto=tcp", "relatime"),
RequiredMountOption: sets.NewString("vers=4.1"),
Capabilities: map[Capability]bool{
CapPersistence: true,
CapExec: true,
},
},
}
}
func (n *nfsDriver) GetDriverInfo() *DriverInfo {
return &n.driverInfo
}
func (n *nfsDriver) SkipUnsupportedTest(pattern testpatterns.TestPattern) {
}
func (n *nfsDriver) GetVolumeSource(readOnly bool, fsType string, testResource interface{}) *v1.VolumeSource {
ntr, ok := testResource.(*nfsTestResource)
Expect(ok).To(BeTrue(), "Failed to cast test resource to NFS Test Resource")
return &v1.VolumeSource{
NFS: &v1.NFSVolumeSource{
Server: ntr.serverIP,
Path: "/",
ReadOnly: readOnly,
},
}
}
func (n *nfsDriver) GetPersistentVolumeSource(readOnly bool, fsType string, testResource interface{}) *v1.PersistentVolumeSource {
ntr, ok := testResource.(*nfsTestResource)
Expect(ok).To(BeTrue(), "Failed to cast test resource to NFS Test Resource")
return &v1.PersistentVolumeSource{
NFS: &v1.NFSVolumeSource{
Server: ntr.serverIP,
Path: "/",
ReadOnly: readOnly,
},
}
}
func (n *nfsDriver) GetDynamicProvisionStorageClass(fsType string) *storagev1.StorageClass {
provisioner := n.externalPluginName
parameters := map[string]string{"mountOptions": "vers=4.1"}
ns := n.driverInfo.Framework.Namespace.Name
suffix := fmt.Sprintf("%s-sc", n.driverInfo.Name)
return getStorageClass(provisioner, parameters, nil, ns, suffix)
}
func (n *nfsDriver) CreateDriver() {
f := n.driverInfo.Framework
cs := f.ClientSet
ns := f.Namespace
n.externalPluginName = fmt.Sprintf("example.com/nfs-%s", ns.Name)
// TODO(mkimuram): cluster-admin gives too much right but system:persistent-volume-provisioner
// is not enough. We should create new clusterrole for testing.
framework.BindClusterRole(cs.RbacV1beta1(), "cluster-admin", ns.Name,
rbacv1beta1.Subject{Kind: rbacv1beta1.ServiceAccountKind, Namespace: ns.Name, Name: "default"})
err := framework.WaitForAuthorizationUpdate(cs.AuthorizationV1beta1(),
serviceaccount.MakeUsername(ns.Name, "default"),
"", "get", schema.GroupResource{Group: "storage.k8s.io", Resource: "storageclasses"}, true)
framework.ExpectNoError(err, "Failed to update authorization: %v", err)
By("creating an external dynamic provisioner pod")
n.externalProvisionerPod = utils.StartExternalProvisioner(cs, ns.Name, n.externalPluginName)
}
func (n *nfsDriver) CleanupDriver() {
f := n.driverInfo.Framework
cs := f.ClientSet
ns := f.Namespace
framework.ExpectNoError(framework.DeletePodWithWait(f, cs, n.externalProvisionerPod))
clusterRoleBindingName := ns.Name + "--" + "cluster-admin"
cs.RbacV1beta1().ClusterRoleBindings().Delete(clusterRoleBindingName, metav1.NewDeleteOptions(0))
}
func (n *nfsDriver) CreateVolume(volType testpatterns.TestVolType) interface{} {
f := n.driverInfo.Framework
cs := f.ClientSet
ns := f.Namespace
// NewNFSServer creates a pod for InlineVolume and PreprovisionedPV,
// and startExternalProvisioner creates a pods for DynamicPV.
// Therefore, we need a different CreateDriver logic for volType.
switch volType {
case testpatterns.InlineVolume:
fallthrough
case testpatterns.PreprovisionedPV:
config, serverPod, serverIP := framework.NewNFSServer(cs, ns.Name, []string{})
n.driverInfo.Config = config
return &nfsTestResource{
serverIP: serverIP,
serverPod: serverPod,
}
case testpatterns.DynamicPV:
// Do nothing
default:
framework.Failf("Unsupported volType:%v is specified", volType)
}
return nil
}
func (n *nfsDriver) DeleteVolume(volType testpatterns.TestVolType, testResource interface{}) {
f := n.driverInfo.Framework
ntr, ok := testResource.(*nfsTestResource)
Expect(ok).To(BeTrue(), "Failed to cast test resource to NFS Test Resource")
switch volType {
case testpatterns.InlineVolume:
fallthrough
case testpatterns.PreprovisionedPV:
framework.CleanUpVolumeServer(f, ntr.serverPod)
case testpatterns.DynamicPV:
// Do nothing
default:
framework.Failf("Unsupported volType:%v is specified", volType)
}
}
// Gluster
type glusterFSDriver struct {
driverInfo DriverInfo
}
type glusterTestResource struct {
prefix string
serverPod *v1.Pod
}
var _ TestDriver = &glusterFSDriver{}
var _ PreprovisionedVolumeTestDriver = &glusterFSDriver{}
var _ InlineVolumeTestDriver = &glusterFSDriver{}
var _ PreprovisionedPVTestDriver = &glusterFSDriver{}
// InitGlusterFSDriver returns glusterFSDriver that implements TestDriver interface
func InitGlusterFSDriver() TestDriver {
return &glusterFSDriver{
driverInfo: DriverInfo{
Name: "gluster",
MaxFileSize: testpatterns.FileSizeMedium,
SupportedFsType: sets.NewString(
"", // Default fsType
),
Capabilities: map[Capability]bool{
CapPersistence: true,
CapExec: true,
},
},
}
}
func (g *glusterFSDriver) GetDriverInfo() *DriverInfo {
return &g.driverInfo
}
func (g *glusterFSDriver) SkipUnsupportedTest(pattern testpatterns.TestPattern) {
framework.SkipUnlessNodeOSDistroIs("gci", "ubuntu", "custom")
if pattern.FsType == "xfs" {
framework.SkipUnlessNodeOSDistroIs("ubuntu", "custom")
}
}
func (g *glusterFSDriver) GetVolumeSource(readOnly bool, fsType string, testResource interface{}) *v1.VolumeSource {
gtr, ok := testResource.(*glusterTestResource)
Expect(ok).To(BeTrue(), "Failed to cast test resource to Gluster Test Resource")
name := gtr.prefix + "-server"
return &v1.VolumeSource{
Glusterfs: &v1.GlusterfsVolumeSource{
EndpointsName: name,
// 'test_vol' comes from test/images/volumes-tester/gluster/run_gluster.sh
Path: "test_vol",
ReadOnly: readOnly,
},
}
}
func (g *glusterFSDriver) GetPersistentVolumeSource(readOnly bool, fsType string, testResource interface{}) *v1.PersistentVolumeSource {
gtr, ok := testResource.(*glusterTestResource)
Expect(ok).To(BeTrue(), "Failed to cast test resource to Gluster Test Resource")
name := gtr.prefix + "-server"
return &v1.PersistentVolumeSource{
Glusterfs: &v1.GlusterfsPersistentVolumeSource{
EndpointsName: name,
// 'test_vol' comes from test/images/volumes-tester/gluster/run_gluster.sh
Path: "test_vol",
ReadOnly: readOnly,
},
}
}
func (g *glusterFSDriver) CreateDriver() {
}
func (g *glusterFSDriver) CleanupDriver() {
}
func (g *glusterFSDriver) CreateVolume(volType testpatterns.TestVolType) interface{} {
f := g.driverInfo.Framework
cs := f.ClientSet
ns := f.Namespace
config, serverPod, _ := framework.NewGlusterfsServer(cs, ns.Name)
g.driverInfo.Config = config
return &glusterTestResource{
prefix: config.Prefix,
serverPod: serverPod,
}
}
func (g *glusterFSDriver) DeleteVolume(volType testpatterns.TestVolType, testResource interface{}) {
f := g.driverInfo.Framework
cs := f.ClientSet
ns := f.Namespace
gtr, ok := testResource.(*glusterTestResource)
Expect(ok).To(BeTrue(), "Failed to cast test resource to Gluster Test Resource")
name := gtr.prefix + "-server"
framework.Logf("Deleting Gluster endpoints %q...", name)
err := cs.CoreV1().Endpoints(ns.Name).Delete(name, nil)
if err != nil {
if !errors.IsNotFound(err) {
framework.Failf("Gluster delete endpoints failed: %v", err)
}
framework.Logf("Gluster endpoints %q not found, assuming deleted", name)
}
framework.Logf("Deleting Gluster server pod %q...", gtr.serverPod.Name)
err = framework.DeletePodWithWait(f, cs, gtr.serverPod)
if err != nil {
framework.Failf("Gluster server pod delete failed: %v", err)
}
}
// iSCSI
// The iscsiadm utility and iscsi target kernel modules must be installed on all nodes.
type iSCSIDriver struct {
driverInfo DriverInfo
}
type iSCSITestResource struct {
serverPod *v1.Pod
serverIP string
}
var _ TestDriver = &iSCSIDriver{}
var _ PreprovisionedVolumeTestDriver = &iSCSIDriver{}
var _ InlineVolumeTestDriver = &iSCSIDriver{}
var _ PreprovisionedPVTestDriver = &iSCSIDriver{}
// InitISCSIDriver returns iSCSIDriver that implements TestDriver interface
func InitISCSIDriver() TestDriver {
return &iSCSIDriver{
driverInfo: DriverInfo{
Name: "iscsi",
FeatureTag: "[Feature:Volumes]",
MaxFileSize: testpatterns.FileSizeMedium,
SupportedFsType: sets.NewString(
"", // Default fsType
"ext2",
// TODO: fix iSCSI driver can work with ext3
//"ext3",
"ext4",
),
Capabilities: map[Capability]bool{
CapPersistence: true,
CapFsGroup: true,
CapBlock: true,
CapExec: true,
},
},
}
}
func (i *iSCSIDriver) GetDriverInfo() *DriverInfo {
return &i.driverInfo
}
func (i *iSCSIDriver) SkipUnsupportedTest(pattern testpatterns.TestPattern) {
}
func (i *iSCSIDriver) GetVolumeSource(readOnly bool, fsType string, testResource interface{}) *v1.VolumeSource {
itr, ok := testResource.(*iSCSITestResource)
Expect(ok).To(BeTrue(), "Failed to cast test resource to iSCSI Test Resource")
volSource := v1.VolumeSource{
ISCSI: &v1.ISCSIVolumeSource{
TargetPortal: itr.serverIP + ":3260",
// from test/images/volume/iscsi/initiatorname.iscsi
IQN: "iqn.2003-01.org.linux-iscsi.f21.x8664:sn.4b0aae584f7c",
Lun: 0,
ReadOnly: readOnly,
},
}
if fsType != "" {
volSource.ISCSI.FSType = fsType
}
return &volSource
}
func (i *iSCSIDriver) GetPersistentVolumeSource(readOnly bool, fsType string, testResource interface{}) *v1.PersistentVolumeSource {
itr, ok := testResource.(*iSCSITestResource)
Expect(ok).To(BeTrue(), "Failed to cast test resource to iSCSI Test Resource")
pvSource := v1.PersistentVolumeSource{
ISCSI: &v1.ISCSIPersistentVolumeSource{
TargetPortal: itr.serverIP + ":3260",
IQN: "iqn.2003-01.org.linux-iscsi.f21.x8664:sn.4b0aae584f7c",
Lun: 0,
ReadOnly: readOnly,
},
}
if fsType != "" {
pvSource.ISCSI.FSType = fsType
}
return &pvSource
}
func (i *iSCSIDriver) CreateDriver() {
}
func (i *iSCSIDriver) CleanupDriver() {
}
func (i *iSCSIDriver) CreateVolume(volType testpatterns.TestVolType) interface{} {
f := i.driverInfo.Framework
cs := f.ClientSet
ns := f.Namespace
config, serverPod, serverIP := framework.NewISCSIServer(cs, ns.Name)
i.driverInfo.Config = config
return &iSCSITestResource{
serverPod: serverPod,
serverIP: serverIP,
}
}
func (i *iSCSIDriver) DeleteVolume(volType testpatterns.TestVolType, testResource interface{}) {
f := i.driverInfo.Framework
itr, ok := testResource.(*iSCSITestResource)
Expect(ok).To(BeTrue(), "Failed to cast test resource to iSCSI Test Resource")
framework.CleanUpVolumeServer(f, itr.serverPod)
}
// Ceph RBD
type rbdDriver struct {
driverInfo DriverInfo
}
type rbdTestResource struct {
serverPod *v1.Pod
serverIP string
secret *v1.Secret
}
var _ TestDriver = &rbdDriver{}
var _ PreprovisionedVolumeTestDriver = &rbdDriver{}
var _ InlineVolumeTestDriver = &rbdDriver{}
var _ PreprovisionedPVTestDriver = &rbdDriver{}
// InitRbdDriver returns rbdDriver that implements TestDriver interface
func InitRbdDriver() TestDriver {
return &rbdDriver{
driverInfo: DriverInfo{
Name: "rbd",
FeatureTag: "[Feature:Volumes]",
MaxFileSize: testpatterns.FileSizeMedium,
SupportedFsType: sets.NewString(
"", // Default fsType
"ext2",
// TODO: fix rbd driver can work with ext3
//"ext3",
"ext4",
),
Capabilities: map[Capability]bool{
CapPersistence: true,
CapFsGroup: true,
CapBlock: true,
CapExec: true,
},
},
}
}
func (r *rbdDriver) GetDriverInfo() *DriverInfo {
return &r.driverInfo
}
func (r *rbdDriver) SkipUnsupportedTest(pattern testpatterns.TestPattern) {
}
func (r *rbdDriver) GetVolumeSource(readOnly bool, fsType string, testResource interface{}) *v1.VolumeSource {
rtr, ok := testResource.(*rbdTestResource)
Expect(ok).To(BeTrue(), "Failed to cast test resource to RBD Test Resource")
volSource := v1.VolumeSource{
RBD: &v1.RBDVolumeSource{
CephMonitors: []string{rtr.serverIP},
RBDPool: "rbd",
RBDImage: "foo",
RadosUser: "admin",
SecretRef: &v1.LocalObjectReference{
Name: rtr.secret.Name,
},
ReadOnly: readOnly,
},
}
if fsType != "" {
volSource.RBD.FSType = fsType
}
return &volSource
}
func (r *rbdDriver) GetPersistentVolumeSource(readOnly bool, fsType string, testResource interface{}) *v1.PersistentVolumeSource {
f := r.driverInfo.Framework
ns := f.Namespace
rtr, ok := testResource.(*rbdTestResource)
Expect(ok).To(BeTrue(), "Failed to cast test resource to RBD Test Resource")
pvSource := v1.PersistentVolumeSource{
RBD: &v1.RBDPersistentVolumeSource{
CephMonitors: []string{rtr.serverIP},
RBDPool: "rbd",
RBDImage: "foo",
RadosUser: "admin",
SecretRef: &v1.SecretReference{
Name: rtr.secret.Name,
Namespace: ns.Name,
},
ReadOnly: readOnly,
},
}
if fsType != "" {
pvSource.RBD.FSType = fsType
}
return &pvSource
}
func (r *rbdDriver) CreateDriver() {
}
func (r *rbdDriver) CleanupDriver() {
}
func (r *rbdDriver) CreateVolume(volType testpatterns.TestVolType) interface{} {
f := r.driverInfo.Framework
cs := f.ClientSet
ns := f.Namespace
config, serverPod, secret, serverIP := framework.NewRBDServer(cs, ns.Name)
r.driverInfo.Config = config
return &rbdTestResource{
serverPod: serverPod,
serverIP: serverIP,
secret: secret,
}
}
func (r *rbdDriver) DeleteVolume(volType testpatterns.TestVolType, testResource interface{}) {
f := r.driverInfo.Framework
rtr, ok := testResource.(*rbdTestResource)
Expect(ok).To(BeTrue(), "Failed to cast test resource to RBD Test Resource")
framework.CleanUpVolumeServerWithSecret(f, rtr.serverPod, rtr.secret)
}
// Ceph
type cephFSDriver struct {
serverIP string
serverPod *v1.Pod
secret *v1.Secret
driverInfo DriverInfo
}
type cephTestResource struct {
serverPod *v1.Pod
serverIP string
secret *v1.Secret
}
var _ TestDriver = &cephFSDriver{}
var _ PreprovisionedVolumeTestDriver = &cephFSDriver{}
var _ InlineVolumeTestDriver = &cephFSDriver{}
var _ PreprovisionedPVTestDriver = &cephFSDriver{}
// InitCephFSDriver returns cephFSDriver that implements TestDriver interface
func InitCephFSDriver() TestDriver {
return &cephFSDriver{
driverInfo: DriverInfo{
Name: "ceph",
FeatureTag: "[Feature:Volumes]",
MaxFileSize: testpatterns.FileSizeMedium,
SupportedFsType: sets.NewString(
"", // Default fsType
),
Capabilities: map[Capability]bool{
CapPersistence: true,
CapExec: true,
},
},
}
}
func (c *cephFSDriver) GetDriverInfo() *DriverInfo {
return &c.driverInfo
}
func (c *cephFSDriver) SkipUnsupportedTest(pattern testpatterns.TestPattern) {
}
func (c *cephFSDriver) GetVolumeSource(readOnly bool, fsType string, testResource interface{}) *v1.VolumeSource {
ctr, ok := testResource.(*cephTestResource)
Expect(ok).To(BeTrue(), "Failed to cast test resource to Ceph Test Resource")
return &v1.VolumeSource{
CephFS: &v1.CephFSVolumeSource{
Monitors: []string{ctr.serverIP + ":6789"},
User: "kube",
SecretRef: &v1.LocalObjectReference{
Name: ctr.secret.Name,
},
ReadOnly: readOnly,
},
}
}
func (c *cephFSDriver) GetPersistentVolumeSource(readOnly bool, fsType string, testResource interface{}) *v1.PersistentVolumeSource {
f := c.driverInfo.Framework
ns := f.Namespace
ctr, ok := testResource.(*cephTestResource)
Expect(ok).To(BeTrue(), "Failed to cast test resource to Ceph Test Resource")
return &v1.PersistentVolumeSource{
CephFS: &v1.CephFSPersistentVolumeSource{
Monitors: []string{ctr.serverIP + ":6789"},
User: "kube",
SecretRef: &v1.SecretReference{
Name: ctr.secret.Name,
Namespace: ns.Name,
},
ReadOnly: readOnly,
},
}
}
func (c *cephFSDriver) CreateDriver() {
}
func (c *cephFSDriver) CleanupDriver() {
}
func (c *cephFSDriver) CreateVolume(volType testpatterns.TestVolType) interface{} {
f := c.driverInfo.Framework
cs := f.ClientSet
ns := f.Namespace
config, serverPod, secret, serverIP := framework.NewRBDServer(cs, ns.Name)
c.driverInfo.Config = config
return &cephTestResource{
serverPod: serverPod,
serverIP: serverIP,
secret: secret,
}
}
func (c *cephFSDriver) DeleteVolume(volType testpatterns.TestVolType, testResource interface{}) {
f := c.driverInfo.Framework
ctr, ok := testResource.(*cephTestResource)
Expect(ok).To(BeTrue(), "Failed to cast test resource to Ceph Test Resource")
framework.CleanUpVolumeServerWithSecret(f, ctr.serverPod, ctr.secret)
}
// Hostpath
type hostPathDriver struct {
node v1.Node
driverInfo DriverInfo
}
var _ TestDriver = &hostPathDriver{}
var _ PreprovisionedVolumeTestDriver = &hostPathDriver{}
var _ InlineVolumeTestDriver = &hostPathDriver{}
// InitHostPathDriver returns hostPathDriver that implements TestDriver interface
func InitHostPathDriver() TestDriver {
return &hostPathDriver{
driverInfo: DriverInfo{
Name: "hostPath",
MaxFileSize: testpatterns.FileSizeMedium,
SupportedFsType: sets.NewString(
"", // Default fsType
),
Capabilities: map[Capability]bool{
CapPersistence: true,
},
},
}
}
func (h *hostPathDriver) GetDriverInfo() *DriverInfo {
return &h.driverInfo
}
func (h *hostPathDriver) SkipUnsupportedTest(pattern testpatterns.TestPattern) {
}
func (h *hostPathDriver) GetVolumeSource(readOnly bool, fsType string, testResource interface{}) *v1.VolumeSource {
// hostPath doesn't support readOnly volume
if readOnly {
return nil
}
return &v1.VolumeSource{
HostPath: &v1.HostPathVolumeSource{
Path: "/tmp",
},
}
}
func (h *hostPathDriver) CreateDriver() {
}
func (h *hostPathDriver) CleanupDriver() {
}
func (h *hostPathDriver) CreateVolume(volType testpatterns.TestVolType) interface{} {
f := h.driverInfo.Framework
cs := f.ClientSet
// pods should be scheduled on the node
nodes := framework.GetReadySchedulableNodesOrDie(cs)
node := nodes.Items[rand.Intn(len(nodes.Items))]
h.driverInfo.Config.ClientNodeName = node.Name
return nil
}
func (h *hostPathDriver) DeleteVolume(volType testpatterns.TestVolType, testResource interface{}) {
}
// HostPathSymlink
type hostPathSymlinkDriver struct {
node v1.Node
driverInfo DriverInfo
}
type hostPathSymlinkTestResource struct {
targetPath string
sourcePath string
prepPod *v1.Pod
}
var _ TestDriver = &hostPathSymlinkDriver{}
var _ PreprovisionedVolumeTestDriver = &hostPathSymlinkDriver{}
var _ InlineVolumeTestDriver = &hostPathSymlinkDriver{}
// InitHostPathSymlinkDriver returns hostPathSymlinkDriver that implements TestDriver interface
func InitHostPathSymlinkDriver() TestDriver {
return &hostPathSymlinkDriver{
driverInfo: DriverInfo{
Name: "hostPathSymlink",
MaxFileSize: testpatterns.FileSizeMedium,
SupportedFsType: sets.NewString(
"", // Default fsType
),
Capabilities: map[Capability]bool{
CapPersistence: true,
},
},
}
}
func (h *hostPathSymlinkDriver) GetDriverInfo() *DriverInfo {
return &h.driverInfo
}
func (h *hostPathSymlinkDriver) SkipUnsupportedTest(pattern testpatterns.TestPattern) {
}
func (h *hostPathSymlinkDriver) GetVolumeSource(readOnly bool, fsType string, testResource interface{}) *v1.VolumeSource {
htr, ok := testResource.(*hostPathSymlinkTestResource)
Expect(ok).To(BeTrue(), "Failed to cast test resource to Hostpath Symlink Test Resource")
// hostPathSymlink doesn't support readOnly volume
if readOnly {
return nil
}
return &v1.VolumeSource{
HostPath: &v1.HostPathVolumeSource{
Path: htr.targetPath,
},
}
}
func (h *hostPathSymlinkDriver) CreateDriver() {
}
func (h *hostPathSymlinkDriver) CleanupDriver() {
}
func (h *hostPathSymlinkDriver) CreateVolume(volType testpatterns.TestVolType) interface{} {
f := h.driverInfo.Framework
cs := f.ClientSet
sourcePath := fmt.Sprintf("/tmp/%v", f.Namespace.Name)
targetPath := fmt.Sprintf("/tmp/%v-link", f.Namespace.Name)
volumeName := "test-volume"
// pods should be scheduled on the node
nodes := framework.GetReadySchedulableNodesOrDie(cs)
node := nodes.Items[rand.Intn(len(nodes.Items))]
h.driverInfo.Config.ClientNodeName = node.Name
cmd := fmt.Sprintf("mkdir %v -m 777 && ln -s %v %v", sourcePath, sourcePath, targetPath)
privileged := true
// Launch pod to initialize hostPath directory and symlink
prepPod := &v1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: fmt.Sprintf("hostpath-symlink-prep-%s", f.Namespace.Name),
},
Spec: v1.PodSpec{
Containers: []v1.Container{
{
Name: fmt.Sprintf("init-volume-%s", f.Namespace.Name),
Image: imageutils.GetE2EImage(imageutils.BusyBox),
Command: []string{"/bin/sh", "-ec", cmd},
VolumeMounts: []v1.VolumeMount{
{
Name: volumeName,
MountPath: "/tmp",
},
},
SecurityContext: &v1.SecurityContext{
Privileged: &privileged,
},
},
},
RestartPolicy: v1.RestartPolicyNever,
Volumes: []v1.Volume{
{
Name: volumeName,
VolumeSource: v1.VolumeSource{
HostPath: &v1.HostPathVolumeSource{
Path: "/tmp",
},
},
},
},
NodeName: node.Name,
},
}
// h.prepPod will be reused in cleanupDriver.
pod, err := f.ClientSet.CoreV1().Pods(f.Namespace.Name).Create(prepPod)
Expect(err).ToNot(HaveOccurred(), "while creating hostPath init pod")
err = framework.WaitForPodSuccessInNamespace(f.ClientSet, pod.Name, pod.Namespace)
Expect(err).ToNot(HaveOccurred(), "while waiting for hostPath init pod to succeed")
err = framework.DeletePodWithWait(f, f.ClientSet, pod)
Expect(err).ToNot(HaveOccurred(), "while deleting hostPath init pod")
return &hostPathSymlinkTestResource{
sourcePath: sourcePath,
targetPath: targetPath,
prepPod: prepPod,
}
}
func (h *hostPathSymlinkDriver) DeleteVolume(volType testpatterns.TestVolType, testResource interface{}) {
f := h.driverInfo.Framework
htr, ok := testResource.(*hostPathSymlinkTestResource)
Expect(ok).To(BeTrue(), "Failed to cast test resource to Hostpath Symlink Test Resource")
cmd := fmt.Sprintf("rm -rf %v&& rm -rf %v", htr.targetPath, htr.sourcePath)
htr.prepPod.Spec.Containers[0].Command = []string{"/bin/sh", "-ec", cmd}
pod, err := f.ClientSet.CoreV1().Pods(f.Namespace.Name).Create(htr.prepPod)
Expect(err).ToNot(HaveOccurred(), "while creating hostPath teardown pod")
err = framework.WaitForPodSuccessInNamespace(f.ClientSet, pod.Name, pod.Namespace)
Expect(err).ToNot(HaveOccurred(), "while waiting for hostPath teardown pod to succeed")
err = framework.DeletePodWithWait(f, f.ClientSet, pod)
Expect(err).ToNot(HaveOccurred(), "while deleting hostPath teardown pod")
}
// emptydir
type emptydirDriver struct {
driverInfo DriverInfo
}
var _ TestDriver = &emptydirDriver{}
var _ PreprovisionedVolumeTestDriver = &emptydirDriver{}
var _ InlineVolumeTestDriver = &emptydirDriver{}
// InitEmptydirDriver returns emptydirDriver that implements TestDriver interface
func InitEmptydirDriver() TestDriver {
return &emptydirDriver{
driverInfo: DriverInfo{
Name: "emptydir",
MaxFileSize: testpatterns.FileSizeMedium,
SupportedFsType: sets.NewString(
"", // Default fsType
),
Capabilities: map[Capability]bool{
CapExec: true,
},
},
}
}
func (e *emptydirDriver) GetDriverInfo() *DriverInfo {
return &e.driverInfo
}
func (e *emptydirDriver) SkipUnsupportedTest(pattern testpatterns.TestPattern) {
}
func (e *emptydirDriver) GetVolumeSource(readOnly bool, fsType string, testResource interface{}) *v1.VolumeSource {
// emptydir doesn't support readOnly volume
if readOnly {
return nil
}
return &v1.VolumeSource{
EmptyDir: &v1.EmptyDirVolumeSource{},
}
}
func (e *emptydirDriver) CreateVolume(volType testpatterns.TestVolType) interface{} {
return nil
}
func (e *emptydirDriver) DeleteVolume(volType testpatterns.TestVolType, testResource interface{}) {
}
func (e *emptydirDriver) CreateDriver() {
}
func (e *emptydirDriver) CleanupDriver() {
}
// Cinder
// This driver assumes that OpenStack client tools are installed
// (/usr/bin/nova, /usr/bin/cinder and /usr/bin/keystone)
// and that the usual OpenStack authentication env. variables are set
// (OS_USERNAME, OS_PASSWORD, OS_TENANT_NAME at least).
type cinderDriver struct {
driverInfo DriverInfo
}
type cinderTestResource struct {
volumeName string
volumeID string
}
var _ TestDriver = &cinderDriver{}
var _ PreprovisionedVolumeTestDriver = &cinderDriver{}
var _ InlineVolumeTestDriver = &cinderDriver{}
var _ PreprovisionedPVTestDriver = &cinderDriver{}
var _ DynamicPVTestDriver = &cinderDriver{}
// InitCinderDriver returns cinderDriver that implements TestDriver interface
func InitCinderDriver() TestDriver {
return &cinderDriver{
driverInfo: DriverInfo{
Name: "cinder",
MaxFileSize: testpatterns.FileSizeMedium,
SupportedFsType: sets.NewString(
"", // Default fsType
"ext3",
),
Capabilities: map[Capability]bool{
CapPersistence: true,
CapFsGroup: true,
CapExec: true,
},
},
}
}
func (c *cinderDriver) GetDriverInfo() *DriverInfo {
return &c.driverInfo
}
func (c *cinderDriver) SkipUnsupportedTest(pattern testpatterns.TestPattern) {
framework.SkipUnlessProviderIs("openstack")
}
func (c *cinderDriver) GetVolumeSource(readOnly bool, fsType string, testResource interface{}) *v1.VolumeSource {
ctr, ok := testResource.(*cinderTestResource)
Expect(ok).To(BeTrue(), "Failed to cast test resource to Cinder Test Resource")
volSource := v1.VolumeSource{
Cinder: &v1.CinderVolumeSource{
VolumeID: ctr.volumeID,
ReadOnly: readOnly,