-
Notifications
You must be signed in to change notification settings - Fork 18
WIP: Support using symlinks to find correct driver #130
Conversation
cmd/oci/main.go
Outdated
|
||
// RegisterDriver registers a flexvolume.Driver by name. This | ||
// is expected to happen during app startup. | ||
func RegisterDriver(name string, driver flexvolume.Driver) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be private? RegisterDriver => registerDriver
cmd/oci/main.go
Outdated
|
||
// GetRegisteredDriver returns an instance of the named driver, or nil if | ||
// the name is unknown. An error is thrown if the named driver is not found. | ||
func GetRegisteredDriver(name string) (flexvolume.Driver, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make private? GetRegisteredDriver => getRegisteredDriver
e5663ef
to
19346b2
Compare
pkg/flexvolume/flexvolume.go
Outdated
|
||
// <driver executable> attach <json options> <node name> | ||
case "attach": | ||
if len(args) != 4 { | ||
ExitWithResult(Fail("attach expected exactly 4 arguments; got ", args)) | ||
Failf("attach expected exactly 4 arguments; got ", args) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be
Failf("attach expected exactly 4 arguments; got %d ", len(args))
cmd/oci/main.go
Outdated
@@ -27,6 +30,12 @@ import ( | |||
var version string | |||
var build string | |||
|
|||
// All registered drivers. | |||
var ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we already know the drivers ahead of time it seems a complex way to do this. Why do we need to have a mutex and a mutable map of drivers? Could we not just create a static map and avoid this registration logic entirely?
drivers = map[string]flexvolume.Driver{
"oci-bvs": driver.OCIFlexvolume,
}
func getDriverDir(path string) string {
dir := path.Base(path)
return strings.TrimPrefix(dir, "oracle~")
}
driverDir := getDriverDir(os.Args[0])
driver, ok := drivers[driverDir]
if !ok {
return nil, fmt.Errorf("No driver found with name %s", name)
}
cmd/oci/main.go
Outdated
@@ -27,6 +30,12 @@ import ( | |||
var version string | |||
var build string | |||
|
|||
// All registered drivers. | |||
var ( | |||
driversMutex sync.Mutex |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since there are no concurrent threads of execution why do we need a mutex?
9793dd6
to
fc9d00b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some changes but overall great work 👍
cmd/oci/main.go
Outdated
} | ||
|
||
dir := path.Base(os.Args[0]) | ||
dir = string(strings.TrimPrefix(dir, "oracle~")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cast to string here is not required:
func TrimPrefix(s, prefix string) string
cmd/oci/main.go
Outdated
return nil, err | ||
} | ||
|
||
dir := path.Base(os.Args[0]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
driverName := strings.TrimPrefix(path.Base(os.Args[0]), "oracle~")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Additionally in the (very unlikely) event that len(os.Args) == 0
we should load the default driver to prevent a panic on os.Args[0]
.
pkg/flexvolume/flexvolume_test.go
Outdated
defer func() { exit = osexit }() | ||
|
||
ExecDriver(mockFlexvolumeDriver{}, []string{"oci", "attach", defaultTestOps, "nodeName"}) | ||
status := ExecDriver( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
status := ExecDriver(mockFlexvolumeDriver{}, []string{"oci", "attach", defaultTestOps, "nodeName"})
pkg/flexvolume/flexvolume_test.go
Outdated
t.Fatalf(`Expected '{"status":"Not supported","message":"getvolumename is broken as of kube 1.6.4"}}'; got %s`, out.(*bytes.Buffer).String()) | ||
} | ||
func TestNoVolumeIDDispatch(t *testing.T) { | ||
status := ExecDriver( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
status := ExecDriver(mockFlexvolumeDriver{}, []string{"oci", "attach", noVolIDTestOps, "nodeName"})
pkg/flexvolume/flexvolume_test.go
Outdated
bak := out | ||
out = new(bytes.Buffer) | ||
defer func() { out = bak }() | ||
status := ExecDriver( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
status := ExecDriver(mockFlexvolumeDriver{}, []string{"oci", "getvolumename", defaultTestOps})
deploy.sh
Outdated
if [ -f "$CONFIG_FILE" ]; then | ||
cp "$CONFIG_FILE" "$driver_dir/$config_file_name" | ||
fi | ||
|
||
while : ; do | ||
touch $LOG_FILE | ||
tail -f $LOG_FILE | ||
done | ||
done |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing trailing \n
pkg/flexvolume/flexvolume.go
Outdated
@@ -67,6 +67,8 @@ const ( | |||
OptionKeyPodUID = "kubernetes.io/pod.uid" | |||
|
|||
OptionKeyServiceAccountName = "kubernetes.io/serviceAccount.name" | |||
|
|||
DefaultSymlinkDirectory = "oci-bvs" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pkg/flexvolume
is intended to be vendor agnostic and should not contain OCI specific code. Suggest moving to cmd/oci
. Additionally, I'd suggest DefaultDriver
would be a more appropriate name for this constant.
@@ -143,127 +162,127 @@ func processOpts(optsStr string) (Options, error) { | |||
|
|||
// ExecDriver executes the appropriate FlexvolumeDriver command based on | |||
// recieved call-out. | |||
func ExecDriver(driver Driver, args []string) { | |||
func ExecDriver(driver Driver, args []string) DriverStatus { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
cmd/oci/main.go
Outdated
} | ||
|
||
func getDriver(name string) (flexvolume.Driver, error) { | ||
driver := drivers[name] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
driver, ok := drivers[name]
if !ok {
cmd/oci/main.go
Outdated
|
||
func getDriver(name string) (flexvolume.Driver, error) { | ||
driver := drivers[name] | ||
if driver == nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAIK this will only be true if drivers["foo"]
is explicitly assigned to nil
because nil is not the zero value for flexvolume.Driver
(and drivers is map[string]flexvolume.Driver
). Hence the need for checking ok
.
fc9d00b
to
98ada0a
Compare
845aba5
to
4b9e908
Compare
) | ||
|
||
// TestAttachNonexistentVolume tests that attach fails for invalid volume OCIDs. | ||
func TestAttachNonexistentVolume(t *testing.T) { | ||
d := &driver.OCIFlexvolumeDriver{} | ||
d := &block.OCIFlexvolumeDriver{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer a constructor of some kind here to make code easy to read. Not necessary in this PR just a thought.
driver := block.New()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few naming tweaks but otherwise LGTM 🎉
pkg/oci/driver/block/block_driver.go
Outdated
) | ||
|
||
// OCIFlexvolumeDriver implements the flexvolume.Driver interface for OCI. | ||
type OCIFlexvolumeDriver struct{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/OCIFlexvolumeDriver/Driver/
(as now will be consumed as block.Driver
).
pkg/oci/driver/block/block_driver.go
Outdated
type OCIFlexvolumeDriver struct{} | ||
|
||
func init() { | ||
driver.RegisterDriver("oci-bvs", &OCIFlexvolumeDriver{}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
pkg/oci/driver/driver.go
Outdated
// OCIFlexvolumeDriver implements the flexvolume.Driver interface for OCI. | ||
type OCIFlexvolumeDriver struct{} | ||
// RegisterDriver adds a driver to the drivers map. | ||
func RegisterDriver(name string, driver flexvolume.Driver) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/RegisterDriver/Register/
(calling code will reference as driver.Register()
)
pkg/oci/driver/driver.go
Outdated
} | ||
|
||
// GetDriver returns a driver from the map associated with a given key. | ||
func GetDriver(name string) (flexvolume.Driver, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/GetDriver/Get/
(calling code will reference as driver.Get()
)
pkg/oci/driver/driver.go
Outdated
} | ||
|
||
// GetDriverName returns the name (map key) of the driver from a given path. | ||
func GetDriverName(args []string) string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/GetDriverName/NameFromArgs/
(calling code will reference as driver.NameFromArgs()
)
4b9e908
to
9f09609
Compare
9f09609
to
78d66b3
Compare
Note: Only needed if FSS Dynamic Shared feature is implemented. There’s only one driver currently so it’s not needed. If we need to use the driver as part of the phase 2 FSS work we’ll need the above or another flex driver binary |
Addresses oracle/oci-volume-provisioner#131
The volume provisioner has been patched to now not use names to dispatch custom logic. A storage class can now use it's provisioner property to determine what driver should be used. At the moment only block volume storage is supported provisioner:
oracle.com/oci-bvs
with aim that file storage will soon be supported also oracle/oci-volume-provisioner#90. Backwards compatible so that existing storage classes using provisioner:oracle.com/oci
will default to using the block volume storage however this should be marked as deprecated and removed in a future release.