Skip to content

Capture the binding metadata CF sends - #36

Merged
norman-abramovitz merged 3 commits into
masterfrom
user-provided-binding-metadata
Jul 28, 2026
Merged

Capture the binding metadata CF sends#36
norman-abramovitz merged 3 commits into
masterfrom
user-provided-binding-metadata

Conversation

@norman-abramovitz

Copy link
Copy Markdown
Contributor

Closes #25.

The actual gap

The literal question in #25 — "can I read the user-provided env?" — was already
answered by existing behavior:

  • User-provided service instances arrive in VCAP_SERVICES under the
    user-provided label, so Services.WithLabel("user-provided"), WithName
    and WithTag have always resolved them.
  • Env vars set with cf set-env are ordinary process environment, already
    returned by CurrentEnv().

What was genuinely broken is next door: VCAP_SERVICES carries eleven fields
per binding object and the decoder kept six, silently discarding the rest.

Field Before After
name, label, tags, plan, credentials, volume_mounts kept kept
syslog_drain_url dropped SyslogDrainURL
instance_guid, instance_name dropped InstanceGUID, InstanceName
binding_guid, binding_name dropped BindingGUID, BindingName

syslog_drain_url is the one a user-provided instance depends on — it is what
cf cups -l sets. And instance_name matters because name holds the binding
name when a binding has one, so without it there was no way to recover the
instance name for a named binding.

Implementation note

mapstructure does not map snake_case onto CamelCase by itself — verified by
adding the fields untagged first and watching four of the five stay empty. Each
field therefore carries an explicit tag, as volume_mounts already did.

The Name and Label doc comments were corrected while here: Name is the
binding name if the binding has one and otherwise the instance name, and Label
is the service offering name, which is user-provided for a user-provided
instance.

API impact

gorelease -base=v1.20.0:

## compatible changes
Service.BindingGUID: added
Service.BindingName: added
Service.InstanceGUID: added
Service.InstanceName: added
Service.SyslogDrainURL: added

# summary
Suggested version: v1.21.0

Purely additive.

Verification

  • make check clean, make test-race passes
  • coverage 90.9% -> 91.0%
  • new tests cover a fully-populated user-provided binding and a plain binding
    where CF omits every new field

Also carries the changelog.d sweep for the fragments v1.20.0 consumed.

VCAP_SERVICES carries eleven fields per binding; the decoder kept six
and silently dropped the rest. syslog_drain_url is the one a
user-provided instance depends on -- it is what cf cups -l sets -- and
without instance_name there was no way to recover the instance name for
a named binding, since Name holds the binding name when one exists.

mapstructure does not map snake_case to CamelCase on its own, so each
field carries an explicit tag, as volume_mounts already did.

Closes #25
@norman-abramovitz
norman-abramovitz merged commit b47284a into master Jul 28, 2026
6 checks passed
@norman-abramovitz
norman-abramovitz deleted the user-provided-binding-metadata branch July 29, 2026 10:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Read user provided env

1 participant