diff --git a/internal/host/plugin/repository_host_set.go b/internal/host/plugin/repository_host_set.go index ec65ba5a8a..c6fd88cbeb 100644 --- a/internal/host/plugin/repository_host_set.go +++ b/internal/host/plugin/repository_host_set.go @@ -816,7 +816,7 @@ func (r *Repository) Endpoints(ctx context.Context, setIds []string) ([]*host.En opts = append(opts, endpoint.WithIpAddrs(h.GetIpAddresses())) } if len(h.GetDnsNames()) > 0 { - opts = append(opts, endpoint.WithIpAddrs(h.GetDnsNames())) + opts = append(opts, endpoint.WithDnsNames(h.GetDnsNames())) } addr, err := pref.Choose(ctx, opts...) if err != nil { diff --git a/internal/host/plugin/repository_host_set_test.go b/internal/host/plugin/repository_host_set_test.go index 31fa3c55e2..7ddb923490 100644 --- a/internal/host/plugin/repository_host_set_test.go +++ b/internal/host/plugin/repository_host_set_test.go @@ -1314,12 +1314,14 @@ func TestRepository_Endpoints(t *testing.T) { hostSet10 := TestSet(t, conn, kms, sched, catalog, plgm, WithName("hostSet10"), WithPreferredEndpoints([]string{"cidr:10.0.0.1/24"})) hostSet192 := TestSet(t, conn, kms, sched, catalog, plgm, WithName("hostSet192"), WithPreferredEndpoints([]string{"cidr:192.168.0.1/24"})) hostSet100 := TestSet(t, conn, kms, sched, catalog, plgm, WithName("hostSet100"), WithPreferredEndpoints([]string{"cidr:100.100.100.100/24"})) + hostSetDNS := TestSet(t, conn, kms, sched, catalog, plgm, WithName("hostSetDNS"), WithPreferredEndpoints([]string{"dns:*"})) hostlessSet := TestSet(t, conn, kms, sched, hostlessCatalog, plgm) - h1 := TestHost(t, conn, catalog.GetPublicId(), "test", withIpAddresses([]string{"10.0.0.5", "192.168.0.5"})) + h1 := TestHost(t, conn, catalog.GetPublicId(), "test", withIpAddresses([]string{"10.0.0.5", "192.168.0.5"}), withDnsNames([]string{"example.com"})) TestSetMembers(t, conn, hostSet10.GetPublicId(), []*Host{h1}) TestSetMembers(t, conn, hostSet192.GetPublicId(), []*Host{h1}) TestSetMembers(t, conn, hostSet100.GetPublicId(), []*Host{h1}) + TestSetMembers(t, conn, hostSetDNS.GetPublicId(), []*Host{h1}) tests := []struct { name string @@ -1371,6 +1373,21 @@ func TestRepository_Endpoints(t *testing.T) { setIds: []string{hostlessSet.GetPublicId()}, want: nil, }, + { + name: "with-dns-names", + setIds: []string{hostSetDNS.GetPublicId()}, + want: []*host.Endpoint{ + { + HostId: func() string { + s, err := newHostId(ctx, catalog.GetPublicId(), "test") + require.NoError(t, err) + return s + }(), + SetId: hostSetDNS.GetPublicId(), + Address: "example.com", + }, + }, + }, } for _, tt := range tests {