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

Some thoughts after converting prometheus-operator resources from YAML to Dhall #27

Open
grdryn opened this issue May 27, 2022 · 0 comments

Comments

@grdryn
Copy link
Contributor

grdryn commented May 27, 2022

I'm relatively new to Dhall & to this project (thanks for creating it!). I (and I'm sure many others) have existing configs in YAML/JSON/whatever, that I want to switch to being generated by Dhall. I've found @Gabriella439's awesome slide on how that can be done, which uses dhall-kubernetes in the example.

I've managed to put together just enough locally to convert my collection of prometheus-operator PrometheusRule custom resource YAML files to Dhall. I've put the steps that I used at the end below.

I think it would be useful to have that schemas.dhall that I generated be a part of this project, and I've created #26 to get it included if you think it would be useful. There are some things that I'm not 100% sure about though, hence this issue rather than just creating the pull request alone:

  1. Would it be useful to structure this project more closely to how the dhall-kubernetes project is structured? E.g. have types/defaults/schemas separated? dhall-kubernetes mentions this dhall-prometheus-operator as the only entry in the "Projects using dhall-kubernetes" section of its README.md; I wonder if there would be benefit if this and any future dhall-*-operator libraries to be layed out in a similar form?
  2. Some of the types here are not in schema form ({ Type: Type, default: {}}). Should we look to have those in the same form too? I haven't looked into what would be involved there.

WDYT? If you think either or both of those would be worthwhile, I can try to find some time to look into them.


Converting a PrometheusRule YAML file to Dhall

  1. Use yaml-to-dhall to generate the corresponding Dhall:
yaml-to-dhall '(https://raw.githubusercontent.com/coralogix/dhall-prometheus-operator/v8.0.0/package.dhall sha256:ebc5f0c5f57d410412c2b7cbb64d0883be648eafc094f0c3e10dba4e6bd46ed4).v1.PrometheusRule.Type' --file ./prometheus/prometheus-rules-developer.yaml --output ./prometheus-rules-developer.dhall
  1. Make a schemas.dhall file for this project, to be able to use with dhall rewrite-with-schemas to clean up the Dhall that was generated in step 1 above.

  2. Rewrite the Dhall with schemas, using a schemas record of a merge of the dhall-kubernetes schemas (pretty much just for ObjectMeta) with the schemas.dhall, using // because of a collision that I don't care about (Error: Field collision on: Probe.Type):

dhall rewrite-with-schemas --schemas 'https://raw.githubusercontent.com/dhall-lang/dhall-kubernetes/v6.0.0/schemas.dhall // /path/to/local/dhall-prometheus-operator-schemas.dhall' --inplace ./prometheus-rules-developer.dhall
  1. Manually tidy up a couple of remaining things:
  • replace the schemas import with separate imports for dhall-kubernetes and dhall-prometheus-operator
  • replace instances of < Int : Integer | String : Text > with Kubernetes.IntOrString (there is no "schema" for this union, so it doesn't get automatically done)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant