mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-16 06:49:02 +08:00
refactor
This commit is contained in:
@@ -15,7 +15,7 @@ import (
|
||||
type DnsDiscoveryRegistry struct {
|
||||
opts []grpc.DialOption
|
||||
namespace string
|
||||
config *rest.Config
|
||||
clientset *kubernetes.Clientset
|
||||
}
|
||||
|
||||
func NewDnsDiscoveryRegistry(namespace string, opts []grpc.DialOption) (*DnsDiscoveryRegistry, error) {
|
||||
@@ -23,19 +23,19 @@ func NewDnsDiscoveryRegistry(namespace string, opts []grpc.DialOption) (*DnsDisc
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
clientset, err := kubernetes.NewForConfig(config)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &DnsDiscoveryRegistry{
|
||||
config: config,
|
||||
clientset: clientset,
|
||||
namespace: namespace,
|
||||
opts: opts,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (d DnsDiscoveryRegistry) GetConns(serviceName string, opts ...grpc.DialOption) ([]*grpc.ClientConn, error) {
|
||||
clientset, err := kubernetes.NewForConfig(d.config)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
endpoints, err := clientset.CoreV1().Endpoints(d.namespace).Get(context.TODO(), serviceName, metav1.GetOptions{})
|
||||
func (d DnsDiscoveryRegistry) GetConns(ctx context.Context, serviceName string, opts ...grpc.DialOption) ([]*grpc.ClientConn, error) {
|
||||
endpoints, err := d.clientset.CoreV1().Endpoints(d.namespace).Get(context.TODO(), serviceName, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -43,7 +43,7 @@ func (d DnsDiscoveryRegistry) GetConns(serviceName string, opts ...grpc.DialOpti
|
||||
for _, subset := range endpoints.Subsets {
|
||||
for _, address := range subset.Addresses {
|
||||
for _, port := range subset.Ports {
|
||||
conn, err := grpc.Dial(net.JoinHostPort(address.IP, string(port.Port)), append(d.opts, opts...)...)
|
||||
conn, err := grpc.DialContext(ctx, net.JoinHostPort(address.IP, string(port.Port)), append(d.opts, opts...)...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -54,8 +54,8 @@ func (d DnsDiscoveryRegistry) GetConns(serviceName string, opts ...grpc.DialOpti
|
||||
return conns, nil
|
||||
}
|
||||
|
||||
func (d DnsDiscoveryRegistry) GetConn(serviceName string, opts ...grpc.DialOption) (*grpc.ClientConn, error) {
|
||||
return grpc.Dial(fmt.Sprintf("%s.%s.svc.cluster.local", serviceName, d.namespace), append(d.opts, opts...)...)
|
||||
func (d DnsDiscoveryRegistry) GetConn(ctx context.Context, serviceName string, opts ...grpc.DialOption) (*grpc.ClientConn, error) {
|
||||
return grpc.DialContext(ctx, fmt.Sprintf("%s.%s.svc.cluster.local", serviceName, d.namespace), append(d.opts, opts...)...)
|
||||
}
|
||||
|
||||
func (d *DnsDiscoveryRegistry) AddOption(opts ...grpc.DialOption) {
|
||||
|
||||
Reference in New Issue
Block a user