-
Notifications
You must be signed in to change notification settings - Fork 35
/
client.go
51 lines (43 loc) · 1.81 KB
/
client.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
50
51
package cluster
import (
"context"
"strings"
"github.com/argoproj/argo-cd/v2/pkg/apiclient"
"github.com/argoproj/argo-cd/v2/pkg/apiclient/cluster"
"github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
"google.golang.org/grpc"
)
const (
errorClusterNotFound = "code = NotFound desc = cluster"
errorPermissionDenied = "code = PermissionDenied desc = permission denied"
)
// ServiceClient wraps the functions to connect to argocd repositories
type ServiceClient interface {
// Create creates a cluster
Create(ctx context.Context, in *cluster.ClusterCreateRequest, opts ...grpc.CallOption) (*v1alpha1.Cluster, error)
// Get returns a cluster by server address
Get(ctx context.Context, in *cluster.ClusterQuery, opts ...grpc.CallOption) (*v1alpha1.Cluster, error)
// Update updates a cluster
Update(ctx context.Context, in *cluster.ClusterUpdateRequest, opts ...grpc.CallOption) (*v1alpha1.Cluster, error)
// Delete deletes a cluster
Delete(ctx context.Context, in *cluster.ClusterQuery, opts ...grpc.CallOption) (*cluster.ClusterResponse, error)
}
// NewClusterServiceClient creates a new API client from a set of config options, or fails fatally if the new client creation fails.
func NewClusterServiceClient(clientOpts *apiclient.ClientOptions) cluster.ClusterServiceClient {
_, repoIf := apiclient.NewClientOrDie(clientOpts).NewClusterClientOrDie()
return repoIf
}
// IsErrorClusterNotFound helper function to test for errorClusterNotFound error.
func IsErrorClusterNotFound(err error) bool {
if err == nil {
return false
}
return strings.Contains(err.Error(), errorClusterNotFound)
}
// IsErrorPermissionDenied helper function to test for errorPermissionDenied error.
func IsErrorPermissionDenied(err error) bool {
if err == nil {
return false
}
return strings.Contains(err.Error(), errorPermissionDenied)
}