Merge pull request #5814 from vmarmol/net-host

Add HostNetworking container option to API.
This commit is contained in:
Abhi Shah
2015-03-24 15:55:27 -07:00
14 changed files with 191 additions and 0 deletions

View File

@@ -462,6 +462,7 @@ func init() {
}
out.DNSPolicy = DNSPolicy(in.DNSPolicy)
out.Version = "v1beta2"
out.HostNetwork = in.HostNetwork
return nil
},
func(in *ContainerManifest, out *newer.PodSpec, s conversion.Scope) error {
@@ -475,6 +476,7 @@ func init() {
return err
}
out.DNSPolicy = newer.DNSPolicy(in.DNSPolicy)
out.HostNetwork = in.HostNetwork
return nil
},

View File

@@ -71,11 +71,17 @@ func init() {
if obj.DNSPolicy == "" {
obj.DNSPolicy = DNSClusterFirst
}
if obj.HostNetwork {
defaultHostNetworkPorts(&obj.Containers)
}
},
func(obj *ContainerManifest) {
if obj.DNSPolicy == "" {
obj.DNSPolicy = DNSClusterFirst
}
if obj.HostNetwork {
defaultHostNetworkPorts(&obj.Containers)
}
},
func(obj *LivenessProbe) {
if obj.TimeoutSeconds == 0 {
@@ -104,3 +110,14 @@ func init() {
},
)
}
// With host networking default all container ports to host ports.
func defaultHostNetworkPorts(containers *[]Container) {
for i := range *containers {
for j := range (*containers)[i].Ports {
if (*containers)[i].Ports[j].HostPort == 0 {
(*containers)[i].Ports[j].HostPort = (*containers)[i].Ports[j].ContainerPort
}
}
}
}

View File

@@ -80,3 +80,28 @@ func TestSetDefaultNamespace(t *testing.T) {
t.Errorf("Expected phase %v, got %v", current.NamespaceActive, s2.Status.Phase)
}
}
func TestSetDefaultContainerManifestHostNetwork(t *testing.T) {
portNum := 8080
s := current.ContainerManifest{}
s.HostNetwork = true
s.Containers = []current.Container{
{
Ports: []current.ContainerPort{
{
ContainerPort: portNum,
},
},
},
}
obj2 := roundTrip(t, runtime.Object(&current.ContainerManifestList{
Items: []current.ContainerManifest{s},
}))
sList2 := obj2.(*current.ContainerManifestList)
s2 := sList2.Items[0]
hostPortNum := s2.Containers[0].Ports[0].HostPort
if hostPortNum != portNum {
t.Errorf("Expected container port to be defaulted, was made %d instead of %d", hostPortNum, portNum)
}
}

View File

@@ -143,6 +143,7 @@ type ContainerPort struct {
// in a pod must have a unique name.
Name string `json:"name,omitempty" description:"name for the port that can be referred to by services; must be a DNS_LABEL and unique without the pod"`
// Optional: If specified, this must be a valid port number, 0 < x < 65536.
// If HostNetwork is specified, this must match ContainerPort.
HostPort int `json:"hostPort,omitempty" description:"number of port to expose on the host; most containers do not need this"`
// Required: This must be a valid port number, 0 < x < 65536.
ContainerPort int `json:"containerPort" description:"number of port to expose on the pod's IP address"`
@@ -1133,6 +1134,10 @@ type ContainerManifest struct {
RestartPolicy RestartPolicy `json:"restartPolicy,omitempty" description:"restart policy for all containers within the pod; one of RestartPolicyAlways, RestartPolicyOnFailure, RestartPolicyNever"`
// Optional: Set DNS policy. Defaults to "ClusterFirst"
DNSPolicy DNSPolicy `json:"dnsPolicy,omitempty" description:"DNS policy for containers within the pod; one of 'ClusterFirst' or 'Default'"`
// Uses the host's network namespace. If this option is set, the ports that will be
// used must be specified.
// Optional: Default to false.
HostNetwork bool `json:"hostNetwork,omitempty" description:"host networking requested for this pod"`
}
// ContainerManifestList is used to communicate container manifests to kubelet.
@@ -1173,6 +1178,10 @@ type PodSpec struct {
// the the scheduler simply schedules this pod onto that host, assuming that it fits
// resource requirements.
Host string `json:"host,omitempty" description:"host requested for this pod"`
// Uses the host's network namespace. If this option is set, the ports that will be
// used must be specified.
// Optional: Default to false.
HostNetwork bool `json:"hostNetwork,omitempty" description:"host networking requested for this pod"`
}
// List holds a list of objects, which may not be known by the server.