From 4b22f7a46266d3a93f50ea085bb96b12b9562bbc Mon Sep 17 00:00:00 2001 From: Brendan Burns Date: Tue, 8 Jul 2014 22:44:15 -0700 Subject: [PATCH] Add support for host ip binding to the API (and kubelet) --- pkg/api/types.go | 4 +++- pkg/kubelet/kubelet.go | 1 + pkg/kubelet/kubelet_test.go | 13 +++++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/pkg/api/types.go b/pkg/api/types.go index 1fa2a5c1448..9570bddc716 100644 --- a/pkg/api/types.go +++ b/pkg/api/types.go @@ -74,6 +74,8 @@ type Port struct { ContainerPort int `yaml:"containerPort" json:"containerPort"` // Optional: Defaults to "TCP". Protocol string `yaml:"protocol,omitempty" json:"protocol,omitempty"` + // Optional: What host IP to bind the external port to. + HostIP string `yaml:"hostIP,omitempty" json:"hostIP,omitempty"` } // VolumeMount describes a mounting of a Volume within a container @@ -86,7 +88,7 @@ type VolumeMount struct { // Exactly one of the following must be set. If both are set, prefer MountPath. // DEPRECATED: Path will be removed in a future version of the API. MountPath string `yaml:"mountPath,omitempty" json:"mountPath,omitempty"` - Path string `yaml:"path,omitempty" json:"path,omitempty"` + Path string `yaml:"path,omitempty" json:"path,omitempty"` // One of: "LOCAL" (local volume) or "HOST" (external mount from the host). Default: LOCAL. MountType string `yaml:"mountType,omitempty" json:"mountType,omitempty"` } diff --git a/pkg/kubelet/kubelet.go b/pkg/kubelet/kubelet.go index 296734315ef..79b5fa48db5 100644 --- a/pkg/kubelet/kubelet.go +++ b/pkg/kubelet/kubelet.go @@ -332,6 +332,7 @@ func makePortsAndBindings(container *api.Container) (map[docker.Port]struct{}, m portBindings[dockerPort] = []docker.PortBinding{ { HostPort: strconv.Itoa(exteriorPort), + HostIp: port.HostIP, }, } } diff --git a/pkg/kubelet/kubelet_test.go b/pkg/kubelet/kubelet_test.go index 5484e2265e1..fe46c73961b 100644 --- a/pkg/kubelet/kubelet_test.go +++ b/pkg/kubelet/kubelet_test.go @@ -529,6 +529,7 @@ func TestMakePortsAndBindings(t *testing.T) { { ContainerPort: 80, HostPort: 8080, + HostIP: "127.0.0.1", }, { ContainerPort: 443, @@ -558,18 +559,30 @@ func TestMakePortsAndBindings(t *testing.T) { if !reflect.DeepEqual(docker.Port("80/tcp"), key) { t.Errorf("Unexpected docker port: %#v", key) } + if value[0].HostIp != "127.0.0.1" { + t.Errorf("Unexpected host IP: %s", value[0].HostIp) + } case "443": if !reflect.DeepEqual(docker.Port("443/tcp"), key) { t.Errorf("Unexpected docker port: %#v", key) } + if value[0].HostIp != "" { + t.Errorf("Unexpected host IP: %s", value[0].HostIp) + } case "444": if !reflect.DeepEqual(docker.Port("444/udp"), key) { t.Errorf("Unexpected docker port: %#v", key) } + if value[0].HostIp != "" { + t.Errorf("Unexpected host IP: %s", value[0].HostIp) + } case "445": if !reflect.DeepEqual(docker.Port("445/tcp"), key) { t.Errorf("Unexpected docker port: %#v", key) } + if value[0].HostIp != "" { + t.Errorf("Unexpected host IP: %s", value[0].HostIp) + } } } }