From c7462f74f4080e4fb01f32a5f747d3dc292a3745 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 --- go.mod | 1 + go.sum | 2 ++ pkg/rgrpc/todo/pool/selector.go | 9 ++++++++- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index c47eacfd0f..12eebbbc82 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 4b43a16a22..21f2b39f56 100644 --- a/go.sum +++ b/go.sum @@ -1566,6 +1566,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