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