-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdriver-config.go
96 lines (83 loc) · 2.61 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
package main
import (
"bufio"
"fmt"
"os"
"path/filepath"
"text/template"
)
type driverConfig struct {
StorageClassFile string
SnapshotClassFile string
Capabilities []string
}
const (
testConfigDir = "test/k8s-integration/config"
configTemplateFile = "test-config-template.in"
configFile = "test-config.yaml"
)
// generateDriverConfigFile loads a testdriver config template and creates a file
// with the test-specific configuration
func generateDriverConfigFile(pkgDir, storageClassFile, snapshotClassFile, deploymentStrat string) (string, error) {
// Load template
t, err := template.ParseFiles(filepath.Join(pkgDir, testConfigDir, configTemplateFile))
if err != nil {
return "", err
}
// Create destination
configFilePath := filepath.Join(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",
}
/* Unsupported Capabilities:
pvcDataSource
RWX
volumeLimits # PD Supports volume limits but test is very slow
singleNodeVolume
dataSource
*/
// TODO: Support adding/removing capabilities based on Kubernetes version.
switch deploymentStrat {
case "gke":
case "gce":
// TODO: OSS K8S supports volume expansion for CSI by default in 1.16+;
// however, at time of writing GKE does not support K8S 1.16+. Add these
// capabilities for both deployment strategies when GKE Supports CSI
// Expansion by default.
caps = append(caps, "controllerExpansion", "nodeExpansion")
default:
return "", fmt.Errorf("got unknown deployment strat %s, expected gce or gke", deploymentStrat)
}
var absSnapshotClassFilePath string
// If snapshot class is passed in as argument, include snapshot specific driver capabiltiites.
if 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(pkgDir, testConfigDir, snapshotClassFile)
}
params := driverConfig{
StorageClassFile: filepath.Join(pkgDir, testConfigDir, storageClassFile),
SnapshotClassFile: absSnapshotClassFilePath,
Capabilities: caps,
}
// Write config file
err = t.Execute(w, params)
if err != nil {
return "", err
}
return configFilePath, nil
}