pkl icon indicating copy to clipboard operation
pkl copied to clipboard

Support kind: kustomization

Open ichoosetoaccept opened this issue 1 year ago • 1 comments

We use kustomize to manage our Kubernetes configuration. Currently the pkl CLI fails when I feed it such a file to transform to YAML.

Here's what a kustomization file is: https://kubectl.docs.kubernetes.io/references/kustomize/kustomization/

Here's the output of an attempt to convert a kustomization file: pkl eval -p input=overlays/t1/kustomization.yaml -o overlays/t1/kustomization.pkl package://pkg.pkl-lang.org/pkl-pantry/[email protected]#/convert.pkl –– Pkl Error –– Cannot find a template for resource of kind Kustomization`.

91 | throw("Cannot find a template for resource of kind \(kind).") ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ at k8s.contrib.convert#getResourceTemplate.<function#2> (https://github.com/apple/pkl-pantry/blob/[email protected]/packages/k8s.contrib/convert.pkl#L91-91)

88 | let (apiVersion = resource["apiVersion"]) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ at k8s.contrib.convert#getResourceTemplate.<function#1> (https://github.com/apple/pkl-pantry/blob/[email protected]/packages/k8s.contrib/convert.pkl#L88-91)

87 | let (kind = resource["kind"]) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ at k8s.contrib.convert#getResourceTemplate (https://github.com/apple/pkl-pantry/blob/[email protected]/packages/k8s.contrib/convert.pkl#L87-91)

65 | let (template = getResourceTemplate(resource)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ at k8s.contrib.convert#resourceConverters["convert resource to conform to Pkl template"].<function#1> (https://github.com/apple/pkl-pantry/blob/[email protected]/packages/k8s.contrib/convert.pkl#L65-65)

106 | resourceConverters.fold(resource, (acc, _, f) -> f.apply(acc)) ^^^^^^^^^^^^ at k8s.contrib.convert#resourceConverterFn.<function#1> (https://github.com/apple/pkl-pantry/blob/[email protected]/packages/k8s.contrib/convert.pkl#L106-106)

106 | resourceConverters.fold(resource, (acc, _, f) -> f.apply(acc)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ at k8s.contrib.convert#resourceConverterFn (https://github.com/apple/pkl-pantry/blob/[email protected]/packages/k8s.contrib/convert.pkl#L106-106)

286 | for (lineIdx, line in renderConvertedValue(resourceConverterFn(resource)).split("\n")) { ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ at k8s.contrib.convert#output.textBuffer (https://github.com/apple/pkl-pantry/blob/[email protected]/packages/k8s.contrib/convert.pkl#L286-286)

304 | text = textBuffer.toList().join("") ^^^^^^^^^^ at k8s.contrib.convert#output.text (https://github.com/apple/pkl-pantry/blob/[email protected]/packages/k8s.contrib/convert.pkl#L304-304)`

ichoosetoaccept avatar Feb 06 '24 20:02 ichoosetoaccept

It makes sense to have Kustomize templates, since Kustomize support ships with kubectl.

For what it's worth, Kustomize and Pkl both serve the same purpose; to produce Kubernetes YAML to get applied. Using Pkl to generate Kustomization feels like a bit of an anti-pattern; you're using Pkl but not using it for what it's best at.

Can you re-file this issue in https://github.com/apple/pkl-k8s?

bioball avatar Feb 06 '24 23:02 bioball

I can and I did, including some additional background and motivation: https://github.com/apple/pkl-k8s/issues/1. Thanks for suggesting it!

ichoosetoaccept avatar Feb 12 '24 22:02 ichoosetoaccept