Skip to content

Commit f1646f7

Browse files
Document Optional annotation feature
Fixing SME review comments Fixing QE review comments Fixing peer review comments updates to add Anchoring IDs in module files and for Additional resources titles in assembly
1 parent a83a0cd commit f1646f7

File tree

4 files changed

+50
-10
lines changed

4 files changed

+50
-10
lines changed

applications/connecting_applications_to_services/exposing-binding-data-from-a-service.adoc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,12 @@ The {servicebinding-title} enables application developers to easily bind workloa
1414

1515
include::modules/sbo-methods-of-exposing-binding-data.adoc[leveloffset=+1]
1616
include::modules/sbo-data-model.adoc[leveloffset=+1]
17+
include::modules/sbo-setting-annotations-mapping-optional.adoc[leveloffset=+1]
1718
include::modules/sbo-rbac-requirements.adoc[leveloffset=+1]
1819
include::modules/sbo-categories-of-exposable-binding-data.adoc[leveloffset=+1]
1920

21+
[role="_additional-resources"]
22+
[id="additional-resources_exposing-binding-data"]
2023
== Additional resources
2124
* link:https://github.com/openshift/console/blob/master/frontend/packages/operator-lifecycle-manager/src/components/descriptors/reference/reference.md[OLM Descriptor Reference].
2225
* xref:../../operators/operator_sdk/osdk-generating-csvs.adoc#osdk-generating-csvs[Defining cluster service versions (CSVs)].

modules/sbo-categories-of-exposable-binding-data.adoc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ The {servicebinding-title} enables you to expose the binding data values from th
1111

1212
This section provides examples to show how you can use the various categories of exposable binding data. You must modify these examples to suit your work environment and requirements.
1313

14-
14+
[id="exposing-a-string-from-a-resource_{context}"]
1515
== Exposing a string from a resource
1616
The following example shows how to expose the string from the `metadata.name` field of the `PostgresCluster` custom resource (CR) as a username:
1717

@@ -28,7 +28,7 @@ metadata:
2828
...
2929
----
3030

31-
31+
[id="exposing-a-constant-value-as-the-binding-item_{context}"]
3232
== Exposing a constant value as the binding item
3333
The following examples show how to expose a constant value from the `PostgresCluster` custom resource (CR):
3434

@@ -45,7 +45,7 @@ metadata:
4545
----
4646
<1> Binding `type` to be exposed with the `postgresql` value.
4747

48-
48+
[id="exposing-an-entire-config-map-or-secret-that-is-referenced-from-a-resource_{context}"]
4949
== Exposing an entire config map or secret that is referenced from a resource
5050
The following examples show how to expose an entire secret through annotations:
5151

@@ -88,7 +88,7 @@ This example uses the `path` attribute with a `urn:alm:descriptor:io.kubernetes:
8888

8989
If you intend to project all the values from a `ConfigMap` service resource, you must specify it as an attribute in the backing service CR. For example, if the attribute is part of the `.spec` section, you can create and use a `specDescriptors` array. Or, if the attribute is part of the `.status` section, you can create and use a `statusDescriptors` array.
9090

91-
91+
[id="exposing-a-specific-entry-from-a-config-map-or-secret-that-is-referenced-from-a-resource_{context}"]
9292
== Exposing a specific entry from a config map or secret that is referenced from a resource
9393
The following examples show how to expose a specific entry from a config map through annotations:
9494

@@ -133,7 +133,7 @@ This example uses the `path` attribute with an `X-Descriptors` update for `servi
133133
* Name of the binding key that is to be projected
134134
* Name of the key in the Secret service resource
135135

136-
136+
[id="exposing-a-resource-definition-value_{context}"]
137137
== Exposing a resource definition value
138138
The following example shows how to expose a resource definition value through annotations:
139139

@@ -164,7 +164,7 @@ The previous example uses the `connectionURL` attribute that points to the requi
164164

165165
If required values are available as attributes of backing service resources, annotating these values using `X-Descriptors` identifies them as the binding data.
166166

167-
167+
[id="exposing-entries-of-a-collection-with-the-key-and-value-from-each-entry_{context}"]
168168
== Exposing entries of a collection with the key and value from each entry
169169
The following example shows how to expose the entries of a collection with the key and value from each entry through annotations:
170170

@@ -228,7 +228,7 @@ status:
228228
The previous example helps you to project all those values with keys such as `primary`,
229229
`secondary`, and so on.
230230

231-
231+
[id="exposing-items-of-a-collection-with-one-key-per-item_{context}"]
232232
== Exposing items of a collection with one key per item
233233
The following example shows how to expose the items of a collection with one key per item through annotations:
234234

@@ -281,7 +281,7 @@ spec:
281281
- power
282282
----
283283

