From 001b07b2923a6149856970ef36286a891af1239d Mon Sep 17 00:00:00 2001 From: Daniel Smith Date: Thu, 26 Jun 2014 15:00:55 -0700 Subject: [PATCH] Use net.JoinHostPort --- pkg/kubelet/kubelet.go | 4 ++-- pkg/registry/endpoints.go | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/pkg/kubelet/kubelet.go b/pkg/kubelet/kubelet.go index 8209dc5600b..4b3a79560a7 100644 --- a/pkg/kubelet/kubelet.go +++ b/pkg/kubelet/kubelet.go @@ -21,6 +21,7 @@ import ( "fmt" "io/ioutil" "math/rand" + "net" "net/http" "os" "os/exec" @@ -128,8 +129,7 @@ func (kl *Kubelet) RunKubelet(config_path, manifest_url, etcd_servers, address s UpdateChannel: updateChannel, } s := &http.Server{ - // TODO: This is broken if address is an ipv6 address. - Addr: fmt.Sprintf("%s:%d", address, port), + Addr: net.JoinHostPort(address, strconv.FormatUint(uint64(port), 10)), Handler: &handler, ReadTimeout: 10 * time.Second, WriteTimeout: 10 * time.Second, diff --git a/pkg/registry/endpoints.go b/pkg/registry/endpoints.go index 3033aa8016f..ab00a911c58 100644 --- a/pkg/registry/endpoints.go +++ b/pkg/registry/endpoints.go @@ -17,7 +17,8 @@ limitations under the License. package registry import ( - "fmt" + "net" + "strconv" "github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/labels" @@ -52,7 +53,10 @@ func (e *EndpointController) SyncServiceEndpoints() error { endpoints := make([]string, len(pods)) for ix, pod := range pods { // TODO: Use port names in the service object, don't just use port #0 - endpoints[ix] = fmt.Sprintf("%s:%d", pod.CurrentState.Host, pod.DesiredState.Manifest.Containers[0].Ports[0].HostPort) + endpoints[ix] = net.JoinHostPort( + pod.CurrentState.Host, + strconv.Itoa(pod.DesiredState.Manifest.Containers[0].Ports[0].HostPort), + ) } err = e.serviceRegistry.UpdateEndpoints(api.Endpoints{ Name: service.ID,