Add argocd CLI. Add cluster server endpoint. Fix protobuf generation

This commit is contained in:
Jesse Suen 2018-02-15 17:13:47 -08:00
parent 80ad02d02c
commit f6904245fe
No known key found for this signature in database
GPG key ID: 95AE9BEA7206422B
20 changed files with 754 additions and 63 deletions

View file

@ -39,7 +39,7 @@ IMAGE_PREFIX=${IMAGE_NAMESPACE}/
endif
.PHONY: all
all: argocd
all: argocd server
.PHONY: protogen
protogen:
@ -49,10 +49,14 @@ protogen:
argocd: protogen
CGO_ENABLED=0 go build -v -i -ldflags '${LDFLAGS} -extldflags "-static"' -o ${DIST_DIR}/argocd ./cmd/argocd
.PHONY: argocd-image
argocd-image:
docker build -t $(IMAGE_PREFIX)argocd:$(IMAGE_TAG) -f Dockerfile-argocd .
@if [ "$(DOCKER_PUSH)" = "true" ] ; then docker push $(IMAGE_PREFIX)workflow-controller:$(IMAGE_TAG) ; fi
.PHONY: server
server: protogen
CGO_ENABLED=0 go build -v -i -ldflags '${LDFLAGS}' -o ${DIST_DIR}/argocd-server ./cmd/argocd-server
.PHONY: server-image
server-image:
docker build -t $(IMAGE_PREFIX)argocd-server:$(IMAGE_TAG) -f Dockerfile-server .
@if [ "$(DOCKER_PUSH)" = "true" ] ; then docker push $(IMAGE_PREFIX)argocd-server:$(IMAGE_TAG) ; fi
.PHONY: lint
lint:

View file

@ -0,0 +1,9 @@
package commands
const (
// cliName is the name of the CLI
cliName = "argocd-server"
// defaultArgoCDConfigMap is the default name of the argocd configmap
defaultArgoCDConfigMap = "argocd-configmap"
)

View file

@ -1,8 +1,8 @@
package commands
import (
"github.com/argoproj/argo-cd/argocd/server"
"github.com/argoproj/argo-cd/errors"
"github.com/argoproj/argo-cd/server"
"github.com/argoproj/argo-cd/util/cmd"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"

11
cmd/argocd-server/main.go Normal file
View file

@ -0,0 +1,11 @@
package main
import (
commands "github.com/argoproj/argo-cd/cmd/argocd-server/commands"
"github.com/argoproj/argo-cd/errors"
)
func main() {
err := commands.NewCommand().Execute()
errors.CheckError(err)
}

View file

@ -0,0 +1,59 @@
package commands
import (
"fmt"
"github.com/spf13/cobra"
)
// NewClusterCommand returns a new instance of an `argocd cluster` command
func NewClusterCommand() *cobra.Command {
var command = &cobra.Command{
Use: "cluster",
Short: fmt.Sprintf("%s cluster (add|list|rm) CLUSTERNAME", cliName),
Run: func(c *cobra.Command, args []string) {
c.HelpFunc()(c, args)
},
}
command.AddCommand(NewClusterAddCommand())
command.AddCommand(NewClusterListCommand())
command.AddCommand(NewClusterRemoveCommand())
return command
}
// NewClusterAddCommand returns a new instance of an `argocd cluster add` command
func NewClusterAddCommand() *cobra.Command {
var command = &cobra.Command{
Use: "add",
Short: fmt.Sprintf("%s cluster add CLUSTERNAME", cliName),
Run: func(c *cobra.Command, args []string) {
c.HelpFunc()(c, args)
},
}
return command
}
// NewClusterListCommand returns a new instance of an `argocd cluster list` command
func NewClusterListCommand() *cobra.Command {
var command = &cobra.Command{
Use: "rm",
Short: fmt.Sprintf("%s cluster rm CLUSTERNAME", cliName),
Run: func(c *cobra.Command, args []string) {
c.HelpFunc()(c, args)
},
}
return command
}
// NewClusterRemoveCommand returns a new instance of an `argocd cluster rm` command
func NewClusterRemoveCommand() *cobra.Command {
var command = &cobra.Command{
Use: "list",
Short: fmt.Sprintf("%s cluster list", cliName),
Run: func(c *cobra.Command, args []string) {
c.HelpFunc()(c, args)
},
}
return command
}

View file

@ -1,11 +1,7 @@
package commands
const (
// cliName is the name of the CLI
cliName = "argocd"
// defaultArgoCDConfigMap is the default name of the argocd configmap
defaultArgoCDConfigMap = "argocd-configmap"
)
var (

View file

@ -0,0 +1,25 @@
package commands
import (
"github.com/argoproj/argo-cd/util/cmd"
"github.com/spf13/cobra"
)
// NewCommand returns a new instance of an argocd command
func NewCommand() *cobra.Command {
var (
logLevel string
)
var command = &cobra.Command{
Use: cliName,
Short: "argocd controls a ArgoCD server",
Run: func(c *cobra.Command, args []string) {
c.HelpFunc()(c, args)
},
}
command.Flags().StringVar(&logLevel, "loglevel", "info", "Set the logging level. One of: debug|info|warn|error")
command.AddCommand(cmd.NewVersionCmd(cliName))
command.AddCommand(NewClusterCommand())
return command
}

View file

@ -9,17 +9,20 @@ PROJECT_ROOT=$(cd $(dirname "$0")/.. ; pwd)
PROTO_FILES=$(find ${PROJECT_ROOT} -name "*.proto" -not -path "${PROJECT_ROOT}/vendor/*")
for i in "${PROTO_FILES}"; do
for i in ${PROTO_FILES}; do
echo $i
dir=$(dirname $i)
#pkgname=$(echo "${dirname}" | sed s%${PROJECT_ROOT}/%%g)
protofile=$(basename $i)
# Both /root/go and ${PROJECT_ROOT} are added to the protoc includes, in order to support
# the need for running make inside docker and on desktop, respectively.
# the requirement of running make inside docker and on desktop, respectively.
#cd ${dir}
protoc \
-I ${dir} \
-I /usr/local/include \
-I /root/go/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis \
-I ${PROJECT_ROOT}/vendor/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis \
--go_out=plugins=grpc:${dir} \
--grpc-gateway_out=logtostderr=true:${dir} \
-I${PROJECT_ROOT} \
-I/usr/local/include \
-I/root/go/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis \
-I${PROJECT_ROOT}/vendor/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis \
--go_out=plugins=grpc:$GOPATH/src \
--grpc-gateway_out=logtostderr=true:$GOPATH/src \
$i
done

View file

@ -0,0 +1,258 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// source: server/cluster/cluster.proto
/*
Package cluster is a generated protocol buffer package.
Cluster Service
Cluster Service API allows
It is generated from these files:
server/cluster/cluster.proto
It has these top-level messages:
ClusterMessage
ClusterListMessage
ClusterQuery
*/
package cluster
import proto "github.com/golang/protobuf/proto"
import fmt "fmt"
import math "math"
import _ "google.golang.org/genproto/googleapis/api/annotations"
import core "github.com/argoproj/argo-cd/server/core"
import (
context "golang.org/x/net/context"
grpc "google.golang.org/grpc"
)
// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
var _ = fmt.Errorf
var _ = math.Inf
// This is a compile-time assertion to ensure that this generated file
// is compatible with the proto package it is being compiled against.
// A compilation error at this line likely means your copy of the
// proto package needs to be updated.
const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package
// ClusterMessage holds Kuberentes cluster information
type ClusterMessage struct {
Name string `protobuf:"bytes,1,opt,name=Name" json:"Name,omitempty"`
Server string `protobuf:"bytes,2,opt,name=Server" json:"Server,omitempty"`
Certificate string `protobuf:"bytes,3,opt,name=Certificate" json:"Certificate,omitempty"`
Token string `protobuf:"bytes,4,opt,name=Token" json:"Token,omitempty"`
Description string `protobuf:"bytes,5,opt,name=Description" json:"Description,omitempty"`
}
func (m *ClusterMessage) Reset() { *m = ClusterMessage{} }
func (m *ClusterMessage) String() string { return proto.CompactTextString(m) }
func (*ClusterMessage) ProtoMessage() {}
func (*ClusterMessage) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} }
func (m *ClusterMessage) GetName() string {
if m != nil {
return m.Name
}
return ""
}
func (m *ClusterMessage) GetServer() string {
if m != nil {
return m.Server
}
return ""
}
func (m *ClusterMessage) GetCertificate() string {
if m != nil {
return m.Certificate
}
return ""
}
func (m *ClusterMessage) GetToken() string {
if m != nil {
return m.Token
}
return ""
}
func (m *ClusterMessage) GetDescription() string {
if m != nil {
return m.Description
}
return ""
}
// ClusterListMessage holds multiple clusters
type ClusterListMessage struct {
Items []*ClusterMessage `protobuf:"bytes,1,rep,name=items" json:"items,omitempty"`
}
func (m *ClusterListMessage) Reset() { *m = ClusterListMessage{} }
func (m *ClusterListMessage) String() string { return proto.CompactTextString(m) }
func (*ClusterListMessage) ProtoMessage() {}
func (*ClusterListMessage) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{1} }
func (m *ClusterListMessage) GetItems() []*ClusterMessage {
if m != nil {
return m.Items
}
return nil
}
type ClusterQuery struct {
}
func (m *ClusterQuery) Reset() { *m = ClusterQuery{} }
func (m *ClusterQuery) String() string { return proto.CompactTextString(m) }
func (*ClusterQuery) ProtoMessage() {}
func (*ClusterQuery) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{2} }
func init() {
proto.RegisterType((*ClusterMessage)(nil), "cluster.ClusterMessage")
proto.RegisterType((*ClusterListMessage)(nil), "cluster.ClusterListMessage")
proto.RegisterType((*ClusterQuery)(nil), "cluster.ClusterQuery")
}
// Reference imports to suppress errors if they are not otherwise used.
var _ context.Context
var _ grpc.ClientConn
// This is a compile-time assertion to ensure that this generated file
// is compatible with the grpc package it is being compiled against.
const _ = grpc.SupportPackageIsVersion4
// Client API for ClusterService service
type ClusterServiceClient interface {
// GetClusters returns list of clusters
GetClusters(ctx context.Context, in *ClusterQuery, opts ...grpc.CallOption) (*ClusterListMessage, error)
// GetCluster returns a cluster by name
GetCluster(ctx context.Context, in *core.NameMessage, opts ...grpc.CallOption) (*ClusterMessage, error)
}
type clusterServiceClient struct {
cc *grpc.ClientConn
}
func NewClusterServiceClient(cc *grpc.ClientConn) ClusterServiceClient {
return &clusterServiceClient{cc}
}
func (c *clusterServiceClient) GetClusters(ctx context.Context, in *ClusterQuery, opts ...grpc.CallOption) (*ClusterListMessage, error) {
out := new(ClusterListMessage)
err := grpc.Invoke(ctx, "/cluster.ClusterService/GetClusters", in, out, c.cc, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *clusterServiceClient) GetCluster(ctx context.Context, in *core.NameMessage, opts ...grpc.CallOption) (*ClusterMessage, error) {
out := new(ClusterMessage)
err := grpc.Invoke(ctx, "/cluster.ClusterService/GetCluster", in, out, c.cc, opts...)
if err != nil {
return nil, err
}
return out, nil
}
// Server API for ClusterService service
type ClusterServiceServer interface {
// GetClusters returns list of clusters
GetClusters(context.Context, *ClusterQuery) (*ClusterListMessage, error)
// GetCluster returns a cluster by name
GetCluster(context.Context, *core.NameMessage) (*ClusterMessage, error)
}
func RegisterClusterServiceServer(s *grpc.Server, srv ClusterServiceServer) {
s.RegisterService(&_ClusterService_serviceDesc, srv)
}
func _ClusterService_GetClusters_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(ClusterQuery)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(ClusterServiceServer).GetClusters(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/cluster.ClusterService/GetClusters",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(ClusterServiceServer).GetClusters(ctx, req.(*ClusterQuery))
}
return interceptor(ctx, in, info, handler)
}
func _ClusterService_GetCluster_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(core.NameMessage)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(ClusterServiceServer).GetCluster(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/cluster.ClusterService/GetCluster",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(ClusterServiceServer).GetCluster(ctx, req.(*core.NameMessage))
}
return interceptor(ctx, in, info, handler)
}
var _ClusterService_serviceDesc = grpc.ServiceDesc{
ServiceName: "cluster.ClusterService",
HandlerType: (*ClusterServiceServer)(nil),
Methods: []grpc.MethodDesc{
{
MethodName: "GetClusters",
Handler: _ClusterService_GetClusters_Handler,
},
{
MethodName: "GetCluster",
Handler: _ClusterService_GetCluster_Handler,
},
},
Streams: []grpc.StreamDesc{},
Metadata: "server/cluster/cluster.proto",
}
func init() { proto.RegisterFile("server/cluster/cluster.proto", fileDescriptor0) }
var fileDescriptor0 = []byte{
// 343 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x52, 0xcd, 0x4a, 0xc3, 0x40,
0x10, 0x26, 0xfd, 0x13, 0xb7, 0x52, 0x74, 0xd0, 0x76, 0x8d, 0x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, 0xb9, 0x5b, 0xef, 0xb7, 0xfc, 0x22, 0x8c, 0x65, 0x0f, 0xc3, 0xec, 0x96, 0xd7,
0x60, 0x1b, 0x79, 0xe3, 0x6a, 0x8a, 0xfa, 0xb5, 0xff, 0x3d, 0x77, 0x9b, 0x1a, 0x90, 0x21, 0xc2,
0x3d, 0xab, 0x9f, 0xa1, 0xcd, 0x41, 0x03, 0x3b, 0xab, 0x8a, 0x44, 0x74, 0xf7, 0x56, 0xe1, 0x85,
0xa1, 0x3c, 0xfe, 0xf1, 0xf3, 0xfb, 0x59, 0x02, 0xd8, 0xa4, 0xec, 0x67, 0x47, 0xc5, 0x86, 0x0c,
0xdc, 0x32, 0x36, 0x17, 0x87, 0x2d, 0x9f, 0x82, 0x4f, 0x03, 0xcd, 0xa9, 0xee, 0x7f, 0x06, 0xbc,
0x7d, 0xd2, 0xdc, 0x85, 0xd6, 0xaa, 0x66, 0xf0, 0x96, 0xf2, 0xdf, 0x4f, 0x0e, 0xef, 0x0e, 0x22,
0x69, 0x9f, 0xa6, 0x23, 0x3f, 0x54, 0x93, 0x40, 0xe8, 0x48, 0x25, 0x5a, 0x3d, 0xd3, 0xa1, 0x17,
0x3e, 0x04, 0xcb, 0x6f, 0x66, 0x54, 0xa3, 0x6d, 0x1f, 0xff, 0x05, 0x00, 0x00, 0xff, 0xff, 0x47,
0xcc, 0x8b, 0x56, 0x4c, 0x02, 0x00, 0x00,
}

View file

@ -0,0 +1,177 @@
// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT.
// source: server/cluster/cluster.proto
/*
Package cluster is a reverse proxy.
It translates gRPC into RESTful JSON APIs.
*/
package cluster
import (
"io"
"net/http"
"github.com/argoproj/argo-cd/server/core"
"github.com/golang/protobuf/proto"
"github.com/grpc-ecosystem/grpc-gateway/runtime"
"github.com/grpc-ecosystem/grpc-gateway/utilities"
"golang.org/x/net/context"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/grpclog"
"google.golang.org/grpc/status"
)
var _ codes.Code
var _ io.Reader
var _ status.Status
var _ = runtime.String
var _ = utilities.NewDoubleArray
func request_ClusterService_GetClusters_0(ctx context.Context, marshaler runtime.Marshaler, client ClusterServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq ClusterQuery
var metadata runtime.ServerMetadata
msg, err := client.GetClusters(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
return msg, metadata, err
}
func request_ClusterService_GetCluster_0(ctx context.Context, marshaler runtime.Marshaler, client ClusterServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq core.NameMessage
var metadata runtime.ServerMetadata
var (
val string
ok bool
err error
_ = err
)
val, ok = pathParams["Name"]
if !ok {
return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "Name")
}
protoReq.Name, err = runtime.String(val)
if err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "Name", err)
}
msg, err := client.GetCluster(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
return msg, metadata, err
}
// RegisterClusterServiceHandlerFromEndpoint is same as RegisterClusterServiceHandler but
// automatically dials to "endpoint" and closes the connection when "ctx" gets done.
func RegisterClusterServiceHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) {
conn, err := grpc.Dial(endpoint, opts...)
if err != nil {
return err
}
defer func() {
if err != nil {
if cerr := conn.Close(); cerr != nil {
grpclog.Printf("Failed to close conn to %s: %v", endpoint, cerr)
}
return
}
go func() {
<-ctx.Done()
if cerr := conn.Close(); cerr != nil {
grpclog.Printf("Failed to close conn to %s: %v", endpoint, cerr)
}
}()
}()
return RegisterClusterServiceHandler(ctx, mux, conn)
}
// RegisterClusterServiceHandler registers the http handlers for service ClusterService to "mux".
// The handlers forward requests to the grpc endpoint over "conn".
func RegisterClusterServiceHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error {
return RegisterClusterServiceHandlerClient(ctx, mux, NewClusterServiceClient(conn))
}
// RegisterClusterServiceHandler registers the http handlers for service ClusterService to "mux".
// The handlers forward requests to the grpc endpoint over the given implementation of "ClusterServiceClient".
// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "ClusterServiceClient"
// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in
// "ClusterServiceClient" to call the correct interceptors.
func RegisterClusterServiceHandlerClient(ctx context.Context, mux *runtime.ServeMux, client ClusterServiceClient) error {
mux.Handle("GET", pattern_ClusterService_GetClusters_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
if cn, ok := w.(http.CloseNotifier); ok {
go func(done <-chan struct{}, closed <-chan bool) {
select {
case <-done:
case <-closed:
cancel()
}
}(ctx.Done(), cn.CloseNotify())
}
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
rctx, err := runtime.AnnotateContext(ctx, mux, req)
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := request_ClusterService_GetClusters_0(rctx, inboundMarshaler, client, req, pathParams)
ctx = runtime.NewServerMetadataContext(ctx, md)
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
forward_ClusterService_GetClusters_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
mux.Handle("GET", pattern_ClusterService_GetCluster_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
if cn, ok := w.(http.CloseNotifier); ok {
go func(done <-chan struct{}, closed <-chan bool) {
select {
case <-done:
case <-closed:
cancel()
}
}(ctx.Done(), cn.CloseNotify())
}
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
rctx, err := runtime.AnnotateContext(ctx, mux, req)
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := request_ClusterService_GetCluster_0(rctx, inboundMarshaler, client, req, pathParams)
ctx = runtime.NewServerMetadataContext(ctx, md)
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
forward_ClusterService_GetCluster_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
return nil
}
var (
pattern_ClusterService_GetClusters_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"api", "v1", "clusters"}, ""))
pattern_ClusterService_GetCluster_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3}, []string{"api", "v1", "clusters", "Name"}, ""))
)
var (
forward_ClusterService_GetClusters_0 = runtime.ForwardResponseMessage
forward_ClusterService_GetCluster_0 = runtime.ForwardResponseMessage
)

View file

@ -0,0 +1,45 @@
syntax = "proto3";
option go_package = "github.com/argoproj/argo-cd/server/cluster";
// Cluster Service
//
// Cluster Service API allows
package cluster;
import "google/api/annotations.proto";
import "server/core/core.proto";
// ClusterMessage holds Kuberentes cluster information
message ClusterMessage {
string Name = 1;
string Server = 2;
string Certificate = 3;
string Token = 4;
string Description = 5;
}
// ClusterListMessage holds multiple clusters
message ClusterListMessage {
repeated ClusterMessage items = 1;
}
message ClusterQuery {}
// ClusterService
service ClusterService {
// GetClusters returns list of clusters
rpc GetClusters(ClusterQuery) returns (ClusterListMessage) {
option (google.api.http) = {
get: "/api/v1/clusters"
};
}
// GetCluster returns a cluster by name
rpc GetCluster(core.NameMessage) returns (ClusterMessage) {
option (google.api.http) = {
get: "/api/v1/clusters/{Name}"
};
}
}

18
server/cluster/server.go Normal file
View file

@ -0,0 +1,18 @@
package cluster
import (
"github.com/argoproj/argo-cd/server/core"
"golang.org/x/net/context"
)
type Server struct{}
// GetClusters returns list of clusters
func (s *Server) GetClusters(ctx context.Context, in *ClusterQuery) (*ClusterListMessage, error) {
return &ClusterListMessage{}, nil
}
// GetCluster returns list of clusters
func (s *Server) GetCluster(ctx context.Context, in *core.NameMessage) (*ClusterMessage, error) {
return &ClusterMessage{}, nil
}

1
server/core/core.go Normal file
View file

@ -0,0 +1 @@
package core

65
server/core/core.pb.go Normal file
View file

@ -0,0 +1,65 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// source: server/core/core.proto
/*
Package core is a generated protocol buffer package.
Core types
It is generated from these files:
server/core/core.proto
It has these top-level messages:
NameMessage
*/
package core
import proto "github.com/golang/protobuf/proto"
import fmt "fmt"
import math "math"
// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
var _ = fmt.Errorf
var _ = math.Inf
// This is a compile-time assertion to ensure that this generated file
// is compatible with the proto package it is being compiled against.
// A compilation error at this line likely means your copy of the
// proto package needs to be updated.
const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package
// NameMessage is a name of a resource
type NameMessage struct {
Name string `protobuf:"bytes,1,opt,name=Name" json:"Name,omitempty"`
}
func (m *NameMessage) Reset() { *m = NameMessage{} }
func (m *NameMessage) String() string { return proto.CompactTextString(m) }
func (*NameMessage) ProtoMessage() {}
func (*NameMessage) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} }
func (m *NameMessage) GetName() string {
if m != nil {
return m.Name
}
return ""
}
func init() {
proto.RegisterType((*NameMessage)(nil), "core.NameMessage")
}
func init() { proto.RegisterFile("server/core/core.proto", fileDescriptor0) }
var fileDescriptor0 = []byte{
// 114 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0x2b, 0x4e, 0x2d, 0x2a,
0x4b, 0x2d, 0xd2, 0x4f, 0xce, 0x2f, 0x4a, 0x05, 0x13, 0x7a, 0x05, 0x45, 0xf9, 0x25, 0xf9, 0x42,
0x2c, 0x20, 0xb6, 0x92, 0x22, 0x17, 0xb7, 0x5f, 0x62, 0x6e, 0xaa, 0x6f, 0x6a, 0x71, 0x71, 0x62,
0x7a, 0xaa, 0x90, 0x10, 0x17, 0x0b, 0x88, 0x2b, 0xc1, 0xa8, 0xc0, 0xa8, 0xc1, 0x19, 0x04, 0x66,
0x3b, 0x69, 0x46, 0xa9, 0xa7, 0x67, 0x96, 0x64, 0x94, 0x26, 0xe9, 0x25, 0xe7, 0xe7, 0xea, 0x27,
0x16, 0xa5, 0xe7, 0x17, 0x14, 0xe5, 0x67, 0x81, 0x19, 0xba, 0xc9, 0x29, 0xfa, 0x48, 0xc6, 0x27,
0xb1, 0x81, 0x8d, 0x36, 0x06, 0x04, 0x00, 0x00, 0xff, 0xff, 0x92, 0x63, 0xdf, 0x1d, 0x74, 0x00,
0x00, 0x00,
}

