-
Notifications
You must be signed in to change notification settings - Fork 5.4k
/
clientset.go
49 lines (42 loc) · 1.59 KB
/
clientset.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package apiclient
import (
"crypto/tls"
"time"
grpc_retry "github.com/grpc-ecosystem/go-grpc-middleware/retry"
log "github.com/sirupsen/logrus"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"github.com/argoproj/argo-cd/util"
argogrpc "github.com/argoproj/argo-cd/util/grpc"
)
// Clientset represets repository server api clients
type Clientset interface {
NewRepoServerClient() (util.Closer, RepoServerServiceClient, error)
}
type clientSet struct {
address string
timeoutSeconds int
}
func (c *clientSet) NewRepoServerClient() (util.Closer, RepoServerServiceClient, error) {
retryOpts := []grpc_retry.CallOption{
grpc_retry.WithMax(3),
grpc_retry.WithBackoff(grpc_retry.BackoffLinear(1000 * time.Millisecond)),
}
opts := []grpc.DialOption{
grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{InsecureSkipVerify: true})),
grpc.WithStreamInterceptor(grpc_retry.StreamClientInterceptor(retryOpts...)),
grpc.WithUnaryInterceptor(grpc_retry.UnaryClientInterceptor(retryOpts...))}
if c.timeoutSeconds > 0 {
opts = append(opts, grpc.WithUnaryInterceptor(argogrpc.WithTimeout(time.Duration(c.timeoutSeconds)*time.Second)))
}
conn, err := grpc.Dial(c.address, opts...)
if err != nil {
log.Errorf("Unable to connect to repository service with address %s", c.address)
return nil, nil, err
}
return conn, NewRepoServerServiceClient(conn), nil
}
// NewRepoServerClientset creates new instance of repo server Clientset
func NewRepoServerClientset(address string, timeoutSeconds int) Clientset {
return &clientSet{address: address, timeoutSeconds: timeoutSeconds}
}