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

WIP: Support using symlinks to find correct driver #130

Closed
wants to merge 3 commits into from

Conversation

harveylowndes
Copy link
Contributor

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.

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) {
Copy link
Member

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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make private? GetRegisteredDriver => getRegisteredDriver

@harveylowndes harveylowndes force-pushed the symlink-flexvol-driver-provisioner branch from e5663ef to 19346b2 Compare June 26, 2018 09:13

// <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)
Copy link
Member

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 (
Copy link
Member

@owainlewis owainlewis Jun 26, 2018

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
Copy link
Member

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?

@harveylowndes harveylowndes force-pushed the symlink-flexvol-driver-provisioner branch from 9793dd6 to fc9d00b Compare June 27, 2018 09:30
Copy link
Contributor

@prydie prydie left a 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~"))
Copy link
Contributor

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])
Copy link
Contributor

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~")

Copy link
Contributor

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].

defer func() { exit = osexit }()

ExecDriver(mockFlexvolumeDriver{}, []string{"oci", "attach", defaultTestOps, "nodeName"})
status := ExecDriver(
Copy link
Contributor

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"})

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(
Copy link
Contributor

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"})

bak := out
out = new(bytes.Buffer)
defer func() { out = bak }()
status := ExecDriver(
Copy link
Contributor

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing trailing \n

@@ -67,6 +67,8 @@ const (
OptionKeyPodUID = "kubernetes.io/pod.uid"

OptionKeyServiceAccountName = "kubernetes.io/serviceAccount.name"

DefaultSymlinkDirectory = "oci-bvs"
Copy link
Contributor

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 {
Copy link
Contributor

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]
Copy link
Contributor

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 {
Copy link
Contributor

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.

@harveylowndes harveylowndes force-pushed the symlink-flexvol-driver-provisioner branch from fc9d00b to 98ada0a Compare July 4, 2018 08:49
@harveylowndes harveylowndes force-pushed the symlink-flexvol-driver-provisioner branch from 845aba5 to 4b9e908 Compare July 4, 2018 13:32
)

// TestAttachNonexistentVolume tests that attach fails for invalid volume OCIDs.
func TestAttachNonexistentVolume(t *testing.T) {
d := &driver.OCIFlexvolumeDriver{}
d := &block.OCIFlexvolumeDriver{}
Copy link
Member

@owainlewis owainlewis Jul 4, 2018

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()

Copy link
Contributor

@prydie prydie left a 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 🎉

)

// OCIFlexvolumeDriver implements the flexvolume.Driver interface for OCI.
type OCIFlexvolumeDriver struct{}
Copy link
Contributor

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).

type OCIFlexvolumeDriver struct{}

func init() {
driver.RegisterDriver("oci-bvs", &OCIFlexvolumeDriver{})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

// 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) {
Copy link
Contributor

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())

}

// GetDriver returns a driver from the map associated with a given key.
func GetDriver(name string) (flexvolume.Driver, error) {
Copy link
Contributor

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())

}

// GetDriverName returns the name (map key) of the driver from a given path.
func GetDriverName(args []string) string {
Copy link
Contributor

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())

@harveylowndes harveylowndes force-pushed the symlink-flexvol-driver-provisioner branch from 4b9e908 to 9f09609 Compare July 4, 2018 14:23
@harveylowndes harveylowndes force-pushed the symlink-flexvol-driver-provisioner branch from 9f09609 to 78d66b3 Compare July 4, 2018 14:40
@harveylowndes harveylowndes changed the title Support using symlinks to find correct driver WIP: Support using symlinks to find correct driver Jul 6, 2018
@MadalinaPatrichi
Copy link
Member

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

@owainlewis owainlewis closed this Sep 26, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants