diff --git a/CHANGELOG.md b/CHANGELOG.md index c742cf5ec..f495fdab1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ - (Feature) (Platform) Storage V1Alpha1 RC - (Feature) (Networking) ArangoRotue WebSocket Support - (Feature) (Scheduler) Helm Driver Param +- (Feature) (Integration) Services Endpoint ## [1.2.43](https://github.com/arangodb/kube-arangodb/tree/1.2.43) (2024-10-14) - (Feature) ArangoRoute CRD diff --git a/integrations/pong/v1/definition/pong.pb.go b/integrations/pong/v1/definition/pong.pb.go index 2466d3c5a..a5f103843 100644 --- a/integrations/pong/v1/definition/pong.pb.go +++ b/integrations/pong/v1/definition/pong.pb.go @@ -91,6 +91,122 @@ func (x *PongV1PingResponse) GetTime() *timestamppb.Timestamp { return nil } +// PongV1 Services Call Response +type PongV1ServicesResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + // List of the Services + Services []*PongV1Service `protobuf:"bytes,1,rep,name=services,proto3" json:"services,omitempty"` +} + +func (x *PongV1ServicesResponse) Reset() { + *x = PongV1ServicesResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_integrations_pong_v1_definition_pong_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *PongV1ServicesResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*PongV1ServicesResponse) ProtoMessage() {} + +func (x *PongV1ServicesResponse) ProtoReflect() protoreflect.Message { + mi := &file_integrations_pong_v1_definition_pong_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use PongV1ServicesResponse.ProtoReflect.Descriptor instead. +func (*PongV1ServicesResponse) Descriptor() ([]byte, []int) { + return file_integrations_pong_v1_definition_pong_proto_rawDescGZIP(), []int{1} +} + +func (x *PongV1ServicesResponse) GetServices() []*PongV1Service { + if x != nil { + return x.Services + } + return nil +} + +// Service Definition +type PongV1Service struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + // Service Name + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` + // Service Version + Version string `protobuf:"bytes,2,opt,name=version,proto3" json:"version,omitempty"` + // states if service is enabled + Enabled bool `protobuf:"varint,3,opt,name=enabled,proto3" json:"enabled,omitempty"` +} + +func (x *PongV1Service) Reset() { + *x = PongV1Service{} + if protoimpl.UnsafeEnabled { + mi := &file_integrations_pong_v1_definition_pong_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *PongV1Service) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*PongV1Service) ProtoMessage() {} + +func (x *PongV1Service) ProtoReflect() protoreflect.Message { + mi := &file_integrations_pong_v1_definition_pong_proto_msgTypes[2] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use PongV1Service.ProtoReflect.Descriptor instead. +func (*PongV1Service) Descriptor() ([]byte, []int) { + return file_integrations_pong_v1_definition_pong_proto_rawDescGZIP(), []int{2} +} + +func (x *PongV1Service) GetName() string { + if x != nil { + return x.Name + } + return "" +} + +func (x *PongV1Service) GetVersion() string { + if x != nil { + return x.Version + } + return "" +} + +func (x *PongV1Service) GetEnabled() bool { + if x != nil { + return x.Enabled + } + return false +} + var File_integrations_pong_v1_definition_pong_proto protoreflect.FileDescriptor var file_integrations_pong_v1_definition_pong_proto_rawDesc = []byte{ @@ -106,15 +222,29 @@ var file_integrations_pong_v1_definition_pong_proto_rawDesc = []byte{ 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x2e, 0x0a, 0x04, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, - 0x6d, 0x70, 0x52, 0x04, 0x74, 0x69, 0x6d, 0x65, 0x32, 0x39, 0x0a, 0x06, 0x50, 0x6f, 0x6e, 0x67, - 0x56, 0x31, 0x12, 0x2f, 0x0a, 0x04, 0x50, 0x69, 0x6e, 0x67, 0x12, 0x0d, 0x2e, 0x73, 0x68, 0x61, - 0x72, 0x65, 0x64, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x18, 0x2e, 0x70, 0x6f, 0x6e, 0x67, - 0x2e, 0x50, 0x6f, 0x6e, 0x67, 0x56, 0x31, 0x50, 0x69, 0x6e, 0x67, 0x52, 0x65, 0x73, 0x70, 0x6f, - 0x6e, 0x73, 0x65, 0x42, 0x43, 0x5a, 0x41, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, - 0x6d, 0x2f, 0x61, 0x72, 0x61, 0x6e, 0x67, 0x6f, 0x64, 0x62, 0x2f, 0x6b, 0x75, 0x62, 0x65, 0x2d, - 0x61, 0x72, 0x61, 0x6e, 0x67, 0x6f, 0x64, 0x62, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x67, 0x72, 0x61, - 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2f, 0x70, 0x6f, 0x6e, 0x67, 0x2f, 0x76, 0x31, 0x2f, 0x64, 0x65, - 0x66, 0x69, 0x6e, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x6d, 0x70, 0x52, 0x04, 0x74, 0x69, 0x6d, 0x65, 0x22, 0x49, 0x0a, 0x16, 0x50, 0x6f, 0x6e, 0x67, + 0x56, 0x31, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, + 0x73, 0x65, 0x12, 0x2f, 0x0a, 0x08, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x18, 0x01, + 0x20, 0x03, 0x28, 0x0b, 0x32, 0x13, 0x2e, 0x70, 0x6f, 0x6e, 0x67, 0x2e, 0x50, 0x6f, 0x6e, 0x67, + 0x56, 0x31, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x52, 0x08, 0x73, 0x65, 0x72, 0x76, 0x69, + 0x63, 0x65, 0x73, 0x22, 0x57, 0x0a, 0x0d, 0x50, 0x6f, 0x6e, 0x67, 0x56, 0x31, 0x53, 0x65, 0x72, + 0x76, 0x69, 0x63, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x76, 0x65, 0x72, 0x73, + 0x69, 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, + 0x6f, 0x6e, 0x12, 0x18, 0x0a, 0x07, 0x65, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x64, 0x18, 0x03, 0x20, + 0x01, 0x28, 0x08, 0x52, 0x07, 0x65, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x64, 0x32, 0x72, 0x0a, 0x06, + 0x50, 0x6f, 0x6e, 0x67, 0x56, 0x31, 0x12, 0x2f, 0x0a, 0x04, 0x50, 0x69, 0x6e, 0x67, 0x12, 0x0d, + 0x2e, 0x73, 0x68, 0x61, 0x72, 0x65, 0x64, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x18, 0x2e, + 0x70, 0x6f, 0x6e, 0x67, 0x2e, 0x50, 0x6f, 0x6e, 0x67, 0x56, 0x31, 0x50, 0x69, 0x6e, 0x67, 0x52, + 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x37, 0x0a, 0x08, 0x53, 0x65, 0x72, 0x76, 0x69, + 0x63, 0x65, 0x73, 0x12, 0x0d, 0x2e, 0x73, 0x68, 0x61, 0x72, 0x65, 0x64, 0x2e, 0x45, 0x6d, 0x70, + 0x74, 0x79, 0x1a, 0x1c, 0x2e, 0x70, 0x6f, 0x6e, 0x67, 0x2e, 0x50, 0x6f, 0x6e, 0x67, 0x56, 0x31, + 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, + 0x42, 0x43, 0x5a, 0x41, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x61, + 0x72, 0x61, 0x6e, 0x67, 0x6f, 0x64, 0x62, 0x2f, 0x6b, 0x75, 0x62, 0x65, 0x2d, 0x61, 0x72, 0x61, + 0x6e, 0x67, 0x6f, 0x64, 0x62, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x67, 0x72, 0x61, 0x74, 0x69, 0x6f, + 0x6e, 0x73, 0x2f, 0x70, 0x6f, 0x6e, 0x67, 0x2f, 0x76, 0x31, 0x2f, 0x64, 0x65, 0x66, 0x69, 0x6e, + 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -129,21 +259,26 @@ func file_integrations_pong_v1_definition_pong_proto_rawDescGZIP() []byte { return file_integrations_pong_v1_definition_pong_proto_rawDescData } -var file_integrations_pong_v1_definition_pong_proto_msgTypes = make([]protoimpl.MessageInfo, 1) +var file_integrations_pong_v1_definition_pong_proto_msgTypes = make([]protoimpl.MessageInfo, 3) var file_integrations_pong_v1_definition_pong_proto_goTypes = []interface{}{ - (*PongV1PingResponse)(nil), // 0: pong.PongV1PingResponse - (*timestamppb.Timestamp)(nil), // 1: google.protobuf.Timestamp - (*definition.Empty)(nil), // 2: shared.Empty + (*PongV1PingResponse)(nil), // 0: pong.PongV1PingResponse + (*PongV1ServicesResponse)(nil), // 1: pong.PongV1ServicesResponse + (*PongV1Service)(nil), // 2: pong.PongV1Service + (*timestamppb.Timestamp)(nil), // 3: google.protobuf.Timestamp + (*definition.Empty)(nil), // 4: shared.Empty } var file_integrations_pong_v1_definition_pong_proto_depIdxs = []int32{ - 1, // 0: pong.PongV1PingResponse.time:type_name -> google.protobuf.Timestamp - 2, // 1: pong.PongV1.Ping:input_type -> shared.Empty - 0, // 2: pong.PongV1.Ping:output_type -> pong.PongV1PingResponse - 2, // [2:3] is the sub-list for method output_type - 1, // [1:2] is the sub-list for method input_type - 1, // [1:1] is the sub-list for extension type_name - 1, // [1:1] is the sub-list for extension extendee - 0, // [0:1] is the sub-list for field type_name + 3, // 0: pong.PongV1PingResponse.time:type_name -> google.protobuf.Timestamp + 2, // 1: pong.PongV1ServicesResponse.services:type_name -> pong.PongV1Service + 4, // 2: pong.PongV1.Ping:input_type -> shared.Empty + 4, // 3: pong.PongV1.Services:input_type -> shared.Empty + 0, // 4: pong.PongV1.Ping:output_type -> pong.PongV1PingResponse + 1, // 5: pong.PongV1.Services:output_type -> pong.PongV1ServicesResponse + 4, // [4:6] is the sub-list for method output_type + 2, // [2:4] is the sub-list for method input_type + 2, // [2:2] is the sub-list for extension type_name + 2, // [2:2] is the sub-list for extension extendee + 0, // [0:2] is the sub-list for field type_name } func init() { file_integrations_pong_v1_definition_pong_proto_init() } @@ -164,6 +299,30 @@ func file_integrations_pong_v1_definition_pong_proto_init() { return nil } } + file_integrations_pong_v1_definition_pong_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*PongV1ServicesResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_integrations_pong_v1_definition_pong_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*PongV1Service); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } } type x struct{} out := protoimpl.TypeBuilder{ @@ -171,7 +330,7 @@ func file_integrations_pong_v1_definition_pong_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_integrations_pong_v1_definition_pong_proto_rawDesc, NumEnums: 0, - NumMessages: 1, + NumMessages: 3, NumExtensions: 0, NumServices: 1, }, diff --git a/integrations/pong/v1/definition/pong.proto b/integrations/pong/v1/definition/pong.proto index e6a1bf7aa..810dcc45b 100644 --- a/integrations/pong/v1/definition/pong.proto +++ b/integrations/pong/v1/definition/pong.proto @@ -32,6 +32,9 @@ option go_package = "github.com/arangodb/kube-arangodb/integrations/pong/v1/defi service PongV1 { // Sends ping to the server rpc Ping(shared.Empty) returns (PongV1PingResponse); + + // Asks for the services details + rpc Services(shared.Empty) returns (PongV1ServicesResponse); } // Responses @@ -41,4 +44,20 @@ service PongV1 { message PongV1PingResponse { // Current time in UTC google.protobuf.Timestamp time = 1; +} + +// PongV1 Services Call Response +message PongV1ServicesResponse { + // List of the Services + repeated PongV1Service services = 1; +} + +// Service Definition +message PongV1Service { + // Service Name + string name = 1; + // Service Version + string version = 2; + // states if service is enabled + bool enabled = 3; } \ No newline at end of file diff --git a/integrations/pong/v1/definition/pong_grpc.pb.go b/integrations/pong/v1/definition/pong_grpc.pb.go index 6d418f034..90822e623 100644 --- a/integrations/pong/v1/definition/pong_grpc.pb.go +++ b/integrations/pong/v1/definition/pong_grpc.pb.go @@ -25,6 +25,8 @@ const _ = grpc.SupportPackageIsVersion7 type PongV1Client interface { // Sends ping to the server Ping(ctx context.Context, in *definition.Empty, opts ...grpc.CallOption) (*PongV1PingResponse, error) + // Asks for the services details + Services(ctx context.Context, in *definition.Empty, opts ...grpc.CallOption) (*PongV1ServicesResponse, error) } type pongV1Client struct { @@ -44,12 +46,23 @@ func (c *pongV1Client) Ping(ctx context.Context, in *definition.Empty, opts ...g return out, nil } +func (c *pongV1Client) Services(ctx context.Context, in *definition.Empty, opts ...grpc.CallOption) (*PongV1ServicesResponse, error) { + out := new(PongV1ServicesResponse) + err := c.cc.Invoke(ctx, "/pong.PongV1/Services", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // PongV1Server is the server API for PongV1 service. // All implementations must embed UnimplementedPongV1Server // for forward compatibility type PongV1Server interface { // Sends ping to the server Ping(context.Context, *definition.Empty) (*PongV1PingResponse, error) + // Asks for the services details + Services(context.Context, *definition.Empty) (*PongV1ServicesResponse, error) mustEmbedUnimplementedPongV1Server() } @@ -60,6 +73,9 @@ type UnimplementedPongV1Server struct { func (UnimplementedPongV1Server) Ping(context.Context, *definition.Empty) (*PongV1PingResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method Ping not implemented") } +func (UnimplementedPongV1Server) Services(context.Context, *definition.Empty) (*PongV1ServicesResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Services not implemented") +} func (UnimplementedPongV1Server) mustEmbedUnimplementedPongV1Server() {} // UnsafePongV1Server may be embedded to opt out of forward compatibility for this service. @@ -91,6 +107,24 @@ func _PongV1_Ping_Handler(srv interface{}, ctx context.Context, dec func(interfa return interceptor(ctx, in, info, handler) } +func _PongV1_Services_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(definition.Empty) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(PongV1Server).Services(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/pong.PongV1/Services", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(PongV1Server).Services(ctx, req.(*definition.Empty)) + } + return interceptor(ctx, in, info, handler) +} + // PongV1_ServiceDesc is the grpc.ServiceDesc for PongV1 service. // It's only intended for direct use with grpc.RegisterService, // and not to be introspected or modified (even as a copy) @@ -102,6 +136,10 @@ var PongV1_ServiceDesc = grpc.ServiceDesc{ MethodName: "Ping", Handler: _PongV1_Ping_Handler, }, + { + MethodName: "Services", + Handler: _PongV1_Services_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "integrations/pong/v1/definition/pong.proto", diff --git a/integrations/pong/v1/impl.go b/integrations/pong/v1/impl.go index 42b5e48ba..6cab661d4 100644 --- a/integrations/pong/v1/impl.go +++ b/integrations/pong/v1/impl.go @@ -29,17 +29,54 @@ import ( pbPongV1 "github.com/arangodb/kube-arangodb/integrations/pong/v1/definition" pbSharedV1 "github.com/arangodb/kube-arangodb/integrations/shared/v1/definition" + "github.com/arangodb/kube-arangodb/pkg/util" + "github.com/arangodb/kube-arangodb/pkg/util/errors" "github.com/arangodb/kube-arangodb/pkg/util/svc" ) -func New() svc.Handler { - return &impl{} +type Service struct { + Name, Version string + Enabled bool +} + +func (s Service) asService() *pbPongV1.PongV1Service { + return &pbPongV1.PongV1Service{ + Name: s.Name, + Version: s.Version, + Enabled: s.Enabled, + } +} + +func New(services ...Service) (svc.Handler, error) { + pServices := make(util.List[Service], 0, len(services)) + + for _, svc := range services { + if pServices.Contains(func(service Service) bool { + return service.Name == svc.Name && service.Version == svc.Version + }) { + return nil, errors.Errorf("Service %s/%s already registered", svc.Name, svc.Version) + } + + pServices = pServices.Append(svc) + } + + pServices = pServices.Sort(func(a Service, b Service) bool { + if a.Name == b.Name { + return a.Version < b.Version + } + + return a.Name < b.Name + }) + + return &impl{services: pServices.List()}, nil } var _ pbPongV1.PongV1Server = &impl{} var _ svc.Handler = &impl{} type impl struct { + services []Service + pbPongV1.UnimplementedPongV1Server } @@ -54,6 +91,19 @@ func (i *impl) Health() svc.HealthState { func (i *impl) Register(registrar *grpc.Server) { pbPongV1.RegisterPongV1Server(registrar, i) } + func (i *impl) Ping(context.Context, *pbSharedV1.Empty) (*pbPongV1.PongV1PingResponse, error) { return &pbPongV1.PongV1PingResponse{Time: timestamppb.New(time.Now().UTC())}, nil } + +func (i *impl) Services(context.Context, *pbSharedV1.Empty) (*pbPongV1.PongV1ServicesResponse, error) { + var r = make([]*pbPongV1.PongV1Service, len(i.services)) + + for id := range i.services { + r[id] = i.services[id].asService() + } + + return &pbPongV1.PongV1ServicesResponse{ + Services: r, + }, nil +} diff --git a/integrations/pong/v1/service_test.go b/integrations/pong/v1/service_test.go index d696b7675..1c0f5d83f 100644 --- a/integrations/pong/v1/service_test.go +++ b/integrations/pong/v1/service_test.go @@ -33,10 +33,13 @@ import ( "github.com/arangodb/kube-arangodb/pkg/util/tests/tgrpc" ) -func Client(t *testing.T, ctx context.Context) pbPongV1.PongV1Client { +func Client(t *testing.T, ctx context.Context, services ...Service) pbPongV1.PongV1Client { + h, err := New(services...) + require.NoError(t, err) + local := svc.NewService(svc.Configuration{ Address: "127.0.0.1:0", - }, New()) + }, h) start := local.Start(ctx) @@ -61,3 +64,36 @@ func Test_Ping(t *testing.T) { require.True(t, r2.GetTime().AsTime().After(r1.GetTime().AsTime())) } + +func Test_Services(t *testing.T) { + ctx, c := context.WithCancel(context.Background()) + defer c() + + v2 := Service{ + Name: "A", + Version: "V2", + Enabled: true, + } + + v3 := Service{ + Name: "A", + Version: "V3", + Enabled: false, + } + + client := Client(t, ctx, + v3, + v2, + ) + + r1, err := client.Services(ctx, &pbSharedV1.Empty{}) + require.NoError(t, err) + + require.Len(t, r1.GetServices(), 2) + + require.NotNil(t, r1.GetServices()[0]) + require.NotNil(t, r1.GetServices()[1]) + + require.EqualValues(t, v2.asService(), r1.GetServices()[0]) + require.EqualValues(t, v3.asService(), r1.GetServices()[1]) +} diff --git a/pkg/integrations/clients/pong_v1.go b/pkg/integrations/clients/pong_v1.go index 239c77a69..a2147eeaf 100644 --- a/pkg/integrations/clients/pong_v1.go +++ b/pkg/integrations/clients/pong_v1.go @@ -21,10 +21,13 @@ package clients import ( + "fmt" + "github.com/spf13/cobra" pbPongV1 "github.com/arangodb/kube-arangodb/integrations/pong/v1/definition" pbSharedV1 "github.com/arangodb/kube-arangodb/integrations/shared/v1/definition" + "github.com/arangodb/kube-arangodb/pkg/util" "github.com/arangodb/kube-arangodb/pkg/util/shutdown" ) @@ -61,6 +64,15 @@ func (s *pongV1) Register(cmd *cobra.Command) error { return err } + services, err := client.Services(shutdown.Context(), &pbSharedV1.Empty{}) + if err != nil { + return err + } + + for _, svc := range services.GetServices() { + println(fmt.Sprintf("%s.%s: %s", svc.GetName(), svc.GetVersion(), util.BoolSwitch(svc.GetEnabled(), "Enabled", "Disabled"))) + } + return nil } return nil diff --git a/pkg/integrations/integration.go b/pkg/integrations/integration.go index 9e756c22c..cb1dcd9b4 100644 --- a/pkg/integrations/integration.go +++ b/pkg/integrations/integration.go @@ -32,6 +32,7 @@ type Factory func() Integration type Integration interface { Name() string + Description() string Register(cmd *cobra.Command, fs FlagEnvHandler) error diff --git a/pkg/integrations/register.go b/pkg/integrations/register.go index c5d0ae7ec..d3fdd1564 100644 --- a/pkg/integrations/register.go +++ b/pkg/integrations/register.go @@ -196,11 +196,7 @@ func (c *configuration) runWithContext(ctx context.Context, cancel context.Cance var internalHandlers, externalHandlers, healthHandlers []svc.Handler - pong := pbImplPongV1.New() - - internalHandlers = append(internalHandlers, pong) - externalHandlers = append(externalHandlers, pong) - healthHandlers = append(healthHandlers, pong) + var services []pbImplPongV1.Service for _, handler := range c.registered { if ok, err := cmd.Flags().GetBool(fmt.Sprintf("integration.%s", handler.Name())); err != nil { @@ -223,6 +219,17 @@ func (c *configuration) runWithContext(ctx context.Context, cancel context.Cance Bool("external", externalEnabled). Info("Service discovered") + ps := strings.Split(handler.Name(), ".") + if len(ps) < 2 { + return errors.Errorf("Expected atleast 2 elements") + } + + services = append(services, pbImplPongV1.Service{ + Name: strings.Join(ps[:len(ps)-1], "."), + Version: ps[len(ps)-1], + Enabled: ok, + }) + if ok && (internalEnabled || externalEnabled) { if svc, err := handler.Handler(ctx, cmd); err != nil { return err @@ -239,6 +246,15 @@ func (c *configuration) runWithContext(ctx context.Context, cancel context.Cance } } + pong, err := pbImplPongV1.New(services...) + if err != nil { + return err + } + + internalHandlers = append(internalHandlers, pong) + externalHandlers = append(externalHandlers, pong) + healthHandlers = append(healthHandlers, pong) + if c.health.shutdownEnabled { healthHandlers = append(healthHandlers, pbImplShutdownV1.New(cancel)) }