Include PVC namespace and name in hostpath directory name

parent 58e3421f
......@@ -4,6 +4,7 @@ import (
"flag"
"os"
"path"
"strings"
"syscall"
"k8s.io/api/core/v1"
......@@ -38,7 +39,9 @@ var _ controller.Provisioner = &LocalProvisioner{}
// Provision creates a storage asset and returns a pv object representing it.
func (p *LocalProvisioner) Provision(options controller.VolumeOptions) (*v1.PersistentVolume, error) {
pvPath := path.Join(p.pvDir, options.PVName)
// We include both the PVC namespace and name for legibility, but also the PV name for uniqueness.
directoryName := strings.Join([]string{options.PVC.Namespace, options.PVC.Name, options.PVName}, "-")
pvPath := path.Join(p.pvDir, directoryName)
glog.Infof("Creating pv with path: %s", pvPath)
err := os.Mkdir(pvPath, 0777)
if err != nil {
......@@ -50,6 +53,10 @@ func (p *LocalProvisioner) Provision(options controller.VolumeOptions) (*v1.Pers
ObjectMeta: metav1.ObjectMeta{
Name: options.PVName,
Annotations: map[string]string{
// Include the path as an annotation. This
// makes it easier to do manual management,
// but also to delete the directory when the
// PV is deleted.
pathAnnotation: pvPath,
},
},
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment