-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding persistent volume claims api (#269)
- Loading branch information
Showing
3 changed files
with
122 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
kubernetes-client/src/com/goyeau/kubernetes/client/api/PersistentVolumeClaimsApi.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.goyeau.kubernetes.client.api | ||
|
||
import cats.effect.Async | ||
import com.goyeau.kubernetes.client.KubeConfig | ||
import com.goyeau.kubernetes.client.operation.* | ||
import io.circe.* | ||
import io.k8s.api.core.v1.{PersistentVolumeClaim, PersistentVolumeClaimList} | ||
import org.http4s.Uri | ||
import org.http4s.client.Client | ||
import org.http4s.headers.Authorization | ||
import org.http4s.implicits.* | ||
|
||
private[client] class PersistentVolumeClaimsApi[F[_]]( | ||
val httpClient: Client[F], | ||
val config: KubeConfig[F], | ||
val authorization: Option[F[Authorization]] | ||
)(implicit | ||
val F: Async[F], | ||
val listDecoder: Decoder[PersistentVolumeClaimList], | ||
val resourceDecoder: Decoder[PersistentVolumeClaim], | ||
encoder: Encoder[PersistentVolumeClaim] | ||
) extends Listable[F, PersistentVolumeClaimList] | ||
with Watchable[F, PersistentVolumeClaim] { | ||
val resourceUri: Uri = uri"/api" / "v1" / "persistentvolumeclaims" | ||
|
||
def namespace(namespace: String): NamespacedPersistentVolumeClaimsApi[F] = | ||
new NamespacedPersistentVolumeClaimsApi(httpClient, config, authorization, namespace) | ||
} | ||
|
||
private[client] class NamespacedPersistentVolumeClaimsApi[F[_]]( | ||
val httpClient: Client[F], | ||
val config: KubeConfig[F], | ||
val authorization: Option[F[Authorization]], | ||
namespace: String | ||
)(implicit | ||
val F: Async[F], | ||
val resourceEncoder: Encoder[PersistentVolumeClaim], | ||
val resourceDecoder: Decoder[PersistentVolumeClaim], | ||
val listDecoder: Decoder[PersistentVolumeClaimList] | ||
) extends Creatable[F, PersistentVolumeClaim] | ||
with Replaceable[F, PersistentVolumeClaim] | ||
with Gettable[F, PersistentVolumeClaim] | ||
with Listable[F, PersistentVolumeClaimList] | ||
with Deletable[F] | ||
with GroupDeletable[F] | ||
with Watchable[F, PersistentVolumeClaim] { | ||
val resourceUri: Uri = uri"/api" / "v1" / "namespaces" / namespace / "persistentvolumeclaims" | ||
} |
71 changes: 71 additions & 0 deletions
71
...etes-client/test/src/com/goyeau/kubernetes/client/api/PersistentVolumeClaimsApiTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package com.goyeau.kubernetes.client.api | ||
|
||
import cats.syntax.all.* | ||
import cats.effect.* | ||
import com.goyeau.kubernetes.client.KubernetesClient | ||
import com.goyeau.kubernetes.client.operation.* | ||
import io.k8s.api.core.v1.{ | ||
PersistentVolumeClaim, | ||
PersistentVolumeClaimList, | ||
PersistentVolumeClaimSpec, | ||
ResourceRequirements | ||
} | ||
import io.k8s.apimachinery.pkg.api.resource.Quantity | ||
import io.k8s.apimachinery.pkg.apis.meta.v1.ObjectMeta | ||
import munit.FunSuite | ||
import org.typelevel.log4cats.Logger | ||
import org.typelevel.log4cats.slf4j.Slf4jLogger | ||
|
||
class PersistentVolumeClaimsApiTest | ||
extends FunSuite | ||
with CreatableTests[IO, PersistentVolumeClaim] | ||
with GettableTests[IO, PersistentVolumeClaim] | ||
with ListableTests[IO, PersistentVolumeClaim, PersistentVolumeClaimList] | ||
with ReplaceableTests[IO, PersistentVolumeClaim] | ||
with DeletableTests[IO, PersistentVolumeClaim, PersistentVolumeClaimList] | ||
with WatchableTests[IO, PersistentVolumeClaim] | ||
with ContextProvider { | ||
|
||
implicit override lazy val F: Async[IO] = IO.asyncForIO | ||
implicit override lazy val logger: Logger[IO] = Slf4jLogger.getLogger[IO] | ||
override lazy val resourceName: String = classOf[PersistentVolumeClaim].getSimpleName | ||
|
||
override def api(implicit client: KubernetesClient[IO]): PersistentVolumeClaimsApi[IO] = client.persistentVolumeClaims | ||
override def namespacedApi(namespaceName: String)(implicit | ||
client: KubernetesClient[IO] | ||
): NamespacedPersistentVolumeClaimsApi[IO] = | ||
client.persistentVolumeClaims.namespace(namespaceName) | ||
|
||
override def sampleResource(resourceName: String, labels: Map[String, String]): PersistentVolumeClaim = | ||
PersistentVolumeClaim( | ||
metadata = ObjectMeta(name = resourceName.some, labels = labels.some).some, | ||
spec = PersistentVolumeClaimSpec( | ||
accessModes = Seq("ReadWriteOnce").some, | ||
resources = ResourceRequirements( | ||
requests = Map("storage" -> Quantity("1Mi")).some | ||
).some, | ||
storageClassName = "local-path".some | ||
).some | ||
) | ||
|
||
override def modifyResource(resource: PersistentVolumeClaim): PersistentVolumeClaim = | ||
resource.copy( | ||
metadata = resource.metadata.map( | ||
_.copy( | ||
labels = resource.metadata.flatMap(_.labels).getOrElse(Map.empty).updated("key", "value").some | ||
) | ||
) | ||
) | ||
|
||
override def checkUpdated(updatedResource: PersistentVolumeClaim): Unit = | ||
assertEquals(updatedResource.metadata.flatMap(_.labels).flatMap(_.get("key")), "value".some) | ||
|
||
override def deleteApi(namespaceName: String)(implicit client: KubernetesClient[IO]): Deletable[IO] = | ||
client.persistentVolumeClaims.namespace(namespaceName) | ||
|
||
override def watchApi(namespaceName: String)(implicit | ||
client: KubernetesClient[IO] | ||
): Watchable[IO, PersistentVolumeClaim] = | ||
client.persistentVolumeClaims.namespace(namespaceName) | ||
|
||
} |