From 275c6b3526884b70c2ecec935bf6c6702538a488 Mon Sep 17 00:00:00 2001
From: Jeremy Scott <js185692@ncr.com>
Date: Thu, 16 Mar 2023 14:34:43 +0000
Subject: [PATCH] Refactor volume type provisioning

---
 provisioner.go | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/provisioner.go b/provisioner.go
index a5318499..9265ba98 100644
--- a/provisioner.go
+++ b/provisioner.go
@@ -282,16 +282,17 @@ func (p *LocalPathProvisioner) Provision(ctx context.Context, opts pvController.
 	fs := v1.PersistentVolumeFilesystem
 
 	var pvs v1.PersistentVolumeSource
-	if pvcVal, ok := opts.PVC.GetAnnotations()["volumeType"]; ok {
-		// volume type specified in PVC
-		pvs = createPersistentVolumeSource(pvcVal, path)
-	} else if scVal, ok := opts.StorageClass.GetAnnotations()["defaultVolumeType"]; ok {
-		// default volume type provided for storage class
-		pvs = createPersistentVolumeSource(scVal, path)
+	defaultVolumeType := "hostPath"
+	if dVal, ok := opts.StorageClass.GetAnnotations()["defaultVolumeType"]; ok {
+		defaultVolumeType = dVal
+	}
+	var volumeType string
+	if val, ok := opts.PVC.GetAnnotations()["volumeType"]; ok {
+		volumeType = val
 	} else {
-		// volume type unspecified, we default to hostPath
-		pvs = createPersistentVolumeSource("hostPath", path)
+		volumeType = defaultVolumeType
 	}
+	pvs = createPersistentVolumeSource(volumeType, path)
 
 	var nodeAffinity *v1.VolumeNodeAffinity
 	if sharedFS {
-- 
GitLab