284-
284+
[id="exposing-values-of-collection-entries-with-one-key-per-entry-value_{context}"]
285285
== Exposing values of collection entries with one key per entry value
286286
The following example shows how to expose the values of collection entries with one key per entry value through annotations:
287287

modules/sbo-methods-of-exposing-binding-data.adoc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ You must expose the binding data from the backing service. Depending on your wor
2626
** Declaring binding data through Operator Lifecycle Manager (OLM) descriptors
2727
** Detection of binding data through owned resources
2828
29+
[id="provisioned-service_{context}"]
2930
== Provisioned service
3031
Provisioned service represents a backing service CR with a reference to a `Secret` resource placed in the `.status.binding.name` field of the backing service CR.
3132

@@ -109,7 +110,7 @@ spec:
109110

110111
This method exposes all the keys in the `hippo-pguser-hippo` referenced `Secret` resource as binding data that is to be projected into the workload.
111112

112-
113+
[id="direct-secret-reference_{context}"]
113114
== Direct secret reference
114115
You can use this method, if all the required binding data values are available in a `Secret` resource that you can reference in your Service Binding definition. In this method, a `ServiceBinding` resource directly references a `Secret` resource to connect to a service. All the keys in the `Secret` resource are exposed as binding data.
115116

@@ -144,6 +145,7 @@ spec:
144145
name: hippo-pguser-hippo
145146
----
146147

148+
[id="declaring-binding-data-through-CRD-or-CR-annotations_{context}"]
147149
== Declaring binding data through CRD or CR annotations
148150
You can use this method to annotate the resources of the backing service to expose the binding data with specific annotations. Adding annotations under the `metadata` section alters the CRs and CRDs of the backing services. {servicebinding-title} detects the annotations added to the CRs and CRDs and then creates a `Secret` resource with the values extracted based on the annotations.
149151

@@ -203,7 +205,7 @@ data:
203205
user: "hippo"
204206
----
205207

206-
208+
[id="declaring-binding-data-through-olm-descriptors_{context}"]
207209
== Declaring binding data through OLM descriptors
208210
You can use this method if your backing service is provided by an Operator. If your Operator is distributed as an OLM bundle, you can add OLM descriptors to describe the binding data that is to be exposed. The OLM descriptors are part of Cluster Service Version resources. The {servicebinding-title} detects the OLM descriptors and then creates a `Secret` resource with the values extracted based on the detected OLM descriptors.
209211

@@ -240,6 +242,7 @@ The following examples show how to define an X-Descriptor depending on the resou
240242
* The absence of the `Secret` or `ConfigMap` specific X-Descriptors indicates that the descriptor is referencing the binding data value at the given path.
241243
====
242244

245+
[id="detection-of-binding-data-through-owned-resources_{context}"]
243246
== Detection of binding data through owned resources
244247
You can use this method if your backing service owns one or more Kubernetes resources such as route, service, config map, or secret that you can use to detect the binding data. In this method, the {servicebinding-title} detects the binding data from resources owned by the backing service CR.
245248

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Module included in the following assemblies:
2+
//
3+
// * applications/connecting_applications_to_services/exposing-binding-data-from-a-service.adoc
4+
5+
:_content-type: PROCEDURE
6+
[id="sbo-setting-annotations-mapping-optional_{context}"]
7+
= Setting annotations mapping to be optional
8+
9+
You can have optional fields in the annotations. For example, a path to the credentials might not be present if the service endpoint does not require authentication. In such cases, a field might not exist in the target path of the annotations. As a result, {servicebinding-title} generates an error, by default.
10+
11+
As a service provider, to indicate whether you require annotations mapping, you can set a value for the `optional` flag in your annotations when enabling services. {servicebinding-title} provides annotations mapping only if the target path is available. When the target path is not available, the {servicebinding-title} skips the optional mapping and continues with the projection of the existing mappings without throwing any errors.
12+
13+
.Procedure
14+
15+
* To make a field in the annotations optional, set the `optional` flag value to `true`:
16+
+
17+
.Example
18+
[source,yaml]
19+
----
20+
apiVersion: apps.example.org/v1beta1
21+
kind: Database
22+
metadata:
23+
name: my-db
24+
namespace: my-petclinic
25+
annotations:
26+
service.binding/username: path={.spec.name},optional=true
27+
...
28+
----
29+
30+
[NOTE]
31+
====
32+
* If you set the `optional` flag value to `false` and the {servicebinding-title} is unable to find the target path, the Operator fails the annotations mapping.
33+
* If the `optional` flag has no value set, the {servicebinding-title} considers the value as `false` by default and fails the annotations mapping.
34+
====

0 commit comments

Comments
 (0)