Merge pull request #177 from inercia/inercia/registries_skip_warning
[Enhancement] Do not print the /etc/hosts message if the registry name can be resolved (thanks @inercia )
This commit is contained in:
commit
c2aeeca226
@ -10,6 +10,7 @@ import (
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/filters"
|
||||
@ -270,7 +271,9 @@ func CreateCluster(c *cli.Context) error {
|
||||
* Registry (optional)
|
||||
* Create the (optional) registry container
|
||||
*/
|
||||
var registryNameExists *dnsNameCheck
|
||||
if clusterSpec.RegistryEnabled {
|
||||
registryNameExists = newAsyncNameExists(clusterSpec.RegistryName, 1*time.Second)
|
||||
if _, err = createRegistry(*clusterSpec); err != nil {
|
||||
deleteCluster()
|
||||
return err
|
||||
@ -325,7 +328,11 @@ func CreateCluster(c *cli.Context) error {
|
||||
|
||||
if clusterSpec.RegistryEnabled {
|
||||
log.Printf("A local registry has been started as %s:%d", clusterSpec.RegistryName, clusterSpec.RegistryPort)
|
||||
log.Printf("Make sure you have an alias in your /etc/hosts file like '127.0.0.1 %s'", clusterSpec.RegistryName)
|
||||
|
||||
exists, err := registryNameExists.Exists()
|
||||
if !exists || err != nil {
|
||||
log.Printf("Make sure you have an alias in your /etc/hosts file like '127.0.0.1 %s'", clusterSpec.RegistryName)
|
||||
}
|
||||
}
|
||||
|
||||
log.Printf(`You can now use the cluster with:
|
||||
|
33
cli/util.go
33
cli/util.go
@ -126,3 +126,36 @@ func fileExists(filename string) bool {
|
||||
_, err := os.Stat(filename)
|
||||
return !os.IsNotExist(err)
|
||||
}
|
||||
|
||||
type dnsNameCheck struct {
|
||||
res chan bool
|
||||
err chan error
|
||||
timeout time.Duration
|
||||
}
|
||||
|
||||
func newAsyncNameExists(name string, timeout time.Duration) *dnsNameCheck {
|
||||
d := &dnsNameCheck{
|
||||
res: make(chan bool),
|
||||
err: make(chan error),
|
||||
timeout: timeout,
|
||||
}
|
||||
go func() {
|
||||
addresses, err := net.LookupHost(name)
|
||||
if err != nil {
|
||||
d.err <- err
|
||||
}
|
||||
d.res <- len(addresses) > 0
|
||||
}()
|
||||
return d
|
||||
}
|
||||
|
||||
func (d dnsNameCheck) Exists() (bool, error) {
|
||||
select {
|
||||
case r := <-d.res:
|
||||
return r, nil
|
||||
case e := <-d.err:
|
||||
return false, e
|
||||
case <-time.After(d.timeout):
|
||||
return false, nil
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user