Skip to content

Commit

Permalink
Add dhall-kubernetes support for "schemas" (#84)
Browse files Browse the repository at this point in the history
For lack of a better term, I'm calling the `{ Type = …, default = … }`
record that the record completion operator expects a "schema".  This
change adds `dhall-kubernetes` support for auto-generating these schemas
for ease of use with the new `::` operator.

See the included example for how this would be used
  • Loading branch information
Gabriella439 authored Nov 18, 2019
1 parent 2fb32a4 commit fee24c0
Show file tree
Hide file tree
Showing 608 changed files with 3,935 additions and 0 deletions.
1 change: 1 addition & 0 deletions dhall-kubernetes-generator/src/Dhall/Kubernetes/Convert.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module Dhall.Kubernetes.Convert
( toTypes
, toDefault
, getImportsMap
, mkImport
) where

import qualified Data.List as List
Expand Down
19 changes: 19 additions & 0 deletions dhall-kubernetes-generator/src/Main.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{-# LANGUAGE OverloadedLists #-}

module Main (main) where

import qualified Data.Map.Strict as Data.Map
Expand Down Expand Up @@ -74,15 +76,32 @@ main = do
let path = "./defaults" Turtle.</> Turtle.fromText (name <> ".dhall")
writeDhall path expr

let toSchema (ModelName key) _ _ =
Dhall.RecordLit
[ ("Type", Dhall.Embed (Convert.mkImport ["types", ".."] (key <> ".dhall")))
, ("default", Dhall.Embed (Convert.mkImport ["defaults", ".."] (key <> ".dhall")))
]

let schemas = Data.Map.intersectionWithKey toSchema types defaults

-- Output schemas that combine both the types and defaults
Turtle.mktree "schemas"
for_ (Data.Map.toList schemas) $ \(ModelName name, expr) -> do
let path = "./schemas" Turtle.</> Turtle.fromText (name <> ".dhall")
writeDhall path expr

-- Output the types record, the defaults record, and the giant union type
let objectNames = Data.Map.keys types
typesMap = Convert.getImportsMap objectNames "types" $ Data.Map.keys types
defaultsMap = Convert.getImportsMap objectNames "defaults" $ Data.Map.keys defaults
schemasMap = Convert.getImportsMap objectNames "schemas" $ Data.Map.keys schemas

typesRecordPath = "./types.dhall"
typesUnionPath = "./typesUnion.dhall"
defaultsRecordPath = "./defaults.dhall"
schemasRecordPath = "./schemas.dhall"

writeDhall typesUnionPath (Dhall.Union $ fmap Just typesMap)
writeDhall typesRecordPath (Dhall.RecordLit typesMap)
writeDhall defaultsRecordPath (Dhall.RecordLit defaultsMap)
writeDhall schemasRecordPath (Dhall.RecordLit schemasMap)
104 changes: 104 additions & 0 deletions examples/aws-iam-authenticator-chart.dhall
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
let kubernetes = ../schemas.dhall

let release = "wintering-rodent"

let name = "aws-iam-authenticator"

let fullName = "${release}-${name}"

let version = "0.1.1"

let chart = "${name}-${version}"

let heritage = "dhall"

in kubernetes.DaemonSet::{
, metadata = kubernetes.ObjectMeta::{
, name = fullName
, labels = toMap
{ app = name
, chart = chart
, release = release
, heritage = heritage
}
}
, spec = Some kubernetes.DaemonSetSpec::{
, updateStrategy = Some kubernetes.DaemonSetUpdateStrategy::{
, type = Some "RollingUpdate"
}
, template = kubernetes.PodTemplateSpec::{
, metadata = kubernetes.ObjectMeta::{
, name = name
, annotations = toMap
{ `scheduler.alpha.kubernetes.io/critical-pod` = ""
}
, labels = toMap
{ app = name
, release = release
}
}
, spec = Some kubernetes.PodSpec::{
, hostNetwork = Some True
, nodeSelector = toMap
{ `node-role.kubernetes.io/master` = ""
}
, tolerations =
[ kubernetes.Toleration::{
, effect = Some "NoSchedule"
, key = Some "node-role.kubernetes.io/master"
}
, kubernetes.Toleration::{
, effect = Some "CriticalAddonsOnly"
, key = Some "Exists"
}
]
, containers =
[ kubernetes.Container::{
, name = fullName
, image = Some "gcr.io/heptio-images/authenticator:v0.1.0"
, args =
[ "server"
, "--config=/etc/aws-iam-authenticator/config.yaml"
, "--state-dir=/var/aws-iam-authenticator"
, "--generate-kubeconfig=/etc/kubernetes/aws-iam-authenticator/kubeconfig.yaml"
]
, volumeMounts =
[ kubernetes.VolumeMount::{
, name = "config"
, mountPath = "/etc/aws-iam-authenticator/"
}
, kubernetes.VolumeMount::{
, name = "state"
, mountPath = "/var/aws-iam-authenticator/"
}
, kubernetes.VolumeMount::{
, name = "output"
, mountPath = "/etc/kubernetes/aws-iam-authenticator/"
}
]
}
]
, volumes =
[ kubernetes.Volume::{
, name = "config"
, configMap = Some kubernetes.ConfigMapVolumeSource::{
, name = Some fullName
}
}
, kubernetes.Volume::{
, name = "output"
, hostPath = Some kubernetes.HostPathVolumeSource::{
, path = "/srv/kubernetes/aws-iam-authenticator/"
}
}
, kubernetes.Volume::{
, name = "state"
, hostPath = Some kubernetes.HostPathVolumeSource::{
, path = "/srv/kubernetes/aws-iam-authenticator/"
}
}
]
}
}
}
}
Loading

0 comments on commit fee24c0

Please sign in to comment.