Skip to content

Simple wrapper library for quick FlexVolume prototypes.

Notifications You must be signed in to change notification settings

jaxxstorm/flexvolume

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 

Repository files navigation

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",
	}
}

About

Simple wrapper library for quick FlexVolume prototypes.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 100.0%