@@ -99,8 +99,7 @@ type Port struct {
|
|||||||
// Optional: If specified, this must be a DNS_LABEL. Each named port
|
// Optional: If specified, this must be a DNS_LABEL. Each named port
|
||||||
// in a pod must have a unique name.
|
// in a pod must have a unique name.
|
||||||
Name string `yaml:"name,omitempty" json:"name,omitempty"`
|
Name string `yaml:"name,omitempty" json:"name,omitempty"`
|
||||||
// Optional: Defaults to ContainerPort. If specified, this must be a
|
// Optional: If specified, this must be a valid port number, 0 < x < 65536.
|
||||||
// valid port number, 0 < x < 65536.
|
|
||||||
HostPort int `yaml:"hostPort,omitempty" json:"hostPort,omitempty"`
|
HostPort int `yaml:"hostPort,omitempty" json:"hostPort,omitempty"`
|
||||||
// Required: This must be a valid port number, 0 < x < 65536.
|
// Required: This must be a valid port number, 0 < x < 65536.
|
||||||
ContainerPort int `yaml:"containerPort" json:"containerPort"`
|
ContainerPort int `yaml:"containerPort" json:"containerPort"`
|
||||||
|
@@ -99,8 +99,7 @@ type Port struct {
|
|||||||
// Optional: If specified, this must be a DNS_LABEL. Each named port
|
// Optional: If specified, this must be a DNS_LABEL. Each named port
|
||||||
// in a pod must have a unique name.
|
// in a pod must have a unique name.
|
||||||
Name string `yaml:"name,omitempty" json:"name,omitempty"`
|
Name string `yaml:"name,omitempty" json:"name,omitempty"`
|
||||||
// Optional: Defaults to ContainerPort. If specified, this must be a
|
// Optional: If specified, this must be a valid port number, 0 < x < 65536.
|
||||||
// valid port number, 0 < x < 65536.
|
|
||||||
HostPort int `yaml:"hostPort,omitempty" json:"hostPort,omitempty"`
|
HostPort int `yaml:"hostPort,omitempty" json:"hostPort,omitempty"`
|
||||||
// Required: This must be a valid port number, 0 < x < 65536.
|
// Required: This must be a valid port number, 0 < x < 65536.
|
||||||
ContainerPort int `yaml:"containerPort" json:"containerPort"`
|
ContainerPort int `yaml:"containerPort" json:"containerPort"`
|
||||||
|
@@ -95,9 +95,7 @@ func validatePorts(ports []Port) errs.ErrorList {
|
|||||||
if !util.IsValidPortNum(port.ContainerPort) {
|
if !util.IsValidPortNum(port.ContainerPort) {
|
||||||
allErrs = append(allErrs, errs.NewInvalid("Port.ContainerPort", port.ContainerPort))
|
allErrs = append(allErrs, errs.NewInvalid("Port.ContainerPort", port.ContainerPort))
|
||||||
}
|
}
|
||||||
if port.HostPort == 0 {
|
if port.HostPort != 0 && !util.IsValidPortNum(port.HostPort) {
|
||||||
port.HostPort = port.ContainerPort
|
|
||||||
} else if !util.IsValidPortNum(port.HostPort) {
|
|
||||||
allErrs = append(allErrs, errs.NewInvalid("Port.HostPort", port.HostPort))
|
allErrs = append(allErrs, errs.NewInvalid("Port.HostPort", port.HostPort))
|
||||||
}
|
}
|
||||||
if len(port.Protocol) == 0 {
|
if len(port.Protocol) == 0 {
|
||||||
@@ -160,6 +158,9 @@ func AccumulateUniquePorts(containers []Container, accumulator map[int]bool, ext
|
|||||||
ctr := &containers[ci]
|
ctr := &containers[ci]
|
||||||
for pi := range ctr.Ports {
|
for pi := range ctr.Ports {
|
||||||
port := extract(&ctr.Ports[pi])
|
port := extract(&ctr.Ports[pi])
|
||||||
|
if port == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
if accumulator[port] {
|
if accumulator[port] {
|
||||||
allErrs = append(allErrs, errs.NewDuplicate("Port", port))
|
allErrs = append(allErrs, errs.NewDuplicate("Port", port))
|
||||||
} else {
|
} else {
|
||||||
|
@@ -73,7 +73,7 @@ func TestValidatePorts(t *testing.T) {
|
|||||||
if errs := validatePorts(nonCanonicalCase); len(errs) != 0 {
|
if errs := validatePorts(nonCanonicalCase); len(errs) != 0 {
|
||||||
t.Errorf("expected success: %v", errs)
|
t.Errorf("expected success: %v", errs)
|
||||||
}
|
}
|
||||||
if nonCanonicalCase[0].HostPort != 80 || nonCanonicalCase[0].Protocol != "TCP" {
|
if nonCanonicalCase[0].HostPort != 0 || nonCanonicalCase[0].Protocol != "TCP" {
|
||||||
t.Errorf("expected default values: %+v", nonCanonicalCase[0])
|
t.Errorf("expected default values: %+v", nonCanonicalCase[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -227,8 +227,12 @@ func makePortsAndBindings(container *api.Container) (map[docker.Port]struct{}, m
|
|||||||
exposedPorts := map[docker.Port]struct{}{}
|
exposedPorts := map[docker.Port]struct{}{}
|
||||||
portBindings := map[docker.Port][]docker.PortBinding{}
|
portBindings := map[docker.Port][]docker.PortBinding{}
|
||||||
for _, port := range container.Ports {
|
for _, port := range container.Ports {
|
||||||
interiorPort := port.ContainerPort
|
|
||||||
exteriorPort := port.HostPort
|
exteriorPort := port.HostPort
|
||||||
|
if exteriorPort == 0 {
|
||||||
|
// No need to do port binding when HostPort is not specified
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
interiorPort := port.ContainerPort
|
||||||
// Some of this port stuff is under-documented voodoo.
|
// Some of this port stuff is under-documented voodoo.
|
||||||
// See http://stackoverflow.com/questions/20428302/binding-a-port-to-a-host-interface-using-the-rest-api
|
// See http://stackoverflow.com/questions/20428302/binding-a-port-to-a-host-interface-using-the-rest-api
|
||||||
var protocol string
|
var protocol string
|
||||||
|
@@ -71,6 +71,9 @@ func (s *RandomFitScheduler) Schedule(pod api.Pod, minionLister MinionLister) (s
|
|||||||
for _, scheduledPod := range machineToPods[machine] {
|
for _, scheduledPod := range machineToPods[machine] {
|
||||||
for _, container := range pod.DesiredState.Manifest.Containers {
|
for _, container := range pod.DesiredState.Manifest.Containers {
|
||||||
for _, port := range container.Ports {
|
for _, port := range container.Ports {
|
||||||
|
if port.HostPort == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
if s.containsPort(scheduledPod, port) {
|
if s.containsPort(scheduledPod, port) {
|
||||||
podFits = false
|
podFits = false
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user