Render empty forwarders for forward zones
ci/woodpecker/pr/pre-commit Pipeline was successful
ci/woodpecker/pr/test Pipeline was successful
ci/woodpecker/pr/build Pipeline was successful

A forward zone with no forwarders now renders "forwarders { };", which
BIND accepts and treats as disabling forwarding for the zone.
This commit is contained in:
2026-10-16 23:32:09 +11:00
parent f149b79cce
commit 53cb7fa059
7 changed files with 51 additions and 10 deletions
+1 -4
View File
@@ -218,10 +218,7 @@ func (r *BindZoneReconciler) buildZoneConfig(ctx context.Context, zone *bindv1al
parts = append(parts, fmt.Sprintf("primaries { %s }", terminateInline(zone.Spec.Primaries)))
}
case bindv1alpha1.ZoneForward:
parts = append(parts, "type forward", "forward only")
if len(zone.Spec.Forwarders) > 0 {
parts = append(parts, fmt.Sprintf("forwarders { %s }", terminateInline(zone.Spec.Forwarders)))
}
parts = append(parts, "type forward", "forward only", bind.ForwardersClause(zone.Spec.Forwarders))
case bindv1alpha1.ZoneStub:
parts = append(parts, "type stub", fmt.Sprintf("file \"%s\"", bind.ZoneFilePath(zone.Spec.ZoneName)))
if len(zone.Spec.Primaries) > 0 {
@@ -63,3 +63,23 @@ func TestBuildZoneConfigPrimaryNoNotifyTargets(t *testing.T) {
t.Errorf("did not expect notify clauses with no targets: %q", cfg)
}
}
func TestBuildZoneConfigForwardForwarders(t *testing.T) {
r := &BindZoneReconciler{}
for _, tc := range []struct {
fwd []string
want string
}{
{nil, "{ type forward; forward only; forwarders { }; };"},
{[]string{"198.18.19.15"}, "{ type forward; forward only; forwarders { 198.18.19.15; }; };"},
} {
zone := &bindv1alpha1.BindZone{Spec: bindv1alpha1.BindZoneSpec{ZoneName: "spamhaus.org", Type: bindv1alpha1.ZoneForward, Forwarders: tc.fwd}}
cfg, err := r.buildZoneConfig(context.Background(), zone, "", nil, "")
if err != nil {
t.Fatalf("buildZoneConfig: %v", err)
}
if cfg != tc.want {
t.Errorf("forwarders %v:\ngot %q\nwant %q", tc.fwd, cfg, tc.want)
}
}
}