
io.k8s.api.resource.v1beta1.ResourceClaimStatus.scala Maven / Gradle / Ivy
package io.k8s.api.resource.v1beta1
import dev.hnaderi.k8s.utils._
/** ResourceClaimStatus tracks whether the resource has been allocated and what the result of that was. */
final case class ResourceClaimStatus(
allocation : Option[io.k8s.api.resource.v1beta1.AllocationResult] = None,
devices : Option[Seq[io.k8s.api.resource.v1beta1.AllocatedDeviceStatus]] = None,
reservedFor : Option[Seq[io.k8s.api.resource.v1beta1.ResourceClaimConsumerReference]] = None
) {
/** Returns a new data with allocation set to new value */
def withAllocation(value: io.k8s.api.resource.v1beta1.AllocationResult) : ResourceClaimStatus = copy(allocation = Some(value))
/** if allocation has a value, transforms to the result of function*/
def mapAllocation(f: io.k8s.api.resource.v1beta1.AllocationResult => io.k8s.api.resource.v1beta1.AllocationResult) : ResourceClaimStatus = copy(allocation = allocation.map(f))
/** Returns a new data with devices set to new value */
def withDevices(value: Seq[io.k8s.api.resource.v1beta1.AllocatedDeviceStatus]) : ResourceClaimStatus = copy(devices = Some(value))
/** Appends new values to devices */
def addDevices(newValues: io.k8s.api.resource.v1beta1.AllocatedDeviceStatus*) : ResourceClaimStatus = copy(devices = Some(devices.fold(newValues)(_ ++ newValues)))
/** if devices has a value, transforms to the result of function*/
def mapDevices(f: Seq[io.k8s.api.resource.v1beta1.AllocatedDeviceStatus] => Seq[io.k8s.api.resource.v1beta1.AllocatedDeviceStatus]) : ResourceClaimStatus = copy(devices = devices.map(f))
/** Returns a new data with reservedFor set to new value */
def withReservedFor(value: Seq[io.k8s.api.resource.v1beta1.ResourceClaimConsumerReference]) : ResourceClaimStatus = copy(reservedFor = Some(value))
/** Appends new values to reservedFor */
def addReservedFor(newValues: io.k8s.api.resource.v1beta1.ResourceClaimConsumerReference*) : ResourceClaimStatus = copy(reservedFor = Some(reservedFor.fold(newValues)(_ ++ newValues)))
/** if reservedFor has a value, transforms to the result of function*/
def mapReservedFor(f: Seq[io.k8s.api.resource.v1beta1.ResourceClaimConsumerReference] => Seq[io.k8s.api.resource.v1beta1.ResourceClaimConsumerReference]) : ResourceClaimStatus = copy(reservedFor = reservedFor.map(f))
}
object ResourceClaimStatus {
implicit val encoder : Encoder[io.k8s.api.resource.v1beta1.ResourceClaimStatus] = new Encoder[io.k8s.api.resource.v1beta1.ResourceClaimStatus] {
def apply[T : Builder](o: io.k8s.api.resource.v1beta1.ResourceClaimStatus) : T = {
val obj = ObjectWriter[T]()
obj
.write("allocation", o.allocation)
.write("devices", o.devices)
.write("reservedFor", o.reservedFor)
.build
}
}
implicit val decoder: Decoder[ResourceClaimStatus] = new Decoder[ResourceClaimStatus] {
def apply[T : Reader](t: T): Either[String, ResourceClaimStatus] = for {
obj <- ObjectReader(t)
allocation <- obj.readOpt[io.k8s.api.resource.v1beta1.AllocationResult]("allocation")
devices <- obj.readOpt[Seq[io.k8s.api.resource.v1beta1.AllocatedDeviceStatus]]("devices")
reservedFor <- obj.readOpt[Seq[io.k8s.api.resource.v1beta1.ResourceClaimConsumerReference]]("reservedFor")
} yield ResourceClaimStatus (
allocation = allocation,
devices = devices,
reservedFor = reservedFor
)
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy