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

Commit 2fe5633

Browse files
committed
discovery: do not set version to latest if not provided
Actually, if the required discovery labels doesn't contain a version label, it'll be set to a default of "latest". This behavior isn't documented in the spec and can create unwanted behaviors. This patch removes this and also adds to the spec an example on how to obtain the latest behavior without this "hidden" default.
1 parent d56ead8 commit 2fe5633

File tree

4 files changed

+71
-14
lines changed

4 files changed

+71
-14
lines changed

discovery/discovery.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,6 @@ func (e *discoveryData) Append(ep discoveryData) {
5454
e.Keys = append(e.Keys, ep.Keys...)
5555
}
5656

57-
const (
58-
defaultVersion = "latest"
59-
)
60-
6157
var (
6258
templateExpression = regexp.MustCompile(`{.*?}`)
6359
errEnough = errors.New("enough discovery information found")
@@ -138,9 +134,6 @@ func createTemplateVars(app App) []string {
138134

139135
func doDiscover(pre string, hostHeaders map[string]http.Header, app App, insecure InsecureOption) (*discoveryData, error) {
140136
app = *app.Copy()
141-
if app.Labels["version"] == "" {
142-
app.Labels["version"] = defaultVersion
143-
}
144137

145138
_, body, err := httpsOrHTTP(pre, hostHeaders, insecure)
146139
if err != nil {

discovery/discovery_test.go

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -402,14 +402,43 @@ func TestDiscoverEndpoints(t *testing.T) {
402402
[]string{"https://example.com/pubkeys.gpg"},
403403
nil,
404404
},
405-
// Test missing labels. version label should default to
406-
// "latest" and the first template should be rendered
405+
// Test missing version label. Only one template should match
407406
{
408407
&mockHTTPDoer{
409408
doer: fakeHTTPGet(
410409
[]meta{
411410
{"/myapp",
412-
"meta05.html",
411+
"meta07.html",
412+
},
413+
},
414+
nil,
415+
),
416+
},
417+
true,
418+
true,
419+
App{
420+
Name: "example.com/myapp",
421+
Labels: map[types.ACIdentifier]string{
422+
"os": "linux",
423+
"arch": "amd64",
424+
},
425+
},
426+
[]ACIEndpoint{
427+
ACIEndpoint{
428+
ACI: "https://storage.example.com/example.com/myapp-latest-linux-amd64.aci",
429+
ASC: "https://storage.example.com/example.com/myapp-latest-linux-amd64.aci.asc",
430+
},
431+
},
432+
[]string{"https://example.com/pubkeys.gpg"},
433+
nil,
434+
},
435+
// Test with required version label. Only one template should match
436+
{
437+
&mockHTTPDoer{
438+
doer: fakeHTTPGet(
439+
[]meta{
440+
{"/myapp",
441+
"meta07.html",
413442
},
414443
},
415444
nil,
@@ -418,18 +447,23 @@ func TestDiscoverEndpoints(t *testing.T) {
418447
true,
419448
true,
420449
App{
421-
Name: "example.com/myapp",
422-
Labels: map[types.ACIdentifier]string{},
450+
Name: "example.com/myapp",
451+
Labels: map[types.ACIdentifier]string{
452+
"version": "1.0.0",
453+
"os": "linux",
454+
"arch": "amd64",
455+
},
423456
},
424457
[]ACIEndpoint{
425458
ACIEndpoint{
426-
ACI: "https://storage.example.com/example.com/myapp-latest.aci",
427-
ASC: "https://storage.example.com/example.com/myapp-latest.aci.asc",
459+
ACI: "https://storage.example.com/example.com/myapp-1.0.0-linux-amd64.aci",
460+
ASC: "https://storage.example.com/example.com/myapp-1.0.0-linux-amd64.aci.asc",
428461
},
429462
},
430463
[]string{"https://example.com/pubkeys.gpg"},
431464
nil,
432465
},
466+
433467
// Test with a label called "name". It should be ignored.
434468
{
435469
&mockHTTPDoer{

discovery/testdata/meta07.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!DOCTYPE html>
2+
3+
<html>
4+
<head>
5+
<title>My app</title>
6+
<meta name="ac-discovery" content="example.com https://storage.example.com/{name}-{version}-{os}-{arch}.{ext}">
7+
<meta name="ac-discovery" content="example.com https://storage.example.com/{name}-latest-{os}-{arch}.{ext}">
8+
<meta name="ac-discovery-pubkeys" content="example.com https://example.com/pubkeys.gpg">
9+
</head>
10+
11+
<body>
12+
<h1>My App</h1>
13+
</body>
14+
</html>

spec/discovery.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,19 @@ Authentication during the discovery process is optional.
106106
If an attempt at fetching any resource (the initial discovery URL, an App Container Image, or signature) returns a `401 Unauthorized`, implementations should enact the authentication policy set by the operator.
107107
For example, some implementations might only perform HTTP basic authentication over HTTPS connections.
108108

109+
110+
### Examples
111+
112+
#### Latest pattern
113+
114+
If a client wants to retrieve the latest available ACI (without knowing its version) it can provide these meta tags:
115+
116+
```html
117+
<meta name="ac-discovery" content="example.com https://storage.example.com/{os}/{arch}/{name}-{version}.{ext}">
118+
<meta name="ac-discovery" content="example.com https://storage.example.com/{os}/{arch}/{name}-latest.{ext}">
119+
```
120+
121+
When requiring a specific version, the first template will be rendered, when not requiring a _version_ label the second template will match.
122+
123+
On the http server, the "latest" url should point to the current latest ACI.
124+

0 commit comments

Comments
 (0)