diff --git a/cmd/dory/dory.go b/cmd/dory/dory.go index b2a5193..12faa98 100644 --- a/cmd/dory/dory.go +++ b/cmd/dory/dory.go @@ -87,6 +87,7 @@ func main() { ListOfStorageResourceOptions: listOfStorageResourceOptions, FactorForConversion: factorForConversion, SupportsCapabilities: supportsCapabilities, + ManagedPluginID: "", } err := flexvol.Config(dockervolOptions) var mess string diff --git a/common/docker/dockervol/dockervol.go b/common/docker/dockervol/dockervol.go index 1985f7c..cc31f12 100644 --- a/common/docker/dockervol/dockervol.go +++ b/common/docker/dockervol/dockervol.go @@ -61,6 +61,7 @@ type Options struct { ListOfStorageResourceOptions []string FactorForConversion int SupportsCapabilities bool + ManagedPluginID string } //DockerVolumePlugin is the client to a specific docker volume plugin @@ -143,7 +144,7 @@ func NewDockerVolumePlugin(options *Options) (*DockerVolumePlugin, error) { var err error if !strings.HasPrefix(options.SocketPath, "/") { // this is a v2 plugin, so we need to find its socket file - options.SocketPath, err = getV2PluginSocket(options.SocketPath, "") + options.SocketPath, options.ManagedPluginID, err = getV2PluginSocket(options.SocketPath, "") } if err != nil { return nil, err @@ -394,22 +395,22 @@ func driverErrorCheck(e Errorer) error { } // name is the name of the docker volume plugin. dockerSocket is the full path to the docker socket. The default is used if an empty string is passed. -func getV2PluginSocket(name, dockerSocket string) (string, error) { +func getV2PluginSocket(name, dockerSocket string) (string, string, error) { c := dockerlt.NewDockerClient(dockerSocket) plugins, err := c.PluginsGet() if err != nil { - return "", fmt.Errorf("failed to get V2 plugins from docker. error=%s", err.Error()) + return "", "", fmt.Errorf("failed to get V2 plugins from docker. error=%s", err.Error()) } for _, plugin := range plugins { if strings.Compare(name, plugin.Name) == 0 || strings.Compare(fmt.Sprintf("%s:latest", name), plugin.Name) == 0 { if !plugin.Enabled { - return fmt.Sprintf("/run/docker/plugins/%s/%s", plugin.ID, plugin.Config.Interface.Socket), fmt.Errorf("found Docker V2 Plugin named %s, but it is disabled", name) + return fmt.Sprintf("/run/docker/plugins/%s/%s", plugin.ID, plugin.Config.Interface.Socket), "", fmt.Errorf("found Docker V2 Plugin named %s, but it is disabled", name) } - return fmt.Sprintf("/run/docker/plugins/%s/%s", plugin.ID, plugin.Config.Interface.Socket), nil + return fmt.Sprintf("/run/docker/plugins/%s/%s", plugin.ID, plugin.Config.Interface.Socket), plugin.ID, nil } } - return "", fmt.Errorf("unable to find V2 plugin named %s", name) + return "", "", fmt.Errorf("unable to find V2 plugin named %s", name) } diff --git a/common/k8s/flexvol/flexvol.go b/common/k8s/flexvol/flexvol.go index c540332..e35b684 100644 --- a/common/k8s/flexvol/flexvol.go +++ b/common/k8s/flexvol/flexvol.go @@ -26,6 +26,7 @@ import ( "path/filepath" "regexp" "time" + "strings" ) const ( @@ -60,6 +61,7 @@ const ( var ( //createVolumes indicate whether the driver should create missing volumes createVolumes = true + pluginID = "" dvp *dockervol.DockerVolumePlugin ) @@ -99,6 +101,7 @@ func (ar *AttachRequest) getBestName() string { func Config(options *dockervol.Options) (err error) { dvp, err = dockervol.NewDockerVolumePlugin(options) createVolumes = options.CreateVolumes + pluginID = options.ManagedPluginID return err } @@ -228,7 +231,14 @@ func Mount(args []string) (string, error) { //Bind mount the docker path to the flexvol path err = linux.BindMount(path, args[0], false) if err != nil { - return "", err + pathForManagedPlugin := "/var/lib/docker/plugins/" + pluginID + "/rootfs"+ path + util.LogDebug.Printf("pathForManagedPlugin: %s", pathForManagedPlugin) + err = linux.BindMount(pathForManagedPlugin, args[0], false) + + if err != nil { + return "", err + } + path = pathForManagedPlugin } // Set selinux context if configured @@ -329,7 +339,10 @@ func getVolumeNameFromMountPath(k8sPath, dockerPath string) (string, error) { return "", err } for _, vol := range volumes.Volumes { - if vol.Mountpoint == dockerPath { + + util.LogDebug.Printf("dockerPath %s, volume mountpoint %s", dockerPath, vol.Mountpoint) + if (vol.Mountpoint == dockerPath || (findStringAfterLastSlash(vol.Mountpoint) == findStringAfterLastSlash(dockerPath))){ + util.LogDebug.Printf(" returning docker volume name %s", vol.Name) return vol.Name, nil } } @@ -349,3 +362,13 @@ func findJSON(args []string, req *AttachRequest) (string, error) { } return "", err } +func findStringAfterLastSlash(s string) string { + + //s := "/var/lib/docker/plugins/a238188db964f8139af8d502a9b134b1f9522ccc27936ae5512b2f1b662f0aa5/rootfs/opt/hpe/data/hpedocker-dm-uuid-mpath-360002ac0000000000101331f00019d52" + + flds := strings.Split(s, "/") + arrayLength := len(flds) + fmt.Printf(" Length = %d, last substring %s" ,arrayLength, flds[arrayLength -1]) + return flds[arrayLength - 1] + +}