mirror of https://github.com/docker/docs.git
Container: Make Node public instead of exposing it through Node().
Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
This commit is contained in:
parent
3dfc92639c
commit
94cf009e46
15
api/api.go
15
api/api.go
|
|
@ -92,20 +92,20 @@ func getContainersJSON(c *context, w http.ResponseWriter, r *http.Request) {
|
||||||
if !strings.Contains(tmp.Status, "Up") && !all {
|
if !strings.Contains(tmp.Status, "Up") && !all {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if !container.Node().IsHealthy() {
|
if !container.Node.IsHealthy() {
|
||||||
tmp.Status = "Pending"
|
tmp.Status = "Pending"
|
||||||
}
|
}
|
||||||
// TODO remove the Node Name in the name when we have a good solution
|
// TODO remove the Node Name in the name when we have a good solution
|
||||||
tmp.Names = make([]string, len(container.Names))
|
tmp.Names = make([]string, len(container.Names))
|
||||||
for i, name := range container.Names {
|
for i, name := range container.Names {
|
||||||
tmp.Names[i] = "/" + container.Node().Name + name
|
tmp.Names[i] = "/" + container.Node.Name + name
|
||||||
}
|
}
|
||||||
// insert node IP
|
// insert node IP
|
||||||
tmp.Ports = make([]dockerclient.Port, len(container.Ports))
|
tmp.Ports = make([]dockerclient.Port, len(container.Ports))
|
||||||
for i, port := range container.Ports {
|
for i, port := range container.Ports {
|
||||||
tmp.Ports[i] = port
|
tmp.Ports[i] = port
|
||||||
if port.IP == "0.0.0.0" {
|
if port.IP == "0.0.0.0" {
|
||||||
tmp.Ports[i].IP = container.Node().IP
|
tmp.Ports[i].IP = container.Node.IP
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
out = append(out, &tmp)
|
out = append(out, &tmp)
|
||||||
|
|
@ -119,7 +119,7 @@ func getContainersJSON(c *context, w http.ResponseWriter, r *http.Request) {
|
||||||
func getContainerJSON(c *context, w http.ResponseWriter, r *http.Request) {
|
func getContainerJSON(c *context, w http.ResponseWriter, r *http.Request) {
|
||||||
container := c.cluster.Container(mux.Vars(r)["name"])
|
container := c.cluster.Container(mux.Vars(r)["name"])
|
||||||
if container != nil {
|
if container != nil {
|
||||||
resp, err := http.Get(container.Node().Addr + "/containers/" + container.Id + "/json")
|
resp, err := http.Get(container.Node.Addr + "/containers/" + container.Id + "/json")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
httpError(w, err.Error(), http.StatusInternalServerError)
|
httpError(w, err.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
|
|
@ -130,7 +130,7 @@ func getContainerJSON(c *context, w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
n, err := json.Marshal(container.Node())
|
n, err := json.Marshal(container.Node)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
httpError(w, err.Error(), http.StatusInternalServerError)
|
httpError(w, err.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
|
|
@ -140,9 +140,8 @@ func getContainerJSON(c *context, w http.ResponseWriter, r *http.Request) {
|
||||||
data = bytes.Replace(data, []byte("\"Name\":\"/"), []byte(fmt.Sprintf("\"Node\":%s,\"Name\":\"/", n)), -1)
|
data = bytes.Replace(data, []byte("\"Name\":\"/"), []byte(fmt.Sprintf("\"Node\":%s,\"Name\":\"/", n)), -1)
|
||||||
|
|
||||||
// insert node IP
|
// insert node IP
|
||||||
data = bytes.Replace(data, []byte("\"HostIp\":\"0.0.0.0\""), []byte(fmt.Sprintf("\"HostIp\":%q", container.Node().IP)), -1)
|
data = bytes.Replace(data, []byte("\"HostIp\":\"0.0.0.0\""), []byte(fmt.Sprintf("\"HostIp\":%q", container.Node.IP)), -1)
|
||||||
w.Write(data)
|
w.Write(data)
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -225,7 +224,7 @@ func proxyContainerAndForceRefresh(c *context, w http.ResponseWriter, r *http.Re
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Debugf("[REFRESH CONTAINER] --> %s", container.Id)
|
log.Debugf("[REFRESH CONTAINER] --> %s", container.Id)
|
||||||
container.Node().ForceRefreshContainer(container.Container)
|
container.Node.ForceRefreshContainer(container.Container)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Proxy a request to the right node
|
// Proxy a request to the right node
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,7 @@ func proxy(tlsConfig *tls.Config, container *cluster.Container, w http.ResponseW
|
||||||
// RequestURI may not be sent to client
|
// RequestURI may not be sent to client
|
||||||
r.RequestURI = ""
|
r.RequestURI = ""
|
||||||
|
|
||||||
parts := strings.SplitN(container.Node().Addr, "://", 2)
|
parts := strings.SplitN(container.Node.Addr, "://", 2)
|
||||||
if len(parts) == 2 {
|
if len(parts) == 2 {
|
||||||
r.URL.Scheme = parts[0]
|
r.URL.Scheme = parts[0]
|
||||||
r.URL.Host = parts[1]
|
r.URL.Host = parts[1]
|
||||||
|
|
@ -66,8 +66,8 @@ func proxy(tlsConfig *tls.Config, container *cluster.Container, w http.ResponseW
|
||||||
}
|
}
|
||||||
|
|
||||||
func hijack(tlsConfig *tls.Config, container *cluster.Container, w http.ResponseWriter, r *http.Request) error {
|
func hijack(tlsConfig *tls.Config, container *cluster.Container, w http.ResponseWriter, r *http.Request) error {
|
||||||
addr := container.Node().Addr
|
addr := container.Node.Addr
|
||||||
if parts := strings.SplitN(container.Node().Addr, "://", 2); len(parts) == 2 {
|
if parts := strings.SplitN(container.Node.Addr, "://", 2); len(parts) == 2 {
|
||||||
addr = parts[1]
|
addr = parts[1]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -107,7 +107,7 @@ func (c *Cluster) Container(IdOrName string) *Container {
|
||||||
|
|
||||||
// Match name, /name or engine/name.
|
// Match name, /name or engine/name.
|
||||||
for _, name := range container.Names {
|
for _, name := range container.Names {
|
||||||
if name == IdOrName || name == "/"+IdOrName || container.node.ID+name == IdOrName || container.node.Name+name == IdOrName {
|
if name == IdOrName || name == "/"+IdOrName || container.Node.ID+name == IdOrName || container.Node.Name+name == IdOrName {
|
||||||
return container
|
return container
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,9 +6,5 @@ type Container struct {
|
||||||
dockerclient.Container
|
dockerclient.Container
|
||||||
|
|
||||||
Info dockerclient.ContainerInfo
|
Info dockerclient.ContainerInfo
|
||||||
node *Node
|
Node *Node
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Container) Node() *Node {
|
|
||||||
return c.node
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -185,7 +185,7 @@ func (n *Node) inspectContainer(c dockerclient.Container, containers map[string]
|
||||||
|
|
||||||
container := &Container{}
|
container := &Container{}
|
||||||
container.Container = c
|
container.Container = c
|
||||||
container.node = n
|
container.Node = n
|
||||||
|
|
||||||
info, err := n.client.InspectContainer(c.Id)
|
info, err := n.client.InspectContainer(c.Id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -61,5 +61,5 @@ func (s *Scheduler) RemoveContainer(container *cluster.Container, force bool) er
|
||||||
s.Lock()
|
s.Lock()
|
||||||
defer s.Unlock()
|
defer s.Unlock()
|
||||||
|
|
||||||
return container.Node().Destroy(container, force)
|
return container.Node.Destroy(container, force)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue