Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

main.go: controller generate gRPC endpoints #37

Merged
merged 1 commit into from
Jan 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ func main() {
ConfigMapName string
ConfigMapGeneratedName string
FileName string
Path string
Port int
Scheme string
InternalAddr string
Expand All @@ -75,8 +74,7 @@ func main() {
flag.StringVar(&config.ConfigMapName, "configmap-name", "", "The name of the original ConfigMap containing the hashring tenant configuration")
flag.StringVar(&config.ConfigMapGeneratedName, "configmap-generated-name", "", "The name of the generated and populated ConfigMap")
flag.StringVar(&config.FileName, "file-name", "", "The name of the configuration file in the ConfigMap")
flag.StringVar(&config.Path, "path", "/api/v1/receive", "The URL path on which receive components accept write requests")
flag.IntVar(&config.Port, "port", 19291, "The port on which receive components are listening for write requests")
flag.IntVar(&config.Port, "port", 10901, "The port on which receive components are listening for write requests")
flag.StringVar(&config.Scheme, "scheme", "http", "The URL scheme on which receive components accept write requests")
flag.StringVar(&config.InternalAddr, "internal-addr", ":8080", "The address on which internal server runs")
flag.Parse()
Expand Down Expand Up @@ -129,7 +127,6 @@ func main() {
configMapGeneratedName: config.ConfigMapGeneratedName,
fileName: config.FileName,
namespace: config.Namespace,
path: config.Path,
port: config.Port,
scheme: config.Scheme,
labelKey: labelKey,
Expand Down Expand Up @@ -296,7 +293,6 @@ type options struct {
configMapGeneratedName string
fileName string
namespace string
path string
port int
scheme string
labelKey string
Expand Down Expand Up @@ -503,15 +499,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
Expand Down
34 changes: 16 additions & 18 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:10901",
"thanos-receive-hashring0-1.h0.namespace.svc.cluster.local:10901",
"thanos-receive-hashring0-2.h0.namespace.svc.cluster.local:10901",
},
}},
},
Expand Down Expand Up @@ -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:10901",
"hashring0-1.h0.namespace.svc.cluster.local:10901",
"hashring0-2.h0.namespace.svc.cluster.local:10901",
},
}},
},
Expand Down Expand Up @@ -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:10901",
"hashring0-1.h0.namespace.svc.cluster.local:10901",
"hashring0-2.h0.namespace.svc.cluster.local:10901",
},
}, {
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:10901",
"hashring1-1.h1.namespace.svc.cluster.local:10901",
},
}},
},
Expand All @@ -200,8 +200,7 @@ func TestController(t *testing.T) {
configMapName: "original",
configMapGeneratedName: "generated",
namespace: "namespace",
path: "/api/v1/receive",
port: 19291,
port: 10901,
scheme: "http",
}
klient := fake.NewSimpleClientset()
Expand Down Expand Up @@ -234,9 +233,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:10901",
"thanos-receive-hashring0-1.h0.namespace.svc.cluster.local:10901",
"thanos-receive-hashring0-2.h0.namespace.svc.cluster.local:10901",
},
}}
intendedLabels := map[string]string{
Expand Down Expand Up @@ -278,8 +277,7 @@ func TestControllerConfigmapUpdate(t *testing.T) {
configMapName: "original",
configMapGeneratedName: "generated",
namespace: "namespace",
path: "/api/v1/receive",
port: 19291,
port: 10901,
scheme: "http",
}
klient := fake.NewSimpleClientset()
Expand Down