Skip to content
This repository was archived by the owner on Jun 23, 2020. It is now read-only.

Commit 61a875b

Browse files
author
Harvey Lowndes
committed
Use symlink in storage class to find correct driver
1 parent beafd42 commit 61a875b

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

cmd/oci/main.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,10 @@ func main() {
5050
log.SetOutput(f)
5151

5252
log.Printf("OCI FlexVolume Driver version: %s (%s)", version, build)
53-
flexvolume.ExecDriver(&driver.OCIFlexvolumeDriver{}, os.Args)
53+
54+
drivers := map[string]flexvolume.Driver{
55+
"oci-bvs": &driver.OCIFlexvolumeDriver{},
56+
}
57+
58+
flexvolume.ExecDriver(drivers, os.Args)
5459
}

deploy.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ set -o pipefail
2020
VENDOR=oracle
2121
DRIVER=oci
2222

23-
driver_dir="/flexmnt/$VENDOR${VENDOR:+"~"}${DRIVER}"
23+
ORACLE_OCI_FOLDER=$VENDOR${VENDOR:+"~"}${DRIVER}
24+
25+
driver_dir="/flexmnt/$ORACLE_OCI_FOLDER"
2426

2527
LOG_FILE="$driver_dir/oci_flexvolume_driver.log"
2628

@@ -33,9 +35,15 @@ if [ ! -d "$driver_dir" ]; then
3335
mkdir "$driver_dir"
3436
fi
3537

38+
if [ ! -d "$driver_dir-bvs" ]; then
39+
mkdir "$driver_dir-bvs"
40+
fi
41+
3642
cp "/$DRIVER" "$driver_dir/.$DRIVER"
3743
mv -f "$driver_dir/.$DRIVER" "$driver_dir/$DRIVER"
3844

45+
ln -sf "../$ORACLE_OCI_FOLDER/$DRIVER" "$driver_dir-bvs/$DRIVER-bvs"
46+
3947
if [ -f "$CONFIG_FILE" ]; then
4048
cp "$CONFIG_FILE" "$driver_dir/$config_file_name"
4149
fi

pkg/flexvolume/flexvolume.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import (
2020
"io"
2121
"log"
2222
"os"
23+
"path"
24+
"strings"
2325
)
2426

2527
// Defined to enable overriding in tests.
@@ -67,6 +69,8 @@ const (
6769
OptionKeyPodUID = "kubernetes.io/pod.uid"
6870

6971
OptionKeyServiceAccountName = "kubernetes.io/serviceAccount.name"
72+
73+
DefaultSymlinkDirectory = "oci-bvs"
7074
)
7175

7276
// Driver is the main Flexvolume interface.
@@ -143,13 +147,27 @@ func processOpts(optsStr string) (Options, error) {
143147

144148
// ExecDriver executes the appropriate FlexvolumeDriver command based on
145149
// recieved call-out.
146-
func ExecDriver(driver Driver, args []string) {
150+
func ExecDriver(drivers map[string]Driver, args []string) {
147151
if len(args) < 2 {
148152
ExitWithResult(Fail("Expected at least one argument"))
149153
}
150154

151155
log.Printf("'%s %s' called with %s", args[0], args[1], args[2:])
152156

157+
driver := drivers[DefaultSymlinkDirectory] //Block volume is default
158+
159+
dir := path.Base(args[0])
160+
dir = strings.TrimPrefix(dir, "oracle~")
161+
162+
if dir != "oci" && dir != DefaultSymlinkDirectory {
163+
driver = drivers[dir]
164+
if driver == nil {
165+
ExitWithResult(Fail("No driver found for ", dir))
166+
}
167+
}
168+
169+
log.Printf("Using %s driver", dir)
170+
153171
switch args[1] {
154172
// <driver executable> init
155173
case "init":

0 commit comments

Comments
 (0)