6.8.3.3. Workload resource mapping
-
Workload resource mapping is available for the secondary workloads of the
ServiceBindingcustom resource (CR) for both the API groups:binding.operators.coreos.comandservicebinding.io. -
You must define
ClusterWorkloadResourceMappingresources only under theservicebinding.ioAPI group. However, theClusterWorkloadResourceMappingresources interact withServiceBindingresources under both thebinding.operators.coreos.comandservicebinding.ioAPI groups.
If you cannot configure custom path locations by using the configuration method for container path, you can define exactly where binding data needs to be projected. Specify where to project the binding data for a given workload kind by defining the ClusterWorkloadResourceMapping resources in the servicebinding.io API group.
The following example shows how to define a mapping for the CronJob.batch/v1 resources.
Example: Mapping for CronJob.batch/v1 resources
apiVersion: servicebinding.io/v1beta1
kind: ClusterWorkloadResourceMapping
metadata:
name: cronjobs.batch
spec:
versions:
- version: "v1"
annotations: .spec.jobTemplate.spec.template.metadata.annotations
containers:
- path: .spec.jobTemplate.spec.template.spec.containers[*]
- path: .spec.jobTemplate.spec.template.spec.initContainers[*]
name: .name
env: .env
volumeMounts: .volumeMounts
volumes: .spec.jobTemplate.spec.template.spec.volumes
- 1
- Name of the
ClusterWorkloadResourceMappingresource, which must be qualified as theplural.groupof the mapped workload resource. - 2
- Version of the resource that is being mapped. Any version that is not specified can be matched with the "*" wildcard.
- 3
- Optional: Identifier of the
.annotationsfield in a pod, specified with a fixed JSONPath. The default value is.spec.template.spec.annotations. - 4
- Identifier of the
.containersand.initContainersfields in a pod, specified with a JSONPath. If no entries under thecontainersfield are defined, the Service Binding Operator defaults to two paths:.spec.template.spec.containers[*]and.spec.template.spec.initContainers[\*], with all other fields set as their default. However, if you specify an entry, then you must define the.pathfield. - 5
- Optional: Identifier of the
.namefield in a container, specified with a fixed JSONPath. The default value is.name. - 6
- Optional: Identifier of the
.envfield in a container, specified with a fixed JSONPath. The default value is.env. - 7
- Optional: Identifier of the
.volumeMountsfield in a container, specified with a fixed JSONPath. The default value is.volumeMounts. - 8
- Optional: Identifier of the
.volumesfield in a pod, specified with a fixed JSONPath. The default value is.spec.template.spec.volumes.
In this context, a fixed JSONPath is a subset of the JSONPath grammar that accepts only the following operations:
-
Field lookup:
.spec.template -
Array indexing:
.spec['template']
All other operations are not accepted.
-
Field lookup:
-
Most of these fields are optional. When they are not specified, the Service Binding Operator assumes defaults compatible with
PodSpecresources. -
The Service Binding Operator requires that each of these fields is structurally equivalent to the corresponding field in a pod deployment. For example, the contents of the
.envfield in a workload resource must be able to accept the same structure of data that the.envfield in a Pod resource would. Otherwise, projecting binding data into such a workload might result in unexpected behavior from the Service Binding Operator.
Behavior specific to the binding.operators.coreos.com API group
You can expect the following behaviors when ClusterWorkloadResourceMapping resources interact with ServiceBinding resources under the binding.operators.coreos.com API group:
-
If a
ServiceBindingresource with thebindAsFiles: falseflag value is created together with one of these mappings, then environment variables are projected into the.envFromfield underneath eachpathfield specified in the correspondingClusterWorkloadResourceMappingresource. As a cluster administrator, you can specify both a
ClusterWorkloadResourceMappingresource and the.spec.application.bindingPath.containersPathfield in aServiceBinding.bindings.coreos.comresource for binding purposes.The Service Binding Operator attempts to project binding data into the locations specified in both a
ClusterWorkloadResourceMappingresource and the.spec.application.bindingPath.containersPathfield. This behavior is equivalent to adding a container entry to the correspondingClusterWorkloadResourceMappingresource with thepath: $containersPathattribute, with all other values taking their default value.