Skip to content

Commit

Permalink
make dynamic persistent volumes path readable and configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
11janci committed Sep 19, 2019
1 parent ddcc09f commit 347d4f9
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 13 deletions.
6 changes: 0 additions & 6 deletions cmd/minikube/cmd/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,6 @@ var settings = []Setting{
validations: []setFn{IsValidAddon},
callbacks: []setFn{EnableOrDisableAddon},
},
{
name: "default-storageclass",
set: SetBool,
validations: []setFn{IsValidAddon},
callbacks: []setFn{EnableOrDisableStorageClasses},
},
{
name: "storage-provisioner",
set: SetBool,
Expand Down
8 changes: 7 additions & 1 deletion cmd/storage-provisioner/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,21 @@ import (
"k8s.io/minikube/pkg/storage"
)

const defaultPvDir = "/pvc"
const pvDirParam = "pv-dir"

func main() {
// Glog requires that /tmp exists.
if err := os.MkdirAll("/tmp", 0755); err != nil {
fmt.Fprintf(os.Stderr, "Error creating tmpdir: %v\n", err)
os.Exit(1)
}

var pvDir = flag.String(pvDirParam, defaultPvDir, "Directory for dynamically provisioned persistent volumes")

flag.Parse()

if err := storage.StartStorageProvisioner(); err != nil {
if err := storage.StartStorageProvisioner(*pvDir); err != nil {
glog.Exit(err)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ spec:
- name: storage-provisioner
image: {{default "gcr.io/k8s-minikube" .ImageRepository}}/storage-provisioner{{.ExoticArch}}:v1.8.1
command: ["/storage-provisioner"]
args: ["pv-dir", "/prv/test"]
imagePullPolicy: IfNotPresent
volumeMounts:
- mountPath: /tmp
Expand Down
6 changes: 3 additions & 3 deletions deploy/iso/minikube-iso/package/automount/minikube-automount
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,9 @@ if [ -n "$BOOT2DOCKER_DATA" ]; then
mkdir /tmp/hostpath_pv
mount --bind /mnt/$PARTNAME/hostpath_pv /tmp/hostpath_pv

mkdir -p /mnt/$PARTNAME/hostpath-provisioner
mkdir /tmp/hostpath-provisioner
mount --bind /mnt/$PARTNAME/hostpath-provisioner /tmp/hostpath-provisioner
mkdir -p /mnt/$PARTNAME/pvc
mkdir /pvc
mount --bind /mnt/$PARTNAME/pvc /pvc

if [ -e "/userdata.tar" ]; then
mv /userdata.tar /var/lib/boot2docker/
Expand Down
11 changes: 8 additions & 3 deletions pkg/storage/storage_provisioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ import (

const provisionerName = "k8s.io/minikube-hostpath"

var pvDir string

type hostPathProvisioner struct {
// The directory to create PV-backing directories in
pvDir string
Expand All @@ -47,7 +49,7 @@ type hostPathProvisioner struct {
// NewHostPathProvisioner creates a new Provisioner using host paths
func NewHostPathProvisioner() controller.Provisioner {
return &hostPathProvisioner{
pvDir: "/tmp/hostpath-provisioner",
pvDir: pvDir,
identity: uuid.NewUUID(),
}
}
Expand All @@ -57,7 +59,7 @@ var _ controller.Provisioner = &hostPathProvisioner{}
// Provision creates a storage asset and returns a PV object representing it.
func (p *hostPathProvisioner) Provision(options controller.ProvisionOptions) (*core.PersistentVolume, error) {
glog.Infof("Provisioning volume %v", options)
path := path.Join(p.pvDir, options.PVName)
path := path.Join(p.pvDir, options.PVC.Name)
if err := os.MkdirAll(path, 0777); err != nil {
return nil, err
}
Expand Down Expand Up @@ -112,8 +114,11 @@ func (p *hostPathProvisioner) Delete(volume *core.PersistentVolume) error {
}

// StartStorageProvisioner will start storage provisioner server
func StartStorageProvisioner() error {
func StartStorageProvisioner(pvDirParam string) error {
glog.Infof("Initializing the Minikube storage provisioner...")

pvDir = pvDirParam

config, err := rest.InClusterConfig()
if err != nil {
return err
Expand Down

0 comments on commit 347d4f9

Please sign in to comment.