Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sub process #31

Open
wants to merge 31 commits into
base: master
Choose a base branch
from
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
9 changes: 3 additions & 6 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
[submodule "vendor/github.com/Sirupsen/logrus"]
path = vendor/github.com/Sirupsen/logrus
url = https://github.com/Sirupsen/logrus
[submodule "vendor/github.com/docker/go-plugins-helpers"]
path = vendor/github.com/docker/go-plugins-helpers
url = https://github.com/docker/go-plugins-helpers
Expand Down Expand Up @@ -40,9 +37,6 @@
[submodule "vendor/github.com/pelletier/go-toml"]
path = vendor/github.com/pelletier/go-toml
url = https://github.com/pelletier/go-toml
[submodule "vendor/github.com/pelletier/go-buffruneio"]
path = vendor/github.com/pelletier/go-buffruneio
url = https://github.com/pelletier/go-buffruneio
[submodule "vendor/github.com/spf13/afero"]
path = vendor/github.com/spf13/afero
url = https://github.com/spf13/afero
Expand All @@ -61,3 +55,6 @@
[submodule "vendor/golang.org/x/crypto"]
path = vendor/golang.org/x/crypto
url = https://go.googlesource.com/crypto
[submodule "vendor/github.com/sirupsen/logrus"]
path = vendor/github.com/sirupsen/logrus
url = https://github.com/sirupsen/logrus
34 changes: 25 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,52 @@ addons:
packages:
- upx-ucl
go:
- 1.8
- 1.9
- tip

before_install:
- curl https://repogen.simplylinux.ch/txt/xenial/sources_4a205a2731f617800bd74e748bc6f343aa6369d6.txt | sudo tee /etc/apt/sources.list
- 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 install -qq pkg-config fuse
- sudo modprobe fuse
- sudo chmod 666 /dev/fuse
- sudo apt-get -y install docker-ce glusterfs-client
- sudo apt-get -y install glusterfs-client
- sudo apt-get -y install docker-ce
- sudo apt-get -y install attr python-jwt
- wget https://launchpad.net/~gluster/+archive/ubuntu/glusterfs-3.12/+files/glusterfs-common_3.12.4-ubuntu1~xenial1_amd64.deb
- wget https://launchpad.net/~gluster/+archive/ubuntu/glusterfs-3.12/+files/glusterfs-client_3.12.4-ubuntu1~xenial1_amd64.deb
- sudo dpkg -i glusterfs-common_3.12.4-ubuntu1~xenial1_amd64.deb
- sudo dpkg -i glusterfs-client_3.12.4-ubuntu1~xenial1_amd64.deb
- rm *.deb
- sudo cat /etc/mtab
- sudo cat /etc/fstab
# - sudo -E apt-get -q -y --purge remove docker-ce
# - sudo -E apt-cache policy docker-ce
# - curl -sSL https://get.docker.com/ | sh
# - sudo -E stop docker
- sudo usermod -aG docker travis
# - sudo cat /etc/default/docker
# - sudo -E start docker
install:
- make dev-deps

