Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

How to implement conditional formatting (or templating) for non-YAML content#1840

Unanswered
lbroudoux asked this question inQ&A
Discussion options

Hi,

In my operator reconciliation loop, I need to manageConfigMap that will hold different types of files - typically.properties and.json content. This content must be customized depending on my Custom Resource: some properties should be set to a CR attribute value, some properties should be added/removed depending on the CR content.

There are straightforward ways to do this in Helm Chart using Go templates and in Ansible Operator SDK using Jinja templates. Is there a recommended/preferred way of doing this in the Java Operator SDK?

I was thinking of loading some template resource as a stream within the reconciler and then using something likeQute orThymeleaf to produce the final result but I don't know how tied to the HTTP/REST world they are....

Any recommendations or suggestions? Thanks!

You must be logged in to vote

Replies: 2 comments 4 replies

Comment options

You could create a YAML file with that content, load it in your operator and then create a builder from it and just edit the values that need replacing.

You must be logged in to vote
4 replies
@lbroudoux
Comment options

Yes that's what I'm doing for regular Kubernetes resources. However it's not convenient to dynamically change properties, json or XML files that are for example wrapped into aConfigMap at hand... there's no builder for that. That's why I'm looking for a more general purpose templating system to build the content to wrap.

@metacosm
Comment options

How would you like it to look like? Maybe that's something that's general-purpose enough that we could implement it at the JOSDK level?

@lbroudoux
Comment options

Hi there,

I did a first implementation usingQute templating from Quarkus and it's very convenient to use.

From my Java code (in a dependent resource), I just use the@CheckedTemplate annotation to get access to a templated JSON file. Seehere for an example.

In this use-case, themicrocksRealm template is a Keycloak realm definition in JSON format containing templated values based onspec. Seehere for an example.

I think this could be super-useful to have this at the JOSDK level, may be in theReconcilerUtils class just next toloadYaml() method... Something likeReconcilerUtils.renderTemplate(Class loader, String templateFile, Object spec) would be nice!

qute-core is the only necessary dependency and it looks lightweight. Don't know though if it would be the best candidate...

@metacosm
Comment options

I will take a look, I have been thinking about this issue on and off for a while actually but I've never really devoted my full attention to it yet. The idea that's been running in my head would be to try to create (at least for the Quarkus side of things) "compiled" templates at build time which would make it efficient to perform these kinds of operations (but also resource cloning) at runtime. It hasn't been a priority so far and I'm actually unsure if there's anything more to it than just a crazy idea 😅

Comment options

Hmm, good question, I usually use mustache if need some simple tamplating:
https://github.com/spullara/mustache.java

You must be logged in to vote
0 replies
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
Q&A
Labels
None yet
3 participants
@lbroudoux@metacosm@csviri

[8]ページ先頭

©2009-2025 Movatter.jp