Skip to content
Closed
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
1 change: 1 addition & 0 deletions cmd/dory/dory.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ func main() {
ListOfStorageResourceOptions: listOfStorageResourceOptions,
FactorForConversion: factorForConversion,
SupportsCapabilities: supportsCapabilities,
ManagedPluginID: "",
}
err := flexvol.Config(dockervolOptions)
var mess string
Expand Down
13 changes: 7 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 @@ -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)
}
27 changes: 25 additions & 2 deletions common/k8s/flexvol/flexvol.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"path/filepath"
"regexp"
"time"
"strings"
)

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

dvp *dockervol.DockerVolumePlugin
)
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
}
Expand All @@ -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]

}