From e24e2cc17d52bb797ccea29259ea90f90abdcb1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Fri, 28 Jun 2024 13:20:40 +0200 Subject: [PATCH] use kuberesolver for kubernetes service endpoints MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jörn Friedrich Dreyer --- changelog/unreleased/respect-service-transport.md | 2 +- go.mod | 1 + go.sum | 2 ++ pkg/rgrpc/todo/pool/selector.go | 9 ++++++++- 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/changelog/unreleased/respect-service-transport.md b/changelog/unreleased/respect-service-transport.md index 8e47d969ec..a651893fe0 100644 --- a/changelog/unreleased/respect-service-transport.md +++ b/changelog/unreleased/respect-service-transport.md @@ -1,5 +1,5 @@ Enhancement: Respect service transport -The service registry now takes into account the service transport when creating grpc clients. This allows using `dns` and `unix` as the protocol in addition to `tcp`. `dns` will turn the gRPC client into a [Thick Client](https://grpc.io/blog/grpc-load-balancing/#thick-client) that can look up multiple endpoints via DNS. Furthermore, we enabled round robin load balancing for the [default transparent retry configuration of gRPC](https://grpc.io/docs/guides/retry/#retry-configuration). +The service registry now takes into account the service transport when creating grpc clients. This allows using `dns`, `unix` and `kubernetes` as the protocol in addition to `tcp`. `dns` will turn the gRPC client into a [Thick Client](https://grpc.io/blog/grpc-load-balancing/#thick-client) that can look up multiple endpoints via DNS. `kubernetes` will use [github.com/sercand/kuberesolver](https://github.com/sercand/kuberesolver) to connect to the kubernetes API and pickh up service changes. Furthermore, we enabled round robin load balancing for the [default transparent retry configuration of gRPC](https://grpc.io/docs/guides/retry/#retry-configuration). https://github.com/cs3org/reva/pull/4744 diff --git a/go.mod b/go.mod index 0c72550a91..15b8391461 100644 --- a/go.mod +++ b/go.mod @@ -71,6 +71,7 @@ require ( github.com/rs/cors v1.10.1 github.com/rs/zerolog v1.32.0 github.com/segmentio/kafka-go v0.4.47 + github.com/sercand/kuberesolver/v5 v5.1.1 github.com/sethvargo/go-password v0.2.0 github.com/shamaton/msgpack/v2 v2.1.1 github.com/shirou/gopsutil v3.21.11+incompatible diff --git a/go.sum b/go.sum index beecd58061..9dc3d395b0 100644 --- a/go.sum +++ b/go.sum @@ -1568,6 +1568,8 @@ github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529 h1:nn5Wsu0esKSJiIVhscUt github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc= github.com/segmentio/kafka-go v0.4.47 h1:IqziR4pA3vrZq7YdRxaT3w1/5fvIH5qpCwstUanQQB0= github.com/segmentio/kafka-go v0.4.47/go.mod h1:HjF6XbOKh0Pjlkr5GVZxt6CsjjwnmhVOfURM5KMd8qg= +github.com/sercand/kuberesolver/v5 v5.1.1 h1:CYH+d67G0sGBj7q5wLK61yzqJJ8gLLC8aeprPTHb6yY= +github.com/sercand/kuberesolver/v5 v5.1.1/go.mod h1:Fs1KbKhVRnB2aDWN12NjKCB+RgYMWZJ294T3BtmVCpQ= github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM= github.com/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ= github.com/sergi/go-diff v1.2.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM= diff --git a/pkg/rgrpc/todo/pool/selector.go b/pkg/rgrpc/todo/pool/selector.go index 72995935bd..a0e347c633 100644 --- a/pkg/rgrpc/todo/pool/selector.go +++ b/pkg/rgrpc/todo/pool/selector.go @@ -44,9 +44,16 @@ import ( tx "github.com/cs3org/go-cs3apis/cs3/tx/v1beta1" "github.com/cs3org/reva/v2/pkg/registry" "github.com/pkg/errors" + "github.com/sercand/kuberesolver/v5" "google.golang.org/grpc" ) +func init() { + // grpc go resolver.Register must only be called during initialization time (i.e. in + // an init() function), and is not thread-safe. + kuberesolver.RegisterInCluster() +} + type Selectable[T any] interface { Next(opts ...Option) (T, error) } @@ -97,7 +104,7 @@ func (s *Selector[T]) Next(opts ...Option) (T, error) { target := s.id prefix := strings.SplitN(s.id, ":", 2)[0] switch prefix { - case "dns", "unix": + case "dns", "unix", "kubernetes": // use target as is default: // use service registry to look up address