Skip to content
Open
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
17 changes: 13 additions & 4 deletions lib/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,12 @@ func (ctrl *ProvisionController) updateDeleteStats(volume *v1.PersistentVolume,
}
}

func (ctrl *ProvisionController) getProvisionedTenantAndStackAndServerNameForClaim(
claim *v1.PersistentVolumeClaim) (tenant string, stack string, service string) {
tenant, stack, service = claim.Labels["io.wise2c.tenant"], claim.Labels["io.wise2c.stack"], claim.Labels["io.wise2c.service"]
return
}

// provisionClaimOperation attempts to provision a volume for the given claim.
// Returns an error for use by goroutinemap when expbackoff is enabled: if nil,
// the operation is deleted, else the operation may be retried with expbackoff.
Expand Down Expand Up @@ -791,12 +797,15 @@ func (ctrl *ProvisionController) provisionClaimOperation(claim *v1.PersistentVol
return err
}
}

tenant, stack, service := ctrl.getProvisionedTenantAndStackAndServerNameForClaim(claim)
options := VolumeOptions{
PersistentVolumeReclaimPolicy: reclaimPolicy,
PVName: pvName,
PVC: claim,
Parameters: parameters,
PVName: pvName,
PVC: claim,
Parameters: parameters,
Tenant: tenant,
Stack: stack,
Service: service,
}

ctrl.eventRecorder.Event(claim, v1.EventTypeNormal, "Provisioning", fmt.Sprintf("External provisioner is provisioning volume for claim %q", claimToClaimKey(claim)))
Expand Down
9 changes: 9 additions & 0 deletions lib/controller/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,13 @@ type VolumeOptions struct {
PVC *v1.PersistentVolumeClaim
// Volume provisioning parameters from StorageClass
Parameters map[string]string

// Tenant: Service tenant name for the persistent volume.
Tenant string

// Stack: The service stack for the persistent volume.
Stack string

// Service: The service name of the persistent volume.
Service string
}
18 changes: 11 additions & 7 deletions nfs-client/cmd/nfs-client-provisioner/provisioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ func isMounted(mp string) bool {
return false
}

func pvName(ns string, name string) string {
return fmt.Sprintf("%s-%s", ns, name)
func pvName(tenant string, stack string, service string, name string) string {
return fmt.Sprintf("%s-%s-%s-%s", tenant, stack, service, name)
}

func mountPoint(server string, path string) string {
Expand Down Expand Up @@ -100,20 +100,23 @@ func (p *nfsProvisioner) Provision(options controller.VolumeOptions) (*v1.Persis
}
server := params["nfsServer"]
path := params["nfsPath"]

mp, err := ensureMount(server, path)
if err != nil {
return nil, fmt.Errorf("unable to mount NFS volume: " + err.Error())
}

pvName := pvName(options.PVC.Namespace, options.PVName)
pvName := pvName(options.Tenant, options.Stack, options.Service, options.PVName)
if err := os.MkdirAll(filepath.Join(mp, pvName), 0777); err != nil {
return nil, errors.New("unable to create directory to provision new pv: " + err.Error())
}

pv := &v1.PersistentVolume{
ObjectMeta: metav1.ObjectMeta{
Name: options.PVName,
Labels: map[string]string{
"io.wise2c.tenant": options.Tenant,
"io.wise2c.stack": options.Stack,
"io.wise2c.service": options.Service,
},
},
Spec: v1.PersistentVolumeSpec{
PersistentVolumeReclaimPolicy: options.PersistentVolumeReclaimPolicy,
Expand All @@ -139,11 +142,12 @@ func (p *nfsProvisioner) Delete(volume *v1.PersistentVolume) error {
path := path.Dir(volume.Spec.PersistentVolumeSource.NFS.Path)
mp, err := ensureMount(server, path)
if err != nil {
glog.Errorf("Failed to mount %s:%s", server, path)
glog.Errorf("Failed to mount %s:%s %s", server, path, mp)
return err
}
// PV is **not** namespaced
pvName := pvName(volume.Spec.ClaimRef.Namespace, volume.ObjectMeta.Name)
tenant, stack, service := volume.Labels["io.wise2c.tenant"], volume.Labels["io.wise2c.stack"], volume.Labels["io.wise2c.service"]
pvName := pvName(tenant, stack, service, volume.ObjectMeta.Name)
oldPath := filepath.Join(mp, pvName)
archivePath := filepath.Join(mp, "archived-"+pvName)
glog.Infof("archiving path %s to %s", oldPath, archivePath)
Expand Down