Allow same-hostport-different-protocol
This commit is contained in:
@@ -673,22 +673,23 @@ func validateProbe(probe *api.Probe) errs.ValidationErrorList {
|
||||
return allErrs
|
||||
}
|
||||
|
||||
// AccumulateUniquePorts runs an extraction function on each Port of each Container,
|
||||
// accumulateUniquePorts runs an extraction function on each Port of each Container,
|
||||
// accumulating the results and returning an error if any ports conflict.
|
||||
func AccumulateUniquePorts(containers []api.Container, accumulator map[int]bool, extract func(*api.ContainerPort) int) errs.ValidationErrorList {
|
||||
func accumulateUniqueHostPorts(containers []api.Container, accumulator map[string]bool) errs.ValidationErrorList {
|
||||
allErrs := errs.ValidationErrorList{}
|
||||
|
||||
for ci, ctr := range containers {
|
||||
cErrs := errs.ValidationErrorList{}
|
||||
for pi := range ctr.Ports {
|
||||
port := extract(&ctr.Ports[pi])
|
||||
port := ctr.Ports[pi].HostPort
|
||||
if port == 0 {
|
||||
continue
|
||||
}
|
||||
if accumulator[port] {
|
||||
cErrs = append(cErrs, errs.NewFieldDuplicate("port", port))
|
||||
str := fmt.Sprintf("%d/%s", port, ctr.Ports[pi].Protocol)
|
||||
if accumulator[str] {
|
||||
cErrs = append(cErrs, errs.NewFieldDuplicate("port", str))
|
||||
} else {
|
||||
accumulator[port] = true
|
||||
accumulator[str] = true
|
||||
}
|
||||
}
|
||||
allErrs = append(allErrs, cErrs.PrefixIndex(ci)...)
|
||||
@@ -696,11 +697,11 @@ func AccumulateUniquePorts(containers []api.Container, accumulator map[int]bool,
|
||||
return allErrs
|
||||
}
|
||||
|
||||
// checkHostPortConflicts checks for colliding Port.HostPort values across
|
||||
// ValidateHostPorts checks for colliding Port.HostPort values across
|
||||
// a slice of containers.
|
||||
func checkHostPortConflicts(containers []api.Container) errs.ValidationErrorList {
|
||||
allPorts := map[int]bool{}
|
||||
return AccumulateUniquePorts(containers, allPorts, func(p *api.ContainerPort) int { return p.HostPort })
|
||||
func ValidateHostPorts(containers []api.Container) errs.ValidationErrorList {
|
||||
allPorts := map[string]bool{}
|
||||
return accumulateUniqueHostPorts(containers, allPorts)
|
||||
}
|
||||
|
||||
func validateExecAction(exec *api.ExecAction) errs.ValidationErrorList {
|
||||
@@ -817,11 +818,7 @@ func validateContainers(containers []api.Container, volumes util.StringSet) errs
|
||||
allErrs = append(allErrs, cErrs.PrefixIndex(i)...)
|
||||
}
|
||||
// Check for colliding ports across all containers.
|
||||
// TODO(thockin): This really is dependent on the network config of the host (IP per pod?)
|
||||
// and the config of the new manifest. But we have not specced that out yet, so we'll just
|
||||
// make some assumptions for now. As of now, pods share a network namespace, which means that
|
||||
// every Port.HostPort across the whole pod must be unique.
|
||||
allErrs = append(allErrs, checkHostPortConflicts(containers)...)
|
||||
allErrs = append(allErrs, ValidateHostPorts(containers)...)
|
||||
|
||||
return allErrs
|
||||
}
|
||||
|
Reference in New Issue
Block a user