-
Notifications
You must be signed in to change notification settings - Fork 34
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
Allow templates to define complex mappings #26
Comments
cc @Avni-Sharma |
@sbose78 Example for template mapping (re #25 (comment)): Kafka CR: status:
listeners:
- type: plain
addresses:
- host: my-cluster-kafka-bootstrap.service-binding-demo.svc
port: 9092
- host: my-cluster-kafka-bootstrap.service-binding-demo.svc
port: 9093
- type: tls
addresses:
- host: my-cluster-kafka-bootstrap.service-binding-demo.svc
port: 9094 Descriptors: - path: listeners
x-descriptors:
- servicebinding:prefix:elementType=template:source:{{ range $idx1, $el1 := .status.listeners }}{{ range $idx2, $el2 := $el1.addresses }}{{ $el1.type }}_{{ $idx2 }}={{ $el2.host }}:{{ $el2.port }}{{ printf "\n" }}{{ end }}{{ end }}:bindAs=envVar Same template from the descriptor but pretty formatted: {{- range $idx1, $el1 := .status.listeners -}}
{{- range $idx2, $el2 := $el1.addresses -}}
{{ $el1.type }}_{{ $idx2 }}={{ $el2.host }}:{{ $el2.port }}{{printf "\n" }}
{{- end -}}
{{- end -}} Executing the template on the Kafka CR example above produces this:
Still it needs some thinking about how properly distinguish keys from values. |
@sbose78 - would you want to take a stab at this one? |
@navidsh , the key should never have the |
@sbose78 The template in my example, produces the following output as "one" string once it executes:
SBO should then, take this text and turn it into a map e.g. {
"plain_0": "my-cluster-kafka-bootstrap.service-binding-demo.svc:9092",
"plain_1": "my-cluster-kafka-bootstrap.service-binding-demo.svc:9093",
"tls_0": "my-cluster-kafka-bootstrap.service-binding-demo.svc:9094"
} It's true that the key cannot have a Maybe picking better delimiters or a better structure could make it easier to convert the output text into key-value map. |
Kafka CR: status:
listeners:
- type: plain
addresses:
- host: my-cluster-kafka-bootstrap.service-binding-demo.svc
port: 9092
- host: my-cluster-kafka-bootstrap.service-binding-demo.svc
port: 9093
- type: tls
addresses:
- host: my-cluster-kafka-bootstrap.service-binding-demo.svc
port: 9094 Descriptors: - path: listeners
x-descriptors:
- servicebinding:elementType=template:source={{ GO TEMPLATE }}:bindAs=envVar Go Template:
This template produces as one string:
The operator would then parse the above string into secret key-value pairs. |
I'm good with this. Let's take this in. |
This was brought up in #25 (review)
We should have a way to define complex mappings inside an annotation / x-descriptor.
The text was updated successfully, but these errors were encountered: