Skip to content

Commit

Permalink
Merge pull request #277 from harana-oss/pv-storageclassname
Browse files Browse the repository at this point in the history
Added storageClassName to PersistentVolume Spec
  • Loading branch information
hagay3 authored Apr 6, 2023
2 parents 68d2a18 + 4469823 commit 9ee406d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
3 changes: 2 additions & 1 deletion client/src/main/scala/skuber/PersistentVolume.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
3 changes: 2 additions & 1 deletion client/src/main/scala/skuber/json/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
22 changes: 20 additions & 2 deletions client/src/test/scala/skuber/json/VolumeFormatSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand All @@ -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

Expand Down

0 comments on commit 9ee406d

Please sign in to comment.