Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't recommend 'kind: List' #183

Merged
merged 1 commit into from
Jul 4, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 18 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -269,33 +269,29 @@ spec:

#### Can I generate a YAML file with many objects in it?

It is usual for k8s YAML files to include multiple objects separated by `---` ("documents" in YAML lingo),
so you might want to do it too.
Kubernetes YAML files commonly include multiple resources as documents separated
by `---`. To generate a single file with a different resource type per
document, you'll need to produce a `List Resource` (where `Resource` is a
union provided by `dhall-kubernetes` that can wrap any resource type), like
this:

If the objects have the same type, this is very easy: you return a Dhall list containing the
objects, and use the `--documents` flag, e.g.:
```dhall
let k8s = ./package.dhall

```bash
dhall-to-yaml --documents <<< "let a = ./examples/deploymentSimple.dhall in [a, a]"
in [ k8s.Resource.Deployment k8s.Deployment::{
, …
}
, k8s.Resource.Service k8s.Service::{
, …
}
]
```

If the objects are of different type, it's not possible to have separate documents in the same YAML file.
However, since [k8s has a builtin `List` type for these cases](https://github.com/kubernetes/kubernetes/blob/master/hack/testdata/list.yaml),
it's possible to use it together with the [union type of all k8s types that we generate][typesUnion].
… and then render the `List` of `Resource`s using the `--documents` flag, like
this:

So if we want to deploy e.g. a Deployment and a Service together, we can do:

```dhall
let k8s = ./typesUnion.dhall

in
{ apiVersion = "v1"
, kind = "List"
, items =
[ k8s.Deployment ./my-deployment.dhall
, k8s.Service ./my-service.dhall
]
}
```bash
dhall-to-yaml --documents --file ./resources.dhall
```

## Projects Using `dhall-kubernetes`
Expand Down