-
Notifications
You must be signed in to change notification settings - Fork 1
/
nfs_driver.go
141 lines (119 loc) · 3.6 KB
/
nfs_driver.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
package driver
import (
"fmt"
. "github.com/onsi/ginkgo"
"k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/kubernetes/test/e2e/framework"
"k8s.io/kubernetes/test/e2e/storage/testpatterns"
"k8s.io/kubernetes/test/e2e/storage/testsuites"
)
type nfsDriver struct {
driverInfo testsuites.DriverInfo
manifests []string
}
var NFSdriver func() testsuites.TestDriver
type nfsVolume struct {
serverIP string
serverPod *v1.Pod
f *framework.Framework
}
// initNFSDriver returns nfsDriver that implements TestDriver interface
func initNFSDriver(name string, manifests ...string) testsuites.TestDriver {
return &nfsDriver{
driverInfo: testsuites.DriverInfo{
Name: name,
MaxFileSize: testpatterns.FileSizeLarge,
SupportedFsType: sets.NewString(
"", // Default fsType
),
Capabilities: map[testsuites.Capability]bool{
testsuites.CapPersistence: true,
testsuites.CapExec: true,
},
},
manifests: manifests,
}
}
func InitNFSDriver() testsuites.TestDriver {
return initNFSDriver("csi-nfsplugin",
"nfs/csi-attacher-nfsplugin.yaml",
"nfs/csi-attacher-rbac.yaml",
"nfs/csi-nodeplugin-nfsplugin.yaml",
"nfs/csi-nodeplugin-rbac.yaml")
}
var _ testsuites.TestDriver = &nfsDriver{}
var _ testsuites.PreprovisionedVolumeTestDriver = &nfsDriver{}
var _ testsuites.PreprovisionedPVTestDriver = &nfsDriver{}
func (n *nfsDriver) GetDriverInfo() *testsuites.DriverInfo {
return &n.driverInfo
}
func (n *nfsDriver) SkipUnsupportedTest(pattern testpatterns.TestPattern) {
if pattern.VolType == testpatterns.DynamicPV {
framework.Skipf("NFS Driver does not support dynamic provisioning -- skipping")
}
}
func (n *nfsDriver) GetPersistentVolumeSource(readOnly bool, fsType string, volume testsuites.TestVolume) (*v1.PersistentVolumeSource, *v1.VolumeNodeAffinity) {
nv, _ := volume.(*nfsVolume)
return &v1.PersistentVolumeSource{
CSI: &v1.CSIPersistentVolumeSource{
Driver: n.driverInfo.Name,
VolumeHandle: "nfs-vol",
VolumeAttributes: map[string]string{
"server": nv.serverIP,
"share": "/",
"readOnly": "true",
},
},
}, nil
}
func (n *nfsDriver) PrepareTest(f *framework.Framework) (*testsuites.PerTestConfig, func()) {
config := &testsuites.PerTestConfig{
Driver: n,
Prefix: "nfs",
Framework: f,
}
//Install the nfs driver from the manifests
cleanup, err := config.Framework.CreateFromManifests(nil, n.manifests...)
if err != nil {
framework.Failf("deploying %s driver: %v", n.driverInfo.Name, err)
}
return config, func() {
By(fmt.Sprintf("uninstalling %s driver", n.driverInfo.Name))
cleanup()
}
}
func (n *nfsDriver) CreateVolume(config *testsuites.PerTestConfig, volType testpatterns.TestVolType) testsuites.TestVolume {
f := config.Framework
cs := f.ClientSet
ns := f.Namespace
switch volType {
case testpatterns.InlineVolume:
fallthrough
case testpatterns.PreprovisionedPV:
//Create nfs server pod
c := framework.VolumeTestConfig{
Namespace: ns.Name,
Prefix: "nfs",
ServerImage: "gcr.io/kubernetes-e2e-test-images/volume/nfs:1.0",
ServerPorts: []int{2049},
ServerVolumes: map[string]string{"": "/exports"},
ServerReadyMessage: "NFS started",
}
config.ServerConfig = &c
serverPod, serverIP := framework.CreateStorageServer(cs, c)
return &nfsVolume{
serverIP: serverIP,
serverPod: serverPod,
f: f,
}
case testpatterns.DynamicPV:
// Do nothing
default:
framework.Failf("Unsupported volType:%v is specified", volType)
}
return nil
}
func (v *nfsVolume) DeleteVolume() {
framework.CleanUpVolumeServer(v.f, v.serverPod)
}