forked from argoproj/argo-workflows
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cluster.go
70 lines (59 loc) · 1.85 KB
/
cluster.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package cluster
import (
"github.com/argoproj/argo-cd/util/db"
appv1 "github.com/argoproj/argo-cd/pkg/apis/application/v1alpha1"
"golang.org/x/net/context"
)
// Server provides a Cluster service
type Server struct {
db db.ArgoDB
}
// NewServer returns a new instance of the Cluster service
func NewServer(db db.ArgoDB) *Server {
return &Server{
db: db,
}
}
// List returns list of clusters
func (s *Server) List(ctx context.Context, q *ClusterQuery) (*appv1.ClusterList, error) {
clusterList, err := s.db.ListClusters(ctx)
if clusterList != nil {
for i, clust := range clusterList.Items {
clusterList.Items[i] = *redact(&clust)
}
}
return clusterList, err
}
// Create creates a cluster
func (s *Server) Create(ctx context.Context, c *appv1.Cluster) (*appv1.Cluster, error) {
clust, err := s.db.CreateCluster(ctx, c)
return redact(clust), err
}
// Get returns a cluster from a query
func (s *Server) Get(ctx context.Context, q *ClusterQuery) (*appv1.Cluster, error) {
clust, err := s.db.GetCluster(ctx, q.Server)
return redact(clust), err
}
// Update updates a cluster
func (s *Server) Update(ctx context.Context, c *appv1.Cluster) (*appv1.Cluster, error) {
clust, err := s.db.UpdateCluster(ctx, c)
return redact(clust), err
}
// UpdateREST updates a cluster (special handler intended to be used only by the gRPC gateway)
func (s *Server) UpdateREST(ctx context.Context, r *ClusterUpdateRequest) (*appv1.Cluster, error) {
return s.Update(ctx, r.Cluster)
}
// Delete deletes a cluster by name
func (s *Server) Delete(ctx context.Context, q *ClusterQuery) (*ClusterResponse, error) {
err := s.db.DeleteCluster(ctx, q.Server)
return &ClusterResponse{}, err
}
func redact(clust *appv1.Cluster) *appv1.Cluster {
if clust == nil {
return nil
}
clust.Config.Password = ""
clust.Config.BearerToken = ""
clust.Config.TLSClientConfig.KeyData = nil
return clust
}