From 45a1486b08a1f728a11800ddfead038c9c04e6a6 Mon Sep 17 00:00:00 2001 From: Monet Lee Date: Fri, 15 Nov 2024 11:39:13 +0800 Subject: [PATCH] fix: revert getConn. (#150) * build: rename k.go * fix: add error handle. * feat: implement kubernetes Discovery. * fix: revert getConn. --- discovery/kubernetes/kubernetes.go | 44 ++++++++++++++++-------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/discovery/kubernetes/kubernetes.go b/discovery/kubernetes/kubernetes.go index d3149a6..4b74ecb 100644 --- a/discovery/kubernetes/kubernetes.go +++ b/discovery/kubernetes/kubernetes.go @@ -90,31 +90,33 @@ func (k *KubernetesConnManager) initializeConnMap() error { // GetConns returns gRPC client connections for a given Kubernetes service name. func (k *KubernetesConnManager) GetConns(ctx context.Context, serviceName string, opts ...grpc.DialOption) ([]*grpc.ClientConn, error) { - k.mu.RLock() - defer k.mu.RUnlock() - if len(k.connMap) == 0 { - if err := k.initializeConnMap(); err != nil { - return nil, err - } - } - - return k.connMap[serviceName], nil + // k.mu.RLock() + // defer k.mu.RUnlock() + // if len(k.connMap) == 0 { + // if err := k.initializeConnMap(); err != nil { + // return nil, err + // } + // } + + // return k.connMap[serviceName], nil + return nil, nil } // GetConn returns a single gRPC client connection for a given Kubernetes service name. func (k *KubernetesConnManager) GetConn(ctx context.Context, serviceName string, opts ...grpc.DialOption) (*grpc.ClientConn, error) { - k.mu.RLock() - if len(k.connMap) == 0 { - k.mu.RUnlock() - if err := k.initializeConnMap(); err != nil { - return nil, err - } - k.mu.RLock() - } - - defer k.mu.RUnlock() - - return k.connMap[serviceName][0], nil + // k.mu.RLock() + // if len(k.connMap) == 0 { + // k.mu.RUnlock() + // if err := k.initializeConnMap(); err != nil { + // return nil, err + // } + // k.mu.RLock() + // } + + // defer k.mu.RUnlock() + + // return k.connMap[serviceName][0], nil + return grpc.DialContext(ctx, serviceName, append(k.dialOptions, grpc.WithTransportCredentials(insecure.NewCredentials()))...) } // GetSelfConnTarget returns the connection target for the current service.