Monocle support
Moncole is an optics library 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 Monocle support of zio-k8s
an additional dependency has to be imported:
libraryDependencies += "com.coralogix" %% "zio-k8s-client-monocle" % "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.monocle.core.v1.PodO._
import com.coralogix.zio.k8s.monocle.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 composeOptional namespaceO).set("namespace-1")
f(pod)