From d3dad14030dd8f63f25e9279368440963d6be538 Mon Sep 17 00:00:00 2001 From: Semir Patel Date: Fri, 15 Sep 2023 09:34:18 -0500 Subject: [PATCH] resource: default peername to "local" for now (#18822) --- agent/grpc-external/services/resource/server.go | 2 +- .../services/resource/write_status.go | 2 +- .../services/resource/write_test.go | 16 ++++++++++++++++ internal/resource/tenancy.go | 11 ++++++++--- 4 files changed, 26 insertions(+), 5 deletions(-) diff --git a/agent/grpc-external/services/resource/server.go b/agent/grpc-external/services/resource/server.go index 52d993ad49..3ae839e69b 100644 --- a/agent/grpc-external/services/resource/server.go +++ b/agent/grpc-external/services/resource/server.go @@ -147,7 +147,7 @@ func validateId(id *pbresource.ID, errorPrefix string) error { id.Tenancy = &pbresource.Tenancy{ Partition: "", Namespace: "", - // TODO(spatel): Remove when peerTenancy introduced. + // TODO(spatel): NET-5475 - Remove as part of peer_name moving to PeerTenancy PeerName: "local", } } diff --git a/agent/grpc-external/services/resource/write_status.go b/agent/grpc-external/services/resource/write_status.go index 0c0395a267..673f193da0 100644 --- a/agent/grpc-external/services/resource/write_status.go +++ b/agent/grpc-external/services/resource/write_status.go @@ -173,7 +173,7 @@ func (s *Server) validateWriteStatusRequest(req *pbresource.WriteStatusRequest) req.Id.Tenancy = &pbresource.Tenancy{ Partition: "", Namespace: "", - // TODO(spatel): Remove when peerTenancy introduced. + // TODO(spatel): NET-5475 - Remove as part of peer_name moving to PeerTenancy PeerName: "local", } } diff --git a/agent/grpc-external/services/resource/write_test.go b/agent/grpc-external/services/resource/write_test.go index 755f8ef2cc..49a526e63d 100644 --- a/agent/grpc-external/services/resource/write_test.go +++ b/agent/grpc-external/services/resource/write_test.go @@ -256,6 +256,14 @@ func TestWrite_Create_Success(t *testing.T) { }, expectedTenancy: resource.DefaultNamespacedTenancy(), }, + // TODO(spatel): NET-5475 - Remove as part of peer_name moving to PeerTenancy + "namespaced resource defaults peername to local when empty": { + modFn: func(artist, _ *pbresource.Resource) *pbresource.Resource { + artist.Id.Tenancy.PeerName = "" + return artist + }, + expectedTenancy: resource.DefaultNamespacedTenancy(), + }, "partitioned resource provides nonempty partition": { modFn: func(_, recordLabel *pbresource.Resource) *pbresource.Resource { return recordLabel @@ -283,6 +291,14 @@ func TestWrite_Create_Success(t *testing.T) { }, expectedTenancy: resource.DefaultPartitionedTenancy(), }, + // TODO(spatel): NET-5475 - Remove as part of peer_name moving to PeerTenancy + "partitioned resource defaults peername to local when empty": { + modFn: func(_, recordLabel *pbresource.Resource) *pbresource.Resource { + recordLabel.Id.Tenancy.PeerName = "" + return recordLabel + }, + expectedTenancy: resource.DefaultPartitionedTenancy(), + }, // TODO(spatel): Add cluster scope tests when we have an actual cluster scoped resource (e.g. partition) } for desc, tc := range testCases { diff --git a/internal/resource/tenancy.go b/internal/resource/tenancy.go index 35ea87eabb..2a377ca2f5 100644 --- a/internal/resource/tenancy.go +++ b/internal/resource/tenancy.go @@ -52,12 +52,17 @@ func Normalize(tenancy *pbresource.Tenancy) { } tenancy.Partition = strings.ToLower(tenancy.Partition) tenancy.Namespace = strings.ToLower(tenancy.Namespace) + + // TODO(spatel): NET-5475 - Remove as part of peer_name moving to PeerTenancy + if tenancy.PeerName == "" { + tenancy.PeerName = "local" + } } // DefaultClusteredTenancy returns the default tenancy for a cluster scoped resource. func DefaultClusteredTenancy() *pbresource.Tenancy { return &pbresource.Tenancy{ - // TODO(spatel): Remove as part of "peer is not part of tenancy" ADR + // TODO(spatel): NET-5475 - Remove as part of peer_name moving to PeerTenancy PeerName: "local", } } @@ -66,7 +71,7 @@ func DefaultClusteredTenancy() *pbresource.Tenancy { func DefaultPartitionedTenancy() *pbresource.Tenancy { return &pbresource.Tenancy{ Partition: DefaultPartitionName, - // TODO(spatel): Remove as part of "peer is not part of tenancy" ADR + // TODO(spatel): NET-5475 - Remove as part of peer_name moving to PeerTenancy PeerName: "local", } } @@ -76,7 +81,7 @@ func DefaultNamespacedTenancy() *pbresource.Tenancy { return &pbresource.Tenancy{ Partition: DefaultPartitionName, Namespace: DefaultNamespaceName, - // TODO(spatel): Remove as part of "peer is not part of tenancy" ADR + // TODO(spatel): NET-5475 - Remove as part of peer_name moving to PeerTenancy PeerName: "local", } }