From 65ab8356e9406035ed99d6047d42bfe44f576437 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20Serv=C3=A9n=20Mar=C3=ADn?= Date: Mon, 13 Jan 2020 13:53:36 +0100 Subject: [PATCH] main.go: controller generate gRPC endpoints MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit updates the controller to generate gRPC endpoints rather than HTTP endpoints, following https://github.com/thanos-io/thanos/pull/1970. Signed-off-by: Lucas Servén Marín --- main.go | 5 ++--- main_test.go | 32 ++++++++++++++++---------------- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/main.go b/main.go index b07250e..58c1d6a 100644 --- a/main.go +++ b/main.go @@ -503,15 +503,14 @@ func (c *controller) populate(hashrings []receive.HashringConfig, statefulsets m var endpoints []string for i := 0; i < int(*sts.Spec.Replicas); i++ { endpoints = append(endpoints, - fmt.Sprintf("%s://%s-%d.%s.%s.svc.%s:%d/%s", - c.options.scheme, + fmt.Sprintf("%s-%d.%s.%s.svc.%s:%d", sts.Name, i, sts.Spec.ServiceName, c.options.namespace, c.options.clusterDomain, c.options.port, - strings.TrimPrefix(c.options.path, "/")), + ), ) } hashrings[i].Endpoints = endpoints diff --git a/main_test.go b/main_test.go index 556ab1e..35c9a02 100644 --- a/main_test.go +++ b/main_test.go @@ -84,9 +84,9 @@ func TestController(t *testing.T) { Hashring: "hashring0", Tenants: []string{"foo", "bar"}, Endpoints: []string{ - "http://thanos-receive-hashring0-0.h0.namespace.svc.cluster.local:19291/api/v1/receive", - "http://thanos-receive-hashring0-1.h0.namespace.svc.cluster.local:19291/api/v1/receive", - "http://thanos-receive-hashring0-2.h0.namespace.svc.cluster.local:19291/api/v1/receive", + "thanos-receive-hashring0-0.h0.namespace.svc.cluster.local:19291", + "thanos-receive-hashring0-1.h0.namespace.svc.cluster.local:19291", + "thanos-receive-hashring0-2.h0.namespace.svc.cluster.local:19291", }, }}, }, @@ -128,9 +128,9 @@ func TestController(t *testing.T) { Hashring: "hashring0", Tenants: []string{"foo", "bar"}, Endpoints: []string{ - "http://hashring0-0.h0.namespace.svc.cluster.local:19291/api/v1/receive", - "http://hashring0-1.h0.namespace.svc.cluster.local:19291/api/v1/receive", - "http://hashring0-2.h0.namespace.svc.cluster.local:19291/api/v1/receive", + "hashring0-0.h0.namespace.svc.cluster.local:19291", + "hashring0-1.h0.namespace.svc.cluster.local:19291", + "hashring0-2.h0.namespace.svc.cluster.local:19291", }, }}, }, @@ -174,15 +174,15 @@ func TestController(t *testing.T) { Hashring: "hashring0", Tenants: []string{"foo", "bar"}, Endpoints: []string{ - "http://hashring0-0.h0.namespace.svc.cluster.local:19291/api/v1/receive", - "http://hashring0-1.h0.namespace.svc.cluster.local:19291/api/v1/receive", - "http://hashring0-2.h0.namespace.svc.cluster.local:19291/api/v1/receive", + "hashring0-0.h0.namespace.svc.cluster.local:19291", + "hashring0-1.h0.namespace.svc.cluster.local:19291", + "hashring0-2.h0.namespace.svc.cluster.local:19291", }, }, { Hashring: "hashring1", Endpoints: []string{ - "http://hashring1-0.h1.namespace.svc.cluster.local:19291/api/v1/receive", - "http://hashring1-1.h1.namespace.svc.cluster.local:19291/api/v1/receive", + "hashring1-0.h1.namespace.svc.cluster.local:19291", + "hashring1-1.h1.namespace.svc.cluster.local:19291", }, }}, }, @@ -200,7 +200,7 @@ func TestController(t *testing.T) { configMapName: "original", configMapGeneratedName: "generated", namespace: "namespace", - path: "/api/v1/receive", + path: "", port: 19291, scheme: "http", } @@ -234,9 +234,9 @@ func TestControllerConfigmapUpdate(t *testing.T) { Hashring: "hashring0", Tenants: []string{"foo", "bar"}, Endpoints: []string{ - "http://thanos-receive-hashring0-0.h0.namespace.svc.cluster.local:19291/api/v1/receive", - "http://thanos-receive-hashring0-1.h0.namespace.svc.cluster.local:19291/api/v1/receive", - "http://thanos-receive-hashring0-2.h0.namespace.svc.cluster.local:19291/api/v1/receive", + "thanos-receive-hashring0-0.h0.namespace.svc.cluster.local:19291", + "thanos-receive-hashring0-1.h0.namespace.svc.cluster.local:19291", + "thanos-receive-hashring0-2.h0.namespace.svc.cluster.local:19291", }, }} intendedLabels := map[string]string{ @@ -278,7 +278,7 @@ func TestControllerConfigmapUpdate(t *testing.T) { configMapName: "original", configMapGeneratedName: "generated", namespace: "namespace", - path: "/api/v1/receive", + path: "", port: 19291, scheme: "http", }