mirror of
https://github.com/coredns/coredns.git
synced 2025-10-27 16:24:19 -04:00
chore: Upgrade to golangci-lint v2 (#7236)
Signed-off-by: Manuel Rüger <manuel@rueg.eu>
This commit is contained in:
4
.github/workflows/golangci-lint.yml
vendored
4
.github/workflows/golangci-lint.yml
vendored
@@ -13,6 +13,6 @@ jobs:
|
||||
with:
|
||||
go-version: ${{ env.GO_VERSION }}
|
||||
- name: golangci-lint
|
||||
uses: golangci/golangci-lint-action@55c2c1448f86e01eaae002a5a3a9624417608d84 # v6.5.2
|
||||
uses: golangci/golangci-lint-action@1481404843c368bc19ca9406f87d6e0fc97bdcfd # v7.0.0
|
||||
with:
|
||||
version: v1.64.8
|
||||
version: v2.0.2
|
||||
|
||||
@@ -1,13 +1,30 @@
|
||||
run:
|
||||
timeout: 5m
|
||||
version: "2"
|
||||
linters:
|
||||
disable-all: true
|
||||
default: none
|
||||
enable:
|
||||
- govet
|
||||
- ineffassign
|
||||
- staticcheck
|
||||
- typecheck
|
||||
- whitespace
|
||||
- unused
|
||||
- gofmt
|
||||
- unconvert
|
||||
- unused
|
||||
- whitespace
|
||||
exclusions:
|
||||
generated: lax
|
||||
presets:
|
||||
- comments
|
||||
- common-false-positives
|
||||
- legacy
|
||||
- std-error-handling
|
||||
paths:
|
||||
- third_party$
|
||||
- builtin$
|
||||
- examples$
|
||||
formatters:
|
||||
enable:
|
||||
- gofmt
|
||||
exclusions:
|
||||
generated: lax
|
||||
paths:
|
||||
- third_party$
|
||||
- builtin$
|
||||
- examples$
|
||||
|
||||
@@ -63,8 +63,7 @@ func NewServerQUIC(addr string, group []*Config) (*ServerQUIC, error) {
|
||||
tlsConfig.NextProtos = []string{"doq"}
|
||||
}
|
||||
|
||||
var quicConfig *quic.Config
|
||||
quicConfig = &quic.Config{
|
||||
var quicConfig = &quic.Config{
|
||||
MaxIdleTimeout: s.idleTimeout,
|
||||
MaxIncomingStreams: math.MaxUint16,
|
||||
MaxIncomingUniStreams: math.MaxUint16,
|
||||
|
||||
@@ -50,15 +50,16 @@ func parse(c *caddy.Controller) (ACL, error) {
|
||||
p := policy{}
|
||||
|
||||
action := strings.ToLower(c.Val())
|
||||
if action == "allow" {
|
||||
switch action {
|
||||
case "allow":
|
||||
p.action = actionAllow
|
||||
} else if action == "block" {
|
||||
case "block":
|
||||
p.action = actionBlock
|
||||
} else if action == "filter" {
|
||||
case "filter":
|
||||
p.action = actionFilter
|
||||
} else if action == "drop" {
|
||||
case "drop":
|
||||
p.action = actionDrop
|
||||
} else {
|
||||
default:
|
||||
return a, c.Errf("unexpected token %q; expect 'allow', 'block', 'filter' or 'drop'", c.Val())
|
||||
}
|
||||
|
||||
|
||||
@@ -54,9 +54,9 @@ func (a Auto) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (i
|
||||
return plugin.NextOrFailure(a.Name(), a.Next, ctx, w, r)
|
||||
}
|
||||
|
||||
a.Zones.RLock()
|
||||
z, ok := a.Zones.Z[zone]
|
||||
a.Zones.RUnlock()
|
||||
a.RLock()
|
||||
z, ok := a.Z[zone]
|
||||
a.RUnlock()
|
||||
|
||||
if !ok || z == nil {
|
||||
return dns.RcodeServerFailure, nil
|
||||
|
||||
@@ -48,11 +48,11 @@ func setup(c *caddy.Controller) error {
|
||||
if err := a.Notify(); err != nil {
|
||||
log.Warning(err)
|
||||
}
|
||||
if a.loader.ReloadInterval == 0 {
|
||||
if a.ReloadInterval == 0 {
|
||||
return nil
|
||||
}
|
||||
go func() {
|
||||
ticker := time.NewTicker(a.loader.ReloadInterval)
|
||||
ticker := time.NewTicker(a.ReloadInterval)
|
||||
defer ticker.Stop()
|
||||
for {
|
||||
select {
|
||||
@@ -71,7 +71,7 @@ func setup(c *caddy.Controller) error {
|
||||
|
||||
c.OnShutdown(func() error {
|
||||
close(walkChan)
|
||||
for _, z := range a.Zones.Z {
|
||||
for _, z := range a.Z {
|
||||
z.Lock()
|
||||
z.OnShutdown()
|
||||
z.Unlock()
|
||||
@@ -103,8 +103,8 @@ func autoParse(c *caddy.Controller) (Auto, error) {
|
||||
for c.Next() {
|
||||
// auto [ZONES...]
|
||||
args := c.RemainingArgs()
|
||||
a.Zones.origins = plugin.OriginsFromArgsOrServerBlock(args, c.ServerBlockKeys)
|
||||
a.loader.upstream = upstream.New()
|
||||
a.origins = plugin.OriginsFromArgsOrServerBlock(args, c.ServerBlockKeys)
|
||||
a.upstream = upstream.New()
|
||||
|
||||
for c.NextBlock() {
|
||||
switch c.Val() {
|
||||
@@ -112,33 +112,33 @@ func autoParse(c *caddy.Controller) (Auto, error) {
|
||||
if !c.NextArg() {
|
||||
return a, c.ArgErr()
|
||||
}
|
||||
a.loader.directory = c.Val()
|
||||
if !filepath.IsAbs(a.loader.directory) && config.Root != "" {
|
||||
a.loader.directory = filepath.Join(config.Root, a.loader.directory)
|
||||
a.directory = c.Val()
|
||||
if !filepath.IsAbs(a.directory) && config.Root != "" {
|
||||
a.directory = filepath.Join(config.Root, a.directory)
|
||||
}
|
||||
_, err := os.Stat(a.loader.directory)
|
||||
_, err := os.Stat(a.directory)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
log.Warningf("Directory does not exist: %s", a.loader.directory)
|
||||
log.Warningf("Directory does not exist: %s", a.directory)
|
||||
} else {
|
||||
return a, c.Errf("Unable to access root path '%s': %v", a.loader.directory, err)
|
||||
return a, c.Errf("Unable to access root path '%s': %v", a.directory, err)
|
||||
}
|
||||
}
|
||||
|
||||
// regexp template
|
||||
if c.NextArg() {
|
||||
a.loader.re, err = regexp.Compile(c.Val())
|
||||
a.re, err = regexp.Compile(c.Val())
|
||||
if err != nil {
|
||||
return a, err
|
||||
}
|
||||
if a.loader.re.NumSubexp() == 0 {
|
||||
if a.re.NumSubexp() == 0 {
|
||||
return a, c.Errf("Need at least one sub expression")
|
||||
}
|
||||
|
||||
if !c.NextArg() {
|
||||
return a, c.ArgErr()
|
||||
}
|
||||
a.loader.template = rewriteToExpand(c.Val())
|
||||
a.template = rewriteToExpand(c.Val())
|
||||
}
|
||||
|
||||
if c.NextArg() {
|
||||
@@ -157,7 +157,7 @@ func autoParse(c *caddy.Controller) (Auto, error) {
|
||||
if err != nil {
|
||||
return a, plugin.Error("file", err)
|
||||
}
|
||||
a.loader.ReloadInterval = d
|
||||
a.ReloadInterval = d
|
||||
|
||||
case "upstream":
|
||||
// remove soon
|
||||
@@ -169,8 +169,8 @@ func autoParse(c *caddy.Controller) (Auto, error) {
|
||||
}
|
||||
}
|
||||
|
||||
if a.loader.ReloadInterval == nilInterval {
|
||||
a.loader.ReloadInterval = 60 * time.Second
|
||||
if a.ReloadInterval == nilInterval {
|
||||
a.ReloadInterval = 60 * time.Second
|
||||
}
|
||||
|
||||
return a, nil
|
||||
|
||||
@@ -111,17 +111,17 @@ func TestAutoParse(t *testing.T) {
|
||||
} else if err != nil && !test.shouldErr {
|
||||
t.Fatalf("Test %d expected no errors, but got '%v'", i, err)
|
||||
} else if !test.shouldErr {
|
||||
if a.loader.directory != test.expectedDirectory {
|
||||
t.Fatalf("Test %d expected %v, got %v", i, test.expectedDirectory, a.loader.directory)
|
||||
if a.directory != test.expectedDirectory {
|
||||
t.Fatalf("Test %d expected %v, got %v", i, test.expectedDirectory, a.directory)
|
||||
}
|
||||
if a.loader.template != test.expectedTempl {
|
||||
t.Fatalf("Test %d expected %v, got %v", i, test.expectedTempl, a.loader.template)
|
||||
if a.template != test.expectedTempl {
|
||||
t.Fatalf("Test %d expected %v, got %v", i, test.expectedTempl, a.template)
|
||||
}
|
||||
if a.loader.re.String() != test.expectedRe {
|
||||
t.Fatalf("Test %d expected %v, got %v", i, test.expectedRe, a.loader.re)
|
||||
if a.re.String() != test.expectedRe {
|
||||
t.Fatalf("Test %d expected %v, got %v", i, test.expectedRe, a.re)
|
||||
}
|
||||
if a.loader.ReloadInterval != test.expectedReloadInterval {
|
||||
t.Fatalf("Test %d expected %v, got %v", i, test.expectedReloadInterval, a.loader.ReloadInterval)
|
||||
if a.ReloadInterval != test.expectedReloadInterval {
|
||||
t.Fatalf("Test %d expected %v, got %v", i, test.expectedReloadInterval, a.ReloadInterval)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,11 +15,11 @@ func (a Auto) Walk() error {
|
||||
// TODO(miek): should add something so that we don't stomp on each other.
|
||||
|
||||
toDelete := make(map[string]bool)
|
||||
for _, n := range a.Zones.Names() {
|
||||
for _, n := range a.Names() {
|
||||
toDelete[n] = true
|
||||
}
|
||||
|
||||
filepath.Walk(a.loader.directory, func(path string, info os.FileInfo, e error) error {
|
||||
filepath.Walk(a.directory, func(path string, info os.FileInfo, e error) error {
|
||||
if e != nil {
|
||||
log.Warningf("error reading %v: %v", path, e)
|
||||
}
|
||||
@@ -27,12 +27,12 @@ func (a Auto) Walk() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
match, origin := matches(a.loader.re, info.Name(), a.loader.template)
|
||||
match, origin := matches(a.re, info.Name(), a.template)
|
||||
if !match {
|
||||
return nil
|
||||
}
|
||||
|
||||
if z, ok := a.Zones.Z[origin]; ok {
|
||||
if z, ok := a.Z[origin]; ok {
|
||||
// we already have this zone
|
||||
toDelete[origin] = false
|
||||
z.SetFile(path)
|
||||
@@ -53,10 +53,10 @@ func (a Auto) Walk() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
zo.ReloadInterval = a.loader.ReloadInterval
|
||||
zo.Upstream = a.loader.upstream
|
||||
zo.ReloadInterval = a.ReloadInterval
|
||||
zo.Upstream = a.upstream
|
||||
|
||||
a.Zones.Add(zo, origin, a.transfer)
|
||||
a.Add(zo, origin, a.transfer)
|
||||
|
||||
if a.metrics != nil {
|
||||
a.metrics.AddZone(origin)
|
||||
@@ -78,7 +78,7 @@ func (a Auto) Walk() error {
|
||||
a.metrics.RemoveZone(origin)
|
||||
}
|
||||
|
||||
a.Zones.Remove(origin)
|
||||
a.Remove(origin)
|
||||
|
||||
log.Infof("Deleting zone `%s'", origin)
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ func TestWalk(t *testing.T) {
|
||||
|
||||
// db.example.org and db.example.com should be here (created in createFiles)
|
||||
for _, name := range []string{"example.com.", "example.org."} {
|
||||
if _, ok := a.Zones.Z[name]; !ok {
|
||||
if _, ok := a.Z[name]; !ok {
|
||||
t.Errorf("%s should have been added", name)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,10 +27,10 @@ func TestWatcher(t *testing.T) {
|
||||
a.Walk()
|
||||
|
||||
// example.org and example.com should exist, we have 3 apex rrs and 1 "real" record. All() returns the non-apex ones.
|
||||
if x := len(a.Zones.Z["example.org."].All()); x != 1 {
|
||||
if x := len(a.Z["example.org."].All()); x != 1 {
|
||||
t.Fatalf("Expected 1 RRs, got %d", x)
|
||||
}
|
||||
if x := len(a.Zones.Z["example.com."].All()); x != 1 {
|
||||
if x := len(a.Z["example.com."].All()); x != 1 {
|
||||
t.Fatalf("Expected 1 RRs, got %d", x)
|
||||
}
|
||||
|
||||
@@ -41,10 +41,10 @@ func TestWatcher(t *testing.T) {
|
||||
|
||||
a.Walk()
|
||||
|
||||
if _, ok := a.Zones.Z["example.com."]; ok {
|
||||
if _, ok := a.Z["example.com."]; ok {
|
||||
t.Errorf("Expected %q to be gone.", "example.com.")
|
||||
}
|
||||
if _, ok := a.Zones.Z["example.org."]; !ok {
|
||||
if _, ok := a.Z["example.org."]; !ok {
|
||||
t.Errorf("Expected %q to still be there.", "example.org.")
|
||||
}
|
||||
}
|
||||
@@ -83,7 +83,7 @@ func TestSymlinks(t *testing.T) {
|
||||
|
||||
a.Walk()
|
||||
|
||||
if storedZone, ok := a.Zones.Z["example.com."]; ok {
|
||||
if storedZone, ok := a.Z["example.com."]; ok {
|
||||
storedFile := storedZone.File()
|
||||
if storedFile != newFile {
|
||||
t.Errorf("Expected %q to reflect new path %q", storedFile, newFile)
|
||||
|
||||
@@ -8,9 +8,9 @@ import (
|
||||
|
||||
// Transfer implements the transfer.Transfer interface.
|
||||
func (a Auto) Transfer(zone string, serial uint32) (<-chan []dns.RR, error) {
|
||||
a.Zones.RLock()
|
||||
z, ok := a.Zones.Z[zone]
|
||||
a.Zones.RUnlock()
|
||||
a.RLock()
|
||||
z, ok := a.Z[zone]
|
||||
a.RUnlock()
|
||||
|
||||
if !ok || z == nil {
|
||||
return nil, transfer.ErrNotAuthoritative
|
||||
@@ -21,7 +21,7 @@ func (a Auto) Transfer(zone string, serial uint32) (<-chan []dns.RR, error) {
|
||||
// Notify sends notifies for all zones with secondaries configured with the transfer plugin
|
||||
func (a Auto) Notify() error {
|
||||
var err error
|
||||
for _, origin := range a.Zones.Names() {
|
||||
for _, origin := range a.Names() {
|
||||
e := a.transfer.Notify(origin)
|
||||
if e != nil {
|
||||
err = e
|
||||
|
||||
@@ -138,26 +138,26 @@ func (h *Azure) updateZones(ctx context.Context) error {
|
||||
|
||||
func updateZoneFromPublicResourceSet(recordSet publicdns.RecordSetListResultPage, newZ *file.Zone) {
|
||||
for _, result := range *(recordSet.Response().Value) {
|
||||
resultFqdn := *(result.RecordSetProperties.Fqdn)
|
||||
resultTTL := uint32(*(result.RecordSetProperties.TTL))
|
||||
if result.RecordSetProperties.ARecords != nil {
|
||||
for _, A := range *(result.RecordSetProperties.ARecords) {
|
||||
resultFqdn := *(result.Fqdn)
|
||||
resultTTL := uint32(*(result.TTL))
|
||||
if result.ARecords != nil {
|
||||
for _, A := range *(result.ARecords) {
|
||||
a := &dns.A{Hdr: dns.RR_Header{Name: resultFqdn, Rrtype: dns.TypeA, Class: dns.ClassINET, Ttl: resultTTL},
|
||||
A: net.ParseIP(*(A.Ipv4Address))}
|
||||
newZ.Insert(a)
|
||||
}
|
||||
}
|
||||
|
||||
if result.RecordSetProperties.AaaaRecords != nil {
|
||||
for _, AAAA := range *(result.RecordSetProperties.AaaaRecords) {
|
||||
if result.AaaaRecords != nil {
|
||||
for _, AAAA := range *(result.AaaaRecords) {
|
||||
aaaa := &dns.AAAA{Hdr: dns.RR_Header{Name: resultFqdn, Rrtype: dns.TypeAAAA, Class: dns.ClassINET, Ttl: resultTTL},
|
||||
AAAA: net.ParseIP(*(AAAA.Ipv6Address))}
|
||||
newZ.Insert(aaaa)
|
||||
}
|
||||
}
|
||||
|
||||
if result.RecordSetProperties.MxRecords != nil {
|
||||
for _, MX := range *(result.RecordSetProperties.MxRecords) {
|
||||
if result.MxRecords != nil {
|
||||
for _, MX := range *(result.MxRecords) {
|
||||
mx := &dns.MX{Hdr: dns.RR_Header{Name: resultFqdn, Rrtype: dns.TypeMX, Class: dns.ClassINET, Ttl: resultTTL},
|
||||
Preference: uint16(*(MX.Preference)),
|
||||
Mx: dns.Fqdn(*(MX.Exchange))}
|
||||
@@ -165,16 +165,16 @@ func updateZoneFromPublicResourceSet(recordSet publicdns.RecordSetListResultPage
|
||||
}
|
||||
}
|
||||
|
||||
if result.RecordSetProperties.PtrRecords != nil {
|
||||
for _, PTR := range *(result.RecordSetProperties.PtrRecords) {
|
||||
if result.PtrRecords != nil {
|
||||
for _, PTR := range *(result.PtrRecords) {
|
||||
ptr := &dns.PTR{Hdr: dns.RR_Header{Name: resultFqdn, Rrtype: dns.TypePTR, Class: dns.ClassINET, Ttl: resultTTL},
|
||||
Ptr: dns.Fqdn(*(PTR.Ptrdname))}
|
||||
newZ.Insert(ptr)
|
||||
}
|
||||
}
|
||||
|
||||
if result.RecordSetProperties.SrvRecords != nil {
|
||||
for _, SRV := range *(result.RecordSetProperties.SrvRecords) {
|
||||
if result.SrvRecords != nil {
|
||||
for _, SRV := range *(result.SrvRecords) {
|
||||
srv := &dns.SRV{Hdr: dns.RR_Header{Name: resultFqdn, Rrtype: dns.TypeSRV, Class: dns.ClassINET, Ttl: resultTTL},
|
||||
Priority: uint16(*(SRV.Priority)),
|
||||
Weight: uint16(*(SRV.Weight)),
|
||||
@@ -184,24 +184,24 @@ func updateZoneFromPublicResourceSet(recordSet publicdns.RecordSetListResultPage
|
||||
}
|
||||
}
|
||||
|
||||
if result.RecordSetProperties.TxtRecords != nil {
|
||||
for _, TXT := range *(result.RecordSetProperties.TxtRecords) {
|
||||
if result.TxtRecords != nil {
|
||||
for _, TXT := range *(result.TxtRecords) {
|
||||
txt := &dns.TXT{Hdr: dns.RR_Header{Name: resultFqdn, Rrtype: dns.TypeTXT, Class: dns.ClassINET, Ttl: resultTTL},
|
||||
Txt: *(TXT.Value)}
|
||||
newZ.Insert(txt)
|
||||
}
|
||||
}
|
||||
|
||||
if result.RecordSetProperties.NsRecords != nil {
|
||||
for _, NS := range *(result.RecordSetProperties.NsRecords) {
|
||||
if result.NsRecords != nil {
|
||||
for _, NS := range *(result.NsRecords) {
|
||||
ns := &dns.NS{Hdr: dns.RR_Header{Name: resultFqdn, Rrtype: dns.TypeNS, Class: dns.ClassINET, Ttl: resultTTL},
|
||||
Ns: *(NS.Nsdname)}
|
||||
newZ.Insert(ns)
|
||||
}
|
||||
}
|
||||
|
||||
if result.RecordSetProperties.SoaRecord != nil {
|
||||
SOA := result.RecordSetProperties.SoaRecord
|
||||
if result.SoaRecord != nil {
|
||||
SOA := result.SoaRecord
|
||||
soa := &dns.SOA{Hdr: dns.RR_Header{Name: resultFqdn, Rrtype: dns.TypeSOA, Class: dns.ClassINET, Ttl: resultTTL},
|
||||
Minttl: uint32(*(SOA.MinimumTTL)),
|
||||
Expire: uint32(*(SOA.ExpireTime)),
|
||||
@@ -213,8 +213,8 @@ func updateZoneFromPublicResourceSet(recordSet publicdns.RecordSetListResultPage
|
||||
newZ.Insert(soa)
|
||||
}
|
||||
|
||||
if result.RecordSetProperties.CnameRecord != nil {
|
||||
CNAME := result.RecordSetProperties.CnameRecord.Cname
|
||||
if result.CnameRecord != nil {
|
||||
CNAME := result.CnameRecord.Cname
|
||||
cname := &dns.CNAME{Hdr: dns.RR_Header{Name: resultFqdn, Rrtype: dns.TypeCNAME, Class: dns.ClassINET, Ttl: resultTTL},
|
||||
Target: dns.Fqdn(*CNAME)}
|
||||
newZ.Insert(cname)
|
||||
@@ -224,25 +224,25 @@ func updateZoneFromPublicResourceSet(recordSet publicdns.RecordSetListResultPage
|
||||
|
||||
func updateZoneFromPrivateResourceSet(recordSet privatedns.RecordSetListResultPage, newZ *file.Zone) {
|
||||
for _, result := range *(recordSet.Response().Value) {
|
||||
resultFqdn := *(result.RecordSetProperties.Fqdn)
|
||||
resultTTL := uint32(*(result.RecordSetProperties.TTL))
|
||||
if result.RecordSetProperties.ARecords != nil {
|
||||
for _, A := range *(result.RecordSetProperties.ARecords) {
|
||||
resultFqdn := *(result.Fqdn)
|
||||
resultTTL := uint32(*(result.TTL))
|
||||
if result.ARecords != nil {
|
||||
for _, A := range *(result.ARecords) {
|
||||
a := &dns.A{Hdr: dns.RR_Header{Name: resultFqdn, Rrtype: dns.TypeA, Class: dns.ClassINET, Ttl: resultTTL},
|
||||
A: net.ParseIP(*(A.Ipv4Address))}
|
||||
newZ.Insert(a)
|
||||
}
|
||||
}
|
||||
if result.RecordSetProperties.AaaaRecords != nil {
|
||||
for _, AAAA := range *(result.RecordSetProperties.AaaaRecords) {
|
||||
if result.AaaaRecords != nil {
|
||||
for _, AAAA := range *(result.AaaaRecords) {
|
||||
aaaa := &dns.AAAA{Hdr: dns.RR_Header{Name: resultFqdn, Rrtype: dns.TypeAAAA, Class: dns.ClassINET, Ttl: resultTTL},
|
||||
AAAA: net.ParseIP(*(AAAA.Ipv6Address))}
|
||||
newZ.Insert(aaaa)
|
||||
}
|
||||
}
|
||||
|
||||
if result.RecordSetProperties.MxRecords != nil {
|
||||
for _, MX := range *(result.RecordSetProperties.MxRecords) {
|
||||
if result.MxRecords != nil {
|
||||
for _, MX := range *(result.MxRecords) {
|
||||
mx := &dns.MX{Hdr: dns.RR_Header{Name: resultFqdn, Rrtype: dns.TypeMX, Class: dns.ClassINET, Ttl: resultTTL},
|
||||
Preference: uint16(*(MX.Preference)),
|
||||
Mx: dns.Fqdn(*(MX.Exchange))}
|
||||
@@ -250,16 +250,16 @@ func updateZoneFromPrivateResourceSet(recordSet privatedns.RecordSetListResultPa
|
||||
}
|
||||
}
|
||||
|
||||
if result.RecordSetProperties.PtrRecords != nil {
|
||||
for _, PTR := range *(result.RecordSetProperties.PtrRecords) {
|
||||
if result.PtrRecords != nil {
|
||||
for _, PTR := range *(result.PtrRecords) {
|
||||
ptr := &dns.PTR{Hdr: dns.RR_Header{Name: resultFqdn, Rrtype: dns.TypePTR, Class: dns.ClassINET, Ttl: resultTTL},
|
||||
Ptr: dns.Fqdn(*(PTR.Ptrdname))}
|
||||
newZ.Insert(ptr)
|
||||
}
|
||||
}
|
||||
|
||||
if result.RecordSetProperties.SrvRecords != nil {
|
||||
for _, SRV := range *(result.RecordSetProperties.SrvRecords) {
|
||||
if result.SrvRecords != nil {
|
||||
for _, SRV := range *(result.SrvRecords) {
|
||||
srv := &dns.SRV{Hdr: dns.RR_Header{Name: resultFqdn, Rrtype: dns.TypeSRV, Class: dns.ClassINET, Ttl: resultTTL},
|
||||
Priority: uint16(*(SRV.Priority)),
|
||||
Weight: uint16(*(SRV.Weight)),
|
||||
@@ -269,16 +269,16 @@ func updateZoneFromPrivateResourceSet(recordSet privatedns.RecordSetListResultPa
|
||||
}
|
||||
}
|
||||
|
||||
if result.RecordSetProperties.TxtRecords != nil {
|
||||
for _, TXT := range *(result.RecordSetProperties.TxtRecords) {
|
||||
if result.TxtRecords != nil {
|
||||
for _, TXT := range *(result.TxtRecords) {
|
||||
txt := &dns.TXT{Hdr: dns.RR_Header{Name: resultFqdn, Rrtype: dns.TypeTXT, Class: dns.ClassINET, Ttl: resultTTL},
|
||||
Txt: *(TXT.Value)}
|
||||
newZ.Insert(txt)
|
||||
}
|
||||
}
|
||||
|
||||
if result.RecordSetProperties.SoaRecord != nil {
|
||||
SOA := result.RecordSetProperties.SoaRecord
|
||||
if result.SoaRecord != nil {
|
||||
SOA := result.SoaRecord
|
||||
soa := &dns.SOA{Hdr: dns.RR_Header{Name: resultFqdn, Rrtype: dns.TypeSOA, Class: dns.ClassINET, Ttl: resultTTL},
|
||||
Minttl: uint32(*(SOA.MinimumTTL)),
|
||||
Expire: uint32(*(SOA.ExpireTime)),
|
||||
@@ -290,8 +290,8 @@ func updateZoneFromPrivateResourceSet(recordSet privatedns.RecordSetListResultPa
|
||||
newZ.Insert(soa)
|
||||
}
|
||||
|
||||
if result.RecordSetProperties.CnameRecord != nil {
|
||||
CNAME := result.RecordSetProperties.CnameRecord.Cname
|
||||
if result.CnameRecord != nil {
|
||||
CNAME := result.CnameRecord.Cname
|
||||
cname := &dns.CNAME{Hdr: dns.RR_Header{Name: resultFqdn, Rrtype: dns.TypeCNAME, Class: dns.ClassINET, Ttl: resultTTL},
|
||||
Target: dns.Fqdn(*CNAME)}
|
||||
newZ.Insert(cname)
|
||||
|
||||
7
plugin/cache/cache.go
vendored
7
plugin/cache/cache.go
vendored
@@ -189,11 +189,12 @@ func (w *ResponseWriter) WriteMsg(res *dns.Msg) error {
|
||||
|
||||
msgTTL := dnsutil.MinimalTTL(res, mt)
|
||||
var duration time.Duration
|
||||
if mt == response.NameError || mt == response.NoData {
|
||||
switch mt {
|
||||
case response.NameError, response.NoData:
|
||||
duration = computeTTL(msgTTL, w.minnttl, w.nttl)
|
||||
} else if mt == response.ServerError {
|
||||
case response.ServerError:
|
||||
duration = w.failttl
|
||||
} else {
|
||||
default:
|
||||
duration = computeTTL(msgTTL, w.minpttl, w.pttl)
|
||||
}
|
||||
|
||||
|
||||
18
plugin/cache/cache_test.go
vendored
18
plugin/cache/cache_test.go
vendored
@@ -467,14 +467,15 @@ func TestServeFromStaleCacheFetchVerify(t *testing.T) {
|
||||
rec := dnstest.NewRecorder(&test.ResponseWriter{})
|
||||
c.now = func() time.Time { return time.Now().Add(time.Duration(tt.futureMinutes) * time.Minute) }
|
||||
|
||||
if tt.upstreamRCode == dns.RcodeSuccess {
|
||||
switch tt.upstreamRCode {
|
||||
case dns.RcodeSuccess:
|
||||
c.Next = ttlBackend(tt.upstreamTtl)
|
||||
} else if tt.upstreamRCode == dns.RcodeServerFailure {
|
||||
case dns.RcodeServerFailure:
|
||||
// Make upstream fail, should now rely on cache during the c.staleUpTo period
|
||||
c.Next = servFailBackend(tt.upstreamTtl)
|
||||
} else if tt.upstreamRCode == dns.RcodeNameError {
|
||||
case dns.RcodeNameError:
|
||||
c.Next = nxDomainBackend(tt.upstreamTtl)
|
||||
} else {
|
||||
default:
|
||||
t.Fatal("upstream code not implemented")
|
||||
}
|
||||
|
||||
@@ -485,12 +486,13 @@ func TestServeFromStaleCacheFetchVerify(t *testing.T) {
|
||||
t.Errorf("Test %d: expected rcode=%v, got rcode=%v", i, tt.expectedRCode, ret)
|
||||
continue
|
||||
}
|
||||
if ret == dns.RcodeSuccess {
|
||||
switch ret {
|
||||
case dns.RcodeSuccess:
|
||||
recTtl := rec.Msg.Answer[0].Header().Ttl
|
||||
if tt.expectedTtl != int(recTtl) {
|
||||
t.Errorf("Test %d: expected TTL=%d, got TTL=%d", i, tt.expectedTtl, recTtl)
|
||||
}
|
||||
} else if ret == dns.RcodeNameError {
|
||||
case dns.RcodeNameError:
|
||||
soaTtl := rec.Msg.Ns[0].Header().Ttl
|
||||
if tt.expectedTtl != int(soaTtl) {
|
||||
t.Errorf("Test %d: expected TTL=%d, got TTL=%d", i, tt.expectedTtl, soaTtl)
|
||||
@@ -631,7 +633,7 @@ func nxDomainBackend(ttl int) plugin.Handler {
|
||||
|
||||
m.Ns = []dns.RR{test.SOA(fmt.Sprintf("example.org. %d IN SOA sns.dns.icann.org. noc.dns.icann.org. 2016082540 7200 3600 1209600 3600", ttl))}
|
||||
|
||||
m.MsgHdr.Rcode = dns.RcodeNameError
|
||||
m.Rcode = dns.RcodeNameError
|
||||
w.WriteMsg(m)
|
||||
return dns.RcodeNameError, nil
|
||||
})
|
||||
@@ -657,7 +659,7 @@ func servFailBackend(ttl int) plugin.Handler {
|
||||
|
||||
m.Ns = []dns.RR{test.SOA(fmt.Sprintf("example.org. %d IN SOA sns.dns.icann.org. noc.dns.icann.org. 2016082540 7200 3600 1209600 3600", ttl))}
|
||||
|
||||
m.MsgHdr.Rcode = dns.RcodeServerFailure
|
||||
m.Rcode = dns.RcodeServerFailure
|
||||
w.WriteMsg(m)
|
||||
return dns.RcodeServerFailure, nil
|
||||
})
|
||||
|
||||
6
plugin/cache/handler.go
vendored
6
plugin/cache/handler.go
vendored
@@ -100,7 +100,7 @@ func (c *Cache) doPrefetch(ctx context.Context, state request.Request, cw *Respo
|
||||
// that we've gathered sofar. See we copy the frequencies info back
|
||||
// into the new item that was stored in the cache.
|
||||
if i1 := c.exists(state); i1 != nil {
|
||||
i1.Freq.Reset(now, i.Freq.Hits())
|
||||
i1.Reset(now, i.Hits())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,9 +112,9 @@ func (c *Cache) shouldPrefetch(i *item, now time.Time) bool {
|
||||
if c.prefetch <= 0 {
|
||||
return false
|
||||
}
|
||||
i.Freq.Update(c.duration, now)
|
||||
i.Update(c.duration, now)
|
||||
threshold := int(math.Ceil(float64(c.percentage) / 100 * float64(i.origTTL)))
|
||||
return i.Freq.Hits() >= c.prefetch && i.ttl(now) <= threshold
|
||||
return i.Hits() >= c.prefetch && i.ttl(now) <= threshold
|
||||
}
|
||||
|
||||
// Name implements the Handler interface.
|
||||
|
||||
@@ -62,7 +62,7 @@ func (d *DNS64) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg)
|
||||
|
||||
RequestsTranslatedCount.WithLabelValues(metrics.WithServer(ctx)).Inc()
|
||||
w.WriteMsg(msg)
|
||||
return msg.MsgHdr.Rcode, nil
|
||||
return msg.Rcode, nil
|
||||
}
|
||||
|
||||
// Name implements the Handler interface.
|
||||
|
||||
@@ -117,7 +117,8 @@ func keyParse(c *caddy.Controller) ([]*DNSKEY, error) {
|
||||
return nil, c.ArgErr()
|
||||
}
|
||||
value := c.Val()
|
||||
if value == "file" {
|
||||
switch value {
|
||||
case "file":
|
||||
ks := c.RemainingArgs()
|
||||
if len(ks) == 0 {
|
||||
return nil, c.ArgErr()
|
||||
@@ -141,7 +142,7 @@ func keyParse(c *caddy.Controller) ([]*DNSKEY, error) {
|
||||
}
|
||||
keys = append(keys, k)
|
||||
}
|
||||
} else if value == "aws_secretsmanager" {
|
||||
case "aws_secretsmanager":
|
||||
ks := c.RemainingArgs()
|
||||
if len(ks) == 0 {
|
||||
return nil, c.ArgErr()
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
func (z *Zone) ClosestEncloser(qname string) (*tree.Elem, bool) {
|
||||
offset, end := dns.NextLabel(qname, 0)
|
||||
for !end {
|
||||
elem, _ := z.Tree.Search(qname)
|
||||
elem, _ := z.Search(qname)
|
||||
if elem != nil {
|
||||
return elem, true
|
||||
}
|
||||
@@ -19,5 +19,5 @@ func (z *Zone) ClosestEncloser(qname string) (*tree.Elem, bool) {
|
||||
offset, end = dns.NextLabel(qname, offset)
|
||||
}
|
||||
|
||||
return z.Tree.Search(z.origin)
|
||||
return z.Search(z.origin)
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ func (f File) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (i
|
||||
return plugin.NextOrFailure(f.Name(), f.Next, ctx, w, r)
|
||||
}
|
||||
|
||||
z, ok := f.Zones.Z[zone]
|
||||
z, ok := f.Z[zone]
|
||||
if !ok || z == nil {
|
||||
return dns.RcodeServerFailure, nil
|
||||
}
|
||||
|
||||
@@ -330,11 +330,11 @@ func (z *Zone) externalLookup(ctx context.Context, state request.Request, elem *
|
||||
}
|
||||
|
||||
targetName := rrs[0].(*dns.CNAME).Target
|
||||
elem, _ = z.Tree.Search(targetName)
|
||||
elem, _ = z.Search(targetName)
|
||||
if elem == nil {
|
||||
lookupRRs, result := z.doLookup(ctx, state, targetName, qtype)
|
||||
rrs = append(rrs, lookupRRs...)
|
||||
return rrs, z.Apex.ns(do), nil, result
|
||||
return rrs, z.ns(do), nil, result
|
||||
}
|
||||
|
||||
i := 0
|
||||
@@ -350,16 +350,16 @@ Redo:
|
||||
rrs = append(rrs, sigs...)
|
||||
}
|
||||
targetName := cname[0].(*dns.CNAME).Target
|
||||
elem, _ = z.Tree.Search(targetName)
|
||||
elem, _ = z.Search(targetName)
|
||||
if elem == nil {
|
||||
lookupRRs, result := z.doLookup(ctx, state, targetName, qtype)
|
||||
rrs = append(rrs, lookupRRs...)
|
||||
return rrs, z.Apex.ns(do), nil, result
|
||||
return rrs, z.ns(do), nil, result
|
||||
}
|
||||
|
||||
i++
|
||||
if i > 8 {
|
||||
return rrs, z.Apex.ns(do), nil, Success
|
||||
return rrs, z.ns(do), nil, Success
|
||||
}
|
||||
|
||||
goto Redo
|
||||
@@ -376,7 +376,7 @@ Redo:
|
||||
}
|
||||
}
|
||||
|
||||
return rrs, z.Apex.ns(do), nil, Success
|
||||
return rrs, z.ns(do), nil, Success
|
||||
}
|
||||
|
||||
func (z *Zone) doLookup(ctx context.Context, state request.Request, target string, qtype uint16) ([]dns.RR, Result) {
|
||||
@@ -414,7 +414,7 @@ func (z *Zone) additionalProcessing(answer []dns.RR, do bool) (extra []dns.RR) {
|
||||
continue
|
||||
}
|
||||
|
||||
elem, _ := z.Tree.Search(name)
|
||||
elem, _ := z.Search(name)
|
||||
if elem == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ func (z *Zone) Reload(t *transfer.Transfer) error {
|
||||
z.Tree = zone.Tree
|
||||
z.Unlock()
|
||||
|
||||
log.Infof("Successfully reloaded zone %q in %q with %d SOA serial", z.origin, zFile, z.Apex.SOA.Serial)
|
||||
log.Infof("Successfully reloaded zone %q in %q with %d SOA serial", z.origin, zFile, z.SOA.Serial)
|
||||
if t != nil {
|
||||
if err := t.Notify(z.origin); err != nil {
|
||||
log.Warningf("Failed sending notifies: %s", err)
|
||||
@@ -62,8 +62,8 @@ func (z *Zone) Reload(t *transfer.Transfer) error {
|
||||
func (z *Zone) SOASerialIfDefined() int64 {
|
||||
z.RLock()
|
||||
defer z.RUnlock()
|
||||
if z.Apex.SOA != nil {
|
||||
return int64(z.Apex.SOA.Serial)
|
||||
if z.SOA != nil {
|
||||
return int64(z.SOA.Serial)
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
@@ -89,10 +89,10 @@ Transfer:
|
||||
if serial == -1 {
|
||||
return false, Err
|
||||
}
|
||||
if z.Apex.SOA == nil {
|
||||
if z.SOA == nil {
|
||||
return true, Err
|
||||
}
|
||||
return less(z.Apex.SOA.Serial, uint32(serial)), Err
|
||||
return less(z.SOA.Serial, uint32(serial)), Err
|
||||
}
|
||||
|
||||
// less returns true of a is smaller than b when taking RFC 1982 serial arithmetic into account.
|
||||
@@ -109,15 +109,15 @@ func less(a, b uint32) bool {
|
||||
// will be marked expired.
|
||||
func (z *Zone) Update() error {
|
||||
// If we don't have a SOA, we don't have a zone, wait for it to appear.
|
||||
for z.Apex.SOA == nil {
|
||||
for z.SOA == nil {
|
||||
time.Sleep(1 * time.Second)
|
||||
}
|
||||
retryActive := false
|
||||
|
||||
Restart:
|
||||
refresh := time.Second * time.Duration(z.Apex.SOA.Refresh)
|
||||
retry := time.Second * time.Duration(z.Apex.SOA.Retry)
|
||||
expire := time.Second * time.Duration(z.Apex.SOA.Expire)
|
||||
refresh := time.Second * time.Duration(z.SOA.Refresh)
|
||||
retry := time.Second * time.Duration(z.SOA.Retry)
|
||||
expire := time.Second * time.Duration(z.SOA.Expire)
|
||||
|
||||
refreshTicker := time.NewTicker(refresh)
|
||||
retryTicker := time.NewTicker(retry)
|
||||
|
||||
@@ -84,7 +84,7 @@ func TestShouldTransfer(t *testing.T) {
|
||||
t.Fatalf("ShouldTransfer should return true for serial: %d", soa.serial)
|
||||
}
|
||||
// Serial smaller
|
||||
z.Apex.SOA = test.SOA(fmt.Sprintf("%s IN SOA bla. bla. %d 0 0 0 0 ", testZone, soa.serial-1))
|
||||
z.SOA = test.SOA(fmt.Sprintf("%s IN SOA bla. bla. %d 0 0 0 0 ", testZone, soa.serial-1))
|
||||
should, err = z.shouldTransfer()
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to run shouldTransfer: %v", err)
|
||||
@@ -93,7 +93,7 @@ func TestShouldTransfer(t *testing.T) {
|
||||
t.Fatalf("ShouldTransfer should return true for serial: %q", soa.serial-1)
|
||||
}
|
||||
// Serial equal
|
||||
z.Apex.SOA = test.SOA(fmt.Sprintf("%s IN SOA bla. bla. %d 0 0 0 0 ", testZone, soa.serial))
|
||||
z.SOA = test.SOA(fmt.Sprintf("%s IN SOA bla. bla. %d 0 0 0 0 ", testZone, soa.serial))
|
||||
should, err = z.shouldTransfer()
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to run shouldTransfer: %v", err)
|
||||
@@ -116,7 +116,7 @@ func TestTransferIn(t *testing.T) {
|
||||
if err := z.TransferIn(); err != nil {
|
||||
t.Fatalf("Unable to run TransferIn: %v", err)
|
||||
}
|
||||
if z.Apex.SOA.String() != fmt.Sprintf("%s 3600 IN SOA bla. bla. 250 0 0 0 0", testZone) {
|
||||
if z.SOA.String() != fmt.Sprintf("%s 3600 IN SOA bla. bla. 250 0 0 0 0", testZone) {
|
||||
t.Fatalf("Unknown SOA transferred")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
|
||||
// Transfer implements the transfer.Transfer interface.
|
||||
func (f File) Transfer(zone string, serial uint32) (<-chan []dns.RR, error) {
|
||||
z, ok := f.Zones.Z[zone]
|
||||
z, ok := f.Z[zone]
|
||||
if !ok || z == nil {
|
||||
return nil, transfer.ErrNotAuthoritative
|
||||
}
|
||||
|
||||
@@ -80,14 +80,14 @@ func (z *Zone) Insert(r dns.RR) error {
|
||||
r.(*dns.NS).Ns = strings.ToLower(r.(*dns.NS).Ns)
|
||||
|
||||
if r.Header().Name == z.origin {
|
||||
z.Apex.NS = append(z.Apex.NS, r)
|
||||
z.NS = append(z.NS, r)
|
||||
return nil
|
||||
}
|
||||
case dns.TypeSOA:
|
||||
r.(*dns.SOA).Ns = strings.ToLower(r.(*dns.SOA).Ns)
|
||||
r.(*dns.SOA).Mbox = strings.ToLower(r.(*dns.SOA).Mbox)
|
||||
|
||||
z.Apex.SOA = r.(*dns.SOA)
|
||||
z.SOA = r.(*dns.SOA)
|
||||
return nil
|
||||
case dns.TypeNSEC3, dns.TypeNSEC3PARAM:
|
||||
return fmt.Errorf("NSEC3 zone is not supported, dropping RR: %s for zone: %s", r.Header().Name, z.origin)
|
||||
@@ -95,11 +95,11 @@ func (z *Zone) Insert(r dns.RR) error {
|
||||
x := r.(*dns.RRSIG)
|
||||
switch x.TypeCovered {
|
||||
case dns.TypeSOA:
|
||||
z.Apex.SIGSOA = append(z.Apex.SIGSOA, x)
|
||||
z.SIGSOA = append(z.SIGSOA, x)
|
||||
return nil
|
||||
case dns.TypeNS:
|
||||
if r.Header().Name == z.origin {
|
||||
z.Apex.SIGNS = append(z.Apex.SIGNS, x)
|
||||
z.SIGNS = append(z.SIGNS, x)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
@@ -133,20 +133,20 @@ func (z *Zone) SetFile(path string) {
|
||||
func (z *Zone) ApexIfDefined() ([]dns.RR, error) {
|
||||
z.RLock()
|
||||
defer z.RUnlock()
|
||||
if z.Apex.SOA == nil {
|
||||
if z.SOA == nil {
|
||||
return nil, fmt.Errorf("no SOA")
|
||||
}
|
||||
|
||||
rrs := []dns.RR{z.Apex.SOA}
|
||||
rrs := []dns.RR{z.SOA}
|
||||
|
||||
if len(z.Apex.SIGSOA) > 0 {
|
||||
rrs = append(rrs, z.Apex.SIGSOA...)
|
||||
if len(z.SIGSOA) > 0 {
|
||||
rrs = append(rrs, z.SIGSOA...)
|
||||
}
|
||||
if len(z.Apex.NS) > 0 {
|
||||
rrs = append(rrs, z.Apex.NS...)
|
||||
if len(z.NS) > 0 {
|
||||
rrs = append(rrs, z.NS...)
|
||||
}
|
||||
if len(z.Apex.SIGNS) > 0 {
|
||||
rrs = append(rrs, z.Apex.SIGNS...)
|
||||
if len(z.SIGNS) > 0 {
|
||||
rrs = append(rrs, z.SIGNS...)
|
||||
}
|
||||
|
||||
return rrs, nil
|
||||
|
||||
@@ -91,8 +91,8 @@ func (g GeoIP) Metadata(ctx context.Context, state request.Request) context.Cont
|
||||
}
|
||||
}
|
||||
|
||||
switch {
|
||||
case g.db.provides&city == city:
|
||||
switch g.db.provides & city {
|
||||
case city:
|
||||
data, err := g.db.City(srcIP)
|
||||
if err != nil {
|
||||
log.Debugf("Setting up metadata failed due to database lookup error: %v", err)
|
||||
|
||||
@@ -37,7 +37,8 @@ func parse(c *caddy.Controller) ([]Rule, []Rule, error) {
|
||||
selector := strings.ToLower(c.Val())
|
||||
|
||||
var action string
|
||||
if selector == "set" || selector == "clear" {
|
||||
switch selector {
|
||||
case "set", "clear":
|
||||
log.Warningf("The selector for header rule in line %d isn't explicit defined. "+
|
||||
"Assume rule applies for selector 'response'. This syntax is deprecated. "+
|
||||
"In future versions of CoreDNS the selector must be explicit defined.",
|
||||
@@ -45,11 +46,11 @@ func parse(c *caddy.Controller) ([]Rule, []Rule, error) {
|
||||
|
||||
action = selector
|
||||
selector = "response"
|
||||
} else if selector == "query" || selector == "response" {
|
||||
case "query", "response":
|
||||
if c.NextArg() {
|
||||
action = c.Val()
|
||||
}
|
||||
} else {
|
||||
default:
|
||||
return nil, nil, fmt.Errorf("setting up rule: invalid selector=%s should be query or response", selector)
|
||||
}
|
||||
|
||||
|
||||
@@ -13,8 +13,7 @@ import (
|
||||
)
|
||||
|
||||
func TestImplementsTransferer(t *testing.T) {
|
||||
var e plugin.Handler
|
||||
e = &External{}
|
||||
var e plugin.Handler = &External{}
|
||||
_, ok := e.(transfer.Transferer)
|
||||
if !ok {
|
||||
t.Error("Transferer not implemented")
|
||||
|
||||
@@ -140,8 +140,8 @@ func generateEndpointSlices(cidr string, client kubernetes.Interface) {
|
||||
Hostname: &hostname,
|
||||
},
|
||||
}
|
||||
eps.ObjectMeta.Name = "svc" + strconv.Itoa(count)
|
||||
eps.ObjectMeta.Labels = map[string]string{discovery.LabelServiceName: eps.ObjectMeta.Name}
|
||||
eps.Name = "svc" + strconv.Itoa(count)
|
||||
eps.Labels = map[string]string{discovery.LabelServiceName: eps.Name}
|
||||
_, err := client.DiscoveryV1().EndpointSlices("testns").Create(ctx, eps, meta.CreateOptions{})
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
@@ -175,11 +175,12 @@ func generateSvcs(cidr string, svcType string, client kubernetes.Interface) {
|
||||
}
|
||||
default:
|
||||
for ip := ip.Mask(ipnet.Mask); ipnet.Contains(ip); inc(ip) {
|
||||
if count%3 == 0 {
|
||||
switch count % 3 {
|
||||
case 0:
|
||||
createClusterIPSvc(count, client, ip)
|
||||
} else if count%3 == 1 {
|
||||
case 1:
|
||||
createHeadlessSvc(count, client, ip)
|
||||
} else if count%3 == 2 {
|
||||
case 2:
|
||||
createExternalSvc(count, client, ip)
|
||||
}
|
||||
count++
|
||||
|
||||
@@ -62,10 +62,11 @@ func (k *Kubernetes) External(state request.Request, headless bool) ([]msg.Servi
|
||||
|
||||
service := segs[last]
|
||||
last--
|
||||
if last == 0 {
|
||||
switch last {
|
||||
case 0:
|
||||
endpoint = stripUnderscore(segs[last])
|
||||
last--
|
||||
} else if last == 1 {
|
||||
case 1:
|
||||
protocol = stripUnderscore(segs[last])
|
||||
port = stripUnderscore(segs[last-1])
|
||||
last -= 2
|
||||
|
||||
@@ -332,10 +332,10 @@ func endpointHostname(addr object.EndpointAddress, endpointNameMode bool) string
|
||||
return addr.TargetRefName
|
||||
}
|
||||
if strings.Contains(addr.IP, ".") {
|
||||
return strings.Replace(addr.IP, ".", "-", -1)
|
||||
return strings.ReplaceAll(addr.IP, ".", "-")
|
||||
}
|
||||
if strings.Contains(addr.IP, ":") {
|
||||
return strings.Replace(addr.IP, ":", "-", -1)
|
||||
return strings.ReplaceAll(addr.IP, ":", "-")
|
||||
}
|
||||
return ""
|
||||
}
|
||||
@@ -428,7 +428,7 @@ func (k *Kubernetes) findServices(r recordRequest, zone string) (services []msg.
|
||||
|
||||
zonePath := msg.Path(zone, coredns)
|
||||
for _, svc := range serviceList {
|
||||
if !(match(r.namespace, svc.Namespace) && match(r.service, svc.Name)) {
|
||||
if !match(r.namespace, svc.Namespace) || !match(r.service, svc.Name) {
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ func ToPod(obj meta.Object) (meta.Object, error) {
|
||||
Name: apiPod.GetName(),
|
||||
Labels: apiPod.GetLabels(),
|
||||
}
|
||||
t := apiPod.ObjectMeta.DeletionTimestamp
|
||||
t := apiPod.DeletionTimestamp
|
||||
if t != nil && !(*t).Time.IsZero() {
|
||||
// if the pod is in the process of termination, return an error so it can be ignored
|
||||
// during add/update event processing
|
||||
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
)
|
||||
|
||||
var log = clog.NewWithPlugin("loadbalance")
|
||||
var errOpen = errors.New("Weight file open error")
|
||||
var errOpen = errors.New("weight file open error")
|
||||
|
||||
func init() { plugin.Register("loadbalance", setup) }
|
||||
|
||||
|
||||
@@ -90,7 +90,7 @@ func createWeightedFuncs(weightFileName string,
|
||||
randomGen: &randomUint{},
|
||||
},
|
||||
}
|
||||
lb.weighted.randomGen.randInit()
|
||||
lb.weighted.randInit()
|
||||
|
||||
lb.shuffleFunc = func(res *dns.Msg) *dns.Msg {
|
||||
return weightedShuffle(res, lb.weighted)
|
||||
@@ -285,7 +285,7 @@ func (w *weightedRR) parseWeights(scanner *bufio.Scanner) (map[string]weights, e
|
||||
case 1:
|
||||
// (domain) name sanity check
|
||||
if net.ParseIP(fields[0]) != nil {
|
||||
return nil, fmt.Errorf("Wrong domain name:\"%s\" in weight file %s. (Maybe a missing weight value?)",
|
||||
return nil, fmt.Errorf("wrong domain name:\"%s\" in weight file %s. (Maybe a missing weight value?)",
|
||||
fields[0], w.fileName)
|
||||
}
|
||||
dname = fields[0]
|
||||
@@ -304,25 +304,25 @@ func (w *weightedRR) parseWeights(scanner *bufio.Scanner) (map[string]weights, e
|
||||
// IP address and weight value
|
||||
ip := net.ParseIP(fields[0])
|
||||
if ip == nil {
|
||||
return nil, fmt.Errorf("Wrong IP address:\"%s\" in weight file %s", fields[0], w.fileName)
|
||||
return nil, fmt.Errorf("wrong IP address:\"%s\" in weight file %s", fields[0], w.fileName)
|
||||
}
|
||||
weight, err := strconv.ParseUint(fields[1], 10, 8)
|
||||
if err != nil || weight == 0 {
|
||||
return nil, fmt.Errorf("Wrong weight value:\"%s\" in weight file %s", fields[1], w.fileName)
|
||||
return nil, fmt.Errorf("wrong weight value:\"%s\" in weight file %s", fields[1], w.fileName)
|
||||
}
|
||||
witem := &weightItem{address: ip, value: uint8(weight)}
|
||||
if dname == "" {
|
||||
return nil, fmt.Errorf("Missing domain name in weight file %s", w.fileName)
|
||||
return nil, fmt.Errorf("missing domain name in weight file %s", w.fileName)
|
||||
}
|
||||
ws = append(ws, witem)
|
||||
domains[dname] = ws
|
||||
default:
|
||||
return nil, fmt.Errorf("Could not parse weight line:\"%s\" in weight file %s", nextLine, w.fileName)
|
||||
return nil, fmt.Errorf("could not parse weight line:\"%s\" in weight file %s", nextLine, w.fileName)
|
||||
}
|
||||
}
|
||||
|
||||
if err := scanner.Err(); err != nil {
|
||||
return nil, fmt.Errorf("Weight file %s parsing error:%s", w.fileName, err)
|
||||
return nil, fmt.Errorf("weight file %s parsing error:%s", w.fileName, err)
|
||||
}
|
||||
|
||||
return domains, nil
|
||||
|
||||
@@ -96,11 +96,11 @@ func TestWeightFileUpdate(t *testing.T) {
|
||||
{oneDomainWRR, false, testOneDomainWRR, ""},
|
||||
{twoDomainsWRR, false, testTwoDomainsWRR, ""},
|
||||
// negative
|
||||
{missingWeightWRR, true, nil, "Wrong domain name"},
|
||||
{missingDomainWRR, true, nil, "Missing domain name"},
|
||||
{wrongIpWRR, true, nil, "Wrong IP address"},
|
||||
{wrongWeightWRR, true, nil, "Wrong weight value"},
|
||||
{zeroWeightWRR, true, nil, "Wrong weight value"},
|
||||
{missingWeightWRR, true, nil, "wrong domain name"},
|
||||
{missingDomainWRR, true, nil, "missing domain name"},
|
||||
{wrongIpWRR, true, nil, "wrong IP address"},
|
||||
{wrongWeightWRR, true, nil, "wrong weight value"},
|
||||
{zeroWeightWRR, true, nil, "wrong weight value"},
|
||||
}
|
||||
|
||||
for i, test := range tests {
|
||||
|
||||
@@ -54,8 +54,8 @@ func logParse(c *caddy.Controller) ([]Rule, error) {
|
||||
|
||||
if strings.Contains(args[len(args)-1], "{") {
|
||||
format = args[len(args)-1]
|
||||
format = strings.Replace(format, "{common}", CommonLogFormat, -1)
|
||||
format = strings.Replace(format, "{combined}", CombinedLogFormat, -1)
|
||||
format = strings.ReplaceAll(format, "{common}", CommonLogFormat)
|
||||
format = strings.ReplaceAll(format, "{combined}", CombinedLogFormat)
|
||||
args = args[:len(args)-1]
|
||||
}
|
||||
|
||||
|
||||
@@ -119,7 +119,7 @@ func (h *dnsHc) Check(p *Proxy) error {
|
||||
func (h *dnsHc) send(addr string) error {
|
||||
ping := new(dns.Msg)
|
||||
ping.SetQuestion(h.domain, dns.TypeNS)
|
||||
ping.MsgHdr.RecursionDesired = h.recursionDesired
|
||||
ping.RecursionDesired = h.recursionDesired
|
||||
|
||||
m, _, err := h.c.Exchange(ping, addr)
|
||||
// If we got a header, we're alright, basically only care about I/O errors 'n stuff.
|
||||
|
||||
@@ -21,7 +21,7 @@ func TestReplacer(t *testing.T) {
|
||||
w := dnstest.NewRecorder(&test.ResponseWriter{})
|
||||
r := new(dns.Msg)
|
||||
r.SetQuestion("example.org.", dns.TypeHINFO)
|
||||
r.MsgHdr.AuthenticatedData = true
|
||||
r.AuthenticatedData = true
|
||||
state := request.Request{W: w, Req: r}
|
||||
|
||||
replacer := New()
|
||||
@@ -269,7 +269,7 @@ func BenchmarkReplacer(b *testing.B) {
|
||||
w := dnstest.NewRecorder(&test.ResponseWriter{})
|
||||
r := new(dns.Msg)
|
||||
r.SetQuestion("example.org.", dns.TypeHINFO)
|
||||
r.MsgHdr.AuthenticatedData = true
|
||||
r.AuthenticatedData = true
|
||||
state := request.Request{W: w, Req: r}
|
||||
|
||||
b.ResetTimer()
|
||||
@@ -288,7 +288,7 @@ func BenchmarkReplacer_CommonLogFormat(b *testing.B) {
|
||||
r.Id = 1053
|
||||
r.AuthenticatedData = true
|
||||
r.CheckingDisabled = true
|
||||
r.MsgHdr.AuthenticatedData = true
|
||||
r.AuthenticatedData = true
|
||||
w.WriteMsg(r)
|
||||
state := request.Request{W: w, Req: r}
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ func (r *cnameTargetRule) getFromAndToTarget(inputCName string) (from string, to
|
||||
}
|
||||
case SubstringMatch:
|
||||
if strings.Contains(inputCName, r.paramFromTarget) {
|
||||
return inputCName, strings.Replace(inputCName, r.paramFromTarget, r.paramToTarget, -1)
|
||||
return inputCName, strings.ReplaceAll(inputCName, r.paramFromTarget, r.paramToTarget)
|
||||
}
|
||||
case RegexMatch:
|
||||
pattern := regexp.MustCompile(r.paramFromTarget)
|
||||
@@ -60,7 +60,7 @@ func (r *cnameTargetRule) getFromAndToTarget(inputCName string) (from string, to
|
||||
substitution := r.paramToTarget
|
||||
for groupIndex, groupValue := range regexGroups {
|
||||
groupIndexStr := "{" + strconv.Itoa(groupIndex) + "}"
|
||||
substitution = strings.Replace(substitution, groupIndexStr, groupValue, -1)
|
||||
substitution = strings.ReplaceAll(substitution, groupIndexStr, groupValue)
|
||||
}
|
||||
return inputCName, substitution
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ func (r *regexStringRewriter) rewriteString(src string) string {
|
||||
s := r.replacement
|
||||
for groupIndex, groupValue := range regexGroups {
|
||||
groupIndexStr := "{" + strconv.Itoa(groupIndex) + "}"
|
||||
s = strings.Replace(s, groupIndexStr, groupValue, -1)
|
||||
s = strings.ReplaceAll(s, groupIndexStr, groupValue)
|
||||
}
|
||||
return s
|
||||
}
|
||||
@@ -257,7 +257,7 @@ func newSubstringNameRule(nextAction string, auto bool, substring, replacement s
|
||||
|
||||
func (rule *substringNameRule) Rewrite(ctx context.Context, state request.Request) (ResponseRules, Result) {
|
||||
if strings.Contains(state.Name(), rule.substring) {
|
||||
state.Req.Question[0].Name = strings.Replace(state.Name(), rule.substring, rule.replacement, -1)
|
||||
state.Req.Question[0].Name = strings.ReplaceAll(state.Name(), rule.substring, rule.replacement)
|
||||
return rule.responseRuleFor(state)
|
||||
}
|
||||
return nil, RewriteIgnored
|
||||
@@ -285,7 +285,7 @@ func (rule *regexNameRule) Rewrite(ctx context.Context, state request.Request) (
|
||||
s := rule.replacement
|
||||
for groupIndex, groupValue := range regexGroups {
|
||||
groupIndexStr := "{" + strconv.Itoa(groupIndex) + "}"
|
||||
s = strings.Replace(s, groupIndexStr, groupValue, -1)
|
||||
s = strings.ReplaceAll(s, groupIndexStr, groupValue)
|
||||
}
|
||||
state.Req.Question[0].Name = s
|
||||
return rule.responseRuleFor(state)
|
||||
|
||||
@@ -19,8 +19,8 @@ type rcodeResponseRule struct {
|
||||
}
|
||||
|
||||
func (r *rcodeResponseRule) RewriteResponse(res *dns.Msg, rr dns.RR) {
|
||||
if r.old == res.MsgHdr.Rcode {
|
||||
res.MsgHdr.Rcode = r.new
|
||||
if r.old == res.Rcode {
|
||||
res.Rcode = r.new
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -60,13 +60,13 @@ func TestRCodeRewrite(t *testing.T) {
|
||||
m.SetQuestion("srv1.coredns.rocks.", dns.TypeA)
|
||||
m.Question[0].Qclass = dns.ClassINET
|
||||
m.Answer = []dns.RR{test.A("srv1.coredns.rocks. 5 IN A 10.0.0.1")}
|
||||
m.MsgHdr.Rcode = dns.RcodeServerFailure
|
||||
m.Rcode = dns.RcodeServerFailure
|
||||
request := request.Request{Req: m}
|
||||
|
||||
rcRule, _ := rule.(*exactRCodeRule)
|
||||
var rr dns.RR
|
||||
rcRule.response.RewriteResponse(request.Req, rr)
|
||||
if request.Req.MsgHdr.Rcode != dns.RcodeFormatError {
|
||||
if request.Req.Rcode != dns.RcodeFormatError {
|
||||
t.Fatalf("RCode rewrite did not apply changes, request=%#v, err=%v", request.Req, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ func (rw Rewrite) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg
|
||||
}
|
||||
wr.ResponseRules = append(wr.ResponseRules, respRules...)
|
||||
if rule.Mode() == Stop {
|
||||
if !rw.RevertPolicy.DoRevert() {
|
||||
if !rw.DoRevert() {
|
||||
return plugin.NextOrFailure(rw.Name(), rw.Next, ctx, w, r)
|
||||
}
|
||||
rcode, err := plugin.NextOrFailure(rw.Name(), rw.Next, ctx, wr, r)
|
||||
@@ -71,7 +71,7 @@ func (rw Rewrite) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg
|
||||
}
|
||||
}
|
||||
}
|
||||
if !rw.RevertPolicy.DoRevert() || len(wr.ResponseRules) == 0 {
|
||||
if !rw.DoRevert() || len(wr.ResponseRules) == 0 {
|
||||
return plugin.NextOrFailure(rw.Name(), rw.Next, ctx, w, r)
|
||||
}
|
||||
return plugin.NextOrFailure(rw.Name(), rw.Next, ctx, wr, r)
|
||||
|
||||
@@ -29,19 +29,19 @@ func (s *Signer) write(z *file.Zone) error {
|
||||
}
|
||||
|
||||
func write(w io.Writer, z *file.Zone) error {
|
||||
if _, err := io.WriteString(w, z.Apex.SOA.String()); err != nil {
|
||||
if _, err := io.WriteString(w, z.SOA.String()); err != nil {
|
||||
return err
|
||||
}
|
||||
w.Write([]byte("\n")) // RR Stringer() method doesn't include newline, which ends the RR in a zone file, write that here.
|
||||
for _, rr := range z.Apex.SIGSOA {
|
||||
for _, rr := range z.SIGSOA {
|
||||
io.WriteString(w, rr.String())
|
||||
w.Write([]byte("\n"))
|
||||
}
|
||||
for _, rr := range z.Apex.NS {
|
||||
for _, rr := range z.NS {
|
||||
io.WriteString(w, rr.String())
|
||||
w.Write([]byte("\n"))
|
||||
}
|
||||
for _, rr := range z.Apex.SIGNS {
|
||||
for _, rr := range z.SIGNS {
|
||||
io.WriteString(w, rr.String())
|
||||
w.Write([]byte("\n"))
|
||||
}
|
||||
|
||||
@@ -41,10 +41,10 @@ func (s *Signer) Sign(now time.Time) (*file.Zone, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
mttl := z.Apex.SOA.Minttl
|
||||
ttl := z.Apex.SOA.Header().Ttl
|
||||
mttl := z.SOA.Minttl
|
||||
ttl := z.SOA.Header().Ttl
|
||||
inception, expiration := lifetime(now, s.jitterIncep, s.jitterExpir)
|
||||
z.Apex.SOA.Serial = uint32(now.Unix())
|
||||
z.SOA.Serial = uint32(now.Unix())
|
||||
|
||||
for _, pair := range s.keys {
|
||||
pair.Public.Header().Ttl = ttl // set TTL on key so it matches the RRSIG.
|
||||
@@ -58,14 +58,14 @@ func (s *Signer) Sign(now time.Time) (*file.Zone, error) {
|
||||
ln := len(names)
|
||||
|
||||
for _, pair := range s.keys {
|
||||
rrsig, err := pair.signRRs([]dns.RR{z.Apex.SOA}, s.origin, ttl, inception, expiration)
|
||||
rrsig, err := pair.signRRs([]dns.RR{z.SOA}, s.origin, ttl, inception, expiration)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
z.Insert(rrsig)
|
||||
// NS apex may not be set if RR's have been discarded because the origin doesn't match.
|
||||
if len(z.Apex.NS) > 0 {
|
||||
rrsig, err = pair.signRRs(z.Apex.NS, s.origin, ttl, inception, expiration)
|
||||
if len(z.NS) > 0 {
|
||||
rrsig, err = pair.signRRs(z.NS, s.origin, ttl, inception, expiration)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -178,7 +178,7 @@ func signAndLog(s *Signer, why error) {
|
||||
log.Warningf("Error signing %q: failed to move zone file into place: %s", s.origin, err)
|
||||
return
|
||||
}
|
||||
log.Infof("Successfully signed zone %q in %q with key tags %q and %d SOA serial, elapsed %f, next: %s", s.origin, filepath.Join(s.directory, s.signedfile), keyTag(s.keys), z.Apex.SOA.Serial, time.Since(now).Seconds(), now.Add(durationRefreshHours).Format(timeFmt))
|
||||
log.Infof("Successfully signed zone %q in %q with key tags %q and %d SOA serial, elapsed %f, next: %s", s.origin, filepath.Join(s.directory, s.signedfile), keyTag(s.keys), z.SOA.Serial, time.Since(now).Seconds(), now.Add(durationRefreshHours).Format(timeFmt))
|
||||
}
|
||||
|
||||
// refresh checks every val if some zones need to be resigned.
|
||||
|
||||
@@ -170,7 +170,7 @@ func TestSignDS(t *testing.T) {
|
||||
if x := nsec[0].(*dns.NSEC).NextDomain; x != "www.miek.nl." {
|
||||
t.Errorf("Expected no NSEC NextDomain to be %s for %s, got %s", "www.miek.nl.", name, x)
|
||||
}
|
||||
minttl := z.Apex.SOA.Minttl
|
||||
minttl := z.SOA.Minttl
|
||||
if x := nsec[0].Header().Ttl; x != minttl {
|
||||
t.Errorf("Expected no NSEC TTL to be %d for %s, got %d", minttl, "www.miek.nl.", x)
|
||||
}
|
||||
|
||||
@@ -11,10 +11,10 @@ type loggerAdapter struct {
|
||||
}
|
||||
|
||||
func (l *loggerAdapter) Write(p []byte) (n int, err error) {
|
||||
l.P.Warning(string(p))
|
||||
l.Warning(string(p))
|
||||
return len(p), nil
|
||||
}
|
||||
|
||||
func (l *loggerAdapter) Log(msg string) {
|
||||
l.P.Warning(msg)
|
||||
l.Warning(msg)
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ func TestTraceParse(t *testing.T) {
|
||||
continue
|
||||
}
|
||||
|
||||
if "" != m.serviceEndpoint {
|
||||
if m.serviceEndpoint != "" {
|
||||
t.Errorf("Test %v: Expected serviceEndpoint to be '' but found: %s", i, m.serviceEndpoint)
|
||||
}
|
||||
if test.endpoint != m.Endpoint {
|
||||
|
||||
@@ -117,7 +117,7 @@ func (r *restoreTsigWriter) WriteMsg(m *dns.Msg) error {
|
||||
repTSIG = new(dns.TSIG)
|
||||
repTSIG.Hdr = dns.RR_Header{Name: r.reqTSIG.Hdr.Name, Rrtype: dns.TypeTSIG, Class: dns.ClassANY}
|
||||
repTSIG.Algorithm = r.reqTSIG.Algorithm
|
||||
repTSIG.OrigId = m.MsgHdr.Id
|
||||
repTSIG.OrigId = m.Id
|
||||
repTSIG.Error = r.reqTSIG.Error
|
||||
repTSIG.MAC = r.reqTSIG.MAC
|
||||
repTSIG.MACSize = r.reqTSIG.MACSize
|
||||
|
||||
@@ -179,9 +179,7 @@ func TestServeDNSTsigErrors(t *testing.T) {
|
||||
t.Run(tc.desc, func(t *testing.T) {
|
||||
ctx := context.TODO()
|
||||
|
||||
var w *dnstest.Recorder
|
||||
|
||||
w = dnstest.NewRecorder(&ErrWriter{err: tc.tsigErr})
|
||||
var w = dnstest.NewRecorder(&ErrWriter{err: tc.tsigErr})
|
||||
|
||||
r := new(dns.Msg)
|
||||
r.SetQuestion("test.example.", dns.TypeA)
|
||||
|
||||
Reference in New Issue
Block a user