[CE] feat(v2dns): enable v2 dns as default (#20715)

* feat(v2dns): enable v2 dns as default

* changelog
This commit is contained in:
Dan Stough 2024-03-25 16:09:01 -04:00 committed by GitHub
parent d747b51dab
commit 6026ada0c9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 24 additions and 18 deletions

6
.changelog/20715.txt Normal file
View File

@ -0,0 +1,6 @@
```release-note:feature
dns: queries now default to a refactored DNS server that is v1 and v2 Catalog compatible.
Use `v1dns` in the `experiments` agent config to disable.
The legacy server will be removed in a future release of Consul.
See the [Consul 1.19.x Release Notes](https://developer.hashicorp.com/consul/docs/release-notes/consul/v1_19_x) for removed DNS features.
```

View File

@ -878,13 +878,12 @@ func (a *Agent) Start(ctx context.Context) error {
}
// start DNS servers
if a.baseDeps.UseV2DNS() {
a.logger.Warn("DNS v2 is under construction")
if err := a.listenAndServeV2DNS(); err != nil {
if a.baseDeps.UseV1DNS() {
if err := a.listenAndServeV1DNS(); err != nil {
return err
}
} else {
if err := a.listenAndServeV1DNS(); err != nil {
if err := a.listenAndServeV2DNS(); err != nil {
return err
}
}

View File

@ -618,8 +618,8 @@ func TestBuilder_CheckExperimentsInSecondaryDatacenters(t *testing.T) {
"primary server v2catalog": {
hcl: primary + `experiments = ["resource-apis"]`,
},
"primary server v2dns": {
hcl: primary + `experiments = ["v2dns"]`,
"primary server v1dns": {
hcl: primary + `experiments = ["v1dns"]`,
},
"primary server v2tenancy": {
hcl: primary + `experiments = ["v2tenancy"]`,
@ -631,9 +631,8 @@ func TestBuilder_CheckExperimentsInSecondaryDatacenters(t *testing.T) {
hcl: secondary + `experiments = ["resource-apis"]`,
expectErr: true,
},
"secondary server v2dns": {
hcl: secondary + `experiments = ["v2dns"]`,
expectErr: true,
"secondary server v1dns": {
hcl: secondary + `experiments = ["v1dns"]`,
},
"secondary server v2tenancy": {
hcl: secondary + `experiments = ["v2tenancy"]`,

View File

@ -50,10 +50,10 @@ type Deps struct {
EnterpriseDeps
}
// UseV2DNS returns true if "v2-dns" is present in the Experiments
// array of the agent config. It is assumed if the v2 resource APIs are enabled.
func (d Deps) UseV2DNS() bool {
if stringslice.Contains(d.Experiments, V2DNSExperimentName) || d.UseV2Resources() {
// UseV1DNS returns true if "v1dns" is present in the Experiments
// array of the agent config. It is ignored if the v2 resource APIs are enabled.
func (d Deps) UseV1DNS() bool {
if stringslice.Contains(d.Experiments, V1DNSExperimentName) && !d.UseV2Resources() {
return true
}
return false

View File

@ -132,7 +132,7 @@ const (
LeaderTransferMinVersion = "1.6.0"
CatalogResourceExperimentName = "resource-apis"
V2DNSExperimentName = "v2dns"
V1DNSExperimentName = "v1dns"
V2TenancyExperimentName = "v2tenancy"
HCPAllowV2ResourceAPIs = "hcp-v2-resource-apis"
)
@ -143,7 +143,7 @@ const (
// Likely these will all be short lived exclusions.
func IsExperimentAllowedOnSecondaries(name string) bool {
switch name {
case CatalogResourceExperimentName, V2DNSExperimentName, V2TenancyExperimentName:
case CatalogResourceExperimentName, V2TenancyExperimentName:
return false
default:
return true

View File

@ -261,7 +261,8 @@ func TestDNS_CatalogV2_Basic(t *testing.T) {
require.Equal(t, 9, len(in.Answer), "answer count did not match expected\n\n%s", in.String())
require.Equal(t, 9, len(in.Extra), "extra answer count did not match expected\n\n%s", in.String())
} else {
// Expect 1 result per port, per workload, up to the default limit of 3. In practice the results are truncated at 2.
// Expect 1 result per port, per workload, up to the default limit of 3. In practice the results are truncated
// at 2 because of the record byte size.
require.Equal(t, 2, len(in.Answer), "answer count did not match expected\n\n%s", in.String())
require.Equal(t, 2, len(in.Extra), "extra answer count did not match expected\n\n%s", in.String())
}

View File

@ -121,11 +121,11 @@ func dnsTXT(src string, txt []string) *dns.TXT {
func getVersionHCL(enableV2 bool) map[string]string {
versions := map[string]string{
"DNS: v1 / Catalog: v1": "",
"DNS: v1 / Catalog: v1": "experiments=[\"v1dns\"]",
}
if enableV2 {
versions["DNS: v2 / Catalog: v1"] = `experiments=["v2dns"]`
versions["DNS: v2 / Catalog: v1"] = ""
}
return versions
}
@ -3338,6 +3338,7 @@ func TestDNS_V1ConfigReload(t *testing.T) {
min_ttl = 4
}
}
experiments = ["v1dns"]
`)
defer a.Shutdown()
testrpc.WaitForLeader(t, a.RPC, "dc1")