Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding persistent volume claims api #269

Merged
merged 1 commit into from
Mar 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ class KubernetesClient[F[_]: Async: Logger](
lazy val ingresses: IngressessApi[F] = new IngressessApi(httpClient, config, authorization)
lazy val leases: LeasesApi[F] = new LeasesApi(httpClient, config, authorization)
lazy val nodes: NodesApi[F] = new NodesApi(httpClient, config, authorization)
lazy val raw: RawApi[F] = new RawApi[F](httpClient, wsClient, config, authorization)
lazy val persistentVolumeClaims: PersistentVolumeClaimsApi[F] =
new PersistentVolumeClaimsApi(httpClient, config, authorization)
lazy val raw: RawApi[F] = new RawApi[F](httpClient, wsClient, config, authorization)

def customResources[A: Encoder: Decoder, B: Encoder: Decoder](context: CrdContext)(implicit
listDecoder: Decoder[CustomResourceList[A, B]],
Expand Down
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"
}
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)

}
Loading