mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-11 22:20:18 +00:00
Write BoundPods to etcd instead of ContainerManifestList
Rename ManifestFactory -> BoundPodFactory and change the general structure of the call to focus on BoundPod.
This commit is contained in:
committed by
Eric Paris
parent
892942af8f
commit
6ae611aedd
@@ -20,8 +20,8 @@ import (
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
)
|
||||
|
||||
// Allowed returns true if manifests is a collection of manifests
|
||||
// Allowed returns true if pods is a collection of bound pods
|
||||
// which can run without conflict on a single minion.
|
||||
func Allowed(manifests []api.ContainerManifest) bool {
|
||||
return !PortsConflict(manifests)
|
||||
func Allowed(pods []api.BoundPod) bool {
|
||||
return !PortsConflict(pods)
|
||||
}
|
||||
|
@@ -30,27 +30,27 @@ func containerWithHostPorts(ports ...int) api.Container {
|
||||
return c
|
||||
}
|
||||
|
||||
func manifestWithContainers(containers ...api.Container) api.ContainerManifest {
|
||||
m := api.ContainerManifest{}
|
||||
func podWithContainers(containers ...api.Container) api.BoundPod {
|
||||
m := api.BoundPod{}
|
||||
for _, c := range containers {
|
||||
m.Containers = append(m.Containers, c)
|
||||
m.Spec.Containers = append(m.Spec.Containers, c)
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
func TestAllowed(t *testing.T) {
|
||||
table := []struct {
|
||||
allowed bool
|
||||
manifests []api.ContainerManifest
|
||||
allowed bool
|
||||
pods []api.BoundPod
|
||||
}{
|
||||
{
|
||||
allowed: true,
|
||||
manifests: []api.ContainerManifest{
|
||||
manifestWithContainers(
|
||||
pods: []api.BoundPod{
|
||||
podWithContainers(
|
||||
containerWithHostPorts(1, 2, 3),
|
||||
containerWithHostPorts(4, 5, 6),
|
||||
),
|
||||
manifestWithContainers(
|
||||
podWithContainers(
|
||||
containerWithHostPorts(7, 8, 9),
|
||||
containerWithHostPorts(10, 11, 12),
|
||||
),
|
||||
@@ -58,12 +58,12 @@ func TestAllowed(t *testing.T) {
|
||||
},
|
||||
{
|
||||
allowed: true,
|
||||
manifests: []api.ContainerManifest{
|
||||
manifestWithContainers(
|
||||
pods: []api.BoundPod{
|
||||
podWithContainers(
|
||||
containerWithHostPorts(0, 0),
|
||||
containerWithHostPorts(0, 0),
|
||||
),
|
||||
manifestWithContainers(
|
||||
podWithContainers(
|
||||
containerWithHostPorts(0, 0),
|
||||
containerWithHostPorts(0, 0),
|
||||
),
|
||||
@@ -71,19 +71,19 @@ func TestAllowed(t *testing.T) {
|
||||
},
|
||||
{
|
||||
allowed: false,
|
||||
manifests: []api.ContainerManifest{
|
||||
manifestWithContainers(
|
||||
pods: []api.BoundPod{
|
||||
podWithContainers(
|
||||
containerWithHostPorts(3, 3),
|
||||
),
|
||||
},
|
||||
},
|
||||
{
|
||||
allowed: false,
|
||||
manifests: []api.ContainerManifest{
|
||||
manifestWithContainers(
|
||||
pods: []api.BoundPod{
|
||||
podWithContainers(
|
||||
containerWithHostPorts(6),
|
||||
),
|
||||
manifestWithContainers(
|
||||
podWithContainers(
|
||||
containerWithHostPorts(6),
|
||||
),
|
||||
},
|
||||
@@ -91,8 +91,8 @@ func TestAllowed(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, item := range table {
|
||||
if e, a := item.allowed, Allowed(item.manifests); e != a {
|
||||
t.Errorf("Expected %v, got %v: \n%v\v", e, a, item.manifests)
|
||||
if e, a := item.allowed, Allowed(item.pods); e != a {
|
||||
t.Errorf("Expected %v, got %v: \n%v\v", e, a, item.pods)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -22,10 +22,10 @@ import (
|
||||
|
||||
// PortsConflict returns true iff two containers attempt to expose
|
||||
// the same host port.
|
||||
func PortsConflict(manifests []api.ContainerManifest) bool {
|
||||
func PortsConflict(pods []api.BoundPod) bool {
|
||||
hostPorts := map[int]struct{}{}
|
||||
for _, manifest := range manifests {
|
||||
for _, container := range manifest.Containers {
|
||||
for _, pod := range pods {
|
||||
for _, container := range pod.Spec.Containers {
|
||||
for _, port := range container.Ports {
|
||||
if port.HostPort == 0 {
|
||||
continue
|
||||
|
Reference in New Issue
Block a user