Fixes races in test and klog (#3079)
Various fixes to make things less flaky: * kubernetes: put klog.SetOutput in the setup function, not in the init function to see if that helps * file: make z.Expired a boolean instead of a pointer to a boolean * test: fix TestSecondaryZoneTransfer test, which wasn't actually testing in the right way. It's more right now, but may still be racy (race introduced because a file's lazy loading of zones) Signed-off-by: Miek Gieben <miek@miek.nl>
This commit is contained in:
parent
3219a2b93a
commit
a01b202b6a
6 changed files with 11 additions and 16 deletions
|
@ -72,7 +72,7 @@ func (f File) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (i
|
||||||
z.RLock()
|
z.RLock()
|
||||||
exp := z.Expired
|
exp := z.Expired
|
||||||
z.RUnlock()
|
z.RUnlock()
|
||||||
if exp != nil && *exp {
|
if exp {
|
||||||
log.Errorf("Zone %s is expired", zone)
|
log.Errorf("Zone %s is expired", zone)
|
||||||
return dns.RcodeServerFailure, nil
|
return dns.RcodeServerFailure, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,7 +54,7 @@ Transfer:
|
||||||
z.Lock()
|
z.Lock()
|
||||||
z.Tree = z1.Tree
|
z.Tree = z1.Tree
|
||||||
z.Apex = z1.Apex
|
z.Apex = z1.Apex
|
||||||
*z.Expired = false
|
z.Expired = false
|
||||||
z.Unlock()
|
z.Unlock()
|
||||||
log.Infof("Transferred: %s from %s", z.origin, tr)
|
log.Infof("Transferred: %s from %s", z.origin, tr)
|
||||||
return nil
|
return nil
|
||||||
|
@ -129,7 +129,7 @@ Restart:
|
||||||
if !retryActive {
|
if !retryActive {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
*z.Expired = true
|
z.Expired = true
|
||||||
|
|
||||||
case <-retryTicker.C:
|
case <-retryTicker.C:
|
||||||
if !retryActive {
|
if !retryActive {
|
||||||
|
|
|
@ -125,7 +125,6 @@ func TestTransferIn(t *testing.T) {
|
||||||
defer s.Shutdown()
|
defer s.Shutdown()
|
||||||
|
|
||||||
z := new(Zone)
|
z := new(Zone)
|
||||||
z.Expired = new(bool)
|
|
||||||
z.origin = testZone
|
z.origin = testZone
|
||||||
z.TransferFrom = []string{addrstr}
|
z.TransferFrom = []string{addrstr}
|
||||||
|
|
||||||
|
@ -140,7 +139,6 @@ func TestTransferIn(t *testing.T) {
|
||||||
|
|
||||||
func TestIsNotify(t *testing.T) {
|
func TestIsNotify(t *testing.T) {
|
||||||
z := new(Zone)
|
z := new(Zone)
|
||||||
z.Expired = new(bool)
|
|
||||||
z.origin = testZone
|
z.origin = testZone
|
||||||
state := newRequest(testZone, dns.TypeSOA)
|
state := newRequest(testZone, dns.TypeSOA)
|
||||||
// need to set opcode
|
// need to set opcode
|
||||||
|
|
|
@ -22,7 +22,7 @@ type Zone struct {
|
||||||
file string
|
file string
|
||||||
*tree.Tree
|
*tree.Tree
|
||||||
Apex
|
Apex
|
||||||
Expired *bool
|
Expired bool
|
||||||
|
|
||||||
sync.RWMutex
|
sync.RWMutex
|
||||||
|
|
||||||
|
@ -46,16 +46,13 @@ type Apex struct {
|
||||||
|
|
||||||
// NewZone returns a new zone.
|
// NewZone returns a new zone.
|
||||||
func NewZone(name, file string) *Zone {
|
func NewZone(name, file string) *Zone {
|
||||||
z := &Zone{
|
return &Zone{
|
||||||
origin: dns.Fqdn(name),
|
origin: dns.Fqdn(name),
|
||||||
origLen: dns.CountLabel(dns.Fqdn(name)),
|
origLen: dns.CountLabel(dns.Fqdn(name)),
|
||||||
file: filepath.Clean(file),
|
file: filepath.Clean(file),
|
||||||
Tree: &tree.Tree{},
|
Tree: &tree.Tree{},
|
||||||
Expired: new(bool),
|
|
||||||
reloadShutdown: make(chan bool),
|
reloadShutdown: make(chan bool),
|
||||||
}
|
}
|
||||||
*z.Expired = false
|
|
||||||
return z
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy copies a zone.
|
// Copy copies a zone.
|
||||||
|
|
|
@ -19,7 +19,7 @@ import (
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
|
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
|
|
||||||
// Pull this in for logtostderr flag parsing
|
// Pull this in setting klog's output to stdout
|
||||||
"k8s.io/klog"
|
"k8s.io/klog"
|
||||||
|
|
||||||
// Excluding azure because it is failing to compile
|
// Excluding azure because it is failing to compile
|
||||||
|
@ -35,8 +35,6 @@ import (
|
||||||
var log = clog.NewWithPlugin("kubernetes")
|
var log = clog.NewWithPlugin("kubernetes")
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
klog.SetOutput(os.Stdout)
|
|
||||||
|
|
||||||
caddy.RegisterPlugin("kubernetes", caddy.Plugin{
|
caddy.RegisterPlugin("kubernetes", caddy.Plugin{
|
||||||
ServerType: "dns",
|
ServerType: "dns",
|
||||||
Action: setup,
|
Action: setup,
|
||||||
|
@ -44,6 +42,8 @@ func init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func setup(c *caddy.Controller) error {
|
func setup(c *caddy.Controller) error {
|
||||||
|
klog.SetOutput(os.Stdout)
|
||||||
|
|
||||||
k, err := kubernetesParse(c)
|
k, err := kubernetesParse(c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return plugin.Error("kubernetes", err)
|
return plugin.Error("kubernetes", err)
|
||||||
|
|
|
@ -73,13 +73,13 @@ func TestSecondaryZoneTransfer(t *testing.T) {
|
||||||
var r *dns.Msg
|
var r *dns.Msg
|
||||||
// This is now async; we we need to wait for it to be transferred.
|
// This is now async; we we need to wait for it to be transferred.
|
||||||
for i := 0; i < 10; i++ {
|
for i := 0; i < 10; i++ {
|
||||||
r, _ = dns.Exchange(m, udp)
|
r, err = dns.Exchange(m, udp)
|
||||||
if len(r.Answer) == 0 {
|
if len(r.Answer) != 0 {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
time.Sleep(100 * time.Microsecond)
|
time.Sleep(100 * time.Microsecond)
|
||||||
}
|
}
|
||||||
if len(r.Answer) != 0 {
|
if len(r.Answer) == 0 {
|
||||||
t.Fatalf("Expected answer section")
|
t.Fatalf("Expected answer section")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue