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

Commit

Permalink
discovery: add port parameter
Browse files Browse the repository at this point in the history
Currently the ACI spec only supports discovery on ports 80 and 443, this
does not allow using a discovery server in any other ports.

Fix the problem by adding support for arbitrary ports when querying a
discovery server.

fixes rkt/rkt#365
  • Loading branch information
iaguis committed Jan 13, 2015
1 parent 8010a93 commit bdf34f4
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 5 deletions.
10 changes: 9 additions & 1 deletion SPEC.md
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,15 @@ For example, if the ACE is looking for `example.com/reduce-worker` it will reque

https://example.com/reduce-worker?ac-discovery=1

Then inspect the HTML returned for meta tags that have the following format:
As a convenience feature, trying to fetch an app container image with a port number, will assume that the discovery server is listening in this port.

For example, if the ACE is looking for `example.com:8080/reduce-worker` it will request:

https://example.com:8080/reduce-worker?ac-discovery=1

**Note**: the app name is still considered as `example.com/reduce-worker`

After requesting it, inspect the HTML returned for meta tags that have the following format:

```
<meta name="ac-discovery" content="prefix-match url-tmpl">
Expand Down
5 changes: 3 additions & 2 deletions actool/discover.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@ func runDiscover(args []string) (exit int) {
}

for _, name := range args {
app, err := discovery.NewAppFromString(name)
nameWithoutPort, port := discovery.ExtractPort(name)
app, err := discovery.NewAppFromString(nameWithoutPort)
if err != nil {
stderr("%s: %s", name, err)
return 1
}
eps, err := discovery.DiscoverEndpoints(*app, transportFlags.Insecure)
eps, err := discovery.DiscoverEndpoints(*app, port, transportFlags.Insecure)

if err != nil {
stderr("error fetching %s: %s", name, err)
Expand Down
5 changes: 4 additions & 1 deletion discovery/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,11 @@ func doDiscover(app App, pre string, insecure bool) (*Endpoints, error) {
// DiscoverEndpoints will make HTTPS requests to find the ac-discovery meta
// tags and optionally will use HTTP if insecure is set. Based on the app
// passed the discovery templates will be filled out and returned in eps.
func DiscoverEndpoints(app App, insecure bool) (eps *Endpoints, err error) {
func DiscoverEndpoints(app App, port string, insecure bool) (eps *Endpoints, err error) {
parts := strings.Split(string(app.Name), "/")
if port != "" {
parts[0] += ":" + port
}
for i := range parts {
end := len(parts) - i
pre := strings.Join(parts[:end], "/")
Expand Down
2 changes: 1 addition & 1 deletion discovery/discovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func TestDiscoverEndpoints(t *testing.T) {

for i, tt := range tests {
httpGet = tt.get
de, err := DiscoverEndpoints(tt.app, true)
de, err := DiscoverEndpoints(tt.app, "", true)
if err != nil && !tt.expectDiscoverySuccess {
continue
}
Expand Down
13 changes: 13 additions & 0 deletions discovery/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,19 @@ func NewApp(name string, labels map[string]string) (*App, error) {
}, nil
}

func ExtractPort(name string) (nameWithoutPort string, port string) {
nameParts := strings.SplitN(name, "/", 2)
hostParts := strings.Split(nameParts[0], ":")
port = ""
if len(hostParts) > 1 {
port = hostParts[1]
}
// discard port in img since it's not part of an app name
nameWithoutPort = hostParts[0] + "/" + nameParts[1]

return nameWithoutPort, port
}

// NewAppFromString takes a command line app parameter and returns a map of labels.
//
// Example app parameters:
Expand Down

0 comments on commit bdf34f4

Please sign in to comment.