ZIO Optics support
ZIO Optics is an optics library for the ZIO ecosystem that helps writing code that modifies deeply nested data structures. This fits well some of the Kubernetes resources that can consists of many layers of data structures, including optional fields, lists and maps in the middle.
To enable the ZIO Optics support of zio-k8s
an additional dependency has to be imported:
libraryDependencies += "com.coralogix" %% "zio-k8s-client-optics" % "3.1.0"
This library defines a hierarchy of optics defined for the Kubernetes resource types. The following example demonstrates how to create a lens that can set the namespace inside the metadata section of a pod:
import com.coralogix.zio.k8s.model.core.v1.{ Container, Pod, PodSpec }
import com.coralogix.zio.k8s.model.pkg.apis.meta.v1.ObjectMeta
import com.coralogix.zio.k8s.optics.core.v1.PodO._
import com.coralogix.zio.k8s.optics.pkg.apis.meta.v1.ObjectMetaO._
val pod = Pod(
metadata = ObjectMeta(
name = "test-pod"
),
spec = PodSpec(
containers = Vector(
Container(
name = "test-container-1"
)
)
)
)
val f = (metadataO >>> namespaceO).set("namespace-1")(_)
f(pod)