Skip to content

Commit fc83dc1

Browse files
authored
Document VCAP_SERVICES to service binding files translation (#5314)
Add a v3 API docs section describing how the service-binding-k8s and file-based-vcap-services app features expose service bindings on the container file system, including the per-binding file layout, naming rules, reserved attributes, size limit, and examples.
1 parent 69ad89a commit fc83dc1

2 files changed

Lines changed: 106 additions & 0 deletions

File tree

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
### Service binding files
2+
3+
By default, service binding details are exposed to an app through the `VCAP_SERVICES` environment variable. Two mutually exclusive app features instead expose them as files on the container's file system. Only one of the two features may be enabled for an app at a time.
4+
5+
- **file-based-vcap-services** writes the full contents of `VCAP_SERVICES` verbatim to a single file named `vcap_services`.
6+
- **service-binding-k8s** translates each service binding into its own directory of files, as described below.
7+
8+
#### Translation of VCAP_SERVICES to service binding files
9+
10+
When **service-binding-k8s** is enabled, the service binding details in `VCAP_SERVICES` are converted into a tree of files, following the [servicebinding.io](https://servicebinding.io/spec/core/1.1.0/#workload-projection) workload-projection specification. The binding's name becomes a directory name, and each of the binding's properties becomes a file within that directory whose contents are the property's value.
11+
12+
The translation follows these rules:
13+
14+
- Each binding name must be unique and valid; duplicate or invalid names cause an error. A name must match `[a-z0-9\-.]{1,253}` (per the Kubernetes/servicebinding.io spec).
15+
- The binding's name is used as the directory name; its properties become the file names.
16+
- The `credentials` attribute is a JSON object: each top-level key becomes a file whose content is that key's value. Nested objects and lists are serialized as JSON.
17+
- Reserved attributes may overwrite credential keys of the same name without error. The reserved attributes are: `binding_guid`, `binding_name`, `instance_guid`, `instance_name`, `name`, `label`, `tags`, `plan`, `syslog_drain_url`, `volume_mounts`, `type`, and `provider`.
18+
- All file names must match `[a-z0-9\-._]{1,253}`; an invalid name causes an error. The underscore follows a post-1.1.0 update to the servicebinding.io spec ([commit `b5d6755`](https://github.com/servicebinding/spec/commit/b5d67551d13c8801f6b8a084c70b7167e3fbbe7e)), which is not yet part of a published spec release.
19+
- List values (for example `tags` or `volume_mounts`) are stored as JSON arrays.
20+
- Empty lists and `null` values are omitted - no file is created.
21+
- Cloud Controller always writes a `type` file and a `provider` file, both set to the service label.
22+
- If the total byte size (file paths plus contents) exceeds **1,000,000 bytes**, an error is raised.
23+
24+
##### Examples
25+
26+
The following examples illustrate individual translation rules, showing only the properties relevant to each rule.
27+
28+
Nested and list credentials are serialized as JSON.
29+
30+
Input (`VCAP_SERVICES`):
31+
32+
```json
33+
{
34+
"foo": [
35+
{
36+
"name": "foo",
37+
"credentials": {
38+
"simple": "value",
39+
"deeply": {
40+
"nested": "value"
41+
},
42+
"list": ["v", "a", "l", "u", "e"]
43+
}
44+
}
45+
]
46+
}
47+
```
48+
49+
Output (service binding files):
50+
51+
```
52+
foo/name: foo
53+
foo/simple: value
54+
foo/deeply: {"nested":"value"}
55+
foo/list: ["v","a","l","u","e"]
56+
```
57+
58+
A reserved attribute overwrites a credential key (the `name` credential is dropped in favor of the binding's `name`).
59+
60+
Input (`VCAP_SERVICES`):
61+
62+
```json
63+
{
64+
"foo": [
65+
{
66+
"name": "foo",
67+
"credentials": {
68+
"name": "user",
69+
"secret": "password"
70+
}
71+
}
72+
]
73+
}
74+
```
75+
76+
Output (service binding files):
77+
78+
```
79+
foo/name: foo
80+
foo/secret: password
81+
```
82+
83+
`null` and empty values are omitted.
84+
85+
Input (`VCAP_SERVICES`):
86+
87+
```json
88+
{
89+
"foo": [
90+
{
91+
"name": "foo",
92+
"binding_guid": "45436ca8-0a7c-45e3-9439-ca1b44db7a2b",
93+
"syslog_drain_url": null,
94+
"volume_mounts": []
95+
}
96+
]
97+
}
98+
```
99+
100+
Output (service binding files):
101+
102+
```
103+
foo/name: foo
104+
foo/binding_guid: 45436ca8-0a7c-45e3-9439-ca1b44db7a2b
105+
```

docs/v3/source/index.html.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ includes:
8888
- resources/app_features/header
8989
- resources/app_features/object
9090
- resources/app_features/supported_features
91+
- resources/app_features/service_binding_files
9192
- resources/app_features/get
9293
- resources/app_features/list
9394
- resources/app_features/update

0 commit comments

Comments
 (0)