Skip to content

Commit

Permalink
Allow multiple server (#19)
Browse files Browse the repository at this point in the history
* update-deps

* Fix update + refactor

* Fix mistake

* Improve integration testing

* Fix count

* Setup env vars

* Fix read of env vars

* Remove fuse-opts

* Allow multiple host via glusterfs command + test it at create

* Update man

* Improve integration tests

* Remove un-used var

* Fix build

* Tweek sleep times

* fix coverage report

* Fix tests + MountExist

* Run test as admin to access docker

* Fix trailling voluri "

* Preserve env for make test

* escape params

* Try fix for travis
  • Loading branch information
sapk authored Dec 11, 2017
1 parent f144c24 commit 82079ba
Show file tree
Hide file tree
Showing 29 changed files with 493 additions and 260 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,6 @@
[submodule "vendor/gopkg.in/yaml.v2"]
path = vendor/gopkg.in/yaml.v2
url = https://gopkg.in/yaml.v2
[submodule "vendor/golang.org/x/crypto"]
path = vendor/golang.org/x/crypto
url = https://go.googlesource.com/crypto
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@ go:
- 1.8
- 1.9
- tip

before_install:
- curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
- sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
- sudo apt-get update
- sudo apt-get -y install docker-ce

install:
- make dev-deps
script:
- make lint
- make build
- make test
- sudo bash <(source $HOME/.bashrc; make test)
- ./docker-volume-gluster
after_success:
- bash <(curl -s https://codecov.io/bash)
- bash <(curl -s https://codecov.io/bash) -f coverage.all
before_deploy:
- make compress
- docker --version
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ test: dev-deps deps format
go vet ./gluster/... || true
go test -v -race -coverprofile=coverage.unit.out -covermode=atomic ./gluster/driver
go test -v -race -coverprofile=coverage.inte.out -covermode=atomic -coverpkg ./gluster/driver ./gluster/integration
gocovmerge `ls coverage.*.out` > coverage.out
go tool cover -html=coverage.out -o coverage.html
gocovmerge coverage.unit.out coverage.inte.out > coverage.all
go tool cover -html=coverage.all -o coverage.html

docs:
@echo -e "$(OK_COLOR)==> Serving docs at http://localhost:$(DOC_PORT).$(NO_COLOR)"
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ Usage:
docker-volume-gluster daemon [flags]
Flags:
-o, --fuse-opts string Fuse options to use moint point (default "big_writes,allow_other,auto_cache")
-h, --help help for daemon
--mount-uniq Set mountpoint based on definition and not the name of volume
Global Flags:
-b, --basedir string Mounted volume base directory (default "/var/lib/docker-volumes/gluster")
Expand Down
158 changes: 158 additions & 0 deletions common/common_driver.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
package common

import (
"fmt"
"os"
"sync"

log "github.com/Sirupsen/logrus"

"github.com/docker/go-plugins-helpers/volume"
)

//Driver needed interface for some commons interactions
type Driver interface {
GetLock() *sync.RWMutex
GetVolumes() map[string]Volume
GetMounts() map[string]Mount
SaveConfig() error
RunCmd(string) error
}

//Volume needed interface for some commons interactions
type Volume interface {
increasable
GetMount() string
GetRemote() string
GetStatus() map[string]interface{}
}

//Mount needed interface for some commons interactions
type Mount interface {
increasable
GetPath() string
}

type increasable interface {
GetConnections() int
SetConnections(int)
}

func getMount(d Driver, mPath string) (Mount, error) {
m, ok := d.GetMounts()[mPath]
if !ok {
return nil, fmt.Errorf("mount %s not found", mPath)
}
log.Debugf("Mount found: %s", m)
return m, nil
}

func getVolumeMount(d Driver, vName string) (Volume, Mount, error) {
v, ok := d.GetVolumes()[vName]
if !ok {
return nil, nil, fmt.Errorf("volume %s not found", vName)
}
log.Debugf("Volume found: %s", v)
m, err := getMount(d, v.GetMount())
return v, m, err
}

//List wrapper around github.com/docker/go-plugins-helpers/volume
func List(d Driver) (*volume.ListResponse, error) {
log.Debugf("Entering List")
d.GetLock().Lock()
defer d.GetLock().Unlock()
var vols []*volume.Volume
for name, v := range d.GetVolumes() {
log.Debugf("Volume found: %s", v)
m, err := getMount(d, v.GetMount())
if err != nil {
return nil, err
}
vols = append(vols, &volume.Volume{Name: name, Status: v.GetStatus(), Mountpoint: m.GetPath()})
}
return &volume.ListResponse{Volumes: vols}, nil
}

//Get wrapper around github.com/docker/go-plugins-helpers/volume
func Get(d Driver, vName string) (Volume, Mount, error) {
log.Debugf("Entering Get: name: %s", vName)
d.GetLock().RLock()
defer d.GetLock().RUnlock()
return getVolumeMount(d, vName)
}

//Remove wrapper around github.com/docker/go-plugins-helpers/volume
func Remove(d Driver, vName string) error {
log.Debugf("Entering Remove: name: %s", vName)
d.GetLock().Lock()
defer d.GetLock().Unlock()
v, m, err := getVolumeMount(d, vName)
if err != nil {
return err
}
if v.GetConnections() == 0 {
if m.GetConnections() == 0 {
if err := os.Remove(m.GetPath()); err != nil {
return err
}
delete(d.GetMounts(), v.GetMount())
}
delete(d.GetVolumes(), vName)
return d.SaveConfig()
}
return fmt.Errorf("volume %s is currently used by a container", vName)
}

//MountExist wrapper around github.com/docker/go-plugins-helpers/volume
func MountExist(d Driver, vName string) (Volume, Mount, error) {
log.Debugf("Entering MountExist: name: %s", vName)
d.GetLock().Lock()
defer d.GetLock().Unlock()
return getVolumeMount(d, vName)
}

func SetN(val int, oList ...increasable) {
for _, o := range oList {
o.SetConnections(val)
}
}

func AddN(val int, oList ...increasable) {
for _, o := range oList {
o.SetConnections(o.GetConnections() + val)
}
}

//Unmount wrapper around github.com/docker/go-plugins-helpers/volume
func Unmount(d Driver, vName string) error {
log.Debugf("Entering Unmount: name: %s", vName)
d.GetLock().Lock()
defer d.GetLock().Unlock()
v, m, err := getVolumeMount(d, vName)
if err != nil {
return err
}

if m.GetConnections() <= 1 {
cmd := fmt.Sprintf("/usr/bin/umount %s", m.GetPath())
if err := d.RunCmd(cmd); err != nil {
return err
}
SetN(0, m, v)
} else {
AddN(-1, m, v)
}

return d.SaveConfig()
}

//Capabilities wrapper around github.com/docker/go-plugins-helpers/volume
func Capabilities() *volume.CapabilitiesResponse {
log.Debugf("Entering Capabilities")
return &volume.CapabilitiesResponse{
Capabilities: volume.Capability{
Scope: "local",

This comment has been minimized.

Copy link
@trajano

trajano Apr 24, 2018

Just a question,,, why would you use "local" here vs "global"?

},
}
}
Loading

0 comments on commit 82079ba

Please sign in to comment.