-
Notifications
You must be signed in to change notification settings - Fork 159
/
Copy pathdriver-config.go
173 lines (157 loc) · 4.96 KB
/
driver-config.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
package main
import (
"bufio"
"fmt"
"os"
"path/filepath"
"strings"
"text/template"
)
type driverConfig struct {
StorageClassFile string
StorageClass string
SnapshotClassFile string
SnapshotClass string
VolumeAttributesClassFile string
VolumeAttributesClass string
Capabilities []string
SupportedFsType []string
MinimumVolumeSize string
NumAllowedTopologies int
Timeouts map[string]string
}
const (
testConfigDir = "test/k8s-integration/config"
configTemplateFile = "test-config-template.in"
configFile = "test-config.yaml"
// configurable timeouts for the k8s e2e testsuites
dataSourceProvisionTimeout = "480s"
// These are keys for the configurable timeout map.
dataSourceProvisionTimeoutKey = "DataSourceProvision"
)
// generateDriverConfigFile loads a testdriver config template and creates a file
// with the test-specific configuration
func generateDriverConfigFile(testParams *testParameters) (string, error) {
// Load template
t, err := template.ParseFiles(filepath.Join(testParams.pkgDir, testConfigDir, configTemplateFile))
if err != nil {
return "", err
}
// Create destination
configFilePath := filepath.Join(testParams.pkgDir, testConfigDir, configFile)
f, err := os.Create(configFilePath)
if err != nil {
return "", err
}
defer f.Close()
w := bufio.NewWriter(f)
defer w.Flush()
// Fill in template parameters. Capabilities can be found here:
// https://github.com/kubernetes/kubernetes/blob/b717be8269a4f381ab6c23e711e8924bc1f64c93/test/e2e/storage/testsuites/testdriver.go#L136
caps := []string{
"persistence",
"block",
"fsGroup",
"exec",
"multipods",
"topology",
"controllerExpansion",
"nodeExpansion",
}
var fsTypes []string
if testParams.platform == "windows" {
fsTypes = []string{"ntfs"}
caps = []string{
"persistence",
"exec",
"multipods",
"topology",
}
} else {
fsTypes = []string{
"ext2",
"ext3",
"ext4",
}
}
/* Unsupported Capabilities:
RWX
volumeLimits # PD Supports volume limits but test is very slow
singleNodeVolume
dataSource
*/
switch testParams.deploymentStrategy {
case "gke":
if testParams.imageType == "cos" {
var gkeVer *version
// The node version is what matters for XFS support. If the node version is not given, we assume
// it's the same as the cluster master version.
if testParams.nodeVersion != "" {
gkeVer = mustParseVersion(testParams.nodeVersion)
} else {
gkeVer = mustParseVersion(testParams.clusterVersion)
}
if gkeVer.lessThan(mustParseVersion("1.18.0")) {
// XFS is not supported on COS before 1.18.0
} else {
fsTypes = append(fsTypes, "xfs")
}
} else {
// XFS is supported on all non-COS images.
fsTypes = append(fsTypes, "xfs")
}
case "gce":
fsTypes = append(fsTypes, "xfs")
default:
return "", fmt.Errorf("got unknown deployment strat %s, expected gce or gke", testParams.deploymentStrategy)
}
var absSnapshotClassFilePath string
var snapshotClassName string
// If snapshot class is passed in as argument, include snapshot specific driver capabiltiites.
if testParams.snapshotClassFile != "" {
caps = append(caps, "snapshotDataSource")
// Update the absolute file path pointing to the snapshot class file, if it is provided as an argument.
absSnapshotClassFilePath = filepath.Join(testParams.pkgDir, testConfigDir, testParams.snapshotClassFile)
snapshotClassName = testParams.snapshotClassFile[:strings.LastIndex(testParams.snapshotClassFile, ".")]
} else {
snapshotClassName = "no-vsc"
}
var absVacFilePath string
if testParams.volumeAttributesClassFile != "" {
absVacFilePath = filepath.Join(testParams.pkgDir, testConfigDir, testParams.volumeAttributesClassFile)
}
if !strings.Contains(testParams.storageClassFile, "sc-extreme") {
caps = append(caps, "pvcDataSource")
}
minimumVolumeSize := "10Gi"
numAllowedTopologies := 1
if testParams.storageClassFile == regionalPDStorageClass {
minimumVolumeSize = "200Gi"
numAllowedTopologies = 2
} else if len(testParams.volumeAttributesClassFile) > 0 {
minimumVolumeSize = "100Gi"
}
timeouts := map[string]string{
dataSourceProvisionTimeoutKey: dataSourceProvisionTimeout,
}
extLoc := strings.LastIndex(testParams.storageClassFile, ".")
scName := testParams.storageClassFile[:extLoc]
params := driverConfig{
StorageClassFile: filepath.Join(testParams.pkgDir, testConfigDir, testParams.storageClassFile),
StorageClass: scName,
SnapshotClassFile: absSnapshotClassFilePath,
SnapshotClass: snapshotClassName,
VolumeAttributesClassFile: absVacFilePath,
SupportedFsType: fsTypes,
Capabilities: caps,
MinimumVolumeSize: minimumVolumeSize,
NumAllowedTopologies: numAllowedTopologies,
Timeouts: timeouts,
}
// Write config file
err = t.Execute(w, params)
if err != nil {
return "", err
}
return configFilePath, nil
}