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

[WIP] Make dynamic persistent volumes path readable and configurable #5400

Closed
wants to merge 4 commits into from
Closed
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
6 changes: 3 additions & 3 deletions cmd/storage-provisioner/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ limitations under the License.
package main

import (
"flag"
"fmt"
"os"

Expand All @@ -31,9 +30,10 @@ func main() {
fmt.Fprintf(os.Stderr, "Error creating tmpdir: %v\n", err)
os.Exit(1)
}
flag.Parse()

if err := storage.StartStorageProvisioner(); err != nil {
var pvDir = "/tmp/hostpath-provisioner"

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

Expand Down
14 changes: 7 additions & 7 deletions pkg/storage/storage_provisioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ type hostPathProvisioner struct {
}

// NewHostPathProvisioner creates a new Provisioner using host paths
func NewHostPathProvisioner() controller.Provisioner {
func NewHostPathProvisioner(pvDir string) controller.Provisioner {
return &hostPathProvisioner{
pvDir: "/tmp/hostpath-provisioner",
pvDir: pvDir,
identity: uuid.NewUUID(),
}
}
Expand All @@ -57,7 +57,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 @@ -103,17 +103,17 @@ func (p *hostPathProvisioner) Delete(volume *core.PersistentVolume) error {
return &controller.IgnoredError{Reason: "identity annotation on PV does not match ours"}
}

path := path.Join(p.pvDir, volume.Name)
if err := os.RemoveAll(path); err != nil {
if err := os.RemoveAll(volume.Spec.PersistentVolumeSource.HostPath.Path); err != nil {
return errors.Wrap(err, "removing hostpath PV")
}

return nil
}

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

config, err := rest.InClusterConfig()
if err != nil {
return err
Expand All @@ -132,7 +132,7 @@ func StartStorageProvisioner() error {

// Create the provisioner: it implements the Provisioner interface expected by
// the controller
hostPathProvisioner := NewHostPathProvisioner()
hostPathProvisioner := NewHostPathProvisioner(pvDir)

// Start the provision controller which will dynamically provision hostPath
// PVs
Expand Down