From df20fb94c8e480714a0d0e717b4f654ac37b587f Mon Sep 17 00:00:00 2001 From: Naden Date: Wed, 5 Apr 2023 21:34:42 +1000 Subject: [PATCH 1/2] Added storageClassName to PersistentVolume Spec --- client/src/main/scala/skuber/PersistentVolume.scala | 3 ++- client/src/main/scala/skuber/json/package.scala | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/client/src/main/scala/skuber/PersistentVolume.scala b/client/src/main/scala/skuber/PersistentVolume.scala index 55d8a0e5..c07a1891 100644 --- a/client/src/main/scala/skuber/PersistentVolume.scala +++ b/client/src/main/scala/skuber/PersistentVolume.scala @@ -48,7 +48,8 @@ object PersistentVolume { source: Volume.PersistentSource, accessModes: List[AccessMode.AccessMode] = List(), claimRef: Option[ObjectReference] = None, - persistentVolumeReclaimPolicy: Option[ReclaimPolicy.ReclaimPolicy] = None) + persistentVolumeReclaimPolicy: Option[ReclaimPolicy.ReclaimPolicy] = None, + storageClassName: Option[String] = None) case class Status(phase: Option[Phase.Phase] = None, accessModes: List[AccessMode.AccessMode] = List()) diff --git a/client/src/main/scala/skuber/json/package.scala b/client/src/main/scala/skuber/json/package.scala index 7d052f24..6bdd0c10 100644 --- a/client/src/main/scala/skuber/json/package.scala +++ b/client/src/main/scala/skuber/json/package.scala @@ -883,7 +883,8 @@ package object format { JsPath.format[PersistentSource] and (JsPath \ "accessModes").formatMaybeEmptyList[PersistentVolume.AccessMode.AccessMode] and (JsPath \ "claimRef").formatNullable[ObjectReference] and - (JsPath \ "persistentVolumeReclaimPolicy").formatNullableEnum(PersistentVolume.ReclaimPolicy)) (PersistentVolume.Spec.apply, p => (p.capacity, p.source, p.accessModes, p.claimRef, p.persistentVolumeReclaimPolicy)) + (JsPath \ "persistentVolumeReclaimPolicy").formatNullableEnum(PersistentVolume.ReclaimPolicy) and + (JsPath \ "storageClassName").formatNullable[String]) (PersistentVolume.Spec.apply, p => (p.capacity, p.source, p.accessModes, p.claimRef, p.persistentVolumeReclaimPolicy, p.storageClassName)) implicit val persVolStatusFmt: Format[PersistentVolume.Status] = ((JsPath \ "phase").formatNullableEnum(PersistentVolume.Phase) and (JsPath \ "accessModes").formatMaybeEmptyList[PersistentVolume.AccessMode.AccessMode]) (PersistentVolume.Status.apply, p => (p.phase, p.accessModes)) From 44698239beabb7f1452c377db811c6cca1489d3d Mon Sep 17 00:00:00 2001 From: Naden Date: Thu, 6 Apr 2023 16:22:14 +1000 Subject: [PATCH 2/2] Added test for PersistentVolume Spec --- .../scala/skuber/json/VolumeFormatSpec.scala | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/client/src/test/scala/skuber/json/VolumeFormatSpec.scala b/client/src/test/scala/skuber/json/VolumeFormatSpec.scala index b1c68dce..2360841f 100644 --- a/client/src/test/scala/skuber/json/VolumeFormatSpec.scala +++ b/client/src/test/scala/skuber/json/VolumeFormatSpec.scala @@ -3,10 +3,11 @@ package skuber.json import org.specs2.execute.{Failure, Result} import org.specs2.mutable.Specification import play.api.libs.json._ +import skuber.PersistentVolume.{AccessMode, ReclaimPolicy} import skuber._ import skuber.json.format._ -import scala.io.Source +import scala.io.Source import skuber.PersistentVolumeClaim.VolumeMode /** @@ -32,9 +33,26 @@ class VolumeReadWriteSpec extends Specification { readPvc.spec mustEqual pvc.spec readPvc.spec.get.storageClassName must beSome("a-storage-class-name") } - } + "A PersistentVolume spec can be symmetrically written to json and the same value read back in \n" >> { + val pvc = PersistentVolume(metadata = ObjectMeta(name = "mypv"), + spec = Some(PersistentVolume.Spec(accessModes = List(PersistentVolume.AccessMode.ReadWriteOnce), + capacity = Map("storage" -> "30Gi"), + claimRef = Some(ObjectReference(name = "claimRef")), + persistentVolumeReclaimPolicy = Some(ReclaimPolicy.Retain), + source = NFS("server", "path"), + storageClassName = Some("a-storage-class-name")))) + val pvJson = Json.toJson(pvc) + val readPv = Json.fromJson[PersistentVolume](pvJson).get + readPv.name mustEqual pvc.name + readPv.spec mustEqual pvc.spec + readPv.spec.get.claimRef must beSome(ObjectReference(name = "claimRef")) + readPv.spec.get.persistentVolumeReclaimPolicy must beSome(ReclaimPolicy.Retain) + readPv.spec.get.source mustEqual NFS("server", "path") + readPv.spec.get.storageClassName must beSome("a-storage-class-name") + } + "A PersistentVolume with unsupported volume type can be read as json using GenericVolumeSource" >> { import skuber.Volume.GenericVolumeSource