Skip to content

Commit

Permalink
fix: revert getConn. (#150)
Browse files Browse the repository at this point in the history
* build: rename k.go

* fix: add error handle.

* feat: implement kubernetes Discovery.

* fix: revert getConn.
  • Loading branch information
mo3et authored Nov 15, 2024
1 parent 16e3539 commit 45a1486
Showing 1 changed file with 23 additions and 21 deletions.
44 changes: 23 additions & 21 deletions discovery/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 45a1486

Please sign in to comment.