Skip to content

Simple wrapper library for quick FlexVolume prototypes.

Notifications You must be signed in to change notification settings

fcantournet/flexvolume

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 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"
    "os/exec"

    "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 {
    device := "/dev/sdb1"
    
    err := os.MkdirAll(target, 0755)
    if err != nil {
        return flexvolume.Response{
            Status:  flexvolume.StatusFailure,
            Message: err.Error(),
            Device:  device,
        }
    }

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

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.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 100.0%