forked from IBM/ibm-csi-common
-
Notifications
You must be signed in to change notification settings - Fork 0
/
multi_vol_multi_pod.go
183 lines (164 loc) · 4.55 KB
/
multi_vol_multi_pod.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
/**
* Copyright 2021 IBM Corp.
*
* 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.
*/
package e2e
import (
"os"
"strconv"
"github.com/IBM/ibm-csi-common/tests/e2e/testsuites"
. "github.com/onsi/ginkgo"
v1 "k8s.io/api/core/v1"
clientset "k8s.io/client-go/kubernetes"
"k8s.io/kubernetes/test/e2e/framework"
)
var _ = Describe("[ics-e2e] [exec-mvmp] [pods-simul] Multiple POD with PVCs", func() {
var (
cs clientset.Interface
cleanupFuncs []func()
volList []testsuites.VolumeDetails
//cmdShotLife string
cmdLongLife string
withPVC bool
maxPVC int
maxPOD int
fw *framework.Framework
ns *v1.Namespace
)
withPVC = true
envOpt := os.Getenv("E2E_NOPVC")
if envOpt == "yes" {
withPVC = false
}
maxPOD = 1
podCount := os.Getenv("E2E_POD_COUNT")
if len(podCount) > 0 {
var err error
maxPOD, err = strconv.Atoi(podCount)
if err != nil {
maxPOD = 1
}
}
maxPVC = 1
pvcCount := os.Getenv("E2E_PVC_COUNT")
if len(pvcCount) > 0 {
var err error
maxPVC, err = strconv.Atoi(pvcCount)
if err != nil {
maxPVC = 1
}
}
fw = framework.NewDefaultFramework("ics-e2e-mvmp")
BeforeEach(func() {
cs = fw.ClientSet
ns = fw.Namespace
cleanupFuncs = make([]func(), 0)
//cmdShotLife = "df -h; echo 'hello world' > /mnt/test-1/data && grep 'hello world' /mnt/test-1/data"
cmdLongLife = "df -h; echo 'hello world' > /mnt/test-1/data && while true; do sleep 2; done"
reclaimPolicy := v1.PersistentVolumeReclaimDelete
accessMode := v1.ReadWriteOnce
volList = []testsuites.VolumeDetails{
{
PVCName: "ics-vol-5iops-",
VolumeType: "ibmc-vpc-block-5iops-tier",
FSType: "ext4",
ClaimSize: "11Gi",
ReclaimPolicy: &reclaimPolicy,
MountOptions: []string{"rw"},
AccessMode: &accessMode,
VolumeMount: testsuites.VolumeMountDetails{
NameGenerate: "test-volume-",
MountPathGenerate: "/mnt/test-",
ReadOnly: false,
},
},
{
PVCName: "ics-vol-gp-",
VolumeType: "ibmc-vpc-block-general-purpose",
FSType: "ext4",
ClaimSize: "12Gi",
ReclaimPolicy: &reclaimPolicy,
MountOptions: []string{"rw"},
AccessMode: &accessMode,
VolumeMount: testsuites.VolumeMountDetails{
NameGenerate: "test-volume-",
MountPathGenerate: "/mnt/test-",
ReadOnly: false,
},
},
{
PVCName: "ics-vol-5iops-",
VolumeType: "ibmc-vpc-block-5iops-tier",
FSType: "ext4",
ClaimSize: "13Gi",
ReclaimPolicy: &reclaimPolicy,
MountOptions: []string{"rw"},
AccessMode: &accessMode,
VolumeMount: testsuites.VolumeMountDetails{
NameGenerate: "test-volume-",
MountPathGenerate: "/mnt/test-",
ReadOnly: false,
},
},
}
})
It("should create multiple pods in parallel with PVC(s), write and read to volume", func() {
By("create multiple pods in parallel with PVC(s)")
var execCmd string
var cmdExits bool
var pods []testsuites.PodDetails
vollistLen := len(volList)
pods = make([]testsuites.PodDetails, 0)
for i := 0; i < maxPOD; i++ {
framework.Logf("creating PVC(s) for POD %d", i+1)
vols := make([]testsuites.VolumeDetails, 0)
xi := 0
for i := 0; vollistLen > 0 && i < maxPVC; i++ {
if xi >= vollistLen {
xi = 0
}
vol := volList[xi]
vols = append(vols, vol)
xi = xi + 1
}
//Create PVC
if withPVC {
execCmd = cmdLongLife
cmdExits = false
for n := range vols {
_, funcs := vols[n].SetupDynamicPersistentVolumeClaim(cs, ns)
cleanupFuncs = append(cleanupFuncs, funcs...)
}
} else {
// Without PVC
execCmd = "echo 'hello world' && while true; do sleep 2; done"
cmdExits = false
}
for i := range cleanupFuncs {
defer cleanupFuncs[i]()
}
pod := testsuites.PodDetails{
Cmd: execCmd,
CmdExits: cmdExits,
Volumes: vols,
}
pods = append(pods, pod)
}
test := testsuites.DynamicallyProvisioneMultiPodWithVolTest{
Pods: pods,
PodCheck: nil,
}
test.RunAsync(cs, ns)
})
})