Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,10 @@ func main() {
// Ensure defaults are applied even if the decoded config was empty/partial.
// (The scheme defaulting may already have done this, but this makes it explicit.)
config.SetObjectDefaults_DNSOperator(&serverConfig)
if err := serverConfig.Controllers.DNSZoneReplicator.ZoneClaims.Validate(); err != nil {
setupLog.Error(err, "invalid server config")
os.Exit(1)
}

setupLog.Info("server config", "config", serverConfig)

Expand Down Expand Up @@ -371,14 +375,24 @@ func main() {
// --- register controllers BEFORE starting provider/manager ---
if err := (&controller.DNSRecordSetReplicator{
DownstreamClient: downstreamCluster.GetClient(),
ZoneClaims: serverConfig.Controllers.DNSZoneReplicator.ZoneClaims.Enabled,
}).SetupWithManager(mcmgr, downstreamCluster); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "DNSRecordSetReplicator")
os.Exit(1)
}
if err := (&controller.DNSZoneReplicator{
zoneReplicator := &controller.DNSZoneReplicator{
DownstreamClient: downstreamCluster.GetClient(),
AccountingNamespace: serverConfig.DownstreamResourceManagement.DNSZoneAccountingNamespace,
}).SetupWithManager(mcmgr, downstreamCluster); err != nil {
}
if claims := serverConfig.Controllers.DNSZoneReplicator.ZoneClaims; claims.Enabled {
zoneReplicator.ZoneClaims = &controller.ZoneClaims{
Reader: downstreamCluster.GetAPIReader(),
Writer: downstreamCluster.GetClient(),
Namespace: serverConfig.DownstreamResourceManagement.DNSZoneAccountingNamespace,
MaxEntries: claims.MaxEntries,
}
}
if err := zoneReplicator.SetupWithManager(mcmgr, downstreamCluster); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "DNSZoneReplicator")
os.Exit(1)
}
Expand Down
8 changes: 8 additions & 0 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,14 @@ rules:
- delete
- patch
- update
- apiGroups:
- dns.networking.miloapis.com
resources:
- zoneclaimsets
verbs:
- create
- get
- update
- apiGroups:
- events.k8s.io
resources:
Expand Down
7 changes: 6 additions & 1 deletion docs/agent/llms-full.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,15 @@ and a Programmed condition (whether it is live in the DNS backend).
Reasons on Programmed fall into a few buckets:

