ZIO K8s

ZIO K8s

  • Overview
  • CRDs
  • Operators
  • Internals
  • API
  • About

›Overview

Overview

  • Contents
  • Getting started
  • Working with resources
  • Generic code
  • Monocle support
  • QuickLens support
  • Test clients

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" % "1.4.9"

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)
← Generic codeQuickLens support →
ZIO K8s
GitHub
Star
Chat with us on Discord
discord
Additional resources
Scaladoc of zio-k8s
Copyright © 2022 ZIO Maintainers