Add endpoint binding parsing to charm bundles #186

Merged
merged 3 commits into from Jan 6, 2016

Conversation

Projects
None yet
3 participants
Contributor

dooferlad commented Jan 6, 2016

This change adds the ability to bind an endpoint to a space inside a charm bundle, for example:

services:
    wordpress:
        charm: wordpress
        num_units: 1
        bindings:
            db: db
            url: public

This will request that wordpress has its database endpoint (db) attached to the db space and the url endpoint attached to the public space.

bundledata.go
+ for name, svc := range verifier.bd.Services {
+ charm, ok := verifier.charms[name]
+ // Only thest the ok path here because the !ok path is tested in verifyServices
+ if ok {
@dimitern

dimitern Jan 6, 2016

To reduce some nesting, how about:

if !ok {
  continue
}
@@ -141,6 +141,9 @@ type ServiceSpec struct {
// Storage holds the constraints for storage to assign
// to units of the service.
Storage map[string]string `bson:",omitempty" json:",omitempty" yaml:",omitempty"`
+
+ // EndpointBindings maps how endpoints are bound to spaces
+ EndpointBindings map[string]string `bson:"bindings,omitempty" json:"bindings,omitempty" yaml:"bindings,omitempty"`
@dimitern

dimitern Jan 6, 2016

As discussed on IRC I'm surprised Storage ... yaml ",omitempty" works correctly for "storage:", but if it does, let's drop the "bindings" in all 3 cases for consistency.

@dooferlad

dooferlad Jan 6, 2016

Contributor

We want the YAML field to be call "bindings" but, internally, we always have used EndpointBindings, hence the explicit name.

@dimitern

dimitern Jan 6, 2016

D'oh. Sure, that's what I asked for anyway :) Please, ignore my previous comment about it.

bundledata.go
+ charm, ok := verifier.charms[name]
+ // Only thest the ok path here because the !ok path is tested in verifyServices
+ if ok {
+ for BoundInterface := range svc.EndpointBindings {
@dimitern

dimitern Jan 6, 2016

I think this needs to be called "endpoint", as it's the relation name we're binding to a space, not the interface of the relation. E.g. with a metadata like this:

provides:
    db:
      interface: mysql

and bundle.yaml having:

...
    bindings:
        db: storage
...

"db" (not "mysql" - the interface) is bound to space "storage".

bundledata.go
+ }
+ }
+
+ if !ok {
@dimitern

dimitern Jan 6, 2016

There needs to be a similar check for charm.Meta().Peers as well.

bundledata.go
+ if !ok {
+ verifier.addErrorf(
+ "service %s wants to bind to interface %s, "+
+ "which isn't provided or required by charm",
@dimitern

dimitern Jan 6, 2016

I think it will be helpful to include the space name in the error message.
s/to interface %s/endpoint %q to space %q/
s/isn't provided or required by charm/isn't among the defined charm relations/ ?

dimitern commented Jan 6, 2016

It's nearly there, just a few issues need fixing.

bundledata.go
+ if !(matchedProvides || matchedRequires || matchedPeers) {
+ verifier.addErrorf(
+ "service %s wants to bind to endpoint %s to space %s, "+
+ "which isn't provided or required by charm",
@dimitern

dimitern Jan 6, 2016

Strictly speaking, "provided or required" is misleading, as it also checks "peers". So how about "isn't defined by the charm" ?

Contributor

dooferlad commented Jan 6, 2016

$$merge$$

Contributor

jujubot commented Jan 6, 2016

Status: merge request accepted. Url: http://juju-ci.vapour.ws:8080/job/github-merge-juju-charm

jujubot added a commit that referenced this pull request Jan 6, 2016

Merge pull request #186 from dooferlad/bundle-endpoint-bindings
Add endpoint binding parsing to charm bundles

This change adds the ability to bind an endpoint to a space inside a charm bundle, for example:
```yaml
services:
    wordpress:
        charm: wordpress
        num_units: 1
        bindings:
            db: db
            url: public
```
This will request that wordpress has its database endpoint (db) attached to the db space and the url endpoint attached to the public space.

@jujubot jujubot merged commit 38b05d2 into juju:v6-unstable Jan 6, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment