Repository: appvia/kev
Pull request #231 (2020-09-07 22:42:52)

PV storage class fix
Addresses #229 

marcinc: > Should we update the /testdata/... fixtures to not include the standard storage class? Most fixtures assume it exists by default.

No, we don't need to change testdata assets. Storage class is a valid parameter so if someone specifies one because they use it then that's OK. 

Patch:
diff --git a/pkg/kev/config/defaults.go b/pkg/kev/config/defaults.go
index 79c7b53..ef9607a 100644
--- a/pkg/kev/config/defaults.go
+++ b/pkg/kev/config/defaults.go
@@ -20,8 +20,8 @@ const (
 	// DefaultVolumeSize default value PV class
 	DefaultVolumeSize = "100Mi"
 
-	// DefaultVolumeClass default PV size
-	DefaultVolumeClass = "standard"
+	// DefaultVolumeStorageClass default PV storage class
+	DefaultVolumeStorageClass = ""
 
 	// DefaultService is a default service
 	DefaultService = NoService
diff --git a/pkg/kev/converter/kubernetes/project_service.go b/pkg/kev/converter/kubernetes/project_service.go
index babed43..9b3497d 100644
--- a/pkg/kev/converter/kubernetes/project_service.go
+++ b/pkg/kev/converter/kubernetes/project_service.go
@@ -219,7 +219,7 @@ func (p *ProjectService) volumes(project *composego.Project) ([]Volumes, error)
 		if len(storageClass) > 0 {
 			temp.StorageClass = storageClass
 		} else {
-			temp.StorageClass = config.DefaultVolumeClass
+			temp.StorageClass = config.DefaultVolumeStorageClass
 		}
 
 		vols[i] = temp
diff --git a/pkg/kev/extract.go b/pkg/kev/extract.go
index 5e34721..ebde1de 100644
--- a/pkg/kev/extract.go
+++ b/pkg/kev/extract.go
@@ -63,7 +63,7 @@ func extractVolumesLabels(c *ComposeProject, out *composeOverlay) {
 		if storageClass, ok := c.Volumes[v].Labels[config.LabelVolumeStorageClass]; ok {
 			labels[config.LabelVolumeStorageClass] = storageClass
 		} else {
-			labels[config.LabelVolumeStorageClass] = config.DefaultVolumeClass
+			labels[config.LabelVolumeStorageClass] = config.DefaultVolumeStorageClass
 		}
 
 		if volSize, ok := c.Volumes[v].Labels[config.LabelVolumeSize]; ok {
diff --git a/pkg/kev/overlay.go b/pkg/kev/overlay.go
index 3c47c60..9726cfc 100644
--- a/pkg/kev/overlay.go
+++ b/pkg/kev/overlay.go
@@ -119,7 +119,8 @@ func (o *composeOverlay) mergeVolumesInto(p *ComposeProject) error {
 		if !ok {
 			return fmt.Errorf("could not find volume %s", override.Name)
 		}
-		if err := mergo.Merge(&base.Labels, &override.Labels, mergo.WithOverride); err != nil {
+
+		if err := mergo.Merge(&base.Labels, &override.Labels, mergo.WithOverwriteWithEmptyValue); err != nil {
 			return errors.Wrapf(err, "cannot merge labels for volume %s", name)
 		}
 		p.Volumes[name] = base


Test patch:
diff --git a/pkg/kev/converter/kubernetes/project_service_test.go b/pkg/kev/converter/kubernetes/project_service_test.go
index 7e546cf..274fcef 100644
--- a/pkg/kev/converter/kubernetes/project_service_test.go
+++ b/pkg/kev/converter/kubernetes/project_service_test.go
@@ -455,7 +455,7 @@ var _ = Describe("ProjectService", func() {
 						Container:    targetPath,
 						PVCName:      projectServiceName + "-claim0",
 						PVCSize:      config.DefaultVolumeSize,
-						StorageClass: config.DefaultVolumeClass,
+						StorageClass: config.DefaultVolumeStorageClass,
 					},
 				}))
 			})
diff --git a/pkg/kev/kev_reconcile_test.go b/pkg/kev/kev_reconcile_test.go
index a8bf176..8c963fb 100644
--- a/pkg/kev/kev_reconcile_test.go
+++ b/pkg/kev/kev_reconcile_test.go
@@ -276,7 +276,7 @@ var _ = Describe("Reconcile", func() {
 
 				v, _ := env.GetVolume("db_data")
 				Expect(v.Labels[config.LabelVolumeSize]).To(Equal("100Mi"))
-				Expect(v.Labels[config.LabelVolumeStorageClass]).To(Equal("standard"))
+				Expect(v.Labels[config.LabelVolumeStorageClass]).To(Equal(""))
 			})
 
 			It("should create a change summary", func() {
diff --git a/pkg/kev/testdata/in-cluster-wordpress/docker-compose.kev.dev.yaml b/pkg/kev/testdata/in-cluster-wordpress/docker-compose.kev.dev.yaml
index 382b54d..b2161b7 100644
--- a/pkg/kev/testdata/in-cluster-wordpress/docker-compose.kev.dev.yaml
+++ b/pkg/kev/testdata/in-cluster-wordpress/docker-compose.kev.dev.yaml
@@ -40,4 +40,4 @@ volumes:
   db_data:
     labels:
       kev.volume.size: 100Mi
-      kev.volume.storage-class: standard
+      kev.volume.storage-class: ""