diff --git a/api/v1/v1.go b/api/v1.go similarity index 88% rename from api/v1/v1.go rename to api/v1.go index 7613fc7..a177390 100644 --- a/api/v1/v1.go +++ b/api/v1.go @@ -11,6 +11,6 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. -package v1 +package api -//go:generate ../../scripts/shell-wrapper.sh protoc.sh ./v1.proto +//go:generate ../scripts/shell-wrapper.sh protoc.sh ./v1.proto diff --git a/api/v1/v1.pb.go b/api/v1.pb.go similarity index 52% rename from api/v1/v1.pb.go rename to api/v1.pb.go index 5068597..fd670bf 100644 --- a/api/v1/v1.pb.go +++ b/api/v1.pb.go @@ -14,17 +14,20 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.25.0 -// protoc v3.12.3 +// protoc-gen-go v1.25.0-devel +// protoc v3.13.0 // source: v1.proto -package v1 +package api import ( + context "context" reflect "reflect" sync "sync" - proto "github.com/golang/protobuf/proto" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoimpl "google.golang.org/protobuf/runtime/protoimpl" ) @@ -36,10 +39,6 @@ const ( _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) ) -// This is a compile-time assertion that a sufficiently up-to-date version -// of the legacy proto package is being used. -const _ = proto.ProtoPackageIsVersion4 - type ConsoleLevel int32 const ( @@ -525,6 +524,91 @@ func (x *ListResponse) GetServices() []*ListService { return nil } +type Empty struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields +} + +func (x *Empty) Reset() { + *x = Empty{} + if protoimpl.UnsafeEnabled { + mi := &file_v1_proto_msgTypes[8] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Empty) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Empty) ProtoMessage() {} + +func (x *Empty) ProtoReflect() protoreflect.Message { + mi := &file_v1_proto_msgTypes[8] + 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 Empty.ProtoReflect.Descriptor instead. +func (*Empty) Descriptor() ([]byte, []int) { + return file_v1_proto_rawDescGZIP(), []int{8} +} + +type StableResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Stable bool `protobuf:"varint,1,opt,name=stable,proto3" json:"stable,omitempty"` +} + +func (x *StableResponse) Reset() { + *x = StableResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_v1_proto_msgTypes[9] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *StableResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*StableResponse) ProtoMessage() {} + +func (x *StableResponse) ProtoReflect() protoreflect.Message { + mi := &file_v1_proto_msgTypes[9] + 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 StableResponse.ProtoReflect.Descriptor instead. +func (*StableResponse) Descriptor() ([]byte, []int) { + return file_v1_proto_rawDescGZIP(), []int{9} +} + +func (x *StableResponse) GetStable() bool { + if x != nil { + return x.Stable + } + return false +} + var File_v1_proto protoreflect.FileDescriptor var file_v1_proto_rawDesc = []byte{ @@ -565,34 +649,43 @@ var file_v1_proto_rawDesc = []byte{ 0x73, 0x65, 0x12, 0x2f, 0x0a, 0x08, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x13, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x31, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x52, 0x08, 0x73, 0x65, 0x72, 0x76, 0x69, - 0x63, 0x65, 0x73, 0x2a, 0x76, 0x0a, 0x0c, 0x43, 0x6f, 0x6e, 0x73, 0x6f, 0x6c, 0x65, 0x4c, 0x65, - 0x76, 0x65, 0x6c, 0x12, 0x1d, 0x0a, 0x19, 0x43, 0x4f, 0x4e, 0x53, 0x4f, 0x4c, 0x45, 0x5f, 0x4c, - 0x45, 0x56, 0x45, 0x4c, 0x5f, 0x55, 0x4e, 0x53, 0x50, 0x45, 0x43, 0x49, 0x46, 0x49, 0x45, 0x44, - 0x10, 0x00, 0x12, 0x16, 0x0a, 0x12, 0x43, 0x4f, 0x4e, 0x53, 0x4f, 0x4c, 0x45, 0x5f, 0x4c, 0x45, - 0x56, 0x45, 0x4c, 0x5f, 0x49, 0x4e, 0x46, 0x4f, 0x10, 0x01, 0x12, 0x16, 0x0a, 0x12, 0x43, 0x4f, - 0x4e, 0x53, 0x4f, 0x4c, 0x45, 0x5f, 0x4c, 0x45, 0x56, 0x45, 0x4c, 0x5f, 0x57, 0x41, 0x52, 0x4e, - 0x10, 0x02, 0x12, 0x17, 0x0a, 0x13, 0x43, 0x4f, 0x4e, 0x53, 0x4f, 0x4c, 0x45, 0x5f, 0x4c, 0x45, - 0x56, 0x45, 0x4c, 0x5f, 0x45, 0x52, 0x52, 0x4f, 0x52, 0x10, 0x03, 0x32, 0x8e, 0x02, 0x0a, 0x10, - 0x4c, 0x6f, 0x63, 0x61, 0x6c, 0x69, 0x7a, 0x65, 0x72, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, - 0x12, 0x4a, 0x0a, 0x0d, 0x45, 0x78, 0x70, 0x6f, 0x73, 0x65, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, - 0x65, 0x12, 0x1c, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x31, 0x2e, 0x45, 0x78, 0x70, 0x6f, 0x73, - 0x65, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, - 0x17, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x6f, 0x6e, 0x73, 0x6f, 0x6c, 0x65, - 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x30, 0x01, 0x12, 0x44, 0x0a, 0x0a, - 0x53, 0x74, 0x6f, 0x70, 0x45, 0x78, 0x70, 0x6f, 0x73, 0x65, 0x12, 0x19, 0x2e, 0x61, 0x70, 0x69, - 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x74, 0x6f, 0x70, 0x45, 0x78, 0x70, 0x6f, 0x73, 0x65, 0x52, 0x65, - 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x17, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x31, 0x2e, 0x43, - 0x6f, 0x6e, 0x73, 0x6f, 0x6c, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, - 0x30, 0x01, 0x12, 0x33, 0x0a, 0x04, 0x4c, 0x69, 0x73, 0x74, 0x12, 0x13, 0x2e, 0x61, 0x70, 0x69, - 0x2e, 0x76, 0x31, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, - 0x14, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x31, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x73, - 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x33, 0x0a, 0x04, 0x50, 0x69, 0x6e, 0x67, 0x12, - 0x13, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x31, 0x2e, 0x50, 0x69, 0x6e, 0x67, 0x52, 0x65, 0x71, - 0x75, 0x65, 0x73, 0x74, 0x1a, 0x14, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x31, 0x2e, 0x50, 0x69, - 0x6e, 0x67, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x29, 0x5a, 0x27, - 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x6a, 0x61, 0x72, 0x65, 0x64, - 0x61, 0x6c, 0x6c, 0x61, 0x72, 0x64, 0x2f, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x69, 0x7a, 0x65, 0x72, - 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x63, 0x65, 0x73, 0x22, 0x07, 0x0a, 0x05, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x22, 0x28, 0x0a, 0x0e, + 0x53, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x16, + 0x0a, 0x06, 0x73, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x06, + 0x73, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x2a, 0x76, 0x0a, 0x0c, 0x43, 0x6f, 0x6e, 0x73, 0x6f, 0x6c, + 0x65, 0x4c, 0x65, 0x76, 0x65, 0x6c, 0x12, 0x1d, 0x0a, 0x19, 0x43, 0x4f, 0x4e, 0x53, 0x4f, 0x4c, + 0x45, 0x5f, 0x4c, 0x45, 0x56, 0x45, 0x4c, 0x5f, 0x55, 0x4e, 0x53, 0x50, 0x45, 0x43, 0x49, 0x46, + 0x49, 0x45, 0x44, 0x10, 0x00, 0x12, 0x16, 0x0a, 0x12, 0x43, 0x4f, 0x4e, 0x53, 0x4f, 0x4c, 0x45, + 0x5f, 0x4c, 0x45, 0x56, 0x45, 0x4c, 0x5f, 0x49, 0x4e, 0x46, 0x4f, 0x10, 0x01, 0x12, 0x16, 0x0a, + 0x12, 0x43, 0x4f, 0x4e, 0x53, 0x4f, 0x4c, 0x45, 0x5f, 0x4c, 0x45, 0x56, 0x45, 0x4c, 0x5f, 0x57, + 0x41, 0x52, 0x4e, 0x10, 0x02, 0x12, 0x17, 0x0a, 0x13, 0x43, 0x4f, 0x4e, 0x53, 0x4f, 0x4c, 0x45, + 0x5f, 0x4c, 0x45, 0x56, 0x45, 0x4c, 0x5f, 0x45, 0x52, 0x52, 0x4f, 0x52, 0x10, 0x03, 0x32, 0xe9, + 0x02, 0x0a, 0x10, 0x4c, 0x6f, 0x63, 0x61, 0x6c, 0x69, 0x7a, 0x65, 0x72, 0x53, 0x65, 0x72, 0x76, + 0x69, 0x63, 0x65, 0x12, 0x4a, 0x0a, 0x0d, 0x45, 0x78, 0x70, 0x6f, 0x73, 0x65, 0x53, 0x65, 0x72, + 0x76, 0x69, 0x63, 0x65, 0x12, 0x1c, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x31, 0x2e, 0x45, 0x78, + 0x70, 0x6f, 0x73, 0x65, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x1a, 0x17, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x6f, 0x6e, 0x73, + 0x6f, 0x6c, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x30, 0x01, 0x12, + 0x44, 0x0a, 0x0a, 0x53, 0x74, 0x6f, 0x70, 0x45, 0x78, 0x70, 0x6f, 0x73, 0x65, 0x12, 0x19, 0x2e, + 0x61, 0x70, 0x69, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x74, 0x6f, 0x70, 0x45, 0x78, 0x70, 0x6f, 0x73, + 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x17, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, + 0x31, 0x2e, 0x43, 0x6f, 0x6e, 0x73, 0x6f, 0x6c, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, + 0x65, 0x22, 0x00, 0x30, 0x01, 0x12, 0x33, 0x0a, 0x04, 0x4c, 0x69, 0x73, 0x74, 0x12, 0x13, 0x2e, + 0x61, 0x70, 0x69, 0x2e, 0x76, 0x31, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x1a, 0x14, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x31, 0x2e, 0x4c, 0x69, 0x73, 0x74, + 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x33, 0x0a, 0x04, 0x50, 0x69, + 0x6e, 0x67, 0x12, 0x13, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x31, 0x2e, 0x50, 0x69, 0x6e, 0x67, + 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x14, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x31, + 0x2e, 0x50, 0x69, 0x6e, 0x67, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, + 0x26, 0x0a, 0x04, 0x4b, 0x69, 0x6c, 0x6c, 0x12, 0x0d, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x31, + 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x0d, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x31, 0x2e, + 0x45, 0x6d, 0x70, 0x74, 0x79, 0x22, 0x00, 0x12, 0x31, 0x0a, 0x06, 0x53, 0x74, 0x61, 0x62, 0x6c, + 0x65, 0x12, 0x0d, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x31, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, + 0x1a, 0x16, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x74, 0x61, 0x62, 0x6c, 0x65, + 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x26, 0x5a, 0x24, 0x67, 0x69, + 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x67, 0x65, 0x74, 0x6f, 0x75, 0x74, 0x72, + 0x65, 0x61, 0x63, 0x68, 0x2f, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x69, 0x7a, 0x65, 0x72, 0x2f, 0x61, + 0x70, 0x69, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -608,7 +701,7 @@ func file_v1_proto_rawDescGZIP() []byte { } var file_v1_proto_enumTypes = make([]protoimpl.EnumInfo, 1) -var file_v1_proto_msgTypes = make([]protoimpl.MessageInfo, 8) +var file_v1_proto_msgTypes = make([]protoimpl.MessageInfo, 10) var file_v1_proto_goTypes = []interface{}{ (ConsoleLevel)(0), // 0: api.v1.ConsoleLevel (*ExposeServiceRequest)(nil), // 1: api.v1.ExposeServiceRequest @@ -619,23 +712,29 @@ var file_v1_proto_goTypes = []interface{}{ (*PingResponse)(nil), // 6: api.v1.PingResponse (*ListService)(nil), // 7: api.v1.ListService (*ListResponse)(nil), // 8: api.v1.ListResponse + (*Empty)(nil), // 9: api.v1.Empty + (*StableResponse)(nil), // 10: api.v1.StableResponse } var file_v1_proto_depIdxs = []int32{ - 0, // 0: api.v1.ConsoleResponse.level:type_name -> api.v1.ConsoleLevel - 7, // 1: api.v1.ListResponse.services:type_name -> api.v1.ListService - 1, // 2: api.v1.LocalizerService.ExposeService:input_type -> api.v1.ExposeServiceRequest - 4, // 3: api.v1.LocalizerService.StopExpose:input_type -> api.v1.StopExposeRequest - 2, // 4: api.v1.LocalizerService.List:input_type -> api.v1.ListRequest - 3, // 5: api.v1.LocalizerService.Ping:input_type -> api.v1.PingRequest - 5, // 6: api.v1.LocalizerService.ExposeService:output_type -> api.v1.ConsoleResponse - 5, // 7: api.v1.LocalizerService.StopExpose:output_type -> api.v1.ConsoleResponse - 8, // 8: api.v1.LocalizerService.List:output_type -> api.v1.ListResponse - 6, // 9: api.v1.LocalizerService.Ping:output_type -> api.v1.PingResponse - 6, // [6:10] is the sub-list for method output_type - 2, // [2:6] 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 + 0, // 0: api.v1.ConsoleResponse.level:type_name -> api.v1.ConsoleLevel + 7, // 1: api.v1.ListResponse.services:type_name -> api.v1.ListService + 1, // 2: api.v1.LocalizerService.ExposeService:input_type -> api.v1.ExposeServiceRequest + 4, // 3: api.v1.LocalizerService.StopExpose:input_type -> api.v1.StopExposeRequest + 2, // 4: api.v1.LocalizerService.List:input_type -> api.v1.ListRequest + 3, // 5: api.v1.LocalizerService.Ping:input_type -> api.v1.PingRequest + 9, // 6: api.v1.LocalizerService.Kill:input_type -> api.v1.Empty + 9, // 7: api.v1.LocalizerService.Stable:input_type -> api.v1.Empty + 5, // 8: api.v1.LocalizerService.ExposeService:output_type -> api.v1.ConsoleResponse + 5, // 9: api.v1.LocalizerService.StopExpose:output_type -> api.v1.ConsoleResponse + 8, // 10: api.v1.LocalizerService.List:output_type -> api.v1.ListResponse + 6, // 11: api.v1.LocalizerService.Ping:output_type -> api.v1.PingResponse + 9, // 12: api.v1.LocalizerService.Kill:output_type -> api.v1.Empty + 10, // 13: api.v1.LocalizerService.Stable:output_type -> api.v1.StableResponse + 8, // [8:14] is the sub-list for method output_type + 2, // [2:8] 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_v1_proto_init() } @@ -740,6 +839,30 @@ func file_v1_proto_init() { return nil } } + file_v1_proto_msgTypes[8].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Empty); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_v1_proto_msgTypes[9].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*StableResponse); 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{ @@ -747,7 +870,7 @@ func file_v1_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_v1_proto_rawDesc, NumEnums: 1, - NumMessages: 8, + NumMessages: 10, NumExtensions: 0, NumServices: 1, }, @@ -761,3 +884,318 @@ func file_v1_proto_init() { file_v1_proto_goTypes = nil file_v1_proto_depIdxs = nil } + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConnInterface + +// 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.SupportPackageIsVersion6 + +// LocalizerServiceClient is the client API for LocalizerService service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type LocalizerServiceClient interface { + ExposeService(ctx context.Context, in *ExposeServiceRequest, opts ...grpc.CallOption) (LocalizerService_ExposeServiceClient, error) + StopExpose(ctx context.Context, in *StopExposeRequest, opts ...grpc.CallOption) (LocalizerService_StopExposeClient, error) + List(ctx context.Context, in *ListRequest, opts ...grpc.CallOption) (*ListResponse, error) + Ping(ctx context.Context, in *PingRequest, opts ...grpc.CallOption) (*PingResponse, error) + Kill(ctx context.Context, in *Empty, opts ...grpc.CallOption) (*Empty, error) + Stable(ctx context.Context, in *Empty, opts ...grpc.CallOption) (*StableResponse, error) +} + +type localizerServiceClient struct { + cc grpc.ClientConnInterface +} + +func NewLocalizerServiceClient(cc grpc.ClientConnInterface) LocalizerServiceClient { + return &localizerServiceClient{cc} +} + +func (c *localizerServiceClient) ExposeService(ctx context.Context, in *ExposeServiceRequest, opts ...grpc.CallOption) (LocalizerService_ExposeServiceClient, error) { + stream, err := c.cc.NewStream(ctx, &_LocalizerService_serviceDesc.Streams[0], "/api.v1.LocalizerService/ExposeService", opts...) + if err != nil { + return nil, err + } + x := &localizerServiceExposeServiceClient{stream} + if err := x.ClientStream.SendMsg(in); err != nil { + return nil, err + } + if err := x.ClientStream.CloseSend(); err != nil { + return nil, err + } + return x, nil +} + +type LocalizerService_ExposeServiceClient interface { + Recv() (*ConsoleResponse, error) + grpc.ClientStream +} + +type localizerServiceExposeServiceClient struct { + grpc.ClientStream +} + +func (x *localizerServiceExposeServiceClient) Recv() (*ConsoleResponse, error) { + m := new(ConsoleResponse) + if err := x.ClientStream.RecvMsg(m); err != nil { + return nil, err + } + return m, nil +} + +func (c *localizerServiceClient) StopExpose(ctx context.Context, in *StopExposeRequest, opts ...grpc.CallOption) (LocalizerService_StopExposeClient, error) { + stream, err := c.cc.NewStream(ctx, &_LocalizerService_serviceDesc.Streams[1], "/api.v1.LocalizerService/StopExpose", opts...) + if err != nil { + return nil, err + } + x := &localizerServiceStopExposeClient{stream} + if err := x.ClientStream.SendMsg(in); err != nil { + return nil, err + } + if err := x.ClientStream.CloseSend(); err != nil { + return nil, err + } + return x, nil +} + +type LocalizerService_StopExposeClient interface { + Recv() (*ConsoleResponse, error) + grpc.ClientStream +} + +type localizerServiceStopExposeClient struct { + grpc.ClientStream +} + +func (x *localizerServiceStopExposeClient) Recv() (*ConsoleResponse, error) { + m := new(ConsoleResponse) + if err := x.ClientStream.RecvMsg(m); err != nil { + return nil, err + } + return m, nil +} + +func (c *localizerServiceClient) List(ctx context.Context, in *ListRequest, opts ...grpc.CallOption) (*ListResponse, error) { + out := new(ListResponse) + err := c.cc.Invoke(ctx, "/api.v1.LocalizerService/List", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *localizerServiceClient) Ping(ctx context.Context, in *PingRequest, opts ...grpc.CallOption) (*PingResponse, error) { + out := new(PingResponse) + err := c.cc.Invoke(ctx, "/api.v1.LocalizerService/Ping", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *localizerServiceClient) Kill(ctx context.Context, in *Empty, opts ...grpc.CallOption) (*Empty, error) { + out := new(Empty) + err := c.cc.Invoke(ctx, "/api.v1.LocalizerService/Kill", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *localizerServiceClient) Stable(ctx context.Context, in *Empty, opts ...grpc.CallOption) (*StableResponse, error) { + out := new(StableResponse) + err := c.cc.Invoke(ctx, "/api.v1.LocalizerService/Stable", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// LocalizerServiceServer is the server API for LocalizerService service. +type LocalizerServiceServer interface { + ExposeService(*ExposeServiceRequest, LocalizerService_ExposeServiceServer) error + StopExpose(*StopExposeRequest, LocalizerService_StopExposeServer) error + List(context.Context, *ListRequest) (*ListResponse, error) + Ping(context.Context, *PingRequest) (*PingResponse, error) + Kill(context.Context, *Empty) (*Empty, error) + Stable(context.Context, *Empty) (*StableResponse, error) +} + +// UnimplementedLocalizerServiceServer can be embedded to have forward compatible implementations. +type UnimplementedLocalizerServiceServer struct { +} + +func (*UnimplementedLocalizerServiceServer) ExposeService(*ExposeServiceRequest, LocalizerService_ExposeServiceServer) error { + return status.Errorf(codes.Unimplemented, "method ExposeService not implemented") +} +func (*UnimplementedLocalizerServiceServer) StopExpose(*StopExposeRequest, LocalizerService_StopExposeServer) error { + return status.Errorf(codes.Unimplemented, "method StopExpose not implemented") +} +func (*UnimplementedLocalizerServiceServer) List(context.Context, *ListRequest) (*ListResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method List not implemented") +} +func (*UnimplementedLocalizerServiceServer) Ping(context.Context, *PingRequest) (*PingResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Ping not implemented") +} +func (*UnimplementedLocalizerServiceServer) Kill(context.Context, *Empty) (*Empty, error) { + return nil, status.Errorf(codes.Unimplemented, "method Kill not implemented") +} +func (*UnimplementedLocalizerServiceServer) Stable(context.Context, *Empty) (*StableResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Stable not implemented") +} + +func RegisterLocalizerServiceServer(s *grpc.Server, srv LocalizerServiceServer) { + s.RegisterService(&_LocalizerService_serviceDesc, srv) +} + +func _LocalizerService_ExposeService_Handler(srv interface{}, stream grpc.ServerStream) error { + m := new(ExposeServiceRequest) + if err := stream.RecvMsg(m); err != nil { + return err + } + return srv.(LocalizerServiceServer).ExposeService(m, &localizerServiceExposeServiceServer{stream}) +} + +type LocalizerService_ExposeServiceServer interface { + Send(*ConsoleResponse) error + grpc.ServerStream +} + +type localizerServiceExposeServiceServer struct { + grpc.ServerStream +} + +func (x *localizerServiceExposeServiceServer) Send(m *ConsoleResponse) error { + return x.ServerStream.SendMsg(m) +} + +func _LocalizerService_StopExpose_Handler(srv interface{}, stream grpc.ServerStream) error { + m := new(StopExposeRequest) + if err := stream.RecvMsg(m); err != nil { + return err + } + return srv.(LocalizerServiceServer).StopExpose(m, &localizerServiceStopExposeServer{stream}) +} + +type LocalizerService_StopExposeServer interface { + Send(*ConsoleResponse) error + grpc.ServerStream +} + +type localizerServiceStopExposeServer struct { + grpc.ServerStream +} + +func (x *localizerServiceStopExposeServer) Send(m *ConsoleResponse) error { + return x.ServerStream.SendMsg(m) +} + +func _LocalizerService_List_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ListRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(LocalizerServiceServer).List(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/api.v1.LocalizerService/List", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(LocalizerServiceServer).List(ctx, req.(*ListRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _LocalizerService_Ping_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(PingRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(LocalizerServiceServer).Ping(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/api.v1.LocalizerService/Ping", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(LocalizerServiceServer).Ping(ctx, req.(*PingRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _LocalizerService_Kill_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(Empty) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(LocalizerServiceServer).Kill(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/api.v1.LocalizerService/Kill", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(LocalizerServiceServer).Kill(ctx, req.(*Empty)) + } + return interceptor(ctx, in, info, handler) +} + +func _LocalizerService_Stable_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(Empty) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(LocalizerServiceServer).Stable(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/api.v1.LocalizerService/Stable", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(LocalizerServiceServer).Stable(ctx, req.(*Empty)) + } + return interceptor(ctx, in, info, handler) +} + +var _LocalizerService_serviceDesc = grpc.ServiceDesc{ + ServiceName: "api.v1.LocalizerService", + HandlerType: (*LocalizerServiceServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "List", + Handler: _LocalizerService_List_Handler, + }, + { + MethodName: "Ping", + Handler: _LocalizerService_Ping_Handler, + }, + { + MethodName: "Kill", + Handler: _LocalizerService_Kill_Handler, + }, + { + MethodName: "Stable", + Handler: _LocalizerService_Stable_Handler, + }, + }, + Streams: []grpc.StreamDesc{ + { + StreamName: "ExposeService", + Handler: _LocalizerService_ExposeService_Handler, + ServerStreams: true, + }, + { + StreamName: "StopExpose", + Handler: _LocalizerService_StopExpose_Handler, + ServerStreams: true, + }, + }, + Metadata: "v1.proto", +} diff --git a/api/v1/v1.proto b/api/v1.proto similarity index 90% rename from api/v1/v1.proto rename to api/v1.proto index 82e2c04..d44b67c 100644 --- a/api/v1/v1.proto +++ b/api/v1.proto @@ -15,7 +15,7 @@ syntax = "proto3"; package api.v1; -option go_package = "github.com/getoutreach/localizer/api/v1"; +option go_package = "github.com/getoutreach/localizer/api"; message ExposeServiceRequest { string namespace = 1; @@ -65,9 +65,17 @@ message ListResponse { repeated ListService services = 1; } +message Empty {} + +message StableResponse { + bool stable = 1; +} + service LocalizerService { rpc ExposeService(ExposeServiceRequest) returns (stream ConsoleResponse) {} rpc StopExpose(StopExposeRequest) returns (stream ConsoleResponse) {} rpc List(ListRequest) returns (ListResponse) {} rpc Ping(PingRequest) returns (PingResponse) {} + rpc Kill(Empty) returns (Empty) {} + rpc Stable(Empty) returns (StableResponse) {} } diff --git a/api/v1/v1_grpc.pb.go b/api/v1/v1_grpc.pb.go deleted file mode 100644 index c3ed97e..0000000 --- a/api/v1/v1_grpc.pb.go +++ /dev/null @@ -1,261 +0,0 @@ -// Code generated by protoc-gen-go-grpc. DO NOT EDIT. - -package v1 - -import ( - context "context" - - grpc "google.golang.org/grpc" - codes "google.golang.org/grpc/codes" - status "google.golang.org/grpc/status" -) - -// 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.SupportPackageIsVersion7 - -// LocalizerServiceClient is the client API for LocalizerService service. -// -// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. -type LocalizerServiceClient interface { - ExposeService(ctx context.Context, in *ExposeServiceRequest, opts ...grpc.CallOption) (LocalizerService_ExposeServiceClient, error) - StopExpose(ctx context.Context, in *StopExposeRequest, opts ...grpc.CallOption) (LocalizerService_StopExposeClient, error) - List(ctx context.Context, in *ListRequest, opts ...grpc.CallOption) (*ListResponse, error) - Ping(ctx context.Context, in *PingRequest, opts ...grpc.CallOption) (*PingResponse, error) -} - -type localizerServiceClient struct { - cc grpc.ClientConnInterface -} - -func NewLocalizerServiceClient(cc grpc.ClientConnInterface) LocalizerServiceClient { - return &localizerServiceClient{cc} -} - -func (c *localizerServiceClient) ExposeService(ctx context.Context, in *ExposeServiceRequest, opts ...grpc.CallOption) (LocalizerService_ExposeServiceClient, error) { - stream, err := c.cc.NewStream(ctx, &_LocalizerService_serviceDesc.Streams[0], "/api.v1.LocalizerService/ExposeService", opts...) - if err != nil { - return nil, err - } - x := &localizerServiceExposeServiceClient{stream} - if err := x.ClientStream.SendMsg(in); err != nil { - return nil, err - } - if err := x.ClientStream.CloseSend(); err != nil { - return nil, err - } - return x, nil -} - -type LocalizerService_ExposeServiceClient interface { - Recv() (*ConsoleResponse, error) - grpc.ClientStream -} - -type localizerServiceExposeServiceClient struct { - grpc.ClientStream -} - -func (x *localizerServiceExposeServiceClient) Recv() (*ConsoleResponse, error) { - m := new(ConsoleResponse) - if err := x.ClientStream.RecvMsg(m); err != nil { - return nil, err - } - return m, nil -} - -func (c *localizerServiceClient) StopExpose(ctx context.Context, in *StopExposeRequest, opts ...grpc.CallOption) (LocalizerService_StopExposeClient, error) { - stream, err := c.cc.NewStream(ctx, &_LocalizerService_serviceDesc.Streams[1], "/api.v1.LocalizerService/StopExpose", opts...) - if err != nil { - return nil, err - } - x := &localizerServiceStopExposeClient{stream} - if err := x.ClientStream.SendMsg(in); err != nil { - return nil, err - } - if err := x.ClientStream.CloseSend(); err != nil { - return nil, err - } - return x, nil -} - -type LocalizerService_StopExposeClient interface { - Recv() (*ConsoleResponse, error) - grpc.ClientStream -} - -type localizerServiceStopExposeClient struct { - grpc.ClientStream -} - -func (x *localizerServiceStopExposeClient) Recv() (*ConsoleResponse, error) { - m := new(ConsoleResponse) - if err := x.ClientStream.RecvMsg(m); err != nil { - return nil, err - } - return m, nil -} - -func (c *localizerServiceClient) List(ctx context.Context, in *ListRequest, opts ...grpc.CallOption) (*ListResponse, error) { - out := new(ListResponse) - err := c.cc.Invoke(ctx, "/api.v1.LocalizerService/List", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *localizerServiceClient) Ping(ctx context.Context, in *PingRequest, opts ...grpc.CallOption) (*PingResponse, error) { - out := new(PingResponse) - err := c.cc.Invoke(ctx, "/api.v1.LocalizerService/Ping", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -// LocalizerServiceServer is the server API for LocalizerService service. -// All implementations must embed UnimplementedLocalizerServiceServer -// for forward compatibility -type LocalizerServiceServer interface { - ExposeService(*ExposeServiceRequest, LocalizerService_ExposeServiceServer) error - StopExpose(*StopExposeRequest, LocalizerService_StopExposeServer) error - List(context.Context, *ListRequest) (*ListResponse, error) - Ping(context.Context, *PingRequest) (*PingResponse, error) - mustEmbedUnimplementedLocalizerServiceServer() -} - -// UnimplementedLocalizerServiceServer must be embedded to have forward compatible implementations. -type UnimplementedLocalizerServiceServer struct { -} - -func (UnimplementedLocalizerServiceServer) ExposeService(*ExposeServiceRequest, LocalizerService_ExposeServiceServer) error { - return status.Errorf(codes.Unimplemented, "method ExposeService not implemented") -} -func (UnimplementedLocalizerServiceServer) StopExpose(*StopExposeRequest, LocalizerService_StopExposeServer) error { - return status.Errorf(codes.Unimplemented, "method StopExpose not implemented") -} -func (UnimplementedLocalizerServiceServer) List(context.Context, *ListRequest) (*ListResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method List not implemented") -} -func (UnimplementedLocalizerServiceServer) Ping(context.Context, *PingRequest) (*PingResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method Ping not implemented") -} -func (UnimplementedLocalizerServiceServer) mustEmbedUnimplementedLocalizerServiceServer() {} - -// UnsafeLocalizerServiceServer may be embedded to opt out of forward compatibility for this service. -// Use of this interface is not recommended, as added methods to LocalizerServiceServer will -// result in compilation errors. -type UnsafeLocalizerServiceServer interface { - mustEmbedUnimplementedLocalizerServiceServer() -} - -func RegisterLocalizerServiceServer(s grpc.ServiceRegistrar, srv LocalizerServiceServer) { - s.RegisterService(&_LocalizerService_serviceDesc, srv) -} - -func _LocalizerService_ExposeService_Handler(srv interface{}, stream grpc.ServerStream) error { - m := new(ExposeServiceRequest) - if err := stream.RecvMsg(m); err != nil { - return err - } - return srv.(LocalizerServiceServer).ExposeService(m, &localizerServiceExposeServiceServer{stream}) -} - -type LocalizerService_ExposeServiceServer interface { - Send(*ConsoleResponse) error - grpc.ServerStream -} - -type localizerServiceExposeServiceServer struct { - grpc.ServerStream -} - -func (x *localizerServiceExposeServiceServer) Send(m *ConsoleResponse) error { - return x.ServerStream.SendMsg(m) -} - -func _LocalizerService_StopExpose_Handler(srv interface{}, stream grpc.ServerStream) error { - m := new(StopExposeRequest) - if err := stream.RecvMsg(m); err != nil { - return err - } - return srv.(LocalizerServiceServer).StopExpose(m, &localizerServiceStopExposeServer{stream}) -} - -type LocalizerService_StopExposeServer interface { - Send(*ConsoleResponse) error - grpc.ServerStream -} - -type localizerServiceStopExposeServer struct { - grpc.ServerStream -} - -func (x *localizerServiceStopExposeServer) Send(m *ConsoleResponse) error { - return x.ServerStream.SendMsg(m) -} - -func _LocalizerService_List_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(ListRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(LocalizerServiceServer).List(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/api.v1.LocalizerService/List", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(LocalizerServiceServer).List(ctx, req.(*ListRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _LocalizerService_Ping_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(PingRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(LocalizerServiceServer).Ping(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/api.v1.LocalizerService/Ping", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(LocalizerServiceServer).Ping(ctx, req.(*PingRequest)) - } - return interceptor(ctx, in, info, handler) -} - -var _LocalizerService_serviceDesc = grpc.ServiceDesc{ - ServiceName: "api.v1.LocalizerService", - HandlerType: (*LocalizerServiceServer)(nil), - Methods: []grpc.MethodDesc{ - { - MethodName: "List", - Handler: _LocalizerService_List_Handler, - }, - { - MethodName: "Ping", - Handler: _LocalizerService_Ping_Handler, - }, - }, - Streams: []grpc.StreamDesc{ - { - StreamName: "ExposeService", - Handler: _LocalizerService_ExposeService_Handler, - ServerStreams: true, - }, - { - StreamName: "StopExpose", - Handler: _LocalizerService_StopExpose_Handler, - ServerStreams: true, - }, - }, - Metadata: "v1.proto", -} diff --git a/cmd/localizer/expose.go b/cmd/localizer/expose.go index 2ee4b4a..b347d59 100644 --- a/cmd/localizer/expose.go +++ b/cmd/localizer/expose.go @@ -21,7 +21,7 @@ import ( "strings" "time" - apiv1 "github.com/getoutreach/localizer/api/v1" + "github.com/getoutreach/localizer/api" "github.com/getoutreach/localizer/pkg/localizer" "github.com/pkg/errors" "github.com/sirupsen/logrus" @@ -62,21 +62,22 @@ func NewExposeCommand(log logrus.FieldLogger) *cli.Command { //nolint:funlen log.Info("connecting to localizer daemon") - client, err := localizer.Connect(ctx, grpc.WithBlock(), grpc.WithInsecure()) + client, closer, err := localizer.Connect(ctx, grpc.WithBlock(), grpc.WithInsecure()) if err != nil { return errors.Wrap(err, "failed to connect to localizer daemon") } + defer closer() - var stream apiv1.LocalizerService_ExposeServiceClient + var stream api.LocalizerService_ExposeServiceClient if c.Bool("stop") { log.Info("sending stop expose request to daemon") - stream, err = client.StopExpose(ctx, &apiv1.StopExposeRequest{ + stream, err = client.StopExpose(ctx, &api.StopExposeRequest{ Namespace: serviceNamespace, Service: serviceName, }) } else { log.Info("sending expose request to daemon") - stream, err = client.ExposeService(ctx, &apiv1.ExposeServiceRequest{ + stream, err = client.ExposeService(ctx, &api.ExposeServiceRequest{ PortMap: c.StringSlice("map"), Namespace: serviceNamespace, Service: serviceName, @@ -96,10 +97,10 @@ func NewExposeCommand(log logrus.FieldLogger) *cli.Command { //nolint:funlen logger := log.Info switch res.Level { - case apiv1.ConsoleLevel_CONSOLE_LEVEL_INFO, apiv1.ConsoleLevel_CONSOLE_LEVEL_UNSPECIFIED: - case apiv1.ConsoleLevel_CONSOLE_LEVEL_WARN: + case api.ConsoleLevel_CONSOLE_LEVEL_INFO, api.ConsoleLevel_CONSOLE_LEVEL_UNSPECIFIED: + case api.ConsoleLevel_CONSOLE_LEVEL_WARN: logger = log.Warn - case apiv1.ConsoleLevel_CONSOLE_LEVEL_ERROR: + case api.ConsoleLevel_CONSOLE_LEVEL_ERROR: logger = log.Error } diff --git a/cmd/localizer/list.go b/cmd/localizer/list.go index 46a07e0..1883e7c 100644 --- a/cmd/localizer/list.go +++ b/cmd/localizer/list.go @@ -23,7 +23,7 @@ import ( "text/tabwriter" "time" - apiv1 "github.com/getoutreach/localizer/api/v1" + "github.com/getoutreach/localizer/api" "github.com/getoutreach/localizer/pkg/localizer" "github.com/pkg/errors" "github.com/sirupsen/logrus" @@ -44,12 +44,13 @@ func NewListCommand(_ logrus.FieldLogger) *cli.Command { //nolint:funlen ctx, cancel := context.WithTimeout(c.Context, 30*time.Second) defer cancel() - client, err := localizer.Connect(ctx, grpc.WithBlock(), grpc.WithInsecure()) + client, closer, err := localizer.Connect(ctx, grpc.WithBlock(), grpc.WithInsecure()) if err != nil { return errors.Wrap(err, "failed to connect to localizer daemon") } + defer closer() - resp, err := client.List(ctx, &apiv1.ListRequest{}) + resp, err := client.List(ctx, &api.ListRequest{}) if err != nil { return err } diff --git a/go.mod b/go.mod index 9ac788b..410048d 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,6 @@ require ( github.com/function61/gokit v0.0.0-20210402130425-341c2c9ecfd0 github.com/go-logr/logr v0.4.0 github.com/go-sql-driver/mysql v1.6.0 // indirect - github.com/golang/protobuf v1.5.2 github.com/google/go-cmp v0.5.5 github.com/gorilla/mux v1.8.0 // indirect github.com/imdario/mergo v0.3.12 // indirect @@ -25,6 +24,7 @@ require ( golang.org/x/net v0.0.0-20210505024714-0287a6fb4125 // indirect golang.org/x/oauth2 v0.0.0-20210427180440-81ed05c6b58c // indirect golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect + golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c // indirect golang.org/x/term v0.0.0-20210503060354-a79de5458b56 // indirect google.golang.org/genproto v0.0.0-20210505142820-a42aa055cf76 // indirect google.golang.org/grpc v1.37.0 diff --git a/go.sum b/go.sum index 909d8d3..06da5d2 100644 --- a/go.sum +++ b/go.sum @@ -790,8 +790,9 @@ golang.org/x/sys v0.0.0-20210225134936-a50acf3fe073/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210315160823-c6e025ad8005/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210423082822-04245dca01da h1:b3NXsE2LusjYGGjL5bxEVZZORm/YEFFrWFjR8eFrw/c= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c h1:F1jZWGFhYfh0Ci55sIpILtKKK8p3i2/krTr0H1rg74I= +golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= diff --git a/internal/proxier/portforward.go b/internal/proxier/portforward.go index 0dc17b4..3034969 100644 --- a/internal/proxier/portforward.go +++ b/internal/proxier/portforward.go @@ -22,6 +22,8 @@ import ( "os" "os/exec" "runtime" + "sync" + "time" "github.com/getoutreach/localizer/pkg/hostsfile" "github.com/metal-stack/go-ipam" @@ -49,6 +51,13 @@ type worker struct { // portForwards are existing port-forwards portForwards map[string]*PortForwardConnection + + // lastTouchTime is the the worker has done any work, whether it + // be creating, releasing, or updating port-forwards. The mutex + // proceeding it is used to protect this value from concurrent + // access. + lastTouchTime time.Time + touchMu sync.Mutex } // NewPortForwarder creates a new port-forward worker that handles @@ -85,15 +94,16 @@ func NewPortForwarder(ctx context.Context, k kubernetes.Interface, reqChan := make(chan PortForwardRequest, 1024) w := &worker{ - k: k, - rest: r, - log: log, - ippool: ipamInstance, - ipCidr: prefix.Cidr, - dns: hosts, - reqChan: reqChan, - doneChan: doneChan, - portForwards: make(map[string]*PortForwardConnection), + k: k, + rest: r, + log: log, + ippool: ipamInstance, + ipCidr: prefix.Cidr, + dns: hosts, + reqChan: reqChan, + doneChan: doneChan, + portForwards: make(map[string]*PortForwardConnection), + lastTouchTime: time.Now(), } go w.Start(ctx) @@ -140,6 +150,26 @@ func (w *worker) Start(ctx context.Context) { } } +// touch notes that the worker is being touched by the proxier. +func (w *worker) touch() { + w.touchMu.Lock() + defer w.touchMu.Unlock() + + w.lastTouchTime = time.Now() +} + +// isStable returns true if the worker hasn't been touched in 2 seconds or +// longer, and returns false otherwise. This was inteded to be used to denote +// some sort of "readiness", as the worker will be constantly creating +// port-forwards when starting up, draining the initial queue created by +// the proxier. +func (w *worker) isStable() bool { + w.touchMu.Lock() + defer w.touchMu.Unlock() + + return time.Since(w.lastTouchTime) >= time.Second*2 +} + // getPodForService finds the first available endpoint for a given service func (w *worker) getPodForService(ctx context.Context, si *ServiceInfo) (PodInfo, error) { e, err := w.k.CoreV1().Endpoints(si.Namespace).Get(ctx, si.Name, metav1.GetOptions{}) @@ -188,6 +218,9 @@ func (w *worker) CreatePortForward(ctx context.Context, req *CreatePortForwardRe return fmt.Errorf("already have a port-forward for this service") } + // The worker is doing meaningful work, not a no-op, note this. + w.touch() + if req.Recreate { log.Infof("recreating port-forward due to: %v", req.RecreateReason) w.setPortForwardConnectionStatus(ctx, req.Service, PortForwardStatusRecreating, req.RecreateReason) @@ -382,6 +415,9 @@ func (w *worker) DeletePortForward(ctx context.Context, req *DeletePortForwardRe return nil } + // The worker is doing meaningful work, not a no-op, note this. + w.touch() + if err := w.stopPortForward(ctx, w.portForwards[serviceKey]); err != nil { log.WithError(err).Warn("failed to cleanup port-forward") } diff --git a/internal/proxier/proxy.go b/internal/proxier/proxy.go index b3a3482..e3c19f7 100644 --- a/internal/proxier/proxy.go +++ b/internal/proxier/proxy.go @@ -122,6 +122,20 @@ func NewProxier(ctx context.Context, k kubernetes.Interface, kconf *rest.Config, return p, nil } +// IsStable is a pass-through function to *worker.isStable. This is mostly to +// determine if the initial queue has been drained by checking if the worker +// that the proxier is using has created, deleted, or updated a port-forward +// in the last 2 seconds. +func (p *Proxier) IsStable() bool { + if p.worker == nil { + // Proxier hasn't actually finished being created yet, definitely not + // stable. + return false + } + + return p.worker.isStable() +} + // Start starts the proxier // TODO: replace raw cluster domain with options struct, maybe also // move into NewProxier diff --git a/internal/server/expose.go b/internal/server/expose.go index 01ebddc..c5976ba 100644 --- a/internal/server/expose.go +++ b/internal/server/expose.go @@ -27,7 +27,7 @@ import ( "k8s.io/client-go/kubernetes" "k8s.io/client-go/rest" - apiv1 "github.com/getoutreach/localizer/api/v1" + "github.com/getoutreach/localizer/api" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -197,11 +197,11 @@ func (e *Exposer) Start(ports []kube.ResolvedServicePort, namespace, serviceName return nil } -func (h *GRPCServiceHandler) StopExpose(req *apiv1.StopExposeRequest, res apiv1.LocalizerService_StopExposeServer) error { +func (h *GRPCServiceHandler) StopExpose(req *api.StopExposeRequest, res api.LocalizerService_StopExposeServer) error { return h.exp.Close(req.Namespace, req.Service) } -func (h *GRPCServiceHandler) ExposeService(req *apiv1.ExposeServiceRequest, res apiv1.LocalizerService_ExposeServiceServer) error { +func (h *GRPCServiceHandler) ExposeService(req *api.ExposeServiceRequest, res api.LocalizerService_ExposeServiceServer) error { log := h.log ctx := h.ctx diff --git a/internal/server/grpc.go b/internal/server/grpc.go index f25a2c6..0678d3a 100644 --- a/internal/server/grpc.go +++ b/internal/server/grpc.go @@ -25,7 +25,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/reflection" - apiv1 "github.com/getoutreach/localizer/api/v1" + "github.com/getoutreach/localizer/api" "github.com/getoutreach/localizer/internal/kevents" "github.com/getoutreach/localizer/pkg/localizer" ) @@ -56,12 +56,13 @@ func (g *GRPCService) CleanupPreviousInstance(ctx context.Context, log logrus.Fi defer cancel() log.Info("checking if an instance of localizer is already running") - client, err := localizer.Connect(ctx, grpc.WithBlock(), grpc.WithInsecure()) + client, closer, err := localizer.Connect(ctx, grpc.WithBlock(), grpc.WithInsecure()) // if we made a connection, see if it's responding to pings // eventually we can expose useful information here? if err == nil { - if _, err := client.Ping(ctx, &apiv1.PingRequest{}); err == nil { + defer closer() + if _, err := client.Ping(ctx, &api.PingRequest{}); err == nil { return fmt.Errorf("localizer instance is already running") } } @@ -107,7 +108,7 @@ func (g *GRPCService) Run(ctx context.Context, log logrus.FieldLogger) error { / g.srv = grpc.NewServer() reflection.Register(g.srv) - apiv1.RegisterLocalizerServiceServer(g.srv, h) + api.RegisterLocalizerServiceServer(g.srv, h) // handle closing the server go func() { @@ -117,7 +118,7 @@ func (g *GRPCService) Run(ctx context.Context, log logrus.FieldLogger) error { / }() // One day Serve() will accept a context? - log.Infof("starting GRPC server on unix://'%s'", localizer.Socket) + log.Infof("starting GRPC server on unix://%s", localizer.Socket) go func() { err := g.srv.Serve(g.lis) if err != nil { diff --git a/internal/server/grpc_server.go b/internal/server/grpc_server.go index 661f96d..171cc6d 100644 --- a/internal/server/grpc_server.go +++ b/internal/server/grpc_server.go @@ -22,7 +22,7 @@ import ( "k8s.io/client-go/rest" ///StartBlock(imports) - apiv1 "github.com/getoutreach/localizer/api/v1" + "github.com/getoutreach/localizer/api" "github.com/getoutreach/localizer/internal/kube" "github.com/getoutreach/localizer/internal/proxier" ///EndBlock(imports) @@ -33,7 +33,7 @@ import ( type GRPCServiceHandler struct { log logrus.FieldLogger - apiv1.UnimplementedLocalizerServiceServer + api.UnimplementedLocalizerServiceServer ///StartBlock(grpcConfig) k kubernetes.Interface diff --git a/internal/server/kill.go b/internal/server/kill.go new file mode 100644 index 0000000..d3df1c0 --- /dev/null +++ b/internal/server/kill.go @@ -0,0 +1,34 @@ +package server + +import ( + "context" + "os" + "time" + + "github.com/getoutreach/localizer/api" + "github.com/getoutreach/localizer/pkg/localizer" + "github.com/pkg/errors" +) + +// Kill implements the Kill RPC for the localizer gRPC server. +// +// This RPC just kills the current localizer process. Note that it actually waits until +// after the RPC returns (responds) before killing the process because if it kills it +// before it attempts to respond, the transport will have been closed already, resulting +// in a perceived error. Because of this stipulation, this RPC is only BEST EFFORT. +func (*GRPCServiceHandler) Kill(ctx context.Context, _ *api.Empty) (*api.Empty, error) { + p, err := os.FindProcess(os.Getpid()) + if err != nil { + return nil, errors.Wrap(err, "find localizer process") + } + + go func(process *os.Process) { + // Give the RPC time to respond. It doesn't need much time, because it is using the local network. + time.Sleep(time.Second * 1) + + _ = os.Remove(localizer.Socket) //nolint:errcheck // Why: We can't do anything about this error, it's best effort. + _ = process.Kill() //nolint:errcheck // Why: We can't do anything about this error, it's best effort. + }(p) + + return &api.Empty{}, nil +} diff --git a/internal/server/list.go b/internal/server/list.go index 79a2eef..0b21b63 100644 --- a/internal/server/list.go +++ b/internal/server/list.go @@ -18,16 +18,16 @@ import ( "fmt" "strings" - apiv1 "github.com/getoutreach/localizer/api/v1" + "github.com/getoutreach/localizer/api" ) -func (h *GRPCServiceHandler) List(ctx context.Context, req *apiv1.ListRequest) (*apiv1.ListResponse, error) { +func (h *GRPCServiceHandler) List(ctx context.Context, req *api.ListRequest) (*api.ListResponse, error) { statuses, err := h.p.List(ctx) if err != nil { return nil, err } - services := make([]*apiv1.ListService, len(statuses)) + services := make([]*api.ListService, len(statuses)) for i := range statuses { s := &statuses[i] @@ -47,7 +47,7 @@ func (h *GRPCServiceHandler) List(ctx context.Context, req *apiv1.ListRequest) ( } } - services[i] = &apiv1.ListService{ + services[i] = &api.ListService{ Namespace: s.ServiceInfo.Namespace, Name: s.ServiceInfo.Name, Endpoint: s.Endpoint.Name, @@ -58,5 +58,5 @@ func (h *GRPCServiceHandler) List(ctx context.Context, req *apiv1.ListRequest) ( } } - return &apiv1.ListResponse{Services: services}, nil + return &api.ListResponse{Services: services}, nil } diff --git a/internal/server/ping.go b/internal/server/ping.go index 5265a21..ee23ed4 100644 --- a/internal/server/ping.go +++ b/internal/server/ping.go @@ -16,9 +16,9 @@ package server import ( "context" - apiv1 "github.com/getoutreach/localizer/api/v1" + "github.com/getoutreach/localizer/api" ) -func (h *GRPCServiceHandler) Ping(ctx context.Context, req *apiv1.PingRequest) (*apiv1.PingResponse, error) { - return &apiv1.PingResponse{}, nil +func (h *GRPCServiceHandler) Ping(ctx context.Context, req *api.PingRequest) (*api.PingResponse, error) { + return &api.PingResponse{}, nil } diff --git a/internal/server/stable.go b/internal/server/stable.go new file mode 100644 index 0000000..43133bb --- /dev/null +++ b/internal/server/stable.go @@ -0,0 +1,14 @@ +package server + +import ( + "context" + + "github.com/getoutreach/localizer/api" +) + +// Stable implements the Stable RPC for the localizer gRPC server. +func (g *GRPCServiceHandler) Stable(ctx context.Context, _ *api.Empty) (*api.StableResponse, error) { + return &api.StableResponse{ + Stable: g.p.IsStable(), + }, nil +} diff --git a/pkg/localizer/localizer.go b/pkg/localizer/localizer.go index f1a8b48..b5167b5 100644 --- a/pkg/localizer/localizer.go +++ b/pkg/localizer/localizer.go @@ -7,7 +7,7 @@ import ( "fmt" "os" - apiv1 "github.com/getoutreach/localizer/api/v1" + "github.com/getoutreach/localizer/api" "github.com/pkg/errors" "google.golang.org/grpc" ) @@ -27,11 +27,13 @@ func IsRunning() bool { // Connect returns a new instance of LocalizerServiceClient given a gRPC client // connection (returned from grpc.Dial*). -func Connect(ctx context.Context, opts ...grpc.DialOption) (apiv1.LocalizerServiceClient, error) { +func Connect(ctx context.Context, opts ...grpc.DialOption) (client api.LocalizerServiceClient, closer func(), err error) { clientConn, err := grpc.DialContext(ctx, fmt.Sprintf("unix://%s", Socket), opts...) if err != nil { - return nil, errors.Wrap(err, "dial localizer") + return nil, nil, errors.Wrap(err, "dial localizer") } - return apiv1.NewLocalizerServiceClient(clientConn), nil + return api.NewLocalizerServiceClient(clientConn), func() { + _ = clientConn.Close() //nolint:errcheck // Why: We can't do anything about an error regarding closing the client connection. We eat the error here so we don't have to nolint on every call. + }, nil }