- Self-clearing, no customer action needed: Pending,
PendingPreviousZoneRemoval (the zone holds its domain and waits a few
minutes for another project's zone to stop serving),
PendingDomainVerification (but see below — this one still needs the
customer to act on a different object).
- Needs a person to act, and never clears by itself: NotOwner, Conflict,
DNSZoneInUse.
InvalidDomain.
- DNSZoneInUse: another zone holds the domain. With zone claims on, the
zone retries every minute and starts serving once the other zone is
deleted; if the other zone is the customer's own, they can delete it.
- Depends on the message: PDNSError. The same reason covers a value the
customer typed wrong, a zone still coming up, and a backend hiccup —
read the message, don't stop at the reason code.
Expand Down
5 changes: 4 additions & 1 deletion docs/architecture/conditions.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ retrying, and keeps failing, for as long as the cause stands.
|---|---|---|---|
| `NotOwner` | per-record `Programmed` | Another record set claimed this owner name first and holds it. | Whoever owns one of the two record sets removes their claim. |
| `Conflict` | per-record `Programmed` | The backend refuses this record because it cannot coexist with data already at the name, such as a `CNAME` beside other types. | Remove the conflicting data, or move the record to another name. |
| `DNSZoneInUse` | zone `Accepted` and `Programmed` | Another zone already claims this domain. | Release the other zone, or use a different domain. |
| `DNSZoneInUse` | zone `Accepted` and `Programmed` | Another zone already claims this domain. With zone claims on, the message says whether another project's zone holds the same name, a parent, or a child, and the zone is retried every minute. | Delete the other zone if it's yours, or use a different domain. With zone claims on, the zone starts serving once the other zone is deleted. |
| `InvalidDomain` | zone `Accepted` and `Programmed` | With zone claims on, the zone's name is a public suffix, such as `co.uk`. | Create the zone for a domain registered under the suffix. |
| `ClaimSetFull` | zone `Accepted` and `Programmed` | With zone claims on, the zone's registered domain already holds `zoneClaims.maxEntries` zones. Retried every minute. | An operator raises the limit, or zones under the domain are deleted. |
| `PendingPreviousZoneRemoval` | zone `Accepted` and `Programmed` | With zone claims on, the zone holds its domain and waits for another project's overlapping zone to stop serving. Retried every 10 seconds. | Nobody. It clears once the other zone's served copy is gone, normally within a few minutes. |
| `TargetUnresolved` | ALIAS record set `TargetResolved` | An ALIAS target resolves to no A or AAAA address, so the name answers SERVFAIL. The record is still `Programmed`. | Whoever owns the target restores it, or the record set points at a live target. |

`NotOwner` is the one most often mistaken for a transient state. It is not.
Expand Down
58 changes: 41 additions & 17 deletions docs/architecture/zone-claims/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,9 @@ Consequences:
</p>

With `zoneClaims.enabled` on, the replicator's `DNSZone` reconcile admits a zone
in `ensureZoneClaim`:
in `admitZoneClaim`, before it writes the zone's exact-name accounting
ConfigMap, so a refused zone never takes the ConfigMap from the project that
holds the name:

1. Compute the registered domain. If there's none, refuse with `InvalidDomain`.
2. Get the claim set with the uncached reader. If it doesn't exist, build it
Expand All @@ -226,22 +228,40 @@ in `ensureZoneClaim`:
4. Copy the zone's `spec.grants` to its entry, skipping a self-grant on an
entry with `handedOverTo`.
5. Run `normalize` and `evaluate`, and update the set with the resourceVersion
you read. On a conflict, go back to step 2.
you read. On a conflict, go back to step 2. If the entry that blocks this
zone is bound to a zone that no longer exists and whose shadow zone is gone
too, drop that entry and evaluate again. An entry whose zone is gone but
whose shadow remains, such as a zone deleted with its finalizer removed, is
kept, so no other project serves an overlapping name beside the orphaned
shadow.
6. Act on the entry's state:
- `Active`: continue to `ensureDomain`, `ensureDomainRef`, and the
verification gate if it's enabled. Before `ensureDownstreamZone`, check
that no other shadow zone for the same `spec.domainName` exists in the
authoritative cluster. If one does, report `Accepted=False` with reason
`PendingPreviousZoneRemoval` and wait for its deletion event.
- `Contested`: delete the shadow zone if one exists, set `Accepted=False`
and `Programmed=False`, and stop.
- `Active`: check every other entry in the set that isn't `Active`, belongs
to another project, is bound to a zone, and has the same name, a parent,
or a child. If any of those zones still has a shadow zone, read with the
uncached reader, report `Accepted=False` with reason
`PendingPreviousZoneRemoval` and retry every 10 seconds. Otherwise,
continue to `ensureDomain`, `ensureDomainRef`, the verification gate if
it's enabled, and `ensureDownstreamZone`.
- `Contested`: set `Accepted=False` and `Programmed=False`, and delete the
shadow zone if one exists. Once the uncached reader confirms the shadow
is gone, delete the zone's own exact-name accounting ConfigMap, if the
zone owns it, so the zone now `Active` for the name can take it. Stop.

After `ensureDownstreamZone` creates or updates the shadow, the reconcile runs
admission again. If the entry is no longer `Active`, or an overlapping zone
of another project now has a shadow, it deletes the shadow it just wrote and
reports the refusal or the wait. A zone that loses its claim withdraws its
shadow on its own next reconcile. Admission and the shadow write aren't
atomic, so this narrows the window in which two projects serve overlapping
names to the time between the shadow write and the second check.

The backend identifies a zone only by name: `EnsureZone` does nothing if the
name exists, and deleting a shadow deletes the backend zone by name. The
shadow check in step 6 keeps a name from changing hands while the old shadow
still exists. Without it, after a handover or a release, the new zone's shadow
could adopt the old backend zone, or lose it when the old shadow is deleted.
The check uses a field index on shadow zones by `spec.domainName`.
The check reads each overlapping zone's shadow by name; it doesn't use an
index.

On zone deletion:

Expand All @@ -256,9 +276,12 @@ requeues each set at its earliest `reservedUntil` to expire reservations.

A `Contested` entry has no shadow zone. When a zone that was serving becomes
`Contested`, after a handover or a release, its shadow is deleted. Its records
stay upstream, so its project can still export them. The record set replicator
mirrors record sets only for a zone that's `Accepted=True`, so a contested
project's records never reach the backend zone that another project serves.
stay upstream, so its project can still export them. The zone is refused
before its shadow is deleted, and the record set replicator doesn't mirror the
record sets of a refused zone into the authoritative cluster; it retries them
every minute. The downstream record set controller also programs a record set
only through its own project's shadow zone, so a contested project's records
never reach the backend zone that another project serves.

## The verification gate

Expand Down Expand Up @@ -316,7 +339,7 @@ Other `Accepted=False` reasons from admission:
|--------|---------|
| `InvalidDomain` | The zone's name is a public suffix and has no registered domain. |
| `ClaimSetFull` | The registered domain's claim set is at `zoneClaims.maxEntries`. |
| `PendingPreviousZoneRemoval` | The zone's entry is `Active`, and the previous zone's shadow for the name is still being removed. |
| `PendingPreviousZoneRemoval` | The zone's entry is `Active`, and an overlapping zone of another project that lost its claim still has a shadow zone. |
| `PendingDomainVerification` | The gate is on and no covering `Domain` is `Verified`. |

## Grants
Expand Down Expand Up @@ -399,7 +422,7 @@ With `zoneClaims.enabled` off, the replicator admits zones by exact name:
name in the accounting namespace, with `owner: <cluster>/<namespace>/<zone>`.

With the setting on, the replicator builds claim sets from those ConfigMaps
lazily. When `ensureZoneClaim` finds no claim set for a registered domain, it
lazily. When `admitZoneClaim` finds no claim set for a registered domain, it
lists the accounting ConfigMaps whose names are that domain or under it and
builds the set from them:

Expand All @@ -421,7 +444,8 @@ builds the set from them:
stops the other.

While the setting is on, the replicator keeps writing the exact-name ConfigMap
for each admitted zone and deletes it with the zone. Turning the setting off
for each admitted zone, and deletes it with the zone or once the zone loses
its claim and its shadow is gone. Turning the setting off
returns to exact-name admission, with a ConfigMap for every zone admitted in the
meantime. A zone that claim sets refused because it's under or over another
project's zone is admitted by exact name again, and with the verification gate
Expand Down Expand Up @@ -460,7 +484,7 @@ setting.
|-------|---------|-------------|
| `controllers.dnsZoneReplicator.zoneClaims.enabled` | `false` | Admit zones through claim sets. Off: admit by exact name with accounting ConfigMaps. |
| `controllers.dnsZoneReplicator.zoneClaims.reservationPeriod` | `0` | How long a deleted zone's name stays reserved for its project. `0` turns reservations off. |
| `controllers.dnsZoneReplicator.zoneClaims.maxEntries` | `256` | The most entries one claim set holds. |
| `controllers.dnsZoneReplicator.zoneClaims.maxEntries` | `256` | The most entries one claim set holds, from 1 to 1024. The `ZoneClaimSet` schema holds at most 1024, and the operator refuses to start with a larger value. |
| `controllers.dnsZoneReplicator.grants.enabled` | `false` | Honor grants and handovers in `spec.grants`. |
| `controllers.dnsZoneReplicator.requireDomainVerification` | `true` | Wait for a verified `Domain` before serving an `Active` zone. The operator refuses to start with `false` while `zoneClaims.enabled` is `false`. |

Expand Down
36 changes: 32 additions & 4 deletions internal/agent/catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,15 @@ var catalog = []ReasonInfo{
Skill: SkillRecordNotProgrammed,
ExpectedDuration: windowBackendProgramming,
},
{
Reason: sharedutil.ReasonPendingPreviousZoneRemoval,
ConditionTypes: []string{sharedutil.CondAccepted, sharedutil.CondProgrammed},
Actionability: ActionabilityTransient,
Explanation: "This zone now holds its domain, and is waiting for another project's zone that " +
"overlaps it to stop serving. It starts serving on its own within a few minutes.",
Remediation: remediationWait,
ExpectedDuration: windowBackendProgramming,
},
{
Reason: sharedutil.ReasonPendingDomainVerification,
ConditionTypes: []string{sharedutil.CondAccepted, sharedutil.CondProgrammed},
Expand Down Expand Up @@ -185,6 +194,18 @@ var catalog = []ReasonInfo{
"delete or rename the loser.",
Skill: SkillRecordNotOwner,
},
{
Reason: sharedutil.ReasonDNSZoneInUse,
ConditionTypes: []string{sharedutil.CondAccepted, sharedutil.CondProgrammed},
Actionability: ActionabilityUser,
Explanation: "Another zone already holds this domain, so this one is not served. When zone " +
"claims are on, the message says whether the other zone holds the same name, a parent, " +
"or a child, and this zone is retried every minute and starts serving once that zone is " +
"deleted. When zone claims are off, it is not retried.",
Remediation: "If the zone holding the domain is yours, delete it or use a different domain. " +
"Otherwise, with zone claims on, this zone serves once the other zone is deleted; with " +
"them off, delete and recreate this zone after that.",
},

// ------------------------------------------------------------- conflict
// Actionability here is the default only. classifyConflict in diagnose.go
Expand Down Expand Up @@ -217,13 +238,20 @@ var catalog = []ReasonInfo{

// --------------------------------------------------------------- platform
{
Reason: sharedutil.ReasonDNSZoneInUse,
ConditionTypes: []string{sharedutil.CondAccepted},
Reason: sharedutil.ReasonClaimSetFull,
ConditionTypes: []string{sharedutil.CondAccepted, sharedutil.CondProgrammed},
Actionability: ActionabilityPlatform,
Explanation: "Another zone already owns this domain in Datum's records, so this one cannot be " +
"provisioned. This is not something a customer can see or cause from their own project.",
Explanation: "The registered domain this zone belongs to already holds the most zones Datum " +
"records for one domain, so this zone cannot be admitted. It is retried every minute.",
Remediation: remediationEscalate,
},
{
Reason: sharedutil.ReasonInvalidDomain,
ConditionTypes: []string{sharedutil.CondAccepted, sharedutil.CondProgrammed},
Actionability: ActionabilityUser,
Explanation: "The zone's name is a public suffix, such as co.uk, which no single zone can claim.",
Remediation: "Create the zone for a domain registered under the suffix instead, such as example.co.uk.",
},
}

// byReason indexes the catalog, rendering each entry's window in the same
Expand Down
16 changes: 16 additions & 0 deletions internal/agent/catalog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ func TestCatalogCoversEveryKnownReason(t *testing.T) {
sharedutil.ReasonPDNSError,
sharedutil.ReasonConflict,
sharedutil.ReasonPendingDomainVerification,
sharedutil.ReasonInvalidDomain,
sharedutil.ReasonClaimSetFull,
sharedutil.ReasonPendingPreviousZoneRemoval,
}
for _, reason := range want {
if _, ok := ExplainReason(reason); !ok {
Expand All @@ -32,6 +35,19 @@ func TestCatalogCoversEveryKnownReason(t *testing.T) {
}
}

func TestDNSZoneInUseIsTheCustomersToActOn(t *testing.T) {
info, ok := ExplainReason(sharedutil.ReasonDNSZoneInUse)
if !ok {
t.Fatal("catalog has no entry for DNSZoneInUse")
}
if info.Actionability != ActionabilityUser {
t.Errorf("actionability = %s, want %s", info.Actionability, ActionabilityUser)
}
if info.Remediation == remediationEscalate {
t.Error("remediation tells the customer to escalate, but a refused zone serves once the other zone is deleted")
}
}

// TestTransientReasonsThatSayWaitDeclareAWindow pins that "wait" is always a
// falsifiable claim: any entry telling the customer this clears on its own
// declares how long that should take, so ActionabilityAt has something to
Expand Down
2 changes: 1 addition & 1 deletion internal/agent/copy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ func diagnosisFixtures() map[string]Diagnosis {
condAt(sharedutil.CondProgrammed, "False", sharedutil.ReasonPending, "waiting", stale)))

out["zone-platform"] = DiagnoseZoneAt(stagingNow, zone("example.com",
cond(sharedutil.CondAccepted, "False", sharedutil.ReasonDNSZoneInUse, "already claimed")))
cond(sharedutil.CondAccepted, "False", sharedutil.ReasonClaimSetFull, "claim set full")))

notOwner := recordSet("www", []dnsv1alpha1.RecordEntry{{Name: "www"}},
ownerStatus("www.example.com.", cond(sharedutil.CondProgrammed, "False", sharedutil.ReasonNotOwner, "taken")))
Expand Down
4 changes: 2 additions & 2 deletions internal/agent/diagnose_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ func TestDiagnoseZone(t *testing.T) {
},
"platform fault": {
zone: zone("example.com",
cond(sharedutil.CondAccepted, "False", sharedutil.ReasonDNSZoneInUse, "already claimed")),
cond(sharedutil.CondAccepted, "False", sharedutil.ReasonClaimSetFull, "claim set full")),
wantHealthy: false,
wantReason: sharedutil.ReasonDNSZoneInUse,
wantReason: sharedutil.ReasonClaimSetFull,
wantActionability: ActionabilityPlatform,
},
}
Expand Down
21 changes: 11 additions & 10 deletions internal/cmd/dns/util/shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,17 @@ const (
CondProgrammed = sharedutil.CondProgrammed
CondDiscovered = sharedutil.CondDiscovered

ReasonAccepted = sharedutil.ReasonAccepted
ReasonPending = sharedutil.ReasonPending
ReasonInvalidDNSRecordSet = sharedutil.ReasonInvalidDNSRecordSet
ReasonProgrammed = sharedutil.ReasonProgrammed
ReasonDiscovered = sharedutil.ReasonDiscovered
ReasonDNSZoneInUse = sharedutil.ReasonDNSZoneInUse
ReasonNotOwner = sharedutil.ReasonNotOwner
ReasonPDNSError = sharedutil.ReasonPDNSError
ReasonConflict = sharedutil.ReasonConflict
ReasonPendingDomainVerification = sharedutil.ReasonPendingDomainVerification
ReasonAccepted = sharedutil.ReasonAccepted
ReasonPending = sharedutil.ReasonPending
ReasonInvalidDNSRecordSet = sharedutil.ReasonInvalidDNSRecordSet
ReasonProgrammed = sharedutil.ReasonProgrammed
ReasonDiscovered = sharedutil.ReasonDiscovered
ReasonDNSZoneInUse = sharedutil.ReasonDNSZoneInUse
ReasonNotOwner = sharedutil.ReasonNotOwner
ReasonPDNSError = sharedutil.ReasonPDNSError
ReasonConflict = sharedutil.ReasonConflict
ReasonPendingDomainVerification = sharedutil.ReasonPendingDomainVerification
ReasonPendingPreviousZoneRemoval = sharedutil.ReasonPendingPreviousZoneRemoval

StatusOK = sharedutil.StatusOK
StatusPending = sharedutil.StatusPending
Expand Down
Loading
Loading