script:
- make lint
- make build
- make test-unit
# - make test-coverage
- sudo -E bash -c 'eval "$(gimme $TRAVIS_GO_VERSION)" && make test-coverage'
# - make test-unit
# - sudo -E bash -c 'eval "$(gimme $TRAVIS_GO_VERSION)" && make test'
# - sudo ls -lah /var/log/glusterfs/
# - sudo cat /var/log/glusterfs/*
- sudo ls -lah /var/log/glusterfs/
- sudo cat /var/log/glusterfs/*
- ./docker-volume-gluster

after_success:
- bash <(curl -s https://codecov.io/bash) -f coverage.*
#after_success:
# - make test-coverage

before_deploy:
- make compress
- make release
- docker --version
- make docker-plugin
Expand All @@ -48,7 +65,6 @@ deploy:
secure: SAD6luuJhgzS7ZavymCxLaTlCbxp9VQax0uf4ozWByt0uwsLKtDM4Je4c9z9bx40PmEBKOpSoso4umL4AcY1yrQ2UTMJD+GxedmqDnge2ibfhHZMTxeDkLF3JLsACfQmibNzN/+b9nNdgyzQYnB4+OvKOmEvtHWwNP7qOuU+9QTNK/rNt5MBXk29aJFL1/t3oIvCfHl1D96pssE6uVURcXiPGkgNcSLBUewYwPwqjGqgG/xu/lgQEwpW6AE4OfwJLpdGMR/V1DUNMNs47Gt7Vh+PBRm/M7cZUYyc+CRuXuSM+PKr9xlH8mFHu6IrcM4n5Sy94A7ldB5dfn9HA+WLXEOhSej3NB06sFkjITnKSWCVCGVzzXuH5CMiwBDRKmhFLunFe9Wcz52W2wIumesaNuZOm9LbiBV47UicggeiZkhar1tvjQoFgw6R57+Wxdhdon7fwVO3euRSH7fm0RyEN1PgO92U5/gHgOO+Khlsl3GPqWNgyqeh0Ej4Ke9mFB0VjO+a8uNAQlrp+v94kQSWqpXUD30/fnZhu+sBURJ1pikH/WAhcnKEvYk7Kq5/kSuYqO0dxxEDrHh00Gwo/uHhhnOp3BNe/v1/TseSS4FOxaLrbTKCDRU+B38bsi8FoZ7J68xK9dT19TF+6ZXqka1LNIyV4ITCjkRenHMfCWWrF78=
file_glob: true
file:
- "./docker-volume-gluster"
- build/*.tar.gz
skip_cleanup: true
on:
Expand Down
11 changes: 9 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,14 @@ test-unit: dev-deps deps format

test-integration: dev-deps deps format
@echo -e "$(OK_COLOR)==> Running integration tests...$(NO_COLOR)"
go test -v -timeout 1h -race -coverprofile=coverage.inte.out -covermode=atomic -coverpkg ./gluster/driver ./gluster/integration
go test -v -timeout 1h -coverprofile=coverage.inte.out -covermode=atomic -coverpkg ./gluster/driver ./gluster/integration
# go test -v -timeout 1h -race -coverprofile=coverage.inte.out -covermode=atomic -coverpkg ./gluster/driver ./gluster/integration

test-coverage: test
@echo -e "$(OK_COLOR)==> Uploading coverage ...$(NO_COLOR)"
curl -s https://codecov.io/bash | bash -s - -F unittests -f coverage.unit.out
curl -s https://codecov.io/bash | bash -s - -F integration -f coverage.inte.out
#Need CODECOV_TOKEN=:uuid

docs:
@echo -e "$(OK_COLOR)==> Serving docs at http://localhost:$(DOC_PORT).$(NO_COLOR)"
Expand Down Expand Up @@ -178,7 +185,7 @@ deps:

update-deps: dev-deps
@echo -e "$(OK_COLOR)==> Updating all dependencies ...$(NO_COLOR)"
$(GOPATH)/bin/vendetta -n $(APP_PACKAGE) -u
$(GOPATH)/bin/vendetta -n $(APP_PACKAGE) -u -p
#@go get -d -v -u ./...


Expand Down
15 changes: 11 additions & 4 deletions common/common_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package common
import (
"fmt"
"os"
"os/exec"
"strings"
"sync"

log "github.com/Sirupsen/logrus"
log "github.com/sirupsen/logrus"

"github.com/docker/go-plugins-helpers/volume"
)
Expand All @@ -17,7 +18,7 @@ type Driver interface {
GetVolumes() map[string]Volume
GetMounts() map[string]Mount
SaveConfig() error
RunCmd(string) error
StartCmd(name string, arg ...string) (*exec.Cmd, error)
}

//Volume needed interface for some commons interactions
Expand All @@ -32,6 +33,8 @@ type Volume interface {
type Mount interface {
increasable
GetPath() string
//GetProcess() *exec.Cmd
SetProcess(*exec.Cmd)
}

type increasable interface {
Expand Down Expand Up @@ -136,8 +139,12 @@ func Unmount(d Driver, vName string) error {
}

if m.GetConnections() <= 1 {
cmd := fmt.Sprintf("/usr/bin/umount %s", m.GetPath())
if err := d.RunCmd(cmd); err != nil {
c, err := d.StartCmd("/usr/bin/umount", m.GetPath())
if err != nil {
return err
}
err = c.Wait()
if err != nil {
return err
}
SetN(0, m, v)
Expand Down
50 changes: 40 additions & 10 deletions gluster/driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@ package driver

import (
"fmt"
"io"
"os"
"os/exec"
"path/filepath"
"strings"
"sync"
"time"

"github.com/sapk/docker-volume-gluster/common"

log "github.com/Sirupsen/logrus"
"github.com/docker/go-plugins-helpers/volume"
log "github.com/sirupsen/logrus"
"github.com/spf13/viper"
)

Expand All @@ -24,13 +27,17 @@ var (
)

type GlusterMountpoint struct {
Path string `json:"path"`
Connections int `json:"connections"`
Path string `json:"path"`
Connections int `json:"connections"`
Process *exec.Cmd `json:"-"`
}

func (d *GlusterMountpoint) GetPath() string {
return d.Path
}
func (d *GlusterMountpoint) SetProcess(c *exec.Cmd) {
d.Process = c
}

func (d *GlusterMountpoint) GetConnections() int {
return d.Connections
Expand Down Expand Up @@ -72,10 +79,13 @@ func (v *GlusterVolume) GetStatus() map[string]interface{} {
type GlusterDriver struct {
lock sync.RWMutex
root string
binary string
mountUniqName bool
persitence *viper.Viper
volumes map[string]*GlusterVolume
mounts map[string]*GlusterMountpoint
logOut *io.PipeWriter
logErr *io.PipeWriter
}

func (d *GlusterDriver) GetVolumes() map[string]common.Volume {
Expand All @@ -101,12 +111,21 @@ func (d *GlusterDriver) GetLock() *sync.RWMutex {
//Init start all needed deps and serve response to API call
func Init(root string, mountUniqName bool) *GlusterDriver {
log.Debugf("Init gluster driver at %s, UniqName: %v", root, mountUniqName)
logger := log.New() //TODO defer close writer
path, err := exec.LookPath("glusterfs")
if err != nil {
log.Fatal("glusterfs binary not found")
}

d := &GlusterDriver{
root: root,
binary: path,
mountUniqName: mountUniqName,
persitence: viper.New(),
volumes: make(map[string]*GlusterVolume),
mounts: make(map[string]*GlusterMountpoint),
logOut: logger.WriterLevel(log.DebugLevel),
logErr: logger.WriterLevel(log.ErrorLevel),
}

d.persitence.SetDefault("volumes", map[string]*GlusterVolume{})
Expand Down Expand Up @@ -236,15 +255,26 @@ func (d *GlusterDriver) Mount(r *volume.MountRequest) (*volume.MountResponse, er
d.GetLock().Lock()
defer d.GetLock().Unlock()

cmd := fmt.Sprintf("glusterfs %s %s", parseVolURI(v.GetRemote()), m.GetPath())
//cmd := fmt.Sprintf("/usr/bin/mount -t glusterfs %s %s", v.VolumeURI, m.Path)
//TODO fuseOpts /usr/bin/mount -t glusterfs v.VolumeURI -o fuseOpts v.Mountpoint
if err := d.RunCmd(cmd); err != nil {
//c, err := d.StartCmd(d.binary, append(parseVolURI(v.GetRemote()), "--log-level", "INFO", "--log-file", "/dev/stdout", "--no-daemon", m.GetPath())...) // TODO --debug
c, err := d.StartCmd(d.binary, append(parseVolURI(v.GetRemote()), "--no-daemon", m.GetPath())...) // TODO --debug

if err != nil {
return nil, err
}

done := make(chan error, 1)
go func() {
done <- c.Wait()
}()
// Wait if failed for 5 seconds
select {
case err := <-done:
return nil, err
case <-time.After(time.Second * 5):
m.SetProcess(c)
common.AddN(1, v, m)
return &volume.MountResponse{Mountpoint: m.GetPath()}, d.SaveConfig()
}
//time.Sleep(3 * time.Second)
common.AddN(1, v, m)
return &volume.MountResponse{Mountpoint: m.GetPath()}, d.SaveConfig()
}

//Unmount unmount the requested volume
Expand Down
27 changes: 15 additions & 12 deletions gluster/driver/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
"regexp"
"strings"

log "github.com/Sirupsen/logrus"
"github.com/docker/go-plugins-helpers/volume"
log "github.com/sirupsen/logrus"
)

const (
Expand Down Expand Up @@ -52,26 +52,29 @@ func (d *GlusterDriver) SaveConfig() error {
return nil
}

//RunCmd run deamon in context of this gvfs drive with custome env
func (d *GlusterDriver) RunCmd(cmd string) error {
log.Debugf(cmd)
out, err := exec.Command("sh", "-c", cmd).CombinedOutput()
if err != nil {
log.Debugf("Error: %v", err)
}
log.Debugf("Output: %v", out)
return err
//StartCmd start deamon in context of this gluster driver and keep it in backgroud
func (d *GlusterDriver) StartCmd(bin string, arg ...string) (*exec.Cmd, error) {
log.Debugf("%s %s", bin, strings.Join(arg, " "))
c := exec.Command(bin, arg...)
c.Stdout = d.logOut
c.Stderr = d.logErr
return c, c.Start()
}

func isValidURI(volURI string) bool {
re := regexp.MustCompile(validHostnameRegex + ":.+")
return re.MatchString(volURI)
}

func parseVolURI(volURI string) string {
func parseVolURI(volURI string) []string {
volParts := strings.Split(volURI, ":")
volServers := strings.Split(volParts[0], ",")
return fmt.Sprintf("--volfile-id='%s' -s '%s'", volParts[1], strings.Join(volServers, "' -s '"))
ret := make([]string, 1+len(volServers))
ret[0] = fmt.Sprintf("--volfile-id=%s", volParts[1])
for i, server := range volServers {
ret[i+1] = fmt.Sprintf("--volfile-server=%s", server)
}
return ret
}

func getMountName(d *GlusterDriver, r *volume.CreateRequest) string {
Expand Down
13 changes: 7 additions & 6 deletions gluster/driver/tools_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package driver

import (
"strings"
"testing"

"github.com/docker/go-plugins-helpers/volume"
Expand Down Expand Up @@ -34,16 +35,16 @@ func TestParseVolURI(t *testing.T) {
value string
result string
}{
{"test:volume", "--volfile-id='volume' -s 'test'"},
{"test,test2:volume", "--volfile-id='volume' -s 'test' -s 'test2'"},
{"192.168.1.1:volume", "--volfile-id='volume' -s '192.168.1.1'"},
{"192.168.1.1,10.8.0.1:volume", "--volfile-id='volume' -s '192.168.1.1' -s '10.8.0.1'"},
{"192.168.1.1,test2:volume", "--volfile-id='volume' -s '192.168.1.1' -s 'test2'"},
{"test:volume", "--volfile-id=volume --volfile-server=test"},
{"test,test2:volume", "--volfile-id=volume --volfile-server=test --volfile-server=test2"},
{"192.168.1.1:volume", "--volfile-id=volume --volfile-server=192.168.1.1"},
{"192.168.1.1,10.8.0.1:volume", "--volfile-id=volume --volfile-server=192.168.1.1 --volfile-server=10.8.0.1"},
{"192.168.1.1,test2:volume", "--volfile-id=volume --volfile-server=192.168.1.1 --volfile-server=test2"},
}

for _, test := range tt {
r := parseVolURI(test.value)
if test.result != r {
if test.result != strings.Join(r, " ") {
t.Errorf("Expected to be '%v' , got '%v'", test.result, r)
}
}
Expand Down
2 changes: 1 addition & 1 deletion gluster/gluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (
"os"
"path/filepath"

log "github.com/Sirupsen/logrus"
"github.com/docker/go-plugins-helpers/volume"
"github.com/sapk/docker-volume-gluster/gluster/driver"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

Expand Down
Loading