From c3ba43a8fa19c9f45e93da8060fc7ce8b251a834 Mon Sep 17 00:00:00 2001 From: Pavel Sviderski Date: Wed, 2 Oct 2024 13:03:17 +1000 Subject: [PATCH] delete old non-distributed cluster state, fix storing endpoints in store --- Makefile | 4 + internal/cli/cli.go | 5 +- internal/machine/api/pb/cluster.go | 8 - internal/machine/api/pb/cluster.pb.go | 660 ++------------------- internal/machine/api/pb/cluster.proto | 43 +- internal/machine/api/pb/cluster_grpc.pb.go | 42 +- internal/machine/api/pb/machine.pb.go | 350 ++++++++--- internal/machine/api/pb/machine.proto | 14 +- internal/machine/cluster/cluster.go | 44 +- internal/machine/cluster/state.go | 60 -- internal/machine/machine.go | 60 +- 11 files changed, 357 insertions(+), 933 deletions(-) delete mode 100644 internal/machine/cluster/state.go diff --git a/Makefile b/Makefile index 14dfd528..d45b4cca 100644 --- a/Makefile +++ b/Makefile @@ -11,6 +11,10 @@ uncloud-dev: scp uncloud-linux-amd64 spy@192.168.40.176:~/ && \ ssh spy@192.168.40.176 sudo install ./uncloud-linux-amd64 /usr/local/bin/uncloud +reset-dev: + ssh spy@192.168.40.243 "sudo systemctl stop uncloud && sudo rm -rf /var/lib/uncloud" + ssh spy@192.168.40.176 "sudo systemctl stop uncloud && sudo rm -rf /var/lib/uncloud" + .PHONY: proto proto: protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative internal/machine/api/pb/*.proto diff --git a/internal/cli/cli.go b/internal/cli/cli.go index 8f93ec2d..5bed991e 100644 --- a/internal/cli/cli.go +++ b/internal/cli/cli.go @@ -15,6 +15,7 @@ import ( "uncloud/internal/cli/config" "uncloud/internal/machine" "uncloud/internal/machine/api/pb" + "uncloud/internal/machine/network" "uncloud/internal/secret" "uncloud/internal/sshexec" ) @@ -332,13 +333,13 @@ func (cli *CLI) ListMachines(ctx context.Context, clusterName string) error { // Print the list of machines in a table format. tw := tabwriter.NewWriter(os.Stdout, 0, 0, 3, ' ', 0) // Print header. - // TODO: print ADDRESS instead of SUBNET which is a machine IP with prefix. - if _, err = fmt.Fprintln(tw, "NAME\tSUBNET\tPUBLIC KEY\tENDPOINTS"); err != nil { + if _, err = fmt.Fprintln(tw, "NAME\tADDRESS\tPUBLIC KEY\tENDPOINTS"); err != nil { return fmt.Errorf("write header: %w", err) } // Print rows. for _, m := range listResp.Machines { subnet, _ := m.Network.Subnet.ToPrefix() + subnet = netip.PrefixFrom(network.MachineIP(subnet), subnet.Bits()) endpoints := make([]string, len(m.Network.Endpoints)) for i, ep := range m.Network.Endpoints { addrPort, _ := ep.ToAddrPort() diff --git a/internal/machine/api/pb/cluster.go b/internal/machine/api/pb/cluster.go index 53d6fc43..75505d01 100644 --- a/internal/machine/api/pb/cluster.go +++ b/internal/machine/api/pb/cluster.go @@ -1,7 +1,6 @@ package pb import ( - "fmt" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" ) @@ -40,10 +39,3 @@ func (c *NetworkConfig) Validate() error { return nil } - -func (r *AddMachineRequest) Validate() error { - if r.Network == nil { - return fmt.Errorf("network not set") - } - return r.Network.Validate() -} diff --git a/internal/machine/api/pb/cluster.pb.go b/internal/machine/api/pb/cluster.pb.go index 6371b988..4fd1352e 100644 --- a/internal/machine/api/pb/cluster.pb.go +++ b/internal/machine/api/pb/cluster.pb.go @@ -170,409 +170,6 @@ func (x *ListMachinesResponse) GetMachines() []*MachineInfo { return nil } -type ListMachineEndpointsRequest struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` -} - -func (x *ListMachineEndpointsRequest) Reset() { - *x = ListMachineEndpointsRequest{} - if protoimpl.UnsafeEnabled { - mi := &file_internal_machine_api_pb_cluster_proto_msgTypes[3] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *ListMachineEndpointsRequest) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*ListMachineEndpointsRequest) ProtoMessage() {} - -func (x *ListMachineEndpointsRequest) ProtoReflect() protoreflect.Message { - mi := &file_internal_machine_api_pb_cluster_proto_msgTypes[3] - 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 ListMachineEndpointsRequest.ProtoReflect.Descriptor instead. -func (*ListMachineEndpointsRequest) Descriptor() ([]byte, []int) { - return file_internal_machine_api_pb_cluster_proto_rawDescGZIP(), []int{3} -} - -func (x *ListMachineEndpointsRequest) GetId() string { - if x != nil { - return x.Id - } - return "" -} - -type ListMachineEndpointsResponse struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Endpoints *MachineEndpoints `protobuf:"bytes,1,opt,name=endpoints,proto3" json:"endpoints,omitempty"` -} - -func (x *ListMachineEndpointsResponse) Reset() { - *x = ListMachineEndpointsResponse{} - if protoimpl.UnsafeEnabled { - mi := &file_internal_machine_api_pb_cluster_proto_msgTypes[4] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *ListMachineEndpointsResponse) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*ListMachineEndpointsResponse) ProtoMessage() {} - -func (x *ListMachineEndpointsResponse) ProtoReflect() protoreflect.Message { - mi := &file_internal_machine_api_pb_cluster_proto_msgTypes[4] - 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 ListMachineEndpointsResponse.ProtoReflect.Descriptor instead. -func (*ListMachineEndpointsResponse) Descriptor() ([]byte, []int) { - return file_internal_machine_api_pb_cluster_proto_rawDescGZIP(), []int{4} -} - -func (x *ListMachineEndpointsResponse) GetEndpoints() *MachineEndpoints { - if x != nil { - return x.Endpoints - } - return nil -} - -type MachineInfo struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` - Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"` - Network *NetworkConfig `protobuf:"bytes,3,opt,name=network,proto3" json:"network,omitempty"` -} - -func (x *MachineInfo) Reset() { - *x = MachineInfo{} - if protoimpl.UnsafeEnabled { - mi := &file_internal_machine_api_pb_cluster_proto_msgTypes[5] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *MachineInfo) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*MachineInfo) ProtoMessage() {} - -func (x *MachineInfo) ProtoReflect() protoreflect.Message { - mi := &file_internal_machine_api_pb_cluster_proto_msgTypes[5] - 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 MachineInfo.ProtoReflect.Descriptor instead. -func (*MachineInfo) Descriptor() ([]byte, []int) { - return file_internal_machine_api_pb_cluster_proto_rawDescGZIP(), []int{5} -} - -func (x *MachineInfo) GetId() string { - if x != nil { - return x.Id - } - return "" -} - -func (x *MachineInfo) GetName() string { - if x != nil { - return x.Name - } - return "" -} - -func (x *MachineInfo) GetNetwork() *NetworkConfig { - if x != nil { - return x.Network - } - return nil -} - -type NetworkConfig struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Subnet *IPPrefix `protobuf:"bytes,1,opt,name=subnet,proto3" json:"subnet,omitempty"` - ManagementIp *IP `protobuf:"bytes,2,opt,name=management_ip,json=managementIp,proto3" json:"management_ip,omitempty"` - Endpoints []*IPPort `protobuf:"bytes,3,rep,name=endpoints,proto3" json:"endpoints,omitempty"` - PublicKey []byte `protobuf:"bytes,4,opt,name=publicKey,proto3" json:"publicKey,omitempty"` -} - -func (x *NetworkConfig) Reset() { - *x = NetworkConfig{} - if protoimpl.UnsafeEnabled { - mi := &file_internal_machine_api_pb_cluster_proto_msgTypes[6] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *NetworkConfig) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*NetworkConfig) ProtoMessage() {} - -func (x *NetworkConfig) ProtoReflect() protoreflect.Message { - mi := &file_internal_machine_api_pb_cluster_proto_msgTypes[6] - 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 NetworkConfig.ProtoReflect.Descriptor instead. -func (*NetworkConfig) Descriptor() ([]byte, []int) { - return file_internal_machine_api_pb_cluster_proto_rawDescGZIP(), []int{6} -} - -func (x *NetworkConfig) GetSubnet() *IPPrefix { - if x != nil { - return x.Subnet - } - return nil -} - -func (x *NetworkConfig) GetManagementIp() *IP { - if x != nil { - return x.ManagementIp - } - return nil -} - -func (x *NetworkConfig) GetEndpoints() []*IPPort { - if x != nil { - return x.Endpoints - } - return nil -} - -func (x *NetworkConfig) GetPublicKey() []byte { - if x != nil { - return x.PublicKey - } - return nil -} - -type MachineEndpoints struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` - Endpoints []*IPPort `protobuf:"bytes,2,rep,name=endpoints,proto3" json:"endpoints,omitempty"` -} - -func (x *MachineEndpoints) Reset() { - *x = MachineEndpoints{} - if protoimpl.UnsafeEnabled { - mi := &file_internal_machine_api_pb_cluster_proto_msgTypes[7] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *MachineEndpoints) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*MachineEndpoints) ProtoMessage() {} - -func (x *MachineEndpoints) ProtoReflect() protoreflect.Message { - mi := &file_internal_machine_api_pb_cluster_proto_msgTypes[7] - 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 MachineEndpoints.ProtoReflect.Descriptor instead. -func (*MachineEndpoints) Descriptor() ([]byte, []int) { - return file_internal_machine_api_pb_cluster_proto_rawDescGZIP(), []int{7} -} - -func (x *MachineEndpoints) GetId() string { - if x != nil { - return x.Id - } - return "" -} - -func (x *MachineEndpoints) GetEndpoints() []*IPPort { - if x != nil { - return x.Endpoints - } - return nil -} - -type User struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Network *NetworkConfig `protobuf:"bytes,1,opt,name=network,proto3" json:"network,omitempty"` -} - -func (x *User) Reset() { - *x = User{} - if protoimpl.UnsafeEnabled { - mi := &file_internal_machine_api_pb_cluster_proto_msgTypes[8] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *User) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*User) ProtoMessage() {} - -func (x *User) ProtoReflect() protoreflect.Message { - mi := &file_internal_machine_api_pb_cluster_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 User.ProtoReflect.Descriptor instead. -func (*User) Descriptor() ([]byte, []int) { - return file_internal_machine_api_pb_cluster_proto_rawDescGZIP(), []int{8} -} - -func (x *User) GetNetwork() *NetworkConfig { - if x != nil { - return x.Network - } - return nil -} - -type State struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Network *IPPrefix `protobuf:"bytes,1,opt,name=Network,proto3" json:"Network,omitempty"` - // The machine configuration in the state is the source of truth set by the administrator. - // The machine itself can't update it. - Machines map[string]*MachineInfo `protobuf:"bytes,2,rep,name=machines,proto3" json:"machines,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` - Endpoints map[string]*MachineEndpoints `protobuf:"bytes,3,rep,name=endpoints,proto3" json:"endpoints,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` - Users []*User `protobuf:"bytes,4,rep,name=users,proto3" json:"users,omitempty"` -} - -func (x *State) Reset() { - *x = State{} - if protoimpl.UnsafeEnabled { - mi := &file_internal_machine_api_pb_cluster_proto_msgTypes[9] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *State) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*State) ProtoMessage() {} - -func (x *State) ProtoReflect() protoreflect.Message { - mi := &file_internal_machine_api_pb_cluster_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 State.ProtoReflect.Descriptor instead. -func (*State) Descriptor() ([]byte, []int) { - return file_internal_machine_api_pb_cluster_proto_rawDescGZIP(), []int{9} -} - -func (x *State) GetNetwork() *IPPrefix { - if x != nil { - return x.Network - } - return nil -} - -func (x *State) GetMachines() map[string]*MachineInfo { - if x != nil { - return x.Machines - } - return nil -} - -func (x *State) GetEndpoints() map[string]*MachineEndpoints { - if x != nil { - return x.Endpoints - } - return nil -} - -func (x *State) GetUsers() []*User { - if x != nil { - return x.Users - } - return nil -} - var File_internal_machine_api_pb_cluster_proto protoreflect.FileDescriptor var file_internal_machine_api_pb_cluster_proto_rawDesc = []byte{ @@ -580,80 +177,24 @@ var file_internal_machine_api_pb_cluster_proto_rawDesc = []byte{ 0x6e, 0x65, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x70, 0x62, 0x2f, 0x63, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x03, 0x61, 0x70, 0x69, 0x1a, 0x1b, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x65, 0x6d, - 0x70, 0x74, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x24, 0x69, 0x6e, 0x74, 0x65, 0x72, + 0x70, 0x74, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x25, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x6d, 0x61, 0x63, 0x68, 0x69, 0x6e, 0x65, 0x2f, 0x61, 0x70, 0x69, 0x2f, - 0x70, 0x62, 0x2f, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, - 0x55, 0x0a, 0x11, 0x41, 0x64, 0x64, 0x4d, 0x61, 0x63, 0x68, 0x69, 0x6e, 0x65, 0x52, 0x65, 0x71, - 0x75, 0x65, 0x73, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, - 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x2c, 0x0a, 0x07, 0x6e, 0x65, 0x74, 0x77, - 0x6f, 0x72, 0x6b, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x12, 0x2e, 0x61, 0x70, 0x69, 0x2e, - 0x4e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x52, 0x07, 0x6e, - 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x22, 0x40, 0x0a, 0x12, 0x41, 0x64, 0x64, 0x4d, 0x61, 0x63, - 0x68, 0x69, 0x6e, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x2a, 0x0a, 0x07, - 0x6d, 0x61, 0x63, 0x68, 0x69, 0x6e, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, - 0x61, 0x70, 0x69, 0x2e, 0x4d, 0x61, 0x63, 0x68, 0x69, 0x6e, 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x52, - 0x07, 0x6d, 0x61, 0x63, 0x68, 0x69, 0x6e, 0x65, 0x22, 0x44, 0x0a, 0x14, 0x4c, 0x69, 0x73, 0x74, - 0x4d, 0x61, 0x63, 0x68, 0x69, 0x6e, 0x65, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, - 0x12, 0x2c, 0x0a, 0x08, 0x6d, 0x61, 0x63, 0x68, 0x69, 0x6e, 0x65, 0x73, 0x18, 0x01, 0x20, 0x03, - 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x4d, 0x61, 0x63, 0x68, 0x69, 0x6e, 0x65, - 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x08, 0x6d, 0x61, 0x63, 0x68, 0x69, 0x6e, 0x65, 0x73, 0x22, 0x2d, - 0x0a, 0x1b, 0x4c, 0x69, 0x73, 0x74, 0x4d, 0x61, 0x63, 0x68, 0x69, 0x6e, 0x65, 0x45, 0x6e, 0x64, - 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x0e, 0x0a, - 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x22, 0x53, 0x0a, - 0x1c, 0x4c, 0x69, 0x73, 0x74, 0x4d, 0x61, 0x63, 0x68, 0x69, 0x6e, 0x65, 0x45, 0x6e, 0x64, 0x70, - 0x6f, 0x69, 0x6e, 0x74, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x33, 0x0a, - 0x09, 0x65, 0x6e, 0x64, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, - 0x32, 0x15, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x4d, 0x61, 0x63, 0x68, 0x69, 0x6e, 0x65, 0x45, 0x6e, - 0x64, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x73, 0x52, 0x09, 0x65, 0x6e, 0x64, 0x70, 0x6f, 0x69, 0x6e, - 0x74, 0x73, 0x22, 0x5f, 0x0a, 0x0b, 0x4d, 0x61, 0x63, 0x68, 0x69, 0x6e, 0x65, 0x49, 0x6e, 0x66, - 0x6f, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, - 0x64, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, - 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x2c, 0x0a, 0x07, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, - 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x12, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x4e, 0x65, 0x74, - 0x77, 0x6f, 0x72, 0x6b, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x52, 0x07, 0x6e, 0x65, 0x74, 0x77, - 0x6f, 0x72, 0x6b, 0x22, 0xad, 0x01, 0x0a, 0x0d, 0x4e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x43, - 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12, 0x25, 0x0a, 0x06, 0x73, 0x75, 0x62, 0x6e, 0x65, 0x74, 0x18, - 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0d, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x49, 0x50, 0x50, 0x72, - 0x65, 0x66, 0x69, 0x78, 0x52, 0x06, 0x73, 0x75, 0x62, 0x6e, 0x65, 0x74, 0x12, 0x2c, 0x0a, 0x0d, - 0x6d, 0x61, 0x6e, 0x61, 0x67, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x5f, 0x69, 0x70, 0x18, 0x02, 0x20, - 0x01, 0x28, 0x0b, 0x32, 0x07, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x49, 0x50, 0x52, 0x0c, 0x6d, 0x61, - 0x6e, 0x61, 0x67, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x49, 0x70, 0x12, 0x29, 0x0a, 0x09, 0x65, 0x6e, - 0x64, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0b, 0x2e, - 0x61, 0x70, 0x69, 0x2e, 0x49, 0x50, 0x50, 0x6f, 0x72, 0x74, 0x52, 0x09, 0x65, 0x6e, 0x64, 0x70, - 0x6f, 0x69, 0x6e, 0x74, 0x73, 0x12, 0x1c, 0x0a, 0x09, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x4b, - 0x65, 0x79, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x09, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63, - 0x4b, 0x65, 0x79, 0x22, 0x4d, 0x0a, 0x10, 0x4d, 0x61, 0x63, 0x68, 0x69, 0x6e, 0x65, 0x45, 0x6e, - 0x64, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x73, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, - 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x29, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x70, 0x6f, - 0x69, 0x6e, 0x74, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0b, 0x2e, 0x61, 0x70, 0x69, - 0x2e, 0x49, 0x50, 0x50, 0x6f, 0x72, 0x74, 0x52, 0x09, 0x65, 0x6e, 0x64, 0x70, 0x6f, 0x69, 0x6e, - 0x74, 0x73, 0x22, 0x34, 0x0a, 0x04, 0x55, 0x73, 0x65, 0x72, 0x12, 0x2c, 0x0a, 0x07, 0x6e, 0x65, - 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x12, 0x2e, 0x61, 0x70, - 0x69, 0x2e, 0x4e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x52, - 0x07, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x22, 0xe4, 0x02, 0x0a, 0x05, 0x53, 0x74, 0x61, - 0x74, 0x65, 0x12, 0x27, 0x0a, 0x07, 0x4e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x18, 0x01, 0x20, - 0x01, 0x28, 0x0b, 0x32, 0x0d, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x49, 0x50, 0x50, 0x72, 0x65, 0x66, - 0x69, 0x78, 0x52, 0x07, 0x4e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x12, 0x34, 0x0a, 0x08, 0x6d, - 0x61, 0x63, 0x68, 0x69, 0x6e, 0x65, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x18, 0x2e, - 0x61, 0x70, 0x69, 0x2e, 0x53, 0x74, 0x61, 0x74, 0x65, 0x2e, 0x4d, 0x61, 0x63, 0x68, 0x69, 0x6e, - 0x65, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x08, 0x6d, 0x61, 0x63, 0x68, 0x69, 0x6e, 0x65, - 0x73, 0x12, 0x37, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x73, 0x18, 0x03, - 0x20, 0x03, 0x28, 0x0b, 0x32, 0x19, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x53, 0x74, 0x61, 0x74, 0x65, - 0x2e, 0x45, 0x6e, 0x64, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, - 0x09, 0x65, 0x6e, 0x64, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x73, 0x12, 0x1f, 0x0a, 0x05, 0x75, 0x73, - 0x65, 0x72, 0x73, 0x18, 0x04, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x09, 0x2e, 0x61, 0x70, 0x69, 0x2e, - 0x55, 0x73, 0x65, 0x72, 0x52, 0x05, 0x75, 0x73, 0x65, 0x72, 0x73, 0x1a, 0x4d, 0x0a, 0x0d, 0x4d, - 0x61, 0x63, 0x68, 0x69, 0x6e, 0x65, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, - 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x26, - 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, - 0x61, 0x70, 0x69, 0x2e, 0x4d, 0x61, 0x63, 0x68, 0x69, 0x6e, 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x52, - 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x1a, 0x53, 0x0a, 0x0e, 0x45, 0x6e, - 0x64, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, - 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x2b, - 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x15, 0x2e, - 0x61, 0x70, 0x69, 0x2e, 0x4d, 0x61, 0x63, 0x68, 0x69, 0x6e, 0x65, 0x45, 0x6e, 0x64, 0x70, 0x6f, - 0x69, 0x6e, 0x74, 0x73, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x32, - 0xe8, 0x01, 0x0a, 0x07, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x12, 0x3d, 0x0a, 0x0a, 0x41, + 0x70, 0x62, 0x2f, 0x6d, 0x61, 0x63, 0x68, 0x69, 0x6e, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x22, 0x55, 0x0a, 0x11, 0x41, 0x64, 0x64, 0x4d, 0x61, 0x63, 0x68, 0x69, 0x6e, 0x65, 0x52, 0x65, + 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x2c, 0x0a, 0x07, 0x6e, 0x65, 0x74, + 0x77, 0x6f, 0x72, 0x6b, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x12, 0x2e, 0x61, 0x70, 0x69, + 0x2e, 0x4e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x52, 0x07, + 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x22, 0x40, 0x0a, 0x12, 0x41, 0x64, 0x64, 0x4d, 0x61, + 0x63, 0x68, 0x69, 0x6e, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x2a, 0x0a, + 0x07, 0x6d, 0x61, 0x63, 0x68, 0x69, 0x6e, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, + 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x4d, 0x61, 0x63, 0x68, 0x69, 0x6e, 0x65, 0x49, 0x6e, 0x66, 0x6f, + 0x52, 0x07, 0x6d, 0x61, 0x63, 0x68, 0x69, 0x6e, 0x65, 0x22, 0x44, 0x0a, 0x14, 0x4c, 0x69, 0x73, + 0x74, 0x4d, 0x61, 0x63, 0x68, 0x69, 0x6e, 0x65, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, + 0x65, 0x12, 0x2c, 0x0a, 0x08, 0x6d, 0x61, 0x63, 0x68, 0x69, 0x6e, 0x65, 0x73, 0x18, 0x01, 0x20, + 0x03, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x4d, 0x61, 0x63, 0x68, 0x69, 0x6e, + 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x08, 0x6d, 0x61, 0x63, 0x68, 0x69, 0x6e, 0x65, 0x73, 0x32, + 0x8b, 0x01, 0x0a, 0x07, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x12, 0x3d, 0x0a, 0x0a, 0x41, 0x64, 0x64, 0x4d, 0x61, 0x63, 0x68, 0x69, 0x6e, 0x65, 0x12, 0x16, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x41, 0x64, 0x64, 0x4d, 0x61, 0x63, 0x68, 0x69, 0x6e, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x17, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x41, 0x64, 0x64, 0x4d, 0x61, 0x63, 0x68, 0x69, @@ -661,17 +202,11 @@ var file_internal_machine_api_pb_cluster_proto_rawDesc = []byte{ 0x73, 0x74, 0x4d, 0x61, 0x63, 0x68, 0x69, 0x6e, 0x65, 0x73, 0x12, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x19, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x4d, 0x61, 0x63, - 0x68, 0x69, 0x6e, 0x65, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x5b, 0x0a, - 0x14, 0x4c, 0x69, 0x73, 0x74, 0x4d, 0x61, 0x63, 0x68, 0x69, 0x6e, 0x65, 0x45, 0x6e, 0x64, 0x70, - 0x6f, 0x69, 0x6e, 0x74, 0x73, 0x12, 0x20, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x4c, 0x69, 0x73, 0x74, - 0x4d, 0x61, 0x63, 0x68, 0x69, 0x6e, 0x65, 0x45, 0x6e, 0x64, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x73, - 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x21, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x4c, 0x69, - 0x73, 0x74, 0x4d, 0x61, 0x63, 0x68, 0x69, 0x6e, 0x65, 0x45, 0x6e, 0x64, 0x70, 0x6f, 0x69, 0x6e, - 0x74, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x37, 0x5a, 0x35, 0x67, 0x69, - 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x70, 0x73, 0x76, 0x69, 0x64, 0x65, 0x72, - 0x73, 0x6b, 0x69, 0x2f, 0x75, 0x6e, 0x63, 0x6c, 0x6f, 0x75, 0x64, 0x2f, 0x69, 0x6e, 0x74, 0x65, - 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x6d, 0x61, 0x63, 0x68, 0x69, 0x6e, 0x65, 0x2f, 0x61, 0x70, 0x69, - 0x2f, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x68, 0x69, 0x6e, 0x65, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x37, 0x5a, + 0x35, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x70, 0x73, 0x76, 0x69, + 0x64, 0x65, 0x72, 0x73, 0x6b, 0x69, 0x2f, 0x75, 0x6e, 0x63, 0x6c, 0x6f, 0x75, 0x64, 0x2f, 0x69, + 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x6d, 0x61, 0x63, 0x68, 0x69, 0x6e, 0x65, 0x2f, + 0x61, 0x70, 0x69, 0x2f, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -686,53 +221,28 @@ func file_internal_machine_api_pb_cluster_proto_rawDescGZIP() []byte { return file_internal_machine_api_pb_cluster_proto_rawDescData } -var file_internal_machine_api_pb_cluster_proto_msgTypes = make([]protoimpl.MessageInfo, 12) +var file_internal_machine_api_pb_cluster_proto_msgTypes = make([]protoimpl.MessageInfo, 3) var file_internal_machine_api_pb_cluster_proto_goTypes = []any{ - (*AddMachineRequest)(nil), // 0: api.AddMachineRequest - (*AddMachineResponse)(nil), // 1: api.AddMachineResponse - (*ListMachinesResponse)(nil), // 2: api.ListMachinesResponse - (*ListMachineEndpointsRequest)(nil), // 3: api.ListMachineEndpointsRequest - (*ListMachineEndpointsResponse)(nil), // 4: api.ListMachineEndpointsResponse - (*MachineInfo)(nil), // 5: api.MachineInfo - (*NetworkConfig)(nil), // 6: api.NetworkConfig - (*MachineEndpoints)(nil), // 7: api.MachineEndpoints - (*User)(nil), // 8: api.User - (*State)(nil), // 9: api.State - nil, // 10: api.State.MachinesEntry - nil, // 11: api.State.EndpointsEntry - (*IPPrefix)(nil), // 12: api.IPPrefix - (*IP)(nil), // 13: api.IP - (*IPPort)(nil), // 14: api.IPPort - (*emptypb.Empty)(nil), // 15: google.protobuf.Empty + (*AddMachineRequest)(nil), // 0: api.AddMachineRequest + (*AddMachineResponse)(nil), // 1: api.AddMachineResponse + (*ListMachinesResponse)(nil), // 2: api.ListMachinesResponse + (*NetworkConfig)(nil), // 3: api.NetworkConfig + (*MachineInfo)(nil), // 4: api.MachineInfo + (*emptypb.Empty)(nil), // 5: google.protobuf.Empty } var file_internal_machine_api_pb_cluster_proto_depIdxs = []int32{ - 6, // 0: api.AddMachineRequest.network:type_name -> api.NetworkConfig - 5, // 1: api.AddMachineResponse.machine:type_name -> api.MachineInfo - 5, // 2: api.ListMachinesResponse.machines:type_name -> api.MachineInfo - 7, // 3: api.ListMachineEndpointsResponse.endpoints:type_name -> api.MachineEndpoints - 6, // 4: api.MachineInfo.network:type_name -> api.NetworkConfig - 12, // 5: api.NetworkConfig.subnet:type_name -> api.IPPrefix - 13, // 6: api.NetworkConfig.management_ip:type_name -> api.IP - 14, // 7: api.NetworkConfig.endpoints:type_name -> api.IPPort - 14, // 8: api.MachineEndpoints.endpoints:type_name -> api.IPPort - 6, // 9: api.User.network:type_name -> api.NetworkConfig - 12, // 10: api.State.Network:type_name -> api.IPPrefix - 10, // 11: api.State.machines:type_name -> api.State.MachinesEntry - 11, // 12: api.State.endpoints:type_name -> api.State.EndpointsEntry - 8, // 13: api.State.users:type_name -> api.User - 5, // 14: api.State.MachinesEntry.value:type_name -> api.MachineInfo - 7, // 15: api.State.EndpointsEntry.value:type_name -> api.MachineEndpoints - 0, // 16: api.Cluster.AddMachine:input_type -> api.AddMachineRequest - 15, // 17: api.Cluster.ListMachines:input_type -> google.protobuf.Empty - 3, // 18: api.Cluster.ListMachineEndpoints:input_type -> api.ListMachineEndpointsRequest - 1, // 19: api.Cluster.AddMachine:output_type -> api.AddMachineResponse - 2, // 20: api.Cluster.ListMachines:output_type -> api.ListMachinesResponse - 4, // 21: api.Cluster.ListMachineEndpoints:output_type -> api.ListMachineEndpointsResponse - 19, // [19:22] is the sub-list for method output_type - 16, // [16:19] is the sub-list for method input_type - 16, // [16:16] is the sub-list for extension type_name - 16, // [16:16] is the sub-list for extension extendee - 0, // [0:16] is the sub-list for field type_name + 3, // 0: api.AddMachineRequest.network:type_name -> api.NetworkConfig + 4, // 1: api.AddMachineResponse.machine:type_name -> api.MachineInfo + 4, // 2: api.ListMachinesResponse.machines:type_name -> api.MachineInfo + 0, // 3: api.Cluster.AddMachine:input_type -> api.AddMachineRequest + 5, // 4: api.Cluster.ListMachines:input_type -> google.protobuf.Empty + 1, // 5: api.Cluster.AddMachine:output_type -> api.AddMachineResponse + 2, // 6: api.Cluster.ListMachines:output_type -> api.ListMachinesResponse + 5, // [5:7] is the sub-list for method output_type + 3, // [3:5] is the sub-list for method input_type + 3, // [3:3] is the sub-list for extension type_name + 3, // [3:3] is the sub-list for extension extendee + 0, // [0:3] is the sub-list for field type_name } func init() { file_internal_machine_api_pb_cluster_proto_init() } @@ -740,7 +250,7 @@ func file_internal_machine_api_pb_cluster_proto_init() { if File_internal_machine_api_pb_cluster_proto != nil { return } - file_internal_machine_api_pb_common_proto_init() + file_internal_machine_api_pb_machine_proto_init() if !protoimpl.UnsafeEnabled { file_internal_machine_api_pb_cluster_proto_msgTypes[0].Exporter = func(v any, i int) any { switch v := v.(*AddMachineRequest); i { @@ -778,90 +288,6 @@ func file_internal_machine_api_pb_cluster_proto_init() { return nil } } - file_internal_machine_api_pb_cluster_proto_msgTypes[3].Exporter = func(v any, i int) any { - switch v := v.(*ListMachineEndpointsRequest); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_internal_machine_api_pb_cluster_proto_msgTypes[4].Exporter = func(v any, i int) any { - switch v := v.(*ListMachineEndpointsResponse); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_internal_machine_api_pb_cluster_proto_msgTypes[5].Exporter = func(v any, i int) any { - switch v := v.(*MachineInfo); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_internal_machine_api_pb_cluster_proto_msgTypes[6].Exporter = func(v any, i int) any { - switch v := v.(*NetworkConfig); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_internal_machine_api_pb_cluster_proto_msgTypes[7].Exporter = func(v any, i int) any { - switch v := v.(*MachineEndpoints); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_internal_machine_api_pb_cluster_proto_msgTypes[8].Exporter = func(v any, i int) any { - switch v := v.(*User); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_internal_machine_api_pb_cluster_proto_msgTypes[9].Exporter = func(v any, i int) any { - switch v := v.(*State); 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{ @@ -869,7 +295,7 @@ func file_internal_machine_api_pb_cluster_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_internal_machine_api_pb_cluster_proto_rawDesc, NumEnums: 0, - NumMessages: 12, + NumMessages: 3, NumExtensions: 0, NumServices: 1, }, diff --git a/internal/machine/api/pb/cluster.proto b/internal/machine/api/pb/cluster.proto index 7b92efcc..811cba4d 100644 --- a/internal/machine/api/pb/cluster.proto +++ b/internal/machine/api/pb/cluster.proto @@ -5,12 +5,11 @@ package api; option go_package = "github.com/psviderski/uncloud/internal/machine/api/pb"; import "google/protobuf/empty.proto"; -import "internal/machine/api/pb/common.proto"; +import "internal/machine/api/pb/machine.proto"; service Cluster { rpc AddMachine(AddMachineRequest) returns (AddMachineResponse); rpc ListMachines(google.protobuf.Empty) returns (ListMachinesResponse); - rpc ListMachineEndpoints(ListMachineEndpointsRequest) returns (ListMachineEndpointsResponse); } message AddMachineRequest { @@ -25,43 +24,3 @@ message AddMachineResponse { message ListMachinesResponse { repeated MachineInfo machines = 1; } - -message ListMachineEndpointsRequest { - string id = 1; -} - -message ListMachineEndpointsResponse { - MachineEndpoints endpoints = 1; -} - -message MachineInfo { - string id = 1; - string name = 2; - NetworkConfig network = 3; -} - -message NetworkConfig { - IPPrefix subnet = 1; - IP management_ip = 2; - repeated IPPort endpoints = 3; - bytes publicKey = 4; -} - -message MachineEndpoints { - string id = 1; - repeated IPPort endpoints = 2; -} - -message User { - NetworkConfig network = 1; -} - -message State { - IPPrefix Network = 1; - // The machine configuration in the state is the source of truth set by the administrator. - // The machine itself can't update it. - map machines = 2; - map endpoints = 3; - repeated User users = 4; -} - diff --git a/internal/machine/api/pb/cluster_grpc.pb.go b/internal/machine/api/pb/cluster_grpc.pb.go index 54891c2a..5fdcb683 100644 --- a/internal/machine/api/pb/cluster_grpc.pb.go +++ b/internal/machine/api/pb/cluster_grpc.pb.go @@ -20,9 +20,8 @@ import ( const _ = grpc.SupportPackageIsVersion9 const ( - Cluster_AddMachine_FullMethodName = "/api.Cluster/AddMachine" - Cluster_ListMachines_FullMethodName = "/api.Cluster/ListMachines" - Cluster_ListMachineEndpoints_FullMethodName = "/api.Cluster/ListMachineEndpoints" + Cluster_AddMachine_FullMethodName = "/api.Cluster/AddMachine" + Cluster_ListMachines_FullMethodName = "/api.Cluster/ListMachines" ) // ClusterClient is the client API for Cluster service. @@ -31,7 +30,6 @@ const ( type ClusterClient interface { AddMachine(ctx context.Context, in *AddMachineRequest, opts ...grpc.CallOption) (*AddMachineResponse, error) ListMachines(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*ListMachinesResponse, error) - ListMachineEndpoints(ctx context.Context, in *ListMachineEndpointsRequest, opts ...grpc.CallOption) (*ListMachineEndpointsResponse, error) } type clusterClient struct { @@ -62,23 +60,12 @@ func (c *clusterClient) ListMachines(ctx context.Context, in *emptypb.Empty, opt return out, nil } -func (c *clusterClient) ListMachineEndpoints(ctx context.Context, in *ListMachineEndpointsRequest, opts ...grpc.CallOption) (*ListMachineEndpointsResponse, error) { - cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) - out := new(ListMachineEndpointsResponse) - err := c.cc.Invoke(ctx, Cluster_ListMachineEndpoints_FullMethodName, in, out, cOpts...) - if err != nil { - return nil, err - } - return out, nil -} - // ClusterServer is the server API for Cluster service. // All implementations must embed UnimplementedClusterServer // for forward compatibility. type ClusterServer interface { AddMachine(context.Context, *AddMachineRequest) (*AddMachineResponse, error) ListMachines(context.Context, *emptypb.Empty) (*ListMachinesResponse, error) - ListMachineEndpoints(context.Context, *ListMachineEndpointsRequest) (*ListMachineEndpointsResponse, error) mustEmbedUnimplementedClusterServer() } @@ -95,9 +82,6 @@ func (UnimplementedClusterServer) AddMachine(context.Context, *AddMachineRequest func (UnimplementedClusterServer) ListMachines(context.Context, *emptypb.Empty) (*ListMachinesResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method ListMachines not implemented") } -func (UnimplementedClusterServer) ListMachineEndpoints(context.Context, *ListMachineEndpointsRequest) (*ListMachineEndpointsResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method ListMachineEndpoints not implemented") -} func (UnimplementedClusterServer) mustEmbedUnimplementedClusterServer() {} func (UnimplementedClusterServer) testEmbeddedByValue() {} @@ -155,24 +139,6 @@ func _Cluster_ListMachines_Handler(srv interface{}, ctx context.Context, dec fun return interceptor(ctx, in, info, handler) } -func _Cluster_ListMachineEndpoints_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(ListMachineEndpointsRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(ClusterServer).ListMachineEndpoints(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: Cluster_ListMachineEndpoints_FullMethodName, - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(ClusterServer).ListMachineEndpoints(ctx, req.(*ListMachineEndpointsRequest)) - } - return interceptor(ctx, in, info, handler) -} - // Cluster_ServiceDesc is the grpc.ServiceDesc for Cluster service. // It's only intended for direct use with grpc.RegisterService, // and not to be introspected or modified (even as a copy) @@ -188,10 +154,6 @@ var Cluster_ServiceDesc = grpc.ServiceDesc{ MethodName: "ListMachines", Handler: _Cluster_ListMachines_Handler, }, - { - MethodName: "ListMachineEndpoints", - Handler: _Cluster_ListMachineEndpoints_Handler, - }, }, Streams: []grpc.StreamDesc{}, Metadata: "internal/machine/api/pb/cluster.proto", diff --git a/internal/machine/api/pb/machine.pb.go b/internal/machine/api/pb/machine.pb.go index ff48c4ed..758e1b0b 100644 --- a/internal/machine/api/pb/machine.pb.go +++ b/internal/machine/api/pb/machine.pb.go @@ -21,6 +21,140 @@ const ( _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) ) +type MachineInfo struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` + Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"` + Network *NetworkConfig `protobuf:"bytes,3,opt,name=network,proto3" json:"network,omitempty"` +} + +func (x *MachineInfo) Reset() { + *x = MachineInfo{} + if protoimpl.UnsafeEnabled { + mi := &file_internal_machine_api_pb_machine_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *MachineInfo) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*MachineInfo) ProtoMessage() {} + +func (x *MachineInfo) ProtoReflect() protoreflect.Message { + mi := &file_internal_machine_api_pb_machine_proto_msgTypes[0] + 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 MachineInfo.ProtoReflect.Descriptor instead. +func (*MachineInfo) Descriptor() ([]byte, []int) { + return file_internal_machine_api_pb_machine_proto_rawDescGZIP(), []int{0} +} + +func (x *MachineInfo) GetId() string { + if x != nil { + return x.Id + } + return "" +} + +func (x *MachineInfo) GetName() string { + if x != nil { + return x.Name + } + return "" +} + +func (x *MachineInfo) GetNetwork() *NetworkConfig { + if x != nil { + return x.Network + } + return nil +} + +type NetworkConfig struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Subnet *IPPrefix `protobuf:"bytes,1,opt,name=subnet,proto3" json:"subnet,omitempty"` + ManagementIp *IP `protobuf:"bytes,2,opt,name=management_ip,json=managementIp,proto3" json:"management_ip,omitempty"` + Endpoints []*IPPort `protobuf:"bytes,3,rep,name=endpoints,proto3" json:"endpoints,omitempty"` + PublicKey []byte `protobuf:"bytes,4,opt,name=publicKey,proto3" json:"publicKey,omitempty"` +} + +func (x *NetworkConfig) Reset() { + *x = NetworkConfig{} + if protoimpl.UnsafeEnabled { + mi := &file_internal_machine_api_pb_machine_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *NetworkConfig) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*NetworkConfig) ProtoMessage() {} + +func (x *NetworkConfig) ProtoReflect() protoreflect.Message { + mi := &file_internal_machine_api_pb_machine_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 NetworkConfig.ProtoReflect.Descriptor instead. +func (*NetworkConfig) Descriptor() ([]byte, []int) { + return file_internal_machine_api_pb_machine_proto_rawDescGZIP(), []int{1} +} + +func (x *NetworkConfig) GetSubnet() *IPPrefix { + if x != nil { + return x.Subnet + } + return nil +} + +func (x *NetworkConfig) GetManagementIp() *IP { + if x != nil { + return x.ManagementIp + } + return nil +} + +func (x *NetworkConfig) GetEndpoints() []*IPPort { + if x != nil { + return x.Endpoints + } + return nil +} + +func (x *NetworkConfig) GetPublicKey() []byte { + if x != nil { + return x.PublicKey + } + return nil +} + type InitClusterRequest struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -33,7 +167,7 @@ type InitClusterRequest struct { func (x *InitClusterRequest) Reset() { *x = InitClusterRequest{} if protoimpl.UnsafeEnabled { - mi := &file_internal_machine_api_pb_machine_proto_msgTypes[0] + mi := &file_internal_machine_api_pb_machine_proto_msgTypes[2] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -46,7 +180,7 @@ func (x *InitClusterRequest) String() string { func (*InitClusterRequest) ProtoMessage() {} func (x *InitClusterRequest) ProtoReflect() protoreflect.Message { - mi := &file_internal_machine_api_pb_machine_proto_msgTypes[0] + mi := &file_internal_machine_api_pb_machine_proto_msgTypes[2] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -59,7 +193,7 @@ func (x *InitClusterRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use InitClusterRequest.ProtoReflect.Descriptor instead. func (*InitClusterRequest) Descriptor() ([]byte, []int) { - return file_internal_machine_api_pb_machine_proto_rawDescGZIP(), []int{0} + return file_internal_machine_api_pb_machine_proto_rawDescGZIP(), []int{2} } func (x *InitClusterRequest) GetMachineName() string { @@ -87,7 +221,7 @@ type InitClusterResponse struct { func (x *InitClusterResponse) Reset() { *x = InitClusterResponse{} if protoimpl.UnsafeEnabled { - mi := &file_internal_machine_api_pb_machine_proto_msgTypes[1] + mi := &file_internal_machine_api_pb_machine_proto_msgTypes[3] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -100,7 +234,7 @@ func (x *InitClusterResponse) String() string { func (*InitClusterResponse) ProtoMessage() {} func (x *InitClusterResponse) ProtoReflect() protoreflect.Message { - mi := &file_internal_machine_api_pb_machine_proto_msgTypes[1] + mi := &file_internal_machine_api_pb_machine_proto_msgTypes[3] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -113,7 +247,7 @@ func (x *InitClusterResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use InitClusterResponse.ProtoReflect.Descriptor instead. func (*InitClusterResponse) Descriptor() ([]byte, []int) { - return file_internal_machine_api_pb_machine_proto_rawDescGZIP(), []int{1} + return file_internal_machine_api_pb_machine_proto_rawDescGZIP(), []int{3} } func (x *InitClusterResponse) GetMachine() *MachineInfo { @@ -135,7 +269,7 @@ type JoinClusterRequest struct { func (x *JoinClusterRequest) Reset() { *x = JoinClusterRequest{} if protoimpl.UnsafeEnabled { - mi := &file_internal_machine_api_pb_machine_proto_msgTypes[2] + mi := &file_internal_machine_api_pb_machine_proto_msgTypes[4] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -148,7 +282,7 @@ func (x *JoinClusterRequest) String() string { func (*JoinClusterRequest) ProtoMessage() {} func (x *JoinClusterRequest) ProtoReflect() protoreflect.Message { - mi := &file_internal_machine_api_pb_machine_proto_msgTypes[2] + mi := &file_internal_machine_api_pb_machine_proto_msgTypes[4] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -161,7 +295,7 @@ func (x *JoinClusterRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use JoinClusterRequest.ProtoReflect.Descriptor instead. func (*JoinClusterRequest) Descriptor() ([]byte, []int) { - return file_internal_machine_api_pb_machine_proto_rawDescGZIP(), []int{2} + return file_internal_machine_api_pb_machine_proto_rawDescGZIP(), []int{4} } func (x *JoinClusterRequest) GetMachine() *MachineInfo { @@ -189,7 +323,7 @@ type TokenResponse struct { func (x *TokenResponse) Reset() { *x = TokenResponse{} if protoimpl.UnsafeEnabled { - mi := &file_internal_machine_api_pb_machine_proto_msgTypes[3] + mi := &file_internal_machine_api_pb_machine_proto_msgTypes[5] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -202,7 +336,7 @@ func (x *TokenResponse) String() string { func (*TokenResponse) ProtoMessage() {} func (x *TokenResponse) ProtoReflect() protoreflect.Message { - mi := &file_internal_machine_api_pb_machine_proto_msgTypes[3] + mi := &file_internal_machine_api_pb_machine_proto_msgTypes[5] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -215,7 +349,7 @@ func (x *TokenResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use TokenResponse.ProtoReflect.Descriptor instead. func (*TokenResponse) Descriptor() ([]byte, []int) { - return file_internal_machine_api_pb_machine_proto_rawDescGZIP(), []int{3} + return file_internal_machine_api_pb_machine_proto_rawDescGZIP(), []int{5} } func (x *TokenResponse) GetToken() string { @@ -234,50 +368,64 @@ var file_internal_machine_api_pb_machine_proto_rawDesc = []byte{ 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x65, 0x6d, 0x70, 0x74, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x24, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x6d, 0x61, 0x63, 0x68, 0x69, 0x6e, 0x65, 0x2f, 0x61, 0x70, 0x69, 0x2f, - 0x70, 0x62, 0x2f, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, - 0x25, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x6d, 0x61, 0x63, 0x68, 0x69, 0x6e, - 0x65, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x70, 0x62, 0x2f, 0x63, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, - 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x5f, 0x0a, 0x12, 0x49, 0x6e, 0x69, 0x74, 0x43, 0x6c, - 0x75, 0x73, 0x74, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x20, 0x0a, 0x0b, - 0x6d, 0x61, 0x63, 0x68, 0x69, 0x6e, 0x65, 0x4e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, - 0x09, 0x52, 0x0b, 0x6d, 0x61, 0x63, 0x68, 0x69, 0x6e, 0x65, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x27, - 0x0a, 0x07, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, - 0x0d, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x49, 0x50, 0x50, 0x72, 0x65, 0x66, 0x69, 0x78, 0x52, 0x07, - 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x22, 0x41, 0x0a, 0x13, 0x49, 0x6e, 0x69, 0x74, 0x43, - 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x2a, - 0x0a, 0x07, 0x6d, 0x61, 0x63, 0x68, 0x69, 0x6e, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, - 0x10, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x4d, 0x61, 0x63, 0x68, 0x69, 0x6e, 0x65, 0x49, 0x6e, 0x66, - 0x6f, 0x52, 0x07, 0x6d, 0x61, 0x63, 0x68, 0x69, 0x6e, 0x65, 0x22, 0x79, 0x0a, 0x12, 0x4a, 0x6f, - 0x69, 0x6e, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, - 0x12, 0x2a, 0x0a, 0x07, 0x6d, 0x61, 0x63, 0x68, 0x69, 0x6e, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, - 0x0b, 0x32, 0x10, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x4d, 0x61, 0x63, 0x68, 0x69, 0x6e, 0x65, 0x49, - 0x6e, 0x66, 0x6f, 0x52, 0x07, 0x6d, 0x61, 0x63, 0x68, 0x69, 0x6e, 0x65, 0x12, 0x37, 0x0a, 0x0e, - 0x6f, 0x74, 0x68, 0x65, 0x72, 0x5f, 0x6d, 0x61, 0x63, 0x68, 0x69, 0x6e, 0x65, 0x73, 0x18, 0x03, - 0x20, 0x03, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x4d, 0x61, 0x63, 0x68, 0x69, - 0x6e, 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x0d, 0x6f, 0x74, 0x68, 0x65, 0x72, 0x4d, 0x61, 0x63, - 0x68, 0x69, 0x6e, 0x65, 0x73, 0x22, 0x25, 0x0a, 0x0d, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x52, 0x65, - 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x18, - 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x32, 0xf5, 0x01, 0x0a, - 0x07, 0x4d, 0x61, 0x63, 0x68, 0x69, 0x6e, 0x65, 0x12, 0x40, 0x0a, 0x0b, 0x49, 0x6e, 0x69, 0x74, - 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x12, 0x17, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x49, 0x6e, - 0x69, 0x74, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, - 0x1a, 0x18, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x49, 0x6e, 0x69, 0x74, 0x43, 0x6c, 0x75, 0x73, 0x74, - 0x65, 0x72, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x3e, 0x0a, 0x0b, 0x4a, 0x6f, - 0x69, 0x6e, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x12, 0x17, 0x2e, 0x61, 0x70, 0x69, 0x2e, - 0x4a, 0x6f, 0x69, 0x6e, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, - 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x12, 0x33, 0x0a, 0x05, 0x54, 0x6f, - 0x6b, 0x65, 0x6e, 0x12, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, - 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x12, 0x2e, 0x61, 0x70, - 0x69, 0x2e, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, - 0x33, 0x0a, 0x07, 0x49, 0x6e, 0x73, 0x70, 0x65, 0x63, 0x74, 0x12, 0x16, 0x2e, 0x67, 0x6f, 0x6f, - 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, - 0x74, 0x79, 0x1a, 0x10, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x4d, 0x61, 0x63, 0x68, 0x69, 0x6e, 0x65, - 0x49, 0x6e, 0x66, 0x6f, 0x42, 0x37, 0x5a, 0x35, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, - 0x6f, 0x6d, 0x2f, 0x70, 0x73, 0x76, 0x69, 0x64, 0x65, 0x72, 0x73, 0x6b, 0x69, 0x2f, 0x75, 0x6e, - 0x63, 0x6c, 0x6f, 0x75, 0x64, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x6d, - 0x61, 0x63, 0x68, 0x69, 0x6e, 0x65, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x70, 0x62, 0x62, 0x06, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x70, 0x62, 0x2f, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, + 0x5f, 0x0a, 0x0b, 0x4d, 0x61, 0x63, 0x68, 0x69, 0x6e, 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x0e, + 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x12, + 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, + 0x6d, 0x65, 0x12, 0x2c, 0x0a, 0x07, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x18, 0x03, 0x20, + 0x01, 0x28, 0x0b, 0x32, 0x12, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x4e, 0x65, 0x74, 0x77, 0x6f, 0x72, + 0x6b, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x52, 0x07, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, + 0x22, 0xad, 0x01, 0x0a, 0x0d, 0x4e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x43, 0x6f, 0x6e, 0x66, + 0x69, 0x67, 0x12, 0x25, 0x0a, 0x06, 0x73, 0x75, 0x62, 0x6e, 0x65, 0x74, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x0b, 0x32, 0x0d, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x49, 0x50, 0x50, 0x72, 0x65, 0x66, 0x69, + 0x78, 0x52, 0x06, 0x73, 0x75, 0x62, 0x6e, 0x65, 0x74, 0x12, 0x2c, 0x0a, 0x0d, 0x6d, 0x61, 0x6e, + 0x61, 0x67, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x5f, 0x69, 0x70, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, + 0x32, 0x07, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x49, 0x50, 0x52, 0x0c, 0x6d, 0x61, 0x6e, 0x61, 0x67, + 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x49, 0x70, 0x12, 0x29, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x70, 0x6f, + 0x69, 0x6e, 0x74, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0b, 0x2e, 0x61, 0x70, 0x69, + 0x2e, 0x49, 0x50, 0x50, 0x6f, 0x72, 0x74, 0x52, 0x09, 0x65, 0x6e, 0x64, 0x70, 0x6f, 0x69, 0x6e, + 0x74, 0x73, 0x12, 0x1c, 0x0a, 0x09, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x4b, 0x65, 0x79, 0x18, + 0x04, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x09, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x4b, 0x65, 0x79, + 0x22, 0x5f, 0x0a, 0x12, 0x49, 0x6e, 0x69, 0x74, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x52, + 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x20, 0x0a, 0x0b, 0x6d, 0x61, 0x63, 0x68, 0x69, 0x6e, + 0x65, 0x4e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6d, 0x61, 0x63, + 0x68, 0x69, 0x6e, 0x65, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x27, 0x0a, 0x07, 0x6e, 0x65, 0x74, 0x77, + 0x6f, 0x72, 0x6b, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0d, 0x2e, 0x61, 0x70, 0x69, 0x2e, + 0x49, 0x50, 0x50, 0x72, 0x65, 0x66, 0x69, 0x78, 0x52, 0x07, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, + 0x6b, 0x22, 0x41, 0x0a, 0x13, 0x49, 0x6e, 0x69, 0x74, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, + 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x2a, 0x0a, 0x07, 0x6d, 0x61, 0x63, 0x68, + 0x69, 0x6e, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x61, 0x70, 0x69, 0x2e, + 0x4d, 0x61, 0x63, 0x68, 0x69, 0x6e, 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x07, 0x6d, 0x61, 0x63, + 0x68, 0x69, 0x6e, 0x65, 0x22, 0x79, 0x0a, 0x12, 0x4a, 0x6f, 0x69, 0x6e, 0x43, 0x6c, 0x75, 0x73, + 0x74, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x2a, 0x0a, 0x07, 0x6d, 0x61, + 0x63, 0x68, 0x69, 0x6e, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x61, 0x70, + 0x69, 0x2e, 0x4d, 0x61, 0x63, 0x68, 0x69, 0x6e, 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x07, 0x6d, + 0x61, 0x63, 0x68, 0x69, 0x6e, 0x65, 0x12, 0x37, 0x0a, 0x0e, 0x6f, 0x74, 0x68, 0x65, 0x72, 0x5f, + 0x6d, 0x61, 0x63, 0x68, 0x69, 0x6e, 0x65, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x10, + 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x4d, 0x61, 0x63, 0x68, 0x69, 0x6e, 0x65, 0x49, 0x6e, 0x66, 0x6f, + 0x52, 0x0d, 0x6f, 0x74, 0x68, 0x65, 0x72, 0x4d, 0x61, 0x63, 0x68, 0x69, 0x6e, 0x65, 0x73, 0x22, + 0x25, 0x0a, 0x0d, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, + 0x12, 0x14, 0x0a, 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x32, 0xf5, 0x01, 0x0a, 0x07, 0x4d, 0x61, 0x63, 0x68, 0x69, + 0x6e, 0x65, 0x12, 0x40, 0x0a, 0x0b, 0x49, 0x6e, 0x69, 0x74, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, + 0x72, 0x12, 0x17, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x49, 0x6e, 0x69, 0x74, 0x43, 0x6c, 0x75, 0x73, + 0x74, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x18, 0x2e, 0x61, 0x70, 0x69, + 0x2e, 0x49, 0x6e, 0x69, 0x74, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x52, 0x65, 0x73, 0x70, + 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x3e, 0x0a, 0x0b, 0x4a, 0x6f, 0x69, 0x6e, 0x43, 0x6c, 0x75, 0x73, + 0x74, 0x65, 0x72, 0x12, 0x17, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x4a, 0x6f, 0x69, 0x6e, 0x43, 0x6c, + 0x75, 0x73, 0x74, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x67, + 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, + 0x6d, 0x70, 0x74, 0x79, 0x12, 0x33, 0x0a, 0x05, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x12, 0x16, 0x2e, + 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, + 0x45, 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x12, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x54, 0x6f, 0x6b, 0x65, + 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x33, 0x0a, 0x07, 0x49, 0x6e, 0x73, + 0x70, 0x65, 0x63, 0x74, 0x12, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x10, 0x2e, 0x61, + 0x70, 0x69, 0x2e, 0x4d, 0x61, 0x63, 0x68, 0x69, 0x6e, 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x42, 0x37, + 0x5a, 0x35, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x70, 0x73, 0x76, + 0x69, 0x64, 0x65, 0x72, 0x73, 0x6b, 0x69, 0x2f, 0x75, 0x6e, 0x63, 0x6c, 0x6f, 0x75, 0x64, 0x2f, + 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x6d, 0x61, 0x63, 0x68, 0x69, 0x6e, 0x65, + 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -292,34 +440,41 @@ func file_internal_machine_api_pb_machine_proto_rawDescGZIP() []byte { return file_internal_machine_api_pb_machine_proto_rawDescData } -var file_internal_machine_api_pb_machine_proto_msgTypes = make([]protoimpl.MessageInfo, 4) +var file_internal_machine_api_pb_machine_proto_msgTypes = make([]protoimpl.MessageInfo, 6) var file_internal_machine_api_pb_machine_proto_goTypes = []any{ - (*InitClusterRequest)(nil), // 0: api.InitClusterRequest - (*InitClusterResponse)(nil), // 1: api.InitClusterResponse - (*JoinClusterRequest)(nil), // 2: api.JoinClusterRequest - (*TokenResponse)(nil), // 3: api.TokenResponse - (*IPPrefix)(nil), // 4: api.IPPrefix - (*MachineInfo)(nil), // 5: api.MachineInfo - (*emptypb.Empty)(nil), // 6: google.protobuf.Empty + (*MachineInfo)(nil), // 0: api.MachineInfo + (*NetworkConfig)(nil), // 1: api.NetworkConfig + (*InitClusterRequest)(nil), // 2: api.InitClusterRequest + (*InitClusterResponse)(nil), // 3: api.InitClusterResponse + (*JoinClusterRequest)(nil), // 4: api.JoinClusterRequest + (*TokenResponse)(nil), // 5: api.TokenResponse + (*IPPrefix)(nil), // 6: api.IPPrefix + (*IP)(nil), // 7: api.IP + (*IPPort)(nil), // 8: api.IPPort + (*emptypb.Empty)(nil), // 9: google.protobuf.Empty } var file_internal_machine_api_pb_machine_proto_depIdxs = []int32{ - 4, // 0: api.InitClusterRequest.network:type_name -> api.IPPrefix - 5, // 1: api.InitClusterResponse.machine:type_name -> api.MachineInfo - 5, // 2: api.JoinClusterRequest.machine:type_name -> api.MachineInfo - 5, // 3: api.JoinClusterRequest.other_machines:type_name -> api.MachineInfo - 0, // 4: api.Machine.InitCluster:input_type -> api.InitClusterRequest - 2, // 5: api.Machine.JoinCluster:input_type -> api.JoinClusterRequest - 6, // 6: api.Machine.Token:input_type -> google.protobuf.Empty - 6, // 7: api.Machine.Inspect:input_type -> google.protobuf.Empty - 1, // 8: api.Machine.InitCluster:output_type -> api.InitClusterResponse - 6, // 9: api.Machine.JoinCluster:output_type -> google.protobuf.Empty - 3, // 10: api.Machine.Token:output_type -> api.TokenResponse - 5, // 11: api.Machine.Inspect:output_type -> api.MachineInfo - 8, // [8:12] is the sub-list for method output_type - 4, // [4:8] is the sub-list for method input_type - 4, // [4:4] is the sub-list for extension type_name - 4, // [4:4] is the sub-list for extension extendee - 0, // [0:4] is the sub-list for field type_name + 1, // 0: api.MachineInfo.network:type_name -> api.NetworkConfig + 6, // 1: api.NetworkConfig.subnet:type_name -> api.IPPrefix + 7, // 2: api.NetworkConfig.management_ip:type_name -> api.IP + 8, // 3: api.NetworkConfig.endpoints:type_name -> api.IPPort + 6, // 4: api.InitClusterRequest.network:type_name -> api.IPPrefix + 0, // 5: api.InitClusterResponse.machine:type_name -> api.MachineInfo + 0, // 6: api.JoinClusterRequest.machine:type_name -> api.MachineInfo + 0, // 7: api.JoinClusterRequest.other_machines:type_name -> api.MachineInfo + 2, // 8: api.Machine.InitCluster:input_type -> api.InitClusterRequest + 4, // 9: api.Machine.JoinCluster:input_type -> api.JoinClusterRequest + 9, // 10: api.Machine.Token:input_type -> google.protobuf.Empty + 9, // 11: api.Machine.Inspect:input_type -> google.protobuf.Empty + 3, // 12: api.Machine.InitCluster:output_type -> api.InitClusterResponse + 9, // 13: api.Machine.JoinCluster:output_type -> google.protobuf.Empty + 5, // 14: api.Machine.Token:output_type -> api.TokenResponse + 0, // 15: api.Machine.Inspect:output_type -> api.MachineInfo + 12, // [12:16] is the sub-list for method output_type + 8, // [8:12] is the sub-list for method input_type + 8, // [8:8] is the sub-list for extension type_name + 8, // [8:8] is the sub-list for extension extendee + 0, // [0:8] is the sub-list for field type_name } func init() { file_internal_machine_api_pb_machine_proto_init() } @@ -328,10 +483,9 @@ func file_internal_machine_api_pb_machine_proto_init() { return } file_internal_machine_api_pb_common_proto_init() - file_internal_machine_api_pb_cluster_proto_init() if !protoimpl.UnsafeEnabled { file_internal_machine_api_pb_machine_proto_msgTypes[0].Exporter = func(v any, i int) any { - switch v := v.(*InitClusterRequest); i { + switch v := v.(*MachineInfo); i { case 0: return &v.state case 1: @@ -343,7 +497,7 @@ func file_internal_machine_api_pb_machine_proto_init() { } } file_internal_machine_api_pb_machine_proto_msgTypes[1].Exporter = func(v any, i int) any { - switch v := v.(*InitClusterResponse); i { + switch v := v.(*NetworkConfig); i { case 0: return &v.state case 1: @@ -355,7 +509,7 @@ func file_internal_machine_api_pb_machine_proto_init() { } } file_internal_machine_api_pb_machine_proto_msgTypes[2].Exporter = func(v any, i int) any { - switch v := v.(*JoinClusterRequest); i { + switch v := v.(*InitClusterRequest); i { case 0: return &v.state case 1: @@ -367,6 +521,30 @@ func file_internal_machine_api_pb_machine_proto_init() { } } file_internal_machine_api_pb_machine_proto_msgTypes[3].Exporter = func(v any, i int) any { + switch v := v.(*InitClusterResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_internal_machine_api_pb_machine_proto_msgTypes[4].Exporter = func(v any, i int) any { + switch v := v.(*JoinClusterRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_internal_machine_api_pb_machine_proto_msgTypes[5].Exporter = func(v any, i int) any { switch v := v.(*TokenResponse); i { case 0: return &v.state @@ -385,7 +563,7 @@ func file_internal_machine_api_pb_machine_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_internal_machine_api_pb_machine_proto_rawDesc, NumEnums: 0, - NumMessages: 4, + NumMessages: 6, NumExtensions: 0, NumServices: 1, }, diff --git a/internal/machine/api/pb/machine.proto b/internal/machine/api/pb/machine.proto index 1295ace1..f36516d7 100644 --- a/internal/machine/api/pb/machine.proto +++ b/internal/machine/api/pb/machine.proto @@ -6,7 +6,6 @@ option go_package = "github.com/psviderski/uncloud/internal/machine/api/pb"; import "google/protobuf/empty.proto"; import "internal/machine/api/pb/common.proto"; -import "internal/machine/api/pb/cluster.proto"; service Machine { rpc InitCluster(InitClusterRequest) returns (InitClusterResponse); @@ -15,6 +14,19 @@ service Machine { rpc Inspect(google.protobuf.Empty) returns (MachineInfo); } +message MachineInfo { + string id = 1; + string name = 2; + NetworkConfig network = 3; +} + +message NetworkConfig { + IPPrefix subnet = 1; + IP management_ip = 2; + repeated IPPort endpoints = 3; + bytes publicKey = 4; +} + message InitClusterRequest { string machineName = 1; IPPrefix network = 2; diff --git a/internal/machine/cluster/cluster.go b/internal/machine/cluster/cluster.go index e24f8597..c71fc56d 100644 --- a/internal/machine/cluster/cluster.go +++ b/internal/machine/cluster/cluster.go @@ -20,16 +20,13 @@ import ( type Cluster struct { pb.UnimplementedClusterServer - state *State store *store.Store - // TODO: temporary channel until the state is replaced with networkDB. newMachinesCh chan *pb.MachineInfo } -func NewCluster(state *State, store *store.Store) *Cluster { +func NewCluster(store *store.Store) *Cluster { return &Cluster{ - state: state, store: store, newMachinesCh: make(chan *pb.MachineInfo, 1), } @@ -41,7 +38,7 @@ func (c *Cluster) Init(ctx context.Context, network netip.Prefix) error { return err } if initialised { - return fmt.Errorf("cluster already initialized") + return fmt.Errorf("cluster is already initialised") } if err = c.store.Put(ctx, "network", network.String()); err != nil { @@ -70,15 +67,11 @@ func (c *Cluster) checkInitialised(ctx context.Context) error { return err } if !initialised { - return status.Error(codes.FailedPrecondition, "cluster is not initialized") + return status.Error(codes.FailedPrecondition, "cluster is not initialised") } return nil } -func (c *Cluster) SetState(state *State) { - c.state = state -} - func (c *Cluster) Network(ctx context.Context) (netip.Prefix, error) { if err := c.checkInitialised(ctx); err != nil { return netip.Prefix{}, err @@ -95,21 +88,6 @@ func (c *Cluster) Network(ctx context.Context) (netip.Prefix, error) { return prefix, nil } -func (c *Cluster) SetNetwork(network *pb.IPPrefix) error { - if c.state == nil { - return status.Error(codes.FailedPrecondition, "cluster is not initialized") - } - - if c.state.State.Network != nil { - return fmt.Errorf("network already set and cannot be changed") - } - if network == nil { - return fmt.Errorf("network not set") - } - c.state.State.Network = network - return nil -} - // TODO: this is a temporary watcher for PoC until the state is state is replaced with networkDB. func (c *Cluster) WatchNewMachines() <-chan *pb.MachineInfo { return c.newMachinesCh @@ -121,7 +99,10 @@ func (c *Cluster) AddMachine(ctx context.Context, req *pb.AddMachineRequest) (*p return nil, err } - if err := req.Validate(); err != nil { + if req.Network == nil { + return nil, status.Error(codes.InvalidArgument, "network not set") + } + if err := req.Network.Validate(); err != nil { return nil, err } if len(req.Network.Endpoints) == 0 { @@ -182,10 +163,10 @@ func (c *Cluster) AddMachine(ctx context.Context, req *pb.AddMachineRequest) (*p Network: &pb.NetworkConfig{ Subnet: pb.NewIPPrefix(subnet), ManagementIp: manageIP, + Endpoints: req.Network.Endpoints, PublicKey: req.Network.PublicKey, }, } - // TODO: announce the new machine to the cluster members and achieve consensus. // We should perhaps not proceed if this machine is in a minority partition. if err = c.store.CreateMachine(ctx, m); err != nil { @@ -213,12 +194,3 @@ func (c *Cluster) ListMachines(ctx context.Context, _ *emptypb.Empty) (*pb.ListM } return &pb.ListMachinesResponse{Machines: machines}, nil } - -func (c *Cluster) AddUser(user *pb.User) error { - c.state.State.Users = append(c.state.State.Users, user) - return c.state.Save() -} - -func (c *Cluster) ListUsers() []*pb.User { - return c.state.State.Users -} diff --git a/internal/machine/cluster/state.go b/internal/machine/cluster/state.go deleted file mode 100644 index d13fd026..00000000 --- a/internal/machine/cluster/state.go +++ /dev/null @@ -1,60 +0,0 @@ -package cluster - -import ( - "fmt" - "google.golang.org/protobuf/proto" - "os" - "path/filepath" - "uncloud/internal/machine/api/pb" -) - -const StateFile = "cluster.pb" - -type State struct { - State *pb.State - path string -} - -func StatePath(dataDir string) string { - return filepath.Join(dataDir, StateFile) -} - -func NewState(path string) *State { - return &State{ - State: &pb.State{ - Machines: make(map[string]*pb.MachineInfo), - Endpoints: make(map[string]*pb.MachineEndpoints), - }, - path: path, - } -} - -func (s *State) Load() error { - data, err := os.ReadFile(s.path) - if err != nil { - return fmt.Errorf("read state file %q: %w", s.path, err) - } - if err = proto.Unmarshal(data, s.State); err != nil { - return fmt.Errorf("parse state file %q: %w", s.path, err) - } - if s.State.Machines == nil { - s.State.Machines = make(map[string]*pb.MachineInfo) - } - if s.State.Endpoints == nil { - s.State.Endpoints = make(map[string]*pb.MachineEndpoints) - } - return nil -} - -func (s *State) Save() error { - dir, _ := filepath.Split(s.path) - if err := os.MkdirAll(dir, 0711); err != nil { - return fmt.Errorf("create state directory %q: %w", dir, err) - } - - data, err := proto.Marshal(s.State) - if err != nil { - return fmt.Errorf("marshal state: %w", err) - } - return os.WriteFile(s.path, data, 0600) -} diff --git a/internal/machine/machine.go b/internal/machine/machine.go index 98997c18..0fd4a73c 100644 --- a/internal/machine/machine.go +++ b/internal/machine/machine.go @@ -119,20 +119,7 @@ func NewMachine(config *Config) (*Machine, error) { return nil, fmt.Errorf("create corrosion API client: %w", err) } corroStore := store.New(corro) - - var c *cluster.Cluster - clusterState := cluster.NewState(cluster.StatePath(config.DataDir)) - if err = clusterState.Load(); err != nil { - if errors.Is(err, os.ErrNotExist) { - // Cluster state file does not exist, initialise the cluster without a state to fail cluster requests. - c = cluster.NewCluster(nil, corroStore) - } else { - return nil, fmt.Errorf("load cluster state: %w", err) - } - } else { - // Cluster state is successfully loaded, initialise the cluster with it. - c = cluster.NewCluster(clusterState, corroStore) - } + c := cluster.NewCluster(corroStore) m := &Machine{ config: *config, @@ -288,10 +275,11 @@ func listenUnixSocket(path string) (net.Listener, error) { gid := 0 // Fall back to the root group if the uncloud group is not found. group, err := user.LookupGroup(DefaultAPISockGroup) if err != nil { + //goland:noinspection GoTypeAssertionOnErrors if _, ok := err.(user.UnknownGroupError); ok { slog.Info( - "Specified group not found, using root group for the API socket.", "group", DefaultAPISockGroup, "path", - path, + "Specified group not found, using root group for the API socket.", + "group", DefaultAPISockGroup, "path", path, ) } else { return nil, fmt.Errorf("lookup %q group ID (GID): %w", DefaultAPISockGroup, err) @@ -359,39 +347,28 @@ func (m *Machine) configureCorrosion() error { return nil } -// InitCluster resets the local machine and initialises a new cluster with it. +// InitCluster initialises a new cluster on the local machine with the provided network configuration. func (m *Machine) InitCluster(ctx context.Context, req *pb.InitClusterRequest) (*pb.InitClusterResponse, error) { - var err error - machineName := req.MachineName - if machineName == "" { - machineName, err = cluster.NewRandomMachineName() - if err != nil { - return nil, status.Errorf(codes.Internal, "generate machine name: %v", err) - } - } - - // TODO: a proper cluster leave mechanism and machine reset should be implemented later. - // For now just reset the machine state and cluster state. - clusterStatePath := cluster.StatePath(m.config.DataDir) - clusterState := cluster.NewState(clusterStatePath) - if err = clusterState.Save(); err != nil { - return nil, status.Errorf(codes.Internal, "save cluster state: %v", err) - } - m.cluster.SetState(clusterState) - slog.Info("Cluster state initialised.", "path", clusterStatePath) - if err = m.cluster.SetNetwork(req.Network); err != nil { - return nil, status.Errorf(codes.InvalidArgument, "set cluster network: %v", err) + if m.Initialised() { + return nil, status.Error(codes.FailedPrecondition, "machine is already configured as a cluster member") } clusterNetwork, err := req.Network.ToPrefix() if err != nil { return nil, status.Errorf(codes.InvalidArgument, "invalid network: %v", err) } + if err = m.cluster.Init(ctx, clusterNetwork); err != nil { return nil, status.Errorf(codes.Internal, "init cluster: %v", err) } slog.Info("Cluster state initialised.", "network", clusterNetwork.String()) + machineName := req.MachineName + if machineName == "" { + if machineName, err = cluster.NewRandomMachineName(); err != nil { + return nil, status.Errorf(codes.Internal, "generate machine name: %v", err) + } + } // Use the public and all routable IPs as endpoints. ips, err := network.ListRoutableIPs() if err != nil { @@ -442,7 +419,7 @@ func (m *Machine) InitCluster(ctx context.Context, req *pb.InitClusterRequest) ( if err = m.state.Save(); err != nil { return nil, status.Errorf(codes.Internal, "save machine state: %v", err) } - slog.Info("Cluster initialised with machine.", "machine", m.state.Name) + slog.Info("Cluster initialised with machine.", "id", m.state.ID, "machine", m.state.Name) // Signal that the machine is initialised as a member of a cluster. m.initialised <- struct{}{} @@ -452,10 +429,11 @@ func (m *Machine) InitCluster(ctx context.Context, req *pb.InitClusterRequest) ( return resp, nil } -// JoinCluster resets the local machine and configures it to join an existing cluster. +// JoinCluster configures the local machine to join an existing cluster. func (m *Machine) JoinCluster(ctx context.Context, req *pb.JoinClusterRequest) (*emptypb.Empty, error) { - // TODO: a proper cluster leave mechanism and machine reset should be implemented later. - // For now assume the machine wasn't part of a cluster. + if m.Initialised() { + return nil, status.Error(codes.FailedPrecondition, "machine is already configured as a cluster member") + } if req.Machine.Id == "" { return nil, status.Error(codes.InvalidArgument, "machine ID not set")