Simple wrapper library for quick FlexVolume prototypes.
Switch branches/tags
Nothing to show
Clone or download
Pull request Compare This branch is 2 commits ahead, 1 commit behind nickschuch:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
README.md
commands.go
types.go

README.md

Kubernetes: FlexVolume

Simple wrapper library for quick FlexVolume prototypes.

Example

This is a simple implementation which creates and deletes folders, nothing crazy.

The following example should demonstate:

  • Setting up the cli
  • Implementing the flexvolume interface
  • Returning the device output required
package main

import (
	"os"

	"github.com/nickschuch/flexvolume"
	"github.com/urfave/cli"
)

func main() {
	app := cli.NewApp()
	app.Commands = flexvolume.Commands(Mock{})
	app.Run(os.Args)
}

type Mock struct {}

func (m Mock) Init() flexvolume.Response {
	return flexvolume.Response{
		Status:  flexvolume.StatusSuccess,
		Message: "Mock is available",
	}
}

func (m Mock) Attach(options map[string]string) flexvolume.Response {
	return flexvolume.Response{
		Status:  flexvolume.StatusSuccess,
		Message: "Successfully attached the mock volume",
	}
}

func (m Mock) Detach(device string) flexvolume.Response {
	return flexvolume.Response{
		Status:  flexvolume.StatusSuccess,
		Message: "Successfully detached the mock volume",
	}
}

func (m Mock) Mount(target, device string, options map[string]string) flexvolume.Response {
	err := os.MkdirAll(target, 0755)
	if err != nil {
		return flexvolume.Response{
			Status:  flexvolume.StatusFailure,
			Message: err.Error(),
			Device:  "/dev/sdb1",
		}
	}

	return flexvolume.Response{
		Status:  flexvolume.StatusSuccess,
		Message: "Successfully mounted the mock volume",
		Device:  "/dev/sdb1",
	}
}

func (m Mock) Unmount(mount string) flexvolume.Response {
	err := os.RemoveAll(mount)
	if err != nil {
		return flexvolume.Response{
			Status:  flexvolume.StatusFailure,
			Message: err.Error(),
		}
	}

	return flexvolume.Response{
		Status:  flexvolume.StatusSuccess,
		Message: "Successfully unmounted the mock volume",
	}
}