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

io.k8s.apimachinery.pkg.apis.meta.v1.OwnerReference.scala Maven / Gradle / Ivy

package io.k8s.apimachinery.pkg.apis.meta.v1

import dev.hnaderi.k8s.utils._

/** OwnerReference contains enough information to let you identify an owning object. An owning object must be in the same namespace as the dependent, or be cluster-scoped, so there is no namespace field. */
final case class OwnerReference(
  name : String,
  uid : String,
  kind : String,
  apiVersion : String,
  blockOwnerDeletion : Option[Boolean] = None,
  controller : Option[Boolean] = None
) {

  /** Returns a new data with name set to new value */
  def withName(value: String) : OwnerReference = copy(name = value)
  /** transforms name to result of function */
  def mapName(f: String => String) : OwnerReference = copy(name = f(name))

  /** Returns a new data with uid set to new value */
  def withUid(value: String) : OwnerReference = copy(uid = value)
  /** transforms uid to result of function */
  def mapUid(f: String => String) : OwnerReference = copy(uid = f(uid))

  /** Returns a new data with kind set to new value */
  def withKind(value: String) : OwnerReference = copy(kind = value)
  /** transforms kind to result of function */
  def mapKind(f: String => String) : OwnerReference = copy(kind = f(kind))

  /** Returns a new data with apiVersion set to new value */
  def withApiVersion(value: String) : OwnerReference = copy(apiVersion = value)
  /** transforms apiVersion to result of function */
  def mapApiVersion(f: String => String) : OwnerReference = copy(apiVersion = f(apiVersion))

  /** Returns a new data with blockOwnerDeletion set to new value */
  def withBlockOwnerDeletion(value: Boolean) : OwnerReference = copy(blockOwnerDeletion = Some(value))
  /** if blockOwnerDeletion has a value, transforms to the result of function*/
  def mapBlockOwnerDeletion(f: Boolean => Boolean) : OwnerReference = copy(blockOwnerDeletion = blockOwnerDeletion.map(f))

  /** Returns a new data with controller set to new value */
  def withController(value: Boolean) : OwnerReference = copy(controller = Some(value))
  /** if controller has a value, transforms to the result of function*/
  def mapController(f: Boolean => Boolean) : OwnerReference = copy(controller = controller.map(f))
}

object OwnerReference {

    implicit val encoder : Encoder[io.k8s.apimachinery.pkg.apis.meta.v1.OwnerReference] = new Encoder[io.k8s.apimachinery.pkg.apis.meta.v1.OwnerReference] {
        def apply[T : Builder](o: io.k8s.apimachinery.pkg.apis.meta.v1.OwnerReference) : T = {
          val obj = ObjectWriter[T]()
          obj
            .write("name", o.name)
            .write("uid", o.uid)
            .write("kind", o.kind)
            .write("apiVersion", o.apiVersion)
            .write("blockOwnerDeletion", o.blockOwnerDeletion)
            .write("controller", o.controller)
            .build
        }
    }

    implicit val decoder: Decoder[OwnerReference] = new Decoder[OwnerReference] {
      def apply[T : Reader](t: T): Either[String, OwnerReference] = for {
          obj <- ObjectReader(t)
          name <- obj.read[String]("name")
          uid <- obj.read[String]("uid")
          kind <- obj.read[String]("kind")
          apiVersion <- obj.read[String]("apiVersion")
          blockOwnerDeletion <- obj.readOpt[Boolean]("blockOwnerDeletion")
          controller <- obj.readOpt[Boolean]("controller")
      } yield OwnerReference (
          name = name,
          uid = uid,
          kind = kind,
          apiVersion = apiVersion,
          blockOwnerDeletion = blockOwnerDeletion,
          controller = controller
        )
    }
}





© 2015 - 2025 Weber Informatics LLC | Privacy Policy