From 87caf458df5b98d36c35d713fae0be56e068f3d2 Mon Sep 17 00:00:00 2001 From: Emile Vauge Date: Tue, 26 Apr 2016 22:26:25 +0200 Subject: [PATCH] Fix Kubernetes schema Signed-off-by: Emile Vauge --- examples/k8s.ingress.yaml | 2 +- provider/k8s/client.go | 9 --------- provider/kubernetes.go | 6 ++++-- provider/kubernetes_test.go | 18 +++++++++--------- 4 files changed, 14 insertions(+), 21 deletions(-) diff --git a/examples/k8s.ingress.yaml b/examples/k8s.ingress.yaml index 5b6c4c0d0..aac7798e4 100644 --- a/examples/k8s.ingress.yaml +++ b/examples/k8s.ingress.yaml @@ -12,7 +12,7 @@ spec: nodePort: 30283 targetPort: 80 protocol: TCP - name: http + name: https selector: app: whoami --- diff --git a/provider/k8s/client.go b/provider/k8s/client.go index c576f9c17..b03bb0e7d 100644 --- a/provider/k8s/client.go +++ b/provider/k8s/client.go @@ -235,15 +235,6 @@ func (c *clientImpl) watch(url string, stopCh <-chan bool) (chan interface{}, ch url = url + "?watch&resourceVersion=" + resourceVersion // Make request to Kubernetes API request := c.request(url) - // request.Transport.Dial = func(network, addr string) (net.Conn, error) { - // conn, err := net.Dial(network, addr) - // if err != nil { - // return nil, err - // } - // // No timeout for long-polling request - // conn.SetDeadline(time.Now()) - // return conn, nil - // } req, err := request.MakeRequest() if err != nil { return watchCh, errCh, fmt.Errorf("failed to make watch request: GET %q : %v", url, err) diff --git a/provider/kubernetes.go b/provider/kubernetes.go index 3fc484901..dc7b395ff 100644 --- a/provider/kubernetes.go +++ b/provider/kubernetes.go @@ -170,10 +170,12 @@ func (provider *Kubernetes) loadIngresses(k8sClient k8s.Client) (*types.Configur log.Errorf("Error retrieving services %s", pa.Backend.ServiceName) } for _, service := range services { - var protocol string + protocol := "http" for _, port := range service.Spec.Ports { if port.Port == pa.Backend.ServicePort.IntValue() { - protocol = port.Name + if port.Port == 443 { + protocol = "https" + } templateObjects.Backends[r.Host+pa.Path].Servers[string(service.UID)] = types.Server{ URL: protocol + "://" + service.Spec.ClusterIP + ":" + pa.Backend.ServicePort.String(), Weight: 1, diff --git a/provider/kubernetes_test.go b/provider/kubernetes_test.go index 04d9b00b5..13daf6e58 100644 --- a/provider/kubernetes_test.go +++ b/provider/kubernetes_test.go @@ -1,6 +1,7 @@ package provider import ( + "encoding/json" "github.com/containous/traefik/provider/k8s" "github.com/containous/traefik/types" "reflect" @@ -35,7 +36,7 @@ func TestLoadIngresses(t *testing.T) { { Backend: k8s.IngressBackend{ ServiceName: "service3", - ServicePort: k8s.FromInt(803), + ServicePort: k8s.FromInt(443), }, }, { @@ -76,7 +77,6 @@ func TestLoadIngresses(t *testing.T) { ClusterIP: "10.0.0.2", Ports: []k8s.ServicePort{ { - Name: "http", Port: 802, }, }, @@ -92,7 +92,7 @@ func TestLoadIngresses(t *testing.T) { Ports: []k8s.ServicePort{ { Name: "http", - Port: 803, + Port: 443, }, }, }, @@ -129,7 +129,7 @@ func TestLoadIngresses(t *testing.T) { Weight: 1, }, "3": { - URL: "http://10.0.0.3:803", + URL: "https://10.0.0.3:443", Weight: 1, }, }, @@ -159,11 +159,11 @@ func TestLoadIngresses(t *testing.T) { }, }, } - if !reflect.DeepEqual(actual.Backends, expected.Backends) { - t.Fatalf("expected %+v, got %+v", expected.Backends, actual.Backends) - } - if !reflect.DeepEqual(actual.Frontends, expected.Frontends) { - t.Fatalf("expected %+v, got %+v", expected.Frontends, actual.Frontends) + actualJSON, _ := json.Marshal(actual) + expectedJSON, _ := json.Marshal(expected) + + if !reflect.DeepEqual(actual, expected) { + t.Fatalf("expected %+v, got %+v", string(expectedJSON), string(actualJSON)) } }