Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Alice and the return to the world of pods and higher-order functions

Roksolana
December 02, 2022

Alice and the return to the world of pods and higher-order functions

"Alice discovered in the past records that all the pods had disappeared. Alice must return to the world of pods and higher-order functions in order to save her friends. To build a bridge with that world, Alice will rely on the power of ZIO K8s.

Join Alice in her exploration of this library and her rescue mission."

Presented at Functional Scala 2022

Roksolana

December 02, 2022
Tweet

More Decks by Roksolana

Other Decks in Programming

Transcript

  1. Roksolana Diachuk • Big Data Developer at Captify • Women

    Who Code Kyiv Data Engineering Lead • Member of Ukrainian Scala community • Speaker
  2. “Oh, don’t be rude, Alice!
 I will only entertain you

    a bit with my riddle” “Like it explains anything”
  3. Version Timestamp User Operation Comment 9 2021-11-01 Alice CREATE New

    pods created 10 2021-11-01 System DELETE All pods lost val deltaTable = DeltaTable.forPath(spark, “/magic-db”) deltaTable.history()
  4. Alice has been thinking of the ways to help the

    pods but nothing came up.She decided to distract herself from anxious thoughts by the work tasks.
  5. anonym% There’s a way to help your friends Alice% What?

    How? anonym% You need to travel to their world Alice% But I don’t know how to get there anonym% There’s a passage close to you anonym% Follow my instructions Alice% But I don’t know how to get there anonym% You don’t Alice% How will I know that you’re telling the truth?
  6. A few months ago new moment got started psql-0 “Freedom

    to the pods!!” And then pods started to disappear
  7. On one of the days someone set the factory on

    fi re Some pods found shelter in functional forest kafka-1 kafka-0
  8. “Never used it, but I can fi gure it out”

    “You’ll need to use Zio-k8s” kafka-1 kafka-2
  9. libraryDependencies ++= Seq( 
 "com.coralogix" %% "zio-k8s-client" % “1.4.8”, "com.softwaremill.sttp.client3"

    %% "async-http-client-backend-zio" % “3.1.1", “com.softwaremill.sttp.client3" %% "slf4j-backend" % “3.1.1" ) ZIO-k8s setup “Looks easy”
  10. case class Config(k8s: K8sClusterConfig) val configDesc = ConfigDescriptor.nested(“k8s") (clusterConfigDescriptor).to[Config] val

    config = TypesafeConfig.fromDefaultLoader[Config](configDesc) val pods = (client ++ cluster) >>> Pods.live
  11. def getPod(namespace: String, name: String): IO[ContextInfoFailure, Pod] = { for

    { ns <- namespace maybePodName <- system .env(name) .mapError(reason => ContextInfoFailure.PodNameMissing(Some(reason))) … } } yield result }
  12. …. result <- maybePodName match { case Some(podName) => pods

    .get(podName, ns) case None => ZIO.fail(ContextInfoFailure.PodNameMissing(None)) } } yield result }
  13. private def tailLogs(podName: String, containerName: Option[String]): ZIO[Pods with Console, K8sFailure,

    Unit] = pods .getLog(podName, K8sNamespace.pods-freedom, containerName, follow = Some(true)) .tap { line => console.putStrLn(line).ignore } .runDrain
  14. tailLogs(“magic-db-cluster-1", Some("magic-db")) 5 Nov 17:23:41 * ERROR! Can’t fi nd

    data storage location
 5 Nov 17:25:13 * ERROR! Can’t fi nd data storage location 5 Nov 17:28:03 * ERROR! Can’t fi nd data storage location 5 Nov 17:31:22 * ERROR! Can’t fi nd data storage location
  15. properties: spec: properties: image: magic-train replicas: 2 scope: Namespaced names:

    plural: nstrains singular: nstrain kind: NsTrain nstrain.yaml