fn: cleanup of docker private registry code (#1130)

* fn: cleanup of docker private registry code

Start using URL parsed ServerAddress and its subdomains
for easier image ensure/pull in docker driver. Previous
code to lookup substrings was faulty without proper
URL parse and hostname tokenization. When searching
for a registry config, if image name does not contain
a registry and if there's a private registry configured,
then search for hub.docker.com and index.docker.io. This
is similar to previous code but with correct subdomain
matching.

* fn-dataplane: take port into account in auth configs
This commit is contained in:
Tolga Ceylan
2018-07-23 18:15:25 -07:00
committed by Owen Cliffe
parent 5b1f72f470
commit cf37a21fab
3 changed files with 161 additions and 61 deletions

View File

@@ -0,0 +1,59 @@
package docker
import (
"testing"
)
func verify(expected []string, checks map[string]bool) bool {
if len(expected) != len(checks) {
return false
}
for _, v := range expected {
_, ok := checks[v]
if !ok {
return false
}
}
return true
}
func TestRegistrySubDomains(t *testing.T) {
var exp []string
var res map[string]bool
exp = []string{"google.com"}
res = getSubdomains("google.com")
if !verify(exp, res) {
t.Fatalf("subdomain results failed expected[%+v] != results[%+v]", exp, res)
}
exp = []string{"top.google.com", "google.com"}
res = getSubdomains("top.google.com")
if !verify(exp, res) {
t.Fatalf("subdomain results failed expected[%+v] != results[%+v]", exp, res)
}
exp = []string{"top.google.com:443", "google.com:443"}
res = getSubdomains("top.google.com:443")
if !verify(exp, res) {
t.Fatalf("subdomain results failed expected[%+v] != results[%+v]", exp, res)
}
exp = []string{"top.top.google.com", "top.google.com", "google.com"}
res = getSubdomains("top.top.google.com")
if !verify(exp, res) {
t.Fatalf("subdomain results failed expected[%+v] != results[%+v]", exp, res)
}
exp = []string{"docker"}
res = getSubdomains("docker")
if !verify(exp, res) {
t.Fatalf("subdomain results failed expected[%+v] != results[%+v]", exp, res)
}
exp = []string{""}
res = getSubdomains("")
if !verify(exp, res) {
t.Fatalf("subdomain results failed expected[%+v] != results[%+v]", exp, res)
}
}