Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions common/docker/dockervol/dockervol.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -400,22 +401,23 @@ 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)
}

25 changes: 23 additions & 2 deletions common/k8s/flexvol/flexvol.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"path/filepath"
"regexp"
"time"
"strings"
)

const (
Expand Down Expand Up @@ -63,6 +64,7 @@ const (
var (
//createVolumes indicate whether the driver should create missing volumes
createVolumes = true
pluginID = ""

execPath string

Expand Down Expand Up @@ -104,6 +106,7 @@ func (ar *AttachRequest) getBestName() string {
func Config(ePath string, options *dockervol.Options) (err error) {
dvp, err = dockervol.NewDockerVolumePlugin(options)
createVolumes = options.CreateVolumes
pluginID = options.ManagedPluginID
execPath = ePath
return err
}
Expand Down Expand Up @@ -235,7 +238,14 @@ func Mount(args []string) (string, error) {

err = doMount(args[0], path, dockerVolName, mountID)
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
Expand Down Expand Up @@ -346,7 +356,9 @@ 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
}
}
Expand All @@ -358,6 +370,15 @@ func getVolumeNameFromMountPath(k8sPath, dockerPath string) (string, error) {
return dockerVolume.Volume.Name, nil
}

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]
}
func findJSON(args []string, req *AttachRequest) (string, error) {
var err error
for i := 1; i < len(args); i++ {
Expand Down