From f6cf5cc25035a050d5a81b3cdfc37e37c90bc4a2 Mon Sep 17 00:00:00 2001 From: Pavel Sviderski Date: Mon, 24 Feb 2025 17:35:19 +1000 Subject: [PATCH] feat(dns): cluster API for reserving/releasing cluster domain in Uncloud DNS --- go.mod | 4 +- go.sum | 20 +- internal/machine/api/pb/cluster.pb.go | 203 ++++++++++++++------- internal/machine/api/pb/cluster.proto | 7 + internal/machine/api/pb/cluster_grpc.pb.go | 76 ++++++++ internal/machine/cluster/dns.go | 109 +++++++++++ internal/machine/machine.go | 2 +- internal/machine/store/store.go | 5 + 8 files changed, 349 insertions(+), 77 deletions(-) create mode 100644 internal/machine/cluster/dns.go diff --git a/go.mod b/go.mod index d1ec58c2..9937b767 100644 --- a/go.mod +++ b/go.mod @@ -16,10 +16,10 @@ require ( github.com/distribution/reference v0.6.0 github.com/docker/cli v27.5.0+incompatible github.com/docker/compose/v2 v2.31.0 - github.com/docker/docker v27.5.0+incompatible + github.com/docker/docker v27.4.0-rc.2+incompatible github.com/docker/go-connections v0.5.0 github.com/docker/go-units v0.5.0 - github.com/google/go-containerregistry v0.20.3 + github.com/google/go-containerregistry v0.20.2 github.com/hashicorp/memberlist v0.5.1 github.com/hashicorp/serf v0.10.1 github.com/ipfs/boxo v0.21.0 diff --git a/go.sum b/go.sum index d5b4ad38..722dc586 100644 --- a/go.sum +++ b/go.sum @@ -5,8 +5,8 @@ cloud.google.com/go/auth v0.4.1/go.mod h1:QVBuVEKpCn4Zp58hzRGvL0tjRGU0YqdRTdCHM1 cloud.google.com/go/auth/oauth2adapt v0.2.2 h1:+TTV8aXpjeChS9M+aTtN/TjdQnzJvmzKFt//oWu7HX4= cloud.google.com/go/auth/oauth2adapt v0.2.2/go.mod h1:wcYjgpZI9+Yu7LyYBg4pqSiaRkfEK3GQcpb7C/uyF1Q= cloud.google.com/go/compute v1.25.1 h1:ZRpHJedLtTpKgr3RV1Fx23NuaAEN1Zfx9hw1u4aJdjU= -cloud.google.com/go/compute/metadata v0.6.0 h1:A6hENjEsCDtC1k8byVsgwvVcioamEHvZ4j01OwKxG9I= -cloud.google.com/go/compute/metadata v0.6.0/go.mod h1:FjyFAW1MW0C203CEOMDTu3Dk1FlqW3Rga40jzHL4hfg= +cloud.google.com/go/compute/metadata v0.5.0 h1:Zr0eK8JbFv6+Wi4ilXAR8FJ3wyNdpxHKJNPos6LTZOY= +cloud.google.com/go/compute/metadata v0.5.0/go.mod h1:aHnloV2TPI38yx4s9+wAZhHykWvVCfu7hQbF+9CWoiY= cloud.google.com/go/iam v1.1.8 h1:r7umDwhj+BQyz0ScZMp4QrGXjSTI3ZINnpgU2nlB/K0= cloud.google.com/go/iam v1.1.8/go.mod h1:GvE6lyMmfxXauzNq8NbgJbeVQNspG+tcdL/W8QO1+zE= cloud.google.com/go/kms v1.16.0 h1:1yZsRPhmargZOmY+fVAh8IKiR9HzCb0U1zsxb5g2nRY= @@ -262,8 +262,8 @@ github.com/docker/compose/v2 v2.31.0/go.mod h1:oQq3UDEdsnB3AUO72AxaoeLbkCgmUu1+8 github.com/docker/distribution v2.7.1+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w= github.com/docker/distribution v2.8.3+incompatible h1:AtKxIZ36LoNK51+Z6RpzLpddBirtxJnzDrHLEKxTAYk= github.com/docker/distribution v2.8.3+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w= -github.com/docker/docker v27.5.0+incompatible h1:um++2NcQtGRTz5eEgO6aJimo6/JxrTXC941hd05JO6U= -github.com/docker/docker v27.5.0+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= +github.com/docker/docker v27.4.0-rc.2+incompatible h1:9OJjVGtelk/zGC3TyKweJ29b9Axzh0s/0vtU4mneumE= +github.com/docker/docker v27.4.0-rc.2+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= github.com/docker/docker-credential-helpers v0.8.2 h1:bX3YxiGzFP5sOXWc3bTPEXdEaZSeVMrFgOr3T+zrFAo= github.com/docker/docker-credential-helpers v0.8.2/go.mod h1:P3ci7E3lwkZg6XiHdRKft1KckHiO9a2rNtyFbZ/ry9M= github.com/docker/go v1.5.1-1.0.20160303222718-d30aec9fd63c h1:lzqkGL9b3znc+ZUgi7FlLnqjQhcXxkNM/quxIjBVMD0= @@ -397,8 +397,8 @@ github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= -github.com/google/go-containerregistry v0.20.3 h1:oNx7IdTI936V8CQRveCjaxOiegWwvM7kqkbXTpyiovI= -github.com/google/go-containerregistry v0.20.3/go.mod h1:w00pIgBRDVUDFM6bq+Qx8lwNWK+cxgCuX1vd3PIBDNI= +github.com/google/go-containerregistry v0.20.2 h1:B1wPJ1SN/S7pB+ZAimcciVD+r+yV/l/DSArMxlbwseo= +github.com/google/go-containerregistry v0.20.2/go.mod h1:z38EKdKh4h7IP2gSfUUqEvalZBqs6AoLeWfUy34nQC8= github.com/google/go-tpm v0.9.0 h1:sQF6YqWMi+SCXpsmS3fd21oPy/vSddwZry4JnmltHVk= github.com/google/go-tpm v0.9.0/go.mod h1:FkNVkc6C+IsvDI9Jw1OveJmxGZUUaKxtrpOS47QWKfU= github.com/google/go-tpm-tools v0.4.4 h1:oiQfAIkc6xTy9Fl5NKTeTJkBTlXdHsxAofmQyxBKY98= @@ -1106,8 +1106,8 @@ go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.33.0 h1:Vh5HayB/0HHfOQA7Ctx go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.33.0/go.mod h1:cpgtDBaqD/6ok/UG0jT15/uKjAY8mRA53diogHBg3UI= go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.27.0 h1:qFffATk0X+HD+f1Z8lswGiOQYKHRlzfmdJm0wEaVrFA= go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.27.0/go.mod h1:MOiCmryaYtc+V0Ei+Tx9o5S1ZjA7kzLucuVuyzBZloQ= -go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.33.0 h1:wpMfgF8E1rkrT1Z6meFh1NDtownE9Ii3n3X2GJYjsaU= -go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.33.0/go.mod h1:wAy0T/dUbs468uOlkT31xjvqQgEVXv58BRFWEgn5v/0= +go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.27.0 h1:QY7/0NeRPKlzusf40ZE4t1VlMKbqSNT7cJRYzWuja0s= +go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.27.0/go.mod h1:HVkSiDhTM9BoUJU8qE6j2eSWLLXvi1USXjyd2BXT8PY= go.opentelemetry.io/otel/metric v1.33.0 h1:r+JOocAyeRVXD8lZpjdQjzMadVZp2M4WmQ+5WtEnklQ= go.opentelemetry.io/otel/metric v1.33.0/go.mod h1:L9+Fyctbp6HFTddIxClbQkjtubW6O9QS3Ann/M82u6M= go.opentelemetry.io/otel/sdk v1.33.0 h1:iax7M131HuAm9QkZotNHEfstof92xM+N8sr3uHXc2IM= @@ -1222,8 +1222,8 @@ golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= golang.org/x/net v0.34.0 h1:Mb7Mrk043xzHgnRM88suvJFwzVrRfHEHJEl5/71CKw0= golang.org/x/net v0.34.0/go.mod h1:di0qlW3YNM5oh6GqDGQr92MyTozJPmybPK4Ev/Gm31k= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= -golang.org/x/oauth2 v0.25.0 h1:CY4y7XT9v0cRI9oupztF8AgiIu99L/ksR/Xp/6jrZ70= -golang.org/x/oauth2 v0.25.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= +golang.org/x/oauth2 v0.24.0 h1:KTBBxWqUa0ykRPLtV69rRto9TLXcqYkeswu48x/gvNE= +golang.org/x/oauth2 v0.24.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= diff --git a/internal/machine/api/pb/cluster.pb.go b/internal/machine/api/pb/cluster.pb.go index ab42e2ca..dba977a1 100644 --- a/internal/machine/api/pb/cluster.pb.go +++ b/internal/machine/api/pb/cluster.pb.go @@ -124,7 +124,7 @@ func (x DNSRecord_RecordType) Number() protoreflect.EnumNumber { // Deprecated: Use DNSRecord_RecordType.Descriptor instead. func (DNSRecord_RecordType) EnumDescriptor() ([]byte, []int) { - return file_internal_machine_api_pb_cluster_proto_rawDescGZIP(), []int{6, 0} + return file_internal_machine_api_pb_cluster_proto_rawDescGZIP(), []int{7, 0} } type AddMachineRequest struct { @@ -378,6 +378,53 @@ func (x *Domain) GetName() string { return "" } +type ReserveDomainRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + ApiEndpoint string `protobuf:"bytes,1,opt,name=api_endpoint,json=apiEndpoint,proto3" json:"api_endpoint,omitempty"` +} + +func (x *ReserveDomainRequest) Reset() { + *x = ReserveDomainRequest{} + 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 *ReserveDomainRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ReserveDomainRequest) ProtoMessage() {} + +func (x *ReserveDomainRequest) 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 ReserveDomainRequest.ProtoReflect.Descriptor instead. +func (*ReserveDomainRequest) Descriptor() ([]byte, []int) { + return file_internal_machine_api_pb_cluster_proto_rawDescGZIP(), []int{5} +} + +func (x *ReserveDomainRequest) GetApiEndpoint() string { + if x != nil { + return x.ApiEndpoint + } + return "" +} + type UpdateDomainRecordsRequest struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -389,7 +436,7 @@ type UpdateDomainRecordsRequest struct { func (x *UpdateDomainRecordsRequest) Reset() { *x = UpdateDomainRecordsRequest{} if protoimpl.UnsafeEnabled { - mi := &file_internal_machine_api_pb_cluster_proto_msgTypes[5] + mi := &file_internal_machine_api_pb_cluster_proto_msgTypes[6] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -402,7 +449,7 @@ func (x *UpdateDomainRecordsRequest) String() string { func (*UpdateDomainRecordsRequest) ProtoMessage() {} func (x *UpdateDomainRecordsRequest) ProtoReflect() protoreflect.Message { - mi := &file_internal_machine_api_pb_cluster_proto_msgTypes[5] + 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 { @@ -415,7 +462,7 @@ func (x *UpdateDomainRecordsRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use UpdateDomainRecordsRequest.ProtoReflect.Descriptor instead. func (*UpdateDomainRecordsRequest) Descriptor() ([]byte, []int) { - return file_internal_machine_api_pb_cluster_proto_rawDescGZIP(), []int{5} + return file_internal_machine_api_pb_cluster_proto_rawDescGZIP(), []int{6} } func (x *UpdateDomainRecordsRequest) GetRecords() []*DNSRecord { @@ -438,7 +485,7 @@ type DNSRecord struct { func (x *DNSRecord) Reset() { *x = DNSRecord{} if protoimpl.UnsafeEnabled { - mi := &file_internal_machine_api_pb_cluster_proto_msgTypes[6] + mi := &file_internal_machine_api_pb_cluster_proto_msgTypes[7] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -451,7 +498,7 @@ func (x *DNSRecord) String() string { func (*DNSRecord) ProtoMessage() {} func (x *DNSRecord) ProtoReflect() protoreflect.Message { - mi := &file_internal_machine_api_pb_cluster_proto_msgTypes[6] + 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 { @@ -464,7 +511,7 @@ func (x *DNSRecord) ProtoReflect() protoreflect.Message { // Deprecated: Use DNSRecord.ProtoReflect.Descriptor instead. func (*DNSRecord) Descriptor() ([]byte, []int) { - return file_internal_machine_api_pb_cluster_proto_rawDescGZIP(), []int{6} + return file_internal_machine_api_pb_cluster_proto_rawDescGZIP(), []int{7} } func (x *DNSRecord) GetName() string { @@ -525,42 +572,53 @@ var file_internal_machine_api_pb_cluster_proto_rawDesc = []byte{ 0x2e, 0x4d, 0x61, 0x63, 0x68, 0x69, 0x6e, 0x65, 0x4d, 0x65, 0x6d, 0x62, 0x65, 0x72, 0x52, 0x08, 0x6d, 0x61, 0x63, 0x68, 0x69, 0x6e, 0x65, 0x73, 0x22, 0x1c, 0x0a, 0x06, 0x44, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, - 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x46, 0x0a, 0x1a, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, - 0x44, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x73, 0x52, 0x65, 0x71, - 0x75, 0x65, 0x73, 0x74, 0x12, 0x28, 0x0a, 0x07, 0x72, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x73, 0x18, - 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x44, 0x4e, 0x53, 0x52, - 0x65, 0x63, 0x6f, 0x72, 0x64, 0x52, 0x07, 0x72, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x73, 0x22, 0x96, - 0x01, 0x0a, 0x09, 0x44, 0x4e, 0x53, 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x12, 0x12, 0x0a, 0x04, - 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, - 0x12, 0x2d, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x19, - 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x44, 0x4e, 0x53, 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x2e, 0x52, - 0x65, 0x63, 0x6f, 0x72, 0x64, 0x54, 0x79, 0x70, 0x65, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x12, - 0x16, 0x0a, 0x06, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x09, 0x52, - 0x06, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x73, 0x22, 0x2e, 0x0a, 0x0a, 0x52, 0x65, 0x63, 0x6f, 0x72, - 0x64, 0x54, 0x79, 0x70, 0x65, 0x12, 0x0f, 0x0a, 0x0b, 0x55, 0x4e, 0x53, 0x50, 0x45, 0x43, 0x49, - 0x46, 0x49, 0x45, 0x44, 0x10, 0x00, 0x12, 0x05, 0x0a, 0x01, 0x41, 0x10, 0x01, 0x12, 0x08, 0x0a, - 0x04, 0x41, 0x41, 0x41, 0x41, 0x10, 0x02, 0x32, 0x8d, 0x02, 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, 0x6e, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, - 0x73, 0x65, 0x12, 0x41, 0x0a, 0x0c, 0x4c, 0x69, 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, 0x30, 0x0a, 0x09, 0x47, 0x65, 0x74, 0x44, 0x6f, 0x6d, 0x61, - 0x69, 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, 0x0b, 0x2e, 0x61, 0x70, 0x69, - 0x2e, 0x44, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x12, 0x4e, 0x0a, 0x13, 0x55, 0x70, 0x64, 0x61, 0x74, - 0x65, 0x44, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x73, 0x12, 0x1f, - 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x44, 0x6f, 0x6d, 0x61, 0x69, - 0x6e, 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x73, 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, 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, + 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x39, 0x0a, 0x14, 0x52, 0x65, 0x73, 0x65, 0x72, 0x76, + 0x65, 0x44, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x21, + 0x0a, 0x0c, 0x61, 0x70, 0x69, 0x5f, 0x65, 0x6e, 0x64, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x61, 0x70, 0x69, 0x45, 0x6e, 0x64, 0x70, 0x6f, 0x69, 0x6e, + 0x74, 0x22, 0x46, 0x0a, 0x1a, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x44, 0x6f, 0x6d, 0x61, 0x69, + 0x6e, 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, + 0x28, 0x0a, 0x07, 0x72, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, + 0x32, 0x0e, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x44, 0x4e, 0x53, 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, + 0x52, 0x07, 0x72, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x73, 0x22, 0x96, 0x01, 0x0a, 0x09, 0x44, 0x4e, + 0x53, 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x2d, 0x0a, 0x04, 0x74, + 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x19, 0x2e, 0x61, 0x70, 0x69, 0x2e, + 0x44, 0x4e, 0x53, 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x2e, 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, + 0x54, 0x79, 0x70, 0x65, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x76, 0x61, + 0x6c, 0x75, 0x65, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x09, 0x52, 0x06, 0x76, 0x61, 0x6c, 0x75, + 0x65, 0x73, 0x22, 0x2e, 0x0a, 0x0a, 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x54, 0x79, 0x70, 0x65, + 0x12, 0x0f, 0x0a, 0x0b, 0x55, 0x4e, 0x53, 0x50, 0x45, 0x43, 0x49, 0x46, 0x49, 0x45, 0x44, 0x10, + 0x00, 0x12, 0x05, 0x0a, 0x01, 0x41, 0x10, 0x01, 0x12, 0x08, 0x0a, 0x04, 0x41, 0x41, 0x41, 0x41, + 0x10, 0x02, 0x32, 0xfc, 0x02, 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, 0x6e, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x41, 0x0a, + 0x0c, 0x4c, 0x69, 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, 0x37, 0x0a, 0x0d, 0x52, 0x65, 0x73, 0x65, 0x72, 0x76, 0x65, 0x44, 0x6f, 0x6d, 0x61, 0x69, + 0x6e, 0x12, 0x19, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x52, 0x65, 0x73, 0x65, 0x72, 0x76, 0x65, 0x44, + 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x0b, 0x2e, 0x61, + 0x70, 0x69, 0x2e, 0x44, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x12, 0x30, 0x0a, 0x09, 0x47, 0x65, 0x74, + 0x44, 0x6f, 0x6d, 0x61, 0x69, 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, 0x0b, + 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x44, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x12, 0x34, 0x0a, 0x0d, 0x52, + 0x65, 0x6c, 0x65, 0x61, 0x73, 0x65, 0x44, 0x6f, 0x6d, 0x61, 0x69, 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, 0x0b, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x44, 0x6f, 0x6d, 0x61, 0x69, + 0x6e, 0x12, 0x4e, 0x0a, 0x13, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x44, 0x6f, 0x6d, 0x61, 0x69, + 0x6e, 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x73, 0x12, 0x1f, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x55, + 0x70, 0x64, 0x61, 0x74, 0x65, 0x44, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x52, 0x65, 0x63, 0x6f, 0x72, + 0x64, 0x73, 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, 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 ( @@ -576,7 +634,7 @@ func file_internal_machine_api_pb_cluster_proto_rawDescGZIP() []byte { } var file_internal_machine_api_pb_cluster_proto_enumTypes = make([]protoimpl.EnumInfo, 2) -var file_internal_machine_api_pb_cluster_proto_msgTypes = make([]protoimpl.MessageInfo, 7) +var file_internal_machine_api_pb_cluster_proto_msgTypes = make([]protoimpl.MessageInfo, 8) var file_internal_machine_api_pb_cluster_proto_goTypes = []any{ (MachineMember_MembershipState)(0), // 0: api.MachineMember.MembershipState (DNSRecord_RecordType)(0), // 1: api.DNSRecord.RecordType @@ -585,30 +643,35 @@ var file_internal_machine_api_pb_cluster_proto_goTypes = []any{ (*MachineMember)(nil), // 4: api.MachineMember (*ListMachinesResponse)(nil), // 5: api.ListMachinesResponse (*Domain)(nil), // 6: api.Domain - (*UpdateDomainRecordsRequest)(nil), // 7: api.UpdateDomainRecordsRequest - (*DNSRecord)(nil), // 8: api.DNSRecord - (*NetworkConfig)(nil), // 9: api.NetworkConfig - (*MachineInfo)(nil), // 10: api.MachineInfo - (*emptypb.Empty)(nil), // 11: google.protobuf.Empty + (*ReserveDomainRequest)(nil), // 7: api.ReserveDomainRequest + (*UpdateDomainRecordsRequest)(nil), // 8: api.UpdateDomainRecordsRequest + (*DNSRecord)(nil), // 9: api.DNSRecord + (*NetworkConfig)(nil), // 10: api.NetworkConfig + (*MachineInfo)(nil), // 11: api.MachineInfo + (*emptypb.Empty)(nil), // 12: google.protobuf.Empty } var file_internal_machine_api_pb_cluster_proto_depIdxs = []int32{ - 9, // 0: api.AddMachineRequest.network:type_name -> api.NetworkConfig - 10, // 1: api.AddMachineResponse.machine:type_name -> api.MachineInfo - 10, // 2: api.MachineMember.machine:type_name -> api.MachineInfo + 10, // 0: api.AddMachineRequest.network:type_name -> api.NetworkConfig + 11, // 1: api.AddMachineResponse.machine:type_name -> api.MachineInfo + 11, // 2: api.MachineMember.machine:type_name -> api.MachineInfo 0, // 3: api.MachineMember.state:type_name -> api.MachineMember.MembershipState 4, // 4: api.ListMachinesResponse.machines:type_name -> api.MachineMember - 8, // 5: api.UpdateDomainRecordsRequest.records:type_name -> api.DNSRecord + 9, // 5: api.UpdateDomainRecordsRequest.records:type_name -> api.DNSRecord 1, // 6: api.DNSRecord.type:type_name -> api.DNSRecord.RecordType 2, // 7: api.Cluster.AddMachine:input_type -> api.AddMachineRequest - 11, // 8: api.Cluster.ListMachines:input_type -> google.protobuf.Empty - 11, // 9: api.Cluster.GetDomain:input_type -> google.protobuf.Empty - 7, // 10: api.Cluster.UpdateDomainRecords:input_type -> api.UpdateDomainRecordsRequest - 3, // 11: api.Cluster.AddMachine:output_type -> api.AddMachineResponse - 5, // 12: api.Cluster.ListMachines:output_type -> api.ListMachinesResponse - 6, // 13: api.Cluster.GetDomain:output_type -> api.Domain - 11, // 14: api.Cluster.UpdateDomainRecords:output_type -> google.protobuf.Empty - 11, // [11:15] is the sub-list for method output_type - 7, // [7:11] is the sub-list for method input_type + 12, // 8: api.Cluster.ListMachines:input_type -> google.protobuf.Empty + 7, // 9: api.Cluster.ReserveDomain:input_type -> api.ReserveDomainRequest + 12, // 10: api.Cluster.GetDomain:input_type -> google.protobuf.Empty + 12, // 11: api.Cluster.ReleaseDomain:input_type -> google.protobuf.Empty + 8, // 12: api.Cluster.UpdateDomainRecords:input_type -> api.UpdateDomainRecordsRequest + 3, // 13: api.Cluster.AddMachine:output_type -> api.AddMachineResponse + 5, // 14: api.Cluster.ListMachines:output_type -> api.ListMachinesResponse + 6, // 15: api.Cluster.ReserveDomain:output_type -> api.Domain + 6, // 16: api.Cluster.GetDomain:output_type -> api.Domain + 6, // 17: api.Cluster.ReleaseDomain:output_type -> api.Domain + 12, // 18: api.Cluster.UpdateDomainRecords:output_type -> google.protobuf.Empty + 13, // [13:19] is the sub-list for method output_type + 7, // [7:13] is the sub-list for method input_type 7, // [7:7] is the sub-list for extension type_name 7, // [7:7] is the sub-list for extension extendee 0, // [0:7] is the sub-list for field type_name @@ -682,7 +745,7 @@ func file_internal_machine_api_pb_cluster_proto_init() { } } file_internal_machine_api_pb_cluster_proto_msgTypes[5].Exporter = func(v any, i int) any { - switch v := v.(*UpdateDomainRecordsRequest); i { + switch v := v.(*ReserveDomainRequest); i { case 0: return &v.state case 1: @@ -694,6 +757,18 @@ func file_internal_machine_api_pb_cluster_proto_init() { } } file_internal_machine_api_pb_cluster_proto_msgTypes[6].Exporter = func(v any, i int) any { + switch v := v.(*UpdateDomainRecordsRequest); 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.(*DNSRecord); i { case 0: return &v.state @@ -712,7 +787,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: 2, - NumMessages: 7, + NumMessages: 8, NumExtensions: 0, NumServices: 1, }, diff --git a/internal/machine/api/pb/cluster.proto b/internal/machine/api/pb/cluster.proto index 5ffc27d2..03e9aa1e 100644 --- a/internal/machine/api/pb/cluster.proto +++ b/internal/machine/api/pb/cluster.proto @@ -10,7 +10,10 @@ import "internal/machine/api/pb/machine.proto"; service Cluster { rpc AddMachine(AddMachineRequest) returns (AddMachineResponse); rpc ListMachines(google.protobuf.Empty) returns (ListMachinesResponse); + + rpc ReserveDomain(ReserveDomainRequest) returns (Domain); rpc GetDomain(google.protobuf.Empty) returns (Domain); + rpc ReleaseDomain(google.protobuf.Empty) returns (Domain); rpc UpdateDomainRecords(UpdateDomainRecordsRequest) returns (google.protobuf.Empty); } @@ -48,6 +51,10 @@ message Domain { string name = 1; } +message ReserveDomainRequest { + string api_endpoint = 1; +} + message UpdateDomainRecordsRequest { repeated DNSRecord records = 1; } diff --git a/internal/machine/api/pb/cluster_grpc.pb.go b/internal/machine/api/pb/cluster_grpc.pb.go index fbcbeabb..7c75612d 100644 --- a/internal/machine/api/pb/cluster_grpc.pb.go +++ b/internal/machine/api/pb/cluster_grpc.pb.go @@ -22,7 +22,9 @@ const _ = grpc.SupportPackageIsVersion9 const ( Cluster_AddMachine_FullMethodName = "/api.Cluster/AddMachine" Cluster_ListMachines_FullMethodName = "/api.Cluster/ListMachines" + Cluster_ReserveDomain_FullMethodName = "/api.Cluster/ReserveDomain" Cluster_GetDomain_FullMethodName = "/api.Cluster/GetDomain" + Cluster_ReleaseDomain_FullMethodName = "/api.Cluster/ReleaseDomain" Cluster_UpdateDomainRecords_FullMethodName = "/api.Cluster/UpdateDomainRecords" ) @@ -32,7 +34,9 @@ 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) + ReserveDomain(ctx context.Context, in *ReserveDomainRequest, opts ...grpc.CallOption) (*Domain, error) GetDomain(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*Domain, error) + ReleaseDomain(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*Domain, error) UpdateDomainRecords(ctx context.Context, in *UpdateDomainRecordsRequest, opts ...grpc.CallOption) (*emptypb.Empty, error) } @@ -64,6 +68,16 @@ func (c *clusterClient) ListMachines(ctx context.Context, in *emptypb.Empty, opt return out, nil } +func (c *clusterClient) ReserveDomain(ctx context.Context, in *ReserveDomainRequest, opts ...grpc.CallOption) (*Domain, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(Domain) + err := c.cc.Invoke(ctx, Cluster_ReserveDomain_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + func (c *clusterClient) GetDomain(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*Domain, error) { cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) out := new(Domain) @@ -74,6 +88,16 @@ func (c *clusterClient) GetDomain(ctx context.Context, in *emptypb.Empty, opts . return out, nil } +func (c *clusterClient) ReleaseDomain(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*Domain, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(Domain) + err := c.cc.Invoke(ctx, Cluster_ReleaseDomain_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + func (c *clusterClient) UpdateDomainRecords(ctx context.Context, in *UpdateDomainRecordsRequest, opts ...grpc.CallOption) (*emptypb.Empty, error) { cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) out := new(emptypb.Empty) @@ -90,7 +114,9 @@ func (c *clusterClient) UpdateDomainRecords(ctx context.Context, in *UpdateDomai type ClusterServer interface { AddMachine(context.Context, *AddMachineRequest) (*AddMachineResponse, error) ListMachines(context.Context, *emptypb.Empty) (*ListMachinesResponse, error) + ReserveDomain(context.Context, *ReserveDomainRequest) (*Domain, error) GetDomain(context.Context, *emptypb.Empty) (*Domain, error) + ReleaseDomain(context.Context, *emptypb.Empty) (*Domain, error) UpdateDomainRecords(context.Context, *UpdateDomainRecordsRequest) (*emptypb.Empty, error) mustEmbedUnimplementedClusterServer() } @@ -108,9 +134,15 @@ 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) ReserveDomain(context.Context, *ReserveDomainRequest) (*Domain, error) { + return nil, status.Errorf(codes.Unimplemented, "method ReserveDomain not implemented") +} func (UnimplementedClusterServer) GetDomain(context.Context, *emptypb.Empty) (*Domain, error) { return nil, status.Errorf(codes.Unimplemented, "method GetDomain not implemented") } +func (UnimplementedClusterServer) ReleaseDomain(context.Context, *emptypb.Empty) (*Domain, error) { + return nil, status.Errorf(codes.Unimplemented, "method ReleaseDomain not implemented") +} func (UnimplementedClusterServer) UpdateDomainRecords(context.Context, *UpdateDomainRecordsRequest) (*emptypb.Empty, error) { return nil, status.Errorf(codes.Unimplemented, "method UpdateDomainRecords not implemented") } @@ -171,6 +203,24 @@ func _Cluster_ListMachines_Handler(srv interface{}, ctx context.Context, dec fun return interceptor(ctx, in, info, handler) } +func _Cluster_ReserveDomain_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ReserveDomainRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ClusterServer).ReserveDomain(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Cluster_ReserveDomain_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ClusterServer).ReserveDomain(ctx, req.(*ReserveDomainRequest)) + } + return interceptor(ctx, in, info, handler) +} + func _Cluster_GetDomain_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(emptypb.Empty) if err := dec(in); err != nil { @@ -189,6 +239,24 @@ func _Cluster_GetDomain_Handler(srv interface{}, ctx context.Context, dec func(i return interceptor(ctx, in, info, handler) } +func _Cluster_ReleaseDomain_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(emptypb.Empty) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ClusterServer).ReleaseDomain(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Cluster_ReleaseDomain_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ClusterServer).ReleaseDomain(ctx, req.(*emptypb.Empty)) + } + return interceptor(ctx, in, info, handler) +} + func _Cluster_UpdateDomainRecords_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(UpdateDomainRecordsRequest) if err := dec(in); err != nil { @@ -222,10 +290,18 @@ var Cluster_ServiceDesc = grpc.ServiceDesc{ MethodName: "ListMachines", Handler: _Cluster_ListMachines_Handler, }, + { + MethodName: "ReserveDomain", + Handler: _Cluster_ReserveDomain_Handler, + }, { MethodName: "GetDomain", Handler: _Cluster_GetDomain_Handler, }, + { + MethodName: "ReleaseDomain", + Handler: _Cluster_ReleaseDomain_Handler, + }, { MethodName: "UpdateDomainRecords", Handler: _Cluster_UpdateDomainRecords_Handler, diff --git a/internal/machine/cluster/dns.go b/internal/machine/cluster/dns.go new file mode 100644 index 00000000..b43070bb --- /dev/null +++ b/internal/machine/cluster/dns.go @@ -0,0 +1,109 @@ +package cluster + +import ( + "context" + "encoding/json" + "errors" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + "google.golang.org/protobuf/types/known/emptypb" + "uncloud/internal/dns" + "uncloud/internal/machine/api/pb" + "uncloud/internal/machine/store" +) + +// uncloudDNSKey is the key used to store the details of the reserved domain in the store. +const uncloudDNSKey = "uncloud_dns" + +type uncloudDNSDomain struct { + Name string + // TODO: encrypt the token in the store. + Token string +} + +func (c *Cluster) ReserveDomain(ctx context.Context, req *pb.ReserveDomainRequest) (*pb.Domain, error) { + if err := c.checkInitialised(ctx); err != nil { + return nil, err + } + + if req.ApiEndpoint == "" { + return nil, status.Error(codes.InvalidArgument, "API endpoint not set") + } + + if _, err := c.storedDomain(ctx); err == nil { + return nil, status.Errorf(codes.AlreadyExists, "domain already reserved") + } else { + if s := status.Convert(err); s.Code() != codes.NotFound { + return nil, err + } + } + + dnsClient := dns.NewClient() + name, token, err := dnsClient.ReserveDomain(req.ApiEndpoint) + if err != nil { + return nil, status.Errorf(codes.Internal, err.Error()) + } + + domain := uncloudDNSDomain{ + Name: name, + Token: token, + } + domainJSON, err := json.Marshal(domain) + if err != nil { + return nil, status.Errorf(codes.Internal, "marshal reserved domain for store: %v", err) + } + if err = c.store.Put(ctx, uncloudDNSKey, domainJSON); err != nil { + return nil, status.Errorf(codes.Internal, "store reserved domain: %v", err) + } + + return &pb.Domain{Name: name}, nil +} + +func (c *Cluster) GetDomain(ctx context.Context, _ *emptypb.Empty) (*pb.Domain, error) { + if err := c.checkInitialised(ctx); err != nil { + return nil, err + } + + domain, err := c.storedDomain(ctx) + if err != nil { + return nil, err + } + + return &pb.Domain{Name: domain.Name}, nil +} + +func (c *Cluster) storedDomain(ctx context.Context) (uncloudDNSDomain, error) { + var domain uncloudDNSDomain + var domainJSON []byte + + if err := c.store.Get(ctx, uncloudDNSKey, &domainJSON); err != nil { + if errors.Is(err, store.ErrKeyNotFound) { + return domain, status.Errorf(codes.NotFound, "domain not found") + } + return domain, status.Errorf(codes.Internal, "get domain from store: %v", err) + } + + if err := json.Unmarshal(domainJSON, &domain); err != nil { + return domain, status.Errorf(codes.Internal, "unmarshal domain: %v", err) + } + + return domain, nil +} + +func (c *Cluster) ReleaseDomain(ctx context.Context, _ *emptypb.Empty) (*pb.Domain, error) { + if err := c.checkInitialised(ctx); err != nil { + return nil, err + } + + domain, err := c.storedDomain(ctx) + if err != nil { + return nil, err + } + + if err = c.store.Delete(ctx, uncloudDNSKey); err != nil { + return nil, status.Errorf(codes.Internal, "delete domain from store: %v", err) + } + // TODO: implement and call Uncloud DNS endpoint to release/delete the domain. + + return &pb.Domain{Name: domain.Name}, nil +} diff --git a/internal/machine/machine.go b/internal/machine/machine.go index 16850b92..1aec9f8f 100644 --- a/internal/machine/machine.go +++ b/internal/machine/machine.go @@ -703,7 +703,7 @@ func (m *Machine) Inspect(_ context.Context, _ *emptypb.Empty) (*pb.MachineInfo, }, nil } -// InspectService returns detailed information about a service and its containers. +// InspectService returns detailed information about a service and its containers stored in the cluster store. func (m *Machine) InspectService( ctx context.Context, req *pb.InspectServiceRequest, ) (*pb.InspectServiceResponse, error) { diff --git a/internal/machine/store/store.go b/internal/machine/store/store.go index 1cc5ef67..099b2078 100644 --- a/internal/machine/store/store.go +++ b/internal/machine/store/store.go @@ -49,6 +49,11 @@ func (s *Store) Put(ctx context.Context, key string, value any) error { return err } +func (s *Store) Delete(ctx context.Context, key string) error { + _, err := s.corro.ExecContext(ctx, "DELETE FROM cluster WHERE key = ?", key) + return err +} + func (s *Store) CreateMachine(ctx context.Context, m *pb.MachineInfo) error { mJSON, err := protojson.Marshal(m) if err != nil {