Skip to content
This repository was archived by the owner on Jun 26, 2024. It is now read-only.

Commit 632aed8

Browse files
committed
docs: document workload resource mapping
Signed-off-by: Andy Sadler <[email protected]>
1 parent 93a55b4 commit 632aed8

File tree

1 file changed

+81
-1
lines changed

1 file changed

+81
-1
lines changed

docs/userguide/modules/creating-service-bindings/pages/custom-path-injection.adoc

Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ spec:
7979
NOTE: This feature is only available for `ServiceBinding` in the
8080
`binding.operators.coreos.com` API group.
8181

82-
SBO provides an API to inject a binding secret name into a custom application resource field.
82+
SBO provides an API to project a binding secret name into a custom application resource field.
8383
Here is an example CR with the secret in a custom location:
8484

8585
[source,yaml]
@@ -132,3 +132,83 @@ metadata:
132132
spec:
133133
secret: binding-request-72ddc0c540ab3a290e138726940591debf14c581
134134
....
135+
136+
== Workload resource mapping
137+
138+
[NOTE]
139+
====
140+
Workload resource mapping is available for the secondary workloads of the ServiceBinding custom resource (CR) for both the API groups: `binding.operators.coreos.com` and `servicebinding.io`.
141+
====
142+
143+
The specification also provides a way of defining exactly where binding data needs to be projected into. This method may be used when the preceding methods would not be able to configure custom path locations correctly. You may define `ClusterWorkloadResourceMapping.servicebindings.io` resources, which specifies where binding data will be projected for a given workload kind.
144+
145+
.Example: Schema of the `ClusterWorkloadResourceMapping` resource
146+
[source,yaml]
147+
----
148+
apiVersion: servicebinding.io/v1alpha3
149+
kind: ClusterWorkloadResourceMapping
150+
metadata:
151+
name: # string <1>
152+
...
153+
spec:
154+
versions: # required, at least one entry must be defined
155+
- version: # string <2>
156+
annotations: # string (Fixed JSONPath), optional <3>
157+
containers: # optional
158+
- path: # string (JSONPath) <4>
159+
name: # string (Fixed JSONPath), optional <5>
160+
env: # string (Fixed JSONPath), optional <6>
161+
volumeMounts: # string (Fixed JSONPath), optional <7>
162+
volumes: # string (Fixed JSONPath), optional <8>
163+
----
164+
<1> Name of the `ClusterWorkloadResourceMapping` resource, which must be qualified as the `plural.group` of the mapped workload resource. For example, `cronjobs.batch` for CronJobs.
165+
<2> Version of the resource that is being mapped. Any version that is not specified can be matched with the "*" wildcard.
166+
<3> Optional: Identifier of the `.annotations` field in a pod, specified with a fixed JSONPath. The default value is `.spec.template.spec.annotations`.
167+
<4> Identifies where containers live, specified with a JSONPath. If no entries are defined, the {servicebinding-title} defaults to two paths: `.spec.template.spec.containers` and `.spec.template.spec.initContainers`, with all other fields set as their default.
168+
<5> Optional: Identifier of the `.name` field in a container, specified with a fixed JSONPath. The default value is `.name`.
169+
<6> Optional: Identifier of the `.env` field in a container, specified with a fixed JSONPath. The default value is `.env`.
170+
<7> Optional: Identifier of the `.volumeMounts` field in a container, specified with a fixed JSONPath. The default value is `.volumeMounts`.
171+
<8> Optional: Identifier of the `.volumes` field in a pod, specified with a fixed JSONPath. The default value is `.spec.template.spec.volumes`.
172+
173+
[IMPORTANT]
174+
====
175+
In this context, a "Fixed JSONPath" is a subset of the JSONPath grammar that accepts only the following operations:
176+
177+
. Field lookup: `.spec.template`
178+
. Array indexing: `.spec['template']`
179+
180+
All other operations are forbidden.
181+
====
182+
183+
[NOTE]
184+
====
185+
* Most of these fields are optional. When they are not specified, the {servicebinding-title} assumes defaults compatible with `Pod` resources.
186+
* The {servicebinding-title} requires that each of these fields is structurally equivalent to the corresponding field in a pod deployment. For example, the contents of the `.env` field in a workload resource must be able to accept the same structure of data that the `.env` field in a Pod resource would. Otherwise, projecting binding data into such a workload might result in unexpected behavior from the {servicebinding-title}.
187+
====
188+
189+
Using the previous schema, you can define the following YAML as an example mapping for `CronJob.batch/v1`
190+
resources:
191+
192+
[source,yaml]
193+
----
194+
apiVersion: servicebinding.io/v1alpha3
195+
kind: ClusterWorkloadResourceMapping
196+
metadata:
197+
name: cronjobs.batch
198+
spec:
199+
versions:
200+
- version: "v1"
201+
annotations: .spec.jobTemplate.spec.template.metadata.annotations
202+
containers:
203+
- path: .spec.jobTemplate.spec.template.spec.containers[*]
204+
- path: .spec.jobTemplate.spec.template.spec.initContainers[*]
205+
volumes: .spec.jobTemplate.spec.template.spec.volumes
206+
----
207+
208+
[NOTE]
209+
====
210+
The following behavior occurs only in the `binding.operators.coreos.com` API group:
211+
212+
. If a `ServiceBinding` resource with the `bindAsFiles: false` flag value is created together with one of these mappings, then environment variables are projected into the `.envFrom` field underneath each `path` field specified in the corresponding `ClusterWorkloadResourceMapping` resource.
213+
. As a cluster administrator, you can specify both a `ClusterWorkloadResourceMapping` resource and the `.spec.application.bindingPath.containersPath` field in a `ServiceBinding.bindings.coreos.com` resource for binding purposes. The {servicebinding-title} attempts to project binding data into the locations specified in both of these methods. This behavior is equivalent to adding a container entry to the corresponding `ClusterWorkloadResourceMapping` resource with the `path: $containersPath` attribute, with all other values taking their default value.
214+
====

0 commit comments

Comments
 (0)