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

Merged
merged 5 commits into from
Feb 13, 2025

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. :)

@mrueg mrueg force-pushed the custom-template branch 2 times, most recently from 89507e7 to 3b1d377 Compare December 18, 2024 18:42
@mrueg
Copy link
Contributor Author

mrueg commented Jan 20, 2025

Policy check is failing due to missing "if", should be fixed with #564

@mrueg mrueg force-pushed the custom-template branch 2 times, most recently from 583b823 to 525ddc1 Compare February 6, 2025 19:47
@mrueg
Copy link
Contributor Author

mrueg commented Feb 6, 2025

@jalseth this includes now a commit that fixes the failing CI due to opa v0 compatibility.

@mrueg mrueg mentioned this pull request Feb 6, 2025
Copy link
Collaborator

@jalseth jalseth left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! And apologies for the long delay in getting to this.

@mrueg mrueg force-pushed the custom-template branch 7 times, most recently from 60e164d to 44f595f Compare February 12, 2025 22:58
@jalseth jalseth merged commit 18719ab into plexsystems:main Feb 13, 2025
11 checks passed
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
2 participants