Support kind: kustomization #41

Closed
opened 2025-12-30 01:19:51 +01:00 by adam · 2 comments
Owner

Originally created by @ichoosetoaccept on GitHub (Feb 6, 2024).

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/k8s.contrib@1.0.0#/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/k8s.contrib@1.0.0/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/k8s.contrib@1.0.0/packages/k8s.contrib/convert.pkl#L88-91)

87 | let (kind = resource["kind"])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
at k8s.contrib.convert#getResourceTemplate (https://github.com/apple/pkl-pantry/blob/k8s.contrib@1.0.0/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/k8s.contrib@1.0.0/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/k8s.contrib@1.0.0/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/k8s.contrib@1.0.0/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/k8s.contrib@1.0.0/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/k8s.contrib@1.0.0/packages/k8s.contrib/convert.pkl#L304-304)`

Originally created by @ichoosetoaccept on GitHub (Feb 6, 2024). 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/k8s.contrib@1.0.0#/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/k8s.contrib@1.0.0/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/k8s.contrib@1.0.0/packages/k8s.contrib/convert.pkl#L88-91) 87 | let (kind = resource["kind"]) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ at k8s.contrib.convert#getResourceTemplate (https://github.com/apple/pkl-pantry/blob/k8s.contrib@1.0.0/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/k8s.contrib@1.0.0/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/k8s.contrib@1.0.0/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/k8s.contrib@1.0.0/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/k8s.contrib@1.0.0/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/k8s.contrib@1.0.0/packages/k8s.contrib/convert.pkl#L304-304)`
adam closed this issue 2025-12-30 01:19:51 +01:00
Author
Owner

@bioball commented on GitHub (Feb 7, 2024):

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 commented on GitHub (Feb 7, 2024): 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?
Author
Owner

@ichoosetoaccept commented on GitHub (Feb 12, 2024):

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

@ichoosetoaccept commented on GitHub (Feb 12, 2024): I can and I did, including some additional background and motivation: https://github.com/apple/pkl-k8s/issues/1. Thanks for suggesting it!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/pkl#41