10
server/core/core.proto Normal file
View file

@ -0,0 +1,10 @@
syntax = "proto3";
option go_package = "github.com/argoproj/argo-cd/server/core";
// Core types
package core;
// NameMessage is a name of a resource
message NameMessage {
string Name = 1;
}

View file

@ -7,7 +7,8 @@ import (
"net/http"
argocd "github.com/argoproj/argo-cd"
"github.com/argoproj/argo-cd/argocd/version"
"github.com/argoproj/argo-cd/server/cluster"
"github.com/argoproj/argo-cd/server/version"
"github.com/grpc-ecosystem/grpc-gateway/runtime"
log "github.com/sirupsen/logrus"
"github.com/soheilhy/cmux"
@ -52,15 +53,15 @@ func (a *ArgoCDServer) Run() {
// gRPC Server
grpcS := grpc.NewServer()
version.RegisterVersionServiceServer(grpcS, &version.Server{})
cluster.RegisterClusterServiceServer(grpcS, &cluster.Server{})
// HTTP 1.1+JSON Server
mux := http.NewServeMux()
gwmux := runtime.NewServeMux()
mux.Handle("/", gwmux)
err = version.RegisterVersionServiceHandlerFromEndpoint(ctx, gwmux, endpoint, []grpc.DialOption{grpc.WithInsecure()})
if err != nil {
panic(err)
}
dOpts := []grpc.DialOption{grpc.WithInsecure()}
mustRegisterGWHandler(version.RegisterVersionServiceHandlerFromEndpoint, ctx, gwmux, endpoint, dOpts)
mustRegisterGWHandler(cluster.RegisterClusterServiceHandlerFromEndpoint, ctx, gwmux, endpoint, dOpts)
httpS := &http.Server{
Addr: endpoint,
Handler: mux,
@ -77,3 +78,13 @@ func (a *ArgoCDServer) Run() {
panic(err)
}
}
type registerFunc func(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) error
// mustRegisterGWHandler is a convenience function to register a gateway handler
func mustRegisterGWHandler(register registerFunc, ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) {
err := register(ctx, mux, endpoint, opts)
if err != nil {
panic(err)
}
}

View file

@ -2,13 +2,14 @@ package version
import (
argocd "github.com/argoproj/argo-cd"
"github.com/golang/protobuf/ptypes/empty"
"golang.org/x/net/context"
)
type Server struct{}
// Version returns the version of the API server
func (v *Server) Version(context.Context, *VersionMessage) (*VersionMessage, error) {
func (s *Server) Version(context.Context, *empty.Empty) (*VersionMessage, error) {
vers := argocd.GetVersion()
return &VersionMessage{
Version: vers.Version,

View file

@ -1,5 +1,5 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// source: version.proto
// source: server/version/version.proto
/*
Package version is a generated protocol buffer package.
@ -9,7 +9,7 @@ Version Service
Version Service API returns the version of the API server.
It is generated from these files:
version.proto
server/version/version.proto
It has these top-level messages:
VersionMessage
@ -20,6 +20,7 @@ import proto "github.com/golang/protobuf/proto"
import fmt "fmt"
import math "math"
import _ "google.golang.org/genproto/googleapis/api/annotations"
import google_protobuf1 "github.com/golang/protobuf/ptypes/empty"
import (
context "golang.org/x/net/context"
@ -126,7 +127,7 @@ const _ = grpc.SupportPackageIsVersion4
type VersionServiceClient interface {
// Version returns version information of the API server
Version(ctx context.Context, in *VersionMessage, opts ...grpc.CallOption) (*VersionMessage, error)
Version(ctx context.Context, in *google_protobuf1.Empty, opts ...grpc.CallOption) (*VersionMessage, error)
}
type versionServiceClient struct {
@ -137,7 +138,7 @@ func NewVersionServiceClient(cc *grpc.ClientConn) VersionServiceClient {
return &versionServiceClient{cc}
}
func (c *versionServiceClient) Version(ctx context.Context, in *VersionMessage, opts ...grpc.CallOption) (*VersionMessage, error) {
func (c *versionServiceClient) Version(ctx context.Context, in *google_protobuf1.Empty, opts ...grpc.CallOption) (*VersionMessage, error) {
out := new(VersionMessage)
err := grpc.Invoke(ctx, "/version.VersionService/Version", in, out, c.cc, opts...)
if err != nil {
@ -150,7 +151,7 @@ func (c *versionServiceClient) Version(ctx context.Context, in *VersionMessage,
type VersionServiceServer interface {
// Version returns version information of the API server
Version(context.Context, *VersionMessage) (*VersionMessage, error)
Version(context.Context, *google_protobuf1.Empty) (*VersionMessage, error)
}
func RegisterVersionServiceServer(s *grpc.Server, srv VersionServiceServer) {
@ -158,7 +159,7 @@ func RegisterVersionServiceServer(s *grpc.Server, srv VersionServiceServer) {
}
func _VersionService_Version_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(VersionMessage)
in := new(google_protobuf1.Empty)
if err := dec(in); err != nil {
return nil, err
}
@ -170,7 +171,7 @@ func _VersionService_Version_Handler(srv interface{}, ctx context.Context, dec f
FullMethod: "/version.VersionService/Version",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(VersionServiceServer).Version(ctx, req.(*VersionMessage))
return srv.(VersionServiceServer).Version(ctx, req.(*google_protobuf1.Empty))
}
return interceptor(ctx, in, info, handler)
}
@ -185,28 +186,31 @@ var _VersionService_serviceDesc = grpc.ServiceDesc{
},
},
Streams: []grpc.StreamDesc{},
Metadata: "version.proto",
Metadata: "server/version/version.proto",
}
func init() { proto.RegisterFile("version.proto", fileDescriptor0) }
func init() { proto.RegisterFile("server/version/version.proto", fileDescriptor0) }
var fileDescriptor0 = []byte{
// 263 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x91, 0x41, 0x4a, 0xc3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 0x4b, 0x23, 0xef, 0x6c, 0x2b, 0x3d, 0xee, 0x59, 0xd0, 0xd7, 0xdb,
0xe1, 0xf2, 0x0d, 0xda, 0x1d, 0x6d, 0x11, 0x1e, 0x86, 0xcb, 0xe1, 0x62, 0x1e, 0xe6, 0xdc, 0x5f,
0x27, 0x3b, 0x04, 0xf2, 0xb3, 0xcf, 0xef, 0x9f, 0xaf, 0xd1, 0x14, 0x26, 0x6e, 0x69, 0x1f, 0x5a,
0xa6, 0x2f, 0xe1, 0x21, 0x5e, 0x63, 0xb7, 0xf8, 0xcd, 0x5f, 0x00, 0x00, 0x00, 0xff, 0xff, 0xca,
0xa9, 0x50, 0xc7, 0xa9, 0x01, 0x00, 0x00,
// 310 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x54, 0x91, 0xcd, 0x4a, 0x03, 0x31,
0x14, 0x85, 0x69, 0xd5, 0xfe, 0x84, 0xd2, 0x45, 0x90, 0x1a, 0xc6, 0x2e, 0xa4, 0x2b, 0x11, 0x9d,
0x80, 0xbe, 0x41, 0xab, 0x74, 0x25, 0x14, 0x2b, 0x2e, 0xdc, 0x65, 0xda, 0xdb, 0x18, 0x99, 0xcc,
0x1d, 0x32, 0x69, 0xc1, 0xad, 0xaf, 0xe0, 0xa3, 0xf9, 0x0a, 0x3e, 0x84, 0x4b, 0x99, 0xfc, 0x8c,
0xcc, 0x6a, 0x72, 0xce, 0x17, 0xce, 0xe4, 0x9e, 0x4b, 0xa6, 0x15, 0x98, 0x03, 0x18, 0x7e, 0x00,
0x53, 0x29, 0x2c, 0xe2, 0x37, 0x2d, 0x0d, 0x5a, 0xa4, 0xfd, 0x20, 0x93, 0xa9, 0x44, 0x94, 0x39,
0x70, 0x51, 0x2a, 0x2e, 0x8a, 0x02, 0xad, 0xb0, 0x0a, 0x8b, 0xca, 0x5f, 0x4b, 0xce, 0x03, 0x75,
0x2a, 0xdb, 0xef, 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 0xff, 0xff, 0x45, 0x81,
0x09, 0xaf, 0xf7, 0x01, 0x00, 0x00,
}

View file

@ -1,5 +1,5 @@
// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT.
// source: version.proto
// source: server/version/version.proto
/*
Package version is a reverse proxy.
@ -13,6 +13,7 @@ import (
"net/http"
"github.com/golang/protobuf/proto"
"github.com/golang/protobuf/ptypes/empty"
"github.com/grpc-ecosystem/grpc-gateway/runtime"
"github.com/grpc-ecosystem/grpc-gateway/utilities"
"golang.org/x/net/context"
@ -28,18 +29,10 @@ var _ status.Status
var _ = runtime.String
var _ = utilities.NewDoubleArray
var (
filter_VersionService_Version_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)}
)
func request_VersionService_Version_0(ctx context.Context, marshaler runtime.Marshaler, client VersionServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq VersionMessage
var protoReq empty.Empty
var metadata runtime.ServerMetadata
if err := runtime.PopulateQueryParameters(&protoReq, req.URL.Query(), filter_VersionService_Version_0); err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
msg, err := client.Version(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
return msg, metadata, err

View file

@ -1,5 +1,5 @@
syntax = "proto3";
option go_package = "version";
option go_package = "github.com/argoproj/argo-cd/server/version";
// Version Service
//
@ -7,6 +7,7 @@ option go_package = "version";
package version;
import "google/api/annotations.proto";
import "google/protobuf/empty.proto";
// VersionMessage represents version of the ArgoCD API server
message VersionMessage {
@ -23,7 +24,7 @@ message VersionMessage {
// VersionService returns the version of the API server.
service VersionService {
// Version returns version information of the API server
rpc Version(VersionMessage) returns (VersionMessage) {
rpc Version(google.protobuf.Empty) returns (VersionMessage) {
option (google.api.http) = {
get: "/api/version"
};