Skip to content

Commit 87e381f

Browse files
authored
Merge pull request #46026 from Srivaralakshmi/SBO_LabelSelector
RHDEVDOCS-4073 - Document on binding workloads using the label selector feature as per the spec 1.0
2 parents 98cf2b6 + 6646f58 commit 87e381f

File tree

1 file changed

+70
-5
lines changed

1 file changed

+70
-5
lines changed

modules/sbo-advanced-binding-options.adoc

Lines changed: 70 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,15 @@
66
[id="sbo-advanced-binding-options_{context}"]
77
= Advanced binding options
88

9-
[role="_abstract"]
10-
Advanced binding options are available only for the `binding.operators.coreos.com` API group.
9+
You can define the `ServiceBinding` custom resource (CR) to use the following advanced binding options:
1110

11+
* Changing binding names: This option is available only for the `binding.operators.coreos.com` API group.
12+
* Composing custom binding data: This option is available only for the `binding.operators.coreos.com` API group.
13+
* Binding workloads using label selectors: This option is available for both the `binding.operators.coreos.com` and `servicebinding.io` API groups.
14+
15+
[id="changing-binding-names_{context}"]
1216
== Changing the binding names before projecting them into the workload
13-
You can specify the rules to change the binding names in the .spec.namingStrategy attribute of the `ServiceBinding` custom resource (CR). For example, consider a Spring PetClinic sample application that connects to the PostgreSQL database. In this case, the PostgreSQL database service exposes the host and port fields of the database to use for binding. The Spring PetClinic sample application can access this exposed binding data through the binding names.
17+
You can specify the rules to change the binding names in the `.spec.namingStrategy` attribute of the `ServiceBinding` CR. For example, consider a Spring PetClinic sample application that connects to the PostgreSQL database. In this case, the PostgreSQL database service exposes the `host` and `port` fields of the database to use for binding. The Spring PetClinic sample application can access this exposed binding data through the binding names.
1418

1519
.Example: Spring PetClinic sample application in the `ServiceBinding` CR
1620
[source,yaml]
@@ -67,6 +71,7 @@ The following items describe the expressions defined in the `POSTGRESQL_{{ .serv
6771

6872
Similar to the previous example, you can define the string templates in `namingStrategy` to define how each key of the binding names should be prepared by the service binding request.
6973

74+
[id="composing-custom-binding-data_{context}"]
7075
== Composing custom binding data
7176
As an application developer, you can compose custom binding data under the following circumstances:
7277

@@ -114,5 +119,65 @@ spec:
114119
----
115120
<1> Name of the backing service resource.
116121
<2> Optional identifier.
117-
<3> Generated JSON name that is to be projected as the file content or environment value. The JSON name contains the attributes of the backing service custom resource.
118-
<4> Generated JSON value that is to be projected as the file content or environment value. The JSON value contains the attributes of the backing service custom resource.
122+
<3> The JSON name that the {servicebinding-title} generates. The {servicebinding-title} projects this JSON name as the name of a file or environment variable.
123+
<4> The JSON value that the {servicebinding-title} generates. The {servicebinding-title} projects this JSON value as a file or environment variable. The JSON value contains the attributes from your specified field of the backing service custom resource.
124+
125+
[id="binding-workloads-using-a-label-selector_{context}"]
126+
== Binding workloads using a label selector
127+
You can use a label selector to specify the workload to bind. If you declare a service binding using the label selectors to pick up workloads, the {servicebinding-title} periodically attempts to find and bind new workloads that match the given label selector.
128+
129+
For example, as a cluster administrator, you can bind a service to every `Deployment` in a namespace with the `environment: production` label by setting an appropriate `labelSelector` field in the `ServiceBinding` CR. This enables the {servicebinding-title} to bind each of these workloads with one `ServiceBinding` CR.
130+
131+
.Example `ServiceBinding` CR in the `binding.operators.coreos.com/v1alpha1` API
132+
[source,yaml]
133+
----
134+
apiVersion: binding.operators.coreos.com/v1alpha1
135+
kind: ServiceBinding
136+
metadata:
137+
name: multi-application-binding
138+
namespace: service-binding-demo
139+
spec:
140+
application:
141+
labelSelector: <1>
142+
matchLabels:
143+
environment: production
144+
group: apps
145+
version: v1
146+
resource: deployments
147+
services:
148+
group: ""
149+
version: v1
150+
kind: Secret
151+
name: super-secret-data
152+
----
153+
<1> Specifies the workload that is being bound.
154+
155+
.Example `ServiceBinding` CR in the `servicebinding.io` API
156+
[source,yaml]
157+
----
158+
apiVersion: servicebindings.io/v1alpha3
159+
kind: ServiceBinding
160+
metadata:
161+
name: multi-application-binding
162+
namespace: service-binding-demo
163+
spec:
164+
workload:
165+
selector: <1>
166+
matchLabels:
167+
environment: production
168+
apiVersion: app/v1
169+
kind: Deployment
170+
service:
171+
apiVersion: v1
172+
kind: Secret
173+
name: super-secret-data
174+
----
175+
<1> Specifies the workload that is being bound.
176+
177+
[IMPORTANT]
178+
====
179+
If you define the following pairs of fields, {servicebinding-title} refuses the binding operation and generates an error:
180+
181+
* The `name` and `labelSelector` fields in the `binding.operators.coreos.com/v1alpha1` API.
182+
* The `name` and `selector` fields in the `servicebinding.io` API (Spec API).
183+
====

0 commit comments

Comments
 (0)