6.8.2. Advanced binding options
You can define the ServiceBinding custom resource (CR) to use the following advanced binding options:
-
Changing binding names: This option is available only for the
binding.operators.coreos.comAPI group. -
Composing custom binding data: This option is available only for the
binding.operators.coreos.comAPI group. -
Binding workloads using label selectors: This option is available for both the
binding.operators.coreos.comandservicebinding.ioAPI groups.
6.8.2.1. Changing the binding names before projecting them into the workload 링크 복사링크가 클립보드에 복사되었습니다!
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.
Example: Spring PetClinic sample application in the ServiceBinding CR
# ...
application:
name: spring-petclinic
group: apps
version: v1
resource: deployments
# ...
Example: PostgreSQL database service in the ServiceBinding CR
# ...
services:
- group: postgres-operator.crunchydata.com
version: v1beta1
kind: PostgresCluster
name: hippo
# ...
If namingStrategy is not defined and the binding names are projected as environment variables, then the host: hippo-pgbouncer value in the backing service and the projected environment variable would appear as shown in the following example:
Example
DATABASE_HOST: hippo-pgbouncer
where:
|
|
Specifies the |
|
| Specifies the binding name. |
After applying the POSTGRESQL_{{ .service.kind | upper }}_{{ .name | upper }}_ENV naming strategy, the list of custom binding names prepared by the service binding request appears as shown in the following example:
Example
POSTGRESQL_DATABASE_HOST_ENV: hippo-pgbouncer
POSTGRESQL_DATABASE_PORT_ENV: 5432
The following items describe the expressions defined in the POSTGRESQL_{{ .service.kind | upper }}_{{ .name | upper }}_ENV naming strategy:
-
.name: Refers to the binding name exposed by the backing service. In the previous example, the binding names areHOSTandPORT. -
.service.kind: Refers to the kind of service resource whose binding names are changed with the naming strategy. -
upper: String function used to post-process the character string while compiling the Go template string. -
POSTGRESQL: Prefix of the custom binding name. -
ENV: Suffix of the custom binding name.
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.