Skip to content
This repository has been archived by the owner on Aug 14, 2020. It is now read-only.

discovery: match template only if satisfies all required labels #580

Conversation

sgotti
Copy link
Member

@sgotti sgotti commented Mar 23, 2016

This is the first part that tries to implement #575 second proposal (remove the "hidden" behavior that sets a version label to "latest" if not provided)

Actually, the spec isn't clear on template rendering and matching and can block some meta tags implementation as, the current implementation, can return unwanted endpoints.

It can probably BREAK some of the current meta tags implementations. But I'd like to ear your thoughts on this since I cannot find better ideas.

discovery: match only templates that satisfy all required labels

Actually the spec doesn't clarify when an endpoint template should be accepted or
not. Now, the appc/spec implementation returns only endpoints that can
be fully rendered. This means that it will also accept a template if it
doesn't contain some of the required discovery labels.

This looks good, but, trying to implement some meta discovery ideas it
will bring to unwanted endpoints.

Example 1:
Suppose I want to implement the "latest" pattern behavior:

<!-- ACIs with specific version -->
<meta name="ac-discovery" content="example.com https://storage.example.com/{name}-{version}-{os}-{arch}.{ext}">
<!-- Latest ACIs -->
<meta name="ac-discovery" content="example.com https://storage.example.com/{name}-latest-{os}-{arch}.{ext}">

If, on discovery, I ask for the name, os and arch
labels only the second template will be rendered (since the first cannot
be fully rendered due to missing version label). So I achieved latest
pattern.

But if I'm asking for a specific version both templates will be
rendered.

Example 2:
As an extension of the first example, suppose I want to create a global
meta discovery for all my images on example.com. So on the root of my
server I'll put some meta tags using example.com as prefix:

<!-- ACIs with specific version -->
<meta name="ac-discovery" content="example.com https://storage.example.com/{name}-{version}-{os}-{arch}.{ext}">
<!-- noarch ACIs -->
<meta name="ac-discovery" content="example.com https://storage.example.com/{name}-{version}-noarch.{ext}">
<!-- Latest ACIs -->
<meta name="ac-discovery" content="example.com https://storage.example.com/{name}-latest-{os}-{arch}.{ext}">
<meta name="ac-discovery" content="example.com https://storage.example.com/{name}-latest.{ext}">

With these tags I want to implement a "latest" and also "noarch" pattern.

If, on discovery, I ask only for the name and version labels the
second template will be rendered. So I achieved noarch pattern.

But, unfortunately, also the last template will be rendered.

And, as the first example, if I'm asking for a specific name,
version, os and arch ALL the templates will be rendered.

Since the spec says:

Note that multiple `ac-discovery` tags MAY be returned for a given
prefix-match [snip] In this case, the client implementation MAY choose
which to use at its own discretion.

If an implementation chooses the second it can download the wrong image version.

This patch makes template matching stricter choosing only template that
fully satisfy the required labels.

It can probably BREAK some of the current meta tags implementations.

It also documents this behavior.

@jonboulle
Copy link
Contributor

Please rebase

@sgotti sgotti force-pushed the discovery_match_template_only_if_satisfies_all_required_labels branch from d56ead8 to c7b344f Compare March 25, 2016 13:44
@sgotti
Copy link
Member Author

sgotti commented Mar 25, 2016

@jonboulle Rebased. Thoughts on this?

Actually the spec doesn't clarify when an endpoint template should be accepted or
not. Now, the appc/spec implementation returns only endpoints that can
be fully rendered. This means that it will also accept a template if it
doesn't contain some of the required discovery labels.

This looks good, but, trying to implement some meta discovery ideas it
will bring to unwanted endpoints.

Example 1:
Suppose I want to implement the "latest" pattern behavior:

```html
<!-- ACIs with specific version -->
<meta name="ac-discovery" content="example.com https://storage.example.com/{name}-{version}-{os}-{arch}.{ext}">
<!-- Latest ACIs -->
<meta name="ac-discovery" content="example.com https://storage.example.com/{name}-latest-{os}-{arch}.{ext}">
```

If, on discovery, I ask for the _name_, _os_ and _arch_
labels only the second template will be rendered (since the first cannot
be fully rendered due to missing _version_ label). So I achieved latest
pattern.

But if I'm asking for a specific _version_ both templates will be
rendered.

Example 2:
As an extension of the first example, suppose I want to create a global
meta discovery for all my images on example.com. So on the root of my
server I'll put some meta tags using example.com as prefix:

```html
<!-- ACIs with specific version -->
<meta name="ac-discovery" content="example.com https://storage.example.com/{name}-{version}-{os}-{arch}.{ext}">
<!-- noarch ACIs -->
<meta name="ac-discovery" content="example.com https://storage.example.com/{name}-{version}-noarch.{ext}">
<!-- Latest ACIs -->
<meta name="ac-discovery" content="example.com https://storage.example.com/{name}-latest-{os}-{arch}.{ext}">
<meta name="ac-discovery" content="example.com https://storage.example.com/{name}-latest.{ext}">
```

With this tags I want to implement a "latest" and also "noarch" pattern.

If, on discovery, I ask only for the _name_ and _version_ labels the
second template will be rendered. So I achieved noarch pattern.

But, unfortunately, also the last template will be rendered.

And, as the first example, if I'm asking for a specific _name_,
_version_, _os_ and _arch_ ALL the templates will be rendered.

Since the spec says:
```
Note that multiple `ac-discovery` tags MAY be returned for a given
prefix-match [snip] In this case, the client implementation MAY choose
which to use at its own discretion.
```

If an implementation chooses the second it can download the wrong image version.

This patch makes template matching stricter choosing only template that
fully satisfy the required labels.

It can probably BREAK some of the current meta tags implementations.

It also documents this behavior.
@sgotti sgotti force-pushed the discovery_match_template_only_if_satisfies_all_required_labels branch from c7b344f to d2793c7 Compare April 11, 2016 11:25
@sgotti
Copy link
Member Author

sgotti commented Apr 12, 2016

I reworked this to return best matching templates instead of being so strict, it will also cause much less breakage obtaining the same result. So I'm closing this in favor of #596 .

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants