TristanCacqueray / dhall-openshift

Typecheck, template and modularize your OpenShift definitions with Dhall
Apache License 2.0
8 stars 0 forks source link

Generate types based on server version #5

Open jfroche opened 4 years ago

jfroche commented 4 years ago

I was wondering if you would be ok to generate the types based on the openapi schema provided by the api server in openshift ? And version the generated types, just like they do in k8s.

We do oc get --raw /openapi/v2 > openshift-openapi-spec.json to get the openapi spec for our cluster (4.4.3)

I have made a Makefile based on your nice readme:

openshift-openapi-spec.json:
    #curl -O https://github.com/openshift/origin/blob/master/api/swagger-spec/openshift-openapi-spec.json
    oc get --raw /openapi/v2 > openshift-openapi-spec.json

dhall-kubernetes:
    git clone https://github.com/dhall-lang/dhall-kubernetes.git
    cd dhall-kubernetes; git am -3 < ../oc.patch

dhall-kubernetes/dhall-kubernetes-generator/dist/build/dhall-kubernetes-generator/dhall-kubernetes-generator:
    cd dhall-kubernetes/dhall-kubernetes-generator; nix-shell --run "runhaskell Setup.hs configure && runhaskell Setup.hs build"

generate: dhall-kubernetes openshift-openapi-spec.json dhall-kubernetes/dhall-kubernetes-generator/dist/build/dhall-kubernetes-generator/dhall-kubernetes-generator
    dhall-kubernetes/dhall-kubernetes-generator/dist/build/dhall-kubernetes-generator/dhall-kubernetes-generator openshift-openapi-spec.json

I can commit/pull request this if you think it would be interesting

TristanCacqueray commented 4 years ago

If I recall correctly, starting with the v4, you need to patch the dhall-kubernetes-generator with https://github.com/dhall-lang/dhall-kubernetes/pull/120 instead of the patch included in the current README. It would be interesting to document how to generate a binding from a running cluster, e.g. using git fetch origin refs/pull/120/merge && git checkout FETCH_HEAD instead of git am -3. However I don't think we should commit the resulting package in this project as it's not reproducible without the cluster. Moreover, I would rather help creating the openapi-to-dhall tool, which should work out of the box with the /openapi/v2 content.

I also investigated generating the openapi-spec file with the sources from https://github.com/openshift/openshift-apiserver using the kube-openapi tool. That would be ideal because we could automate the generation of per version package. However this seems to require quite a bit of work to get a valid openapi-spec.