All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.k8s.api.storage.v1.VolumeError.scala Maven / Gradle / Ivy

package io.k8s.api.storage.v1

import dev.hnaderi.k8s.utils._

/** VolumeError captures an error encountered during a volume operation. */
final case class VolumeError(
  message : Option[String] = None,
  time : Option[io.k8s.apimachinery.pkg.apis.meta.v1.Time] = None
) {

  /** Returns a new data with message set to new value */
  def withMessage(value: String) : VolumeError = copy(message = Some(value))
  /** if message has a value, transforms to the result of function*/
  def mapMessage(f: String => String) : VolumeError = copy(message = message.map(f))

  /** Returns a new data with time set to new value */
  def withTime(value: io.k8s.apimachinery.pkg.apis.meta.v1.Time) : VolumeError = copy(time = Some(value))
  /** if time has a value, transforms to the result of function*/
  def mapTime(f: io.k8s.apimachinery.pkg.apis.meta.v1.Time => io.k8s.apimachinery.pkg.apis.meta.v1.Time) : VolumeError = copy(time = time.map(f))
}

object VolumeError {

    implicit val encoder : Encoder[io.k8s.api.storage.v1.VolumeError] = new Encoder[io.k8s.api.storage.v1.VolumeError] {
        def apply[T : Builder](o: io.k8s.api.storage.v1.VolumeError) : T = {
          val obj = ObjectWriter[T]()
          obj
            .write("message", o.message)
            .write("time", o.time)
            .build
        }
    }

    implicit val decoder: Decoder[VolumeError] = new Decoder[VolumeError] {
      def apply[T : Reader](t: T): Either[String, VolumeError] = for {
          obj <- ObjectReader(t)
          message <- obj.readOpt[String]("message")
          time <- obj.readOpt[io.k8s.apimachinery.pkg.apis.meta.v1.Time]("time")
      } yield VolumeError (
          message = message,
          time = time
        )
    }
}





© 2015 - 2025 Weber Informatics LLC | Privacy Policy