feat(v2dns): enable peering queries (#20581)

This commit is contained in:
Dan Stough 2024-02-12 14:25:45 -05:00 committed by GitHub
parent ec76090be9
commit 5802080db1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 18 additions and 6 deletions

View File

@ -99,6 +99,11 @@ func (f *V1DataFetcher) LoadConfig(config *config.RuntimeConfig) {
// FetchNodes fetches A/AAAA/CNAME // FetchNodes fetches A/AAAA/CNAME
func (f *V1DataFetcher) FetchNodes(ctx Context, req *QueryPayload) ([]*Result, error) { func (f *V1DataFetcher) FetchNodes(ctx Context, req *QueryPayload) ([]*Result, error) {
if req.Tenancy.Namespace != "" && req.Tenancy.Namespace != acl.DefaultNamespaceName {
// Nodes are not namespaced, so this is a name error
return nil, ErrNotFound
}
cfg := f.dynamicConfig.Load().(*v1DataFetcherDynamicConfig) cfg := f.dynamicConfig.Load().(*v1DataFetcherDynamicConfig)
// Make an RPC request // Make an RPC request
args := &structs.NodeSpecificRequest{ args := &structs.NodeSpecificRequest{
@ -430,6 +435,7 @@ func (f *V1DataFetcher) buildResultsFromServiceNodes(nodes []structs.CheckServic
Namespace: n.Service.NamespaceOrEmpty(), Namespace: n.Service.NamespaceOrEmpty(),
Partition: n.Service.PartitionOrEmpty(), Partition: n.Service.PartitionOrEmpty(),
Datacenter: n.Node.Datacenter, Datacenter: n.Node.Datacenter,
PeerName: req.Tenancy.Peer,
}, },
}) })
} }

View File

@ -156,6 +156,9 @@ func Test_FetchEndpoints(t *testing.T) {
Number: 0, Number: 0,
}, },
}, },
Tenancy: ResultTenancy{
PeerName: "test-peer",
},
}, },
} }

View File

@ -62,7 +62,9 @@ func (f *V2DataFetcher) LoadConfig(config *config.RuntimeConfig) {
// FetchNodes fetches A/AAAA/CNAME // FetchNodes fetches A/AAAA/CNAME
func (f *V2DataFetcher) FetchNodes(ctx Context, req *QueryPayload) ([]*Result, error) { func (f *V2DataFetcher) FetchNodes(ctx Context, req *QueryPayload) ([]*Result, error) {
return nil, nil // TODO (v2-dns): NET-6623 - Implement FetchNodes
// Make sure that we validate that namespace is not provided here
return nil, fmt.Errorf("not implemented")
} }
// FetchEndpoints fetches records for A/AAAA/CNAME or SRV requests for services // FetchEndpoints fetches records for A/AAAA/CNAME or SRV requests for services
@ -137,13 +139,15 @@ func (f *V2DataFetcher) FetchEndpoints(reqContext Context, req *QueryPayload, lo
// FetchVirtualIP fetches A/AAAA records for virtual IPs // FetchVirtualIP fetches A/AAAA records for virtual IPs
func (f *V2DataFetcher) FetchVirtualIP(ctx Context, req *QueryPayload) (*Result, error) { func (f *V2DataFetcher) FetchVirtualIP(ctx Context, req *QueryPayload) (*Result, error) {
return nil, nil // TODO (v2-dns): NET-6624 - Implement FetchVirtualIP
return nil, fmt.Errorf("not implemented")
} }
// FetchRecordsByIp is used for PTR requests to look up a service/node from an IP. // FetchRecordsByIp is used for PTR requests to look up a service/node from an IP.
// TODO (v2-dns): Validate non-nil IP
func (f *V2DataFetcher) FetchRecordsByIp(ctx Context, ip net.IP) ([]*Result, error) { func (f *V2DataFetcher) FetchRecordsByIp(ctx Context, ip net.IP) ([]*Result, error) {
return nil, nil // TODO (v2-dns): NET-6795 - Implement FetchRecordsByIp
// Validate non-nil IP
return nil, fmt.Errorf("not implemented")
} }
// FetchWorkload is used to fetch a single workload from the V2 catalog. // FetchWorkload is used to fetch a single workload from the V2 catalog.

View File

@ -17,13 +17,12 @@ import (
"github.com/hashicorp/consul/testrpc" "github.com/hashicorp/consul/testrpc"
) )
// TODO(v2-dns): NET-7910 - Fix ENT and CE variants of DNS v1 compatibility tests
func TestDNS_CE_PeeredServices(t *testing.T) { func TestDNS_CE_PeeredServices(t *testing.T) {
if testing.Short() { if testing.Short() {
t.Skip("too slow for testing.Short") t.Skip("too slow for testing.Short")
} }
for name, experimentsHCL := range getVersionHCL(false) { for name, experimentsHCL := range getVersionHCL(true) {
t.Run(name, func(t *testing.T) { t.Run(name, func(t *testing.T) {
a := StartTestAgent(t, TestAgent{HCL: ``, Overrides: `peering = { test_allow_peer_registrations = true } ` + experimentsHCL}) a := StartTestAgent(t, TestAgent{HCL: ``, Overrides: `peering = { test_allow_peer_registrations = true } ` + experimentsHCL})
defer a.Shutdown() defer a.Shutdown()