Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Service binding resolver #228

Merged
merged 1 commit into from
Sep 27, 2021
Merged

Conversation

menehune23
Copy link
Contributor

@menehune23 menehune23 commented Sep 15, 2021

Summary

Adds a servicebindings.Resolver type which can be used to lazily load and resolve service bindings according to the k8s spec.

Implementation notes:

  • Because the new spec relies on a $SERVICE_BINDING_ROOT env var, this PR maintains backwards compatibility by falling back to $CNB_BINDINGS, then <platform>/bindings if neither env var is set.

  • Bindings can be read from either the new k8s format or the legacy format.

  • Rather than providing top-level functions, this PR uses a dedicated type so that consumers can create interfaces for it and also mock/fake it in unit tests to keep them simple (for instance, this eliminates the need to understand the spec's implementation and write files to the filesystem during unit tests that rely on a binding).

  • Entry values are of a new io.ReadCloser-compatible type, Entry -- rather than simply a string or []byte -- that can stream the entry from the file system. It also supports .ReadString() and .ReadBytes() for ease of use. (Credit to @ryanmoran for the great idea).

Checklist

  • I have viewed, signed, and submitted the Contributor License Agreement.
  • I have linked issue(s) that this PR should close using keywords or the Github UI (See docs)
  • I have added an integration test, if necessary.
  • I have reviewed the styleguide for guidance on my code quality.
  • I'm happy with the commit history on this PR (I have rebased/squashed as needed).

Closes #107

bindings/resolver.go Outdated Show resolved Hide resolved
postal/service.go Outdated Show resolved Hide resolved
bindings/resolver.go Outdated Show resolved Hide resolved
bindings/resolver.go Outdated Show resolved Hide resolved
bindings/resolver.go Outdated Show resolved Hide resolved
bindings/resolver.go Outdated Show resolved Hide resolved
bindings/resolver.go Outdated Show resolved Hide resolved
bindings/resolver.go Outdated Show resolved Hide resolved
bindings/resolver.go Outdated Show resolved Hide resolved
bindings/resolver.go Outdated Show resolved Hide resolved
bindings/resolver.go Outdated Show resolved Hide resolved
bindings/resolver.go Outdated Show resolved Hide resolved
@menehune23 menehune23 force-pushed the bindings branch 2 times, most recently from 314b163 to 2f961af Compare September 22, 2021 01:53
postal/internal/dependency_mappings.go Outdated Show resolved Hide resolved
postal/service.go Outdated Show resolved Hide resolved
postal/service.go Outdated Show resolved Hide resolved
postal/service.go Outdated Show resolved Hide resolved
postal/service_test.go Outdated Show resolved Hide resolved
// 2. CNB_BINDINGS environment variable, if above is not set
// 3. `<platformDir>/bindings`, if both above are not set
func (r *Resolver) Resolve(typ string, provider string, platformDir string) ([]Binding, error) {
if newRoot := bindingRoot(platformDir); r.bindingRoot != newRoot {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that the platform is part of this method: If the binding root changes, we'll refresh and cache new bindings. Note that this implicitly occurs on a new resolver, due to the root being initialized to "".

@ryanmoran
Copy link
Member

I'm happy with where this is heading now. @sophiewigmore do you have anything else you'd like to see before we think about getting this merged?

@menehune23
Copy link
Contributor Author

I'm happy with where this is heading now. @sophiewigmore do you have anything else you'd like to see before we think about getting this merged?

@ryanmoran @sophiewigmore Just let me know before you merge, and I'll clean up the commit history

@sophiewigmore
Copy link
Member

@ryanmoran @menehune23 hey y'all. sorry I missed the update earlier. I've been following along with these discussions and this sounds good to me!

@ForestEckhardt
Copy link
Contributor

@menehune23 I am still a little unsure about the removal of the postal.Install function. I know that it is deprecated but the removal of the function entirely feels like it would necessitate a major bump as we are changing a part of the API by removing functionality. If our goal is to not do a major bump then I feel like that would bee to be added back in unless I am missing something or the intention is to do a major bump and I have just missed the boat on the decision.

@menehune23
Copy link
Contributor Author

menehune23 commented Sep 27, 2021

@menehune23 I am still a little unsure about the removal of the postal.Install function. I know that it is deprecated but the removal of the function entirely feels like it would necessitate a major bump as we are changing a part of the API by removing functionality. If our goal is to not do a major bump then I feel like that would bee to be added back in unless I am missing something or the intention is to do a major bump and I have just missed the boat on the decision.

@ForestEckhardt That's a good point. I'll restore it and its tests until later.

ForestEckhardt
ForestEckhardt previously approved these changes Sep 27, 2021
Signed-off-by: Brayan Henao <bhenao@vmware.com>
@ForestEckhardt ForestEckhardt merged commit d600cb5 into paketo-buildpacks:main Sep 27, 2021
@menehune23 menehune23 deleted the bindings branch September 27, 2021 18:35
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.

Support retrieving bindings by buildpacks
4 participants