我想使用dhall-kubernetes为服务生成ConfigMap。该服务是使用YAML文件配置的。我可以使用dhall在两个过程中创建配置:
$ dhall-to-yaml < server.dhall > server.yaml
$ dhall-to-yaml < configmap.dhall
apiVersion: v1
data:
server.yaml: |
server:
port: 8080
kind: ConfigMap
metadata:
name: my-configmap
server.dhall:
let _config = { server.port = 8080 } in _config
configmap.dhall:
let kubernetes =
./package.dhall sha256:d9eac5668d5ed9cb3364c0a39721d4694e4247dad16d8a82827e4619ee1d6188
let _configMap1 =
kubernetes.ConfigMap::{
, metadata = kubernetes.ObjectMeta::{ name = "my-configmap" }
, data = Some
[ { mapKey = "server.yaml", mapValue = ./server.yaml as Text } ]
}
in _configMap1
包.dhall
https://raw.githubusercontent.com/dhall-lang/dhall-kubernetes/master/package.dhall
通过在dhall中生成yaml,是否可以只使用一次dhall对yaml的调用?类似这样的东西:
let kubernetes =
./package.dhall sha256:d9eac5668d5ed9cb3364c0a39721d4694e4247dad16d8a82827e4619ee1d6188
let _config = { server.port = 8080 }
let _configMap3 =
kubernetes.ConfigMap::{
, metadata = kubernetes.ObjectMeta::{ name = "my-configmap" }
, data = Some
[ { mapKey = "server.yaml"
, mapValue = makeYAML _config -- make this work
}
]
}
in _configMap3
我在Prelude中找到了JSON.renderYAML函数,但这似乎并不是所需要的。
要使用Prelude.JSON.renderYAML
生成YAML,首先需要将配置转换为输入Prelude.JSON.Type
类型。请参阅下面我的makeYAML
版本中包含的makeJSON
功能:
let Prelude = https://prelude.dhall-lang.org/v15.0.0/package.dhall
let J = Prelude.JSON
let Config = { server : { port : Natural } }
let makeJSON
: Config → J.Type
= λ(c : Config)
→ J.object
( toMap
{ server = J.object (toMap { port = J.natural c.server.port }) }
)
let makeYAML
: Config → Text
= λ(c : Config) → J.renderYAML (makeJSON c)
let example =
let _config
: Config
= { server.port = 8080 }
in assert
: makeYAML _config
≡ ''
"server":
"port": 8080
''
in makeYAML