plugin/chaos: randomize author list (#2794)

Randomize the author list on request; keep the zowners.go file stable so
a 'go generate' remain stable.

chaos.Owners could potentially be a map and be randomized by ranging
over it, but this seems simpler and fewer lines of code.

Bit of Easter hacking; seems more fair to randomize this list.

Signed-off-by: Miek Gieben <miek@miek.nl>
This commit is contained in:
Miek Gieben
2019-04-23 16:21:28 +01:00
committed by Yong Tang
parent 2c418b9fd5
commit 3adfeaa857

View File

@@ -3,7 +3,9 @@ package chaos
import (
"context"
"math/rand"
"os"
"time"
"github.com/coredns/coredns/plugin"
"github.com/coredns/coredns/request"
@@ -34,8 +36,10 @@ func (c Chaos) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (
default:
return plugin.NextOrFailure(c.Name(), c.Next, ctx, w, r)
case "authors.bind.":
for _, a := range c.Authors {
m.Answer = append(m.Answer, &dns.TXT{Hdr: hdr, Txt: []string{a}})
rnd := rand.New(rand.NewSource(time.Now().Unix()))
for _, i := range rnd.Perm(len(c.Authors)) {
m.Answer = append(m.Answer, &dns.TXT{Hdr: hdr, Txt: []string{c.Authors[i]}})
}
case "version.bind.", "version.server.":
m.Answer = []dns.RR{&dns.TXT{Hdr: hdr, Txt: []string{c.Version}}}