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

Support custom constraint (templates) #553

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mrueg
Copy link
Contributor

@mrueg mrueg commented Nov 26, 2024

This PR adds support for a custom template to generate constraints and constrainttemplates with. This can be helpful in case you want to generate a helm chart or a different non-structured deployment artifact using konstraint. I've added internal/commands/constrainttemplate_template.tpl and internal/commands/constraint_template.tpl as examples how this could look like.

In addition, this adds sprout as a dependency to support more functions in the custom document template.

TODO:

  • Complete the custom constaint template to allow reproducing the generated examples (currently matchers are missing)
  • Add documentation

Fixes: #236

@mrueg mrueg marked this pull request as draft November 26, 2024 23:17
@mrueg mrueg force-pushed the custom-template branch 4 times, most recently from 1c129ee to d1bc817 Compare December 3, 2024 11:01
@mrueg mrueg marked this pull request as ready for review December 3, 2024 11:02
@@ -181,18 +181,21 @@ func (r Rego) AnnotationParameters() map[string]apiextensionsv1.JSONSchemaProps
return r.annoParameters
}

func (r Rego) GetAnnotation(name string) (any, bool) {
func (r Rego) GetAnnotation(name string) (any, error) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had to change the signature here due to https://go.dev/src/text/template/funcs.go?s=14790:14826

@mrueg
Copy link
Contributor Author

mrueg commented Dec 6, 2024

@jalseth @jpreese would love to get some feedback on this, if you got some free cycles to spare. :)

@mrueg mrueg force-pushed the custom-template branch 5 times, most recently from b48022a to bcb185d Compare December 12, 2024 01:18
@mrueg
Copy link
Contributor Author

mrueg commented Dec 12, 2024

I added a bit of doc to explain when this can be useful. :)

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

Successfully merging this pull request may close these issues.

Add templating support
1 participant