Skip to content

[reconfigurator] Consider Internal DNS generation in planner - #8683

Merged
smklein merged 1 commit into
mainfrom
planner-use-dns
Jul 31, 2025
Merged

smklein merged 1 commit into
mainfrom
planner-use-dns

Conversation

@smklein

@smklein smklein commented Jul 24, 2025 •

Copy link
Copy Markdown
Collaborator

Refuse to tear down an Internal DNS zone unless we're at sufficient redundancy, with an expected generation number for "last deployed data".

Also:

  • Fixes a blippy bug that was overly conservative for expunged datasets, when finding duplicate dataset kinds
  • Adds internal DNS generation statuses when converting a system description to an inventory collection

Fixes #8545

Base automatically changed from inventory-collect-dns to main July 24, 2025 18:27
@smklein
smklein force-pushed the planner-use-dns branch 2 times, most recently from 19a0eb0 to 5fa52dc Compare July 24, 2025 18:44
@smklein
smklein marked this pull request as ready for review July 24, 2025 18:47
@smklein
smklein requested a review from jgallagher July 24, 2025 18:49
@smklein smklein assigned davepacheco and unassigned davepacheco Jul 24, 2025
@smklein
smklein requested a review from davepacheco July 24, 2025 18:50
debug!(self.log, "Found internal dns zone in inventory"; "id" => ?status.zone_id);
if internal_dns_zones.contains(&status.zone_id)
&& status.generation
== self.input.internal_dns_version()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've forgotten what this is in the planning input. Is it the latest known internal DNS version?

status.generation < input.internal_dns_version would mean the server is out of date. What would status.generation > input.internal_dns_version mean? Presumably that our planning input is out of date; what does that mean for planning upgrades? I'm wondering if the planner should do something here if it finds this condition (maybe report that no internal DNS zones can be upgraded? maybe bail out of planning entirely with an error?).

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe it's the following:

  • PlanningInput is constructed by PlanningInputFromDb
  • This reads the internal_dns_version from the datastore with datastore.dns_group_latest_version(opctx, DnsGroup::Internal)
  • This happens within the blueprint planner background task (or I guess via the CLI, if requested explicitly)

So:

  • status.generation < input.internal_dns_version means the server is out-of-date (slow propagation, the normal case).
  • status.generation > input.internal_dns_version could mean "someone concurrently increased the internal DNS version and propagated through the inventory system after we read the internal_dns_version value from the DB during PlanningInput collection". I do think this is possible, because we call PlanningInputFromDb::assemble before we call datastore.inventory_get_latest_collection.

I think the "good news" is that in this latter case (Collection is ahead of our PlanningInput), we already wouldn't be able to set the target (regardless of how we interpret this data here) because blueprint_target_set_current would see: "hey, our parent blueprint changed (by someone else, presumably, who updated the Internal DNS generation"). I am kinda making the assumption that "increasing internal DNS generations requires a new blueprint" but I think that's true?

... anyway, the current behavior is: can_zone_be_shut_down_safely will return false in this case. Basically: "don't mess with this zone". But this probably won't matter, because regardless of what we return, the blueprint-under-construction is already out-of-date, and can't be used as the target.

I'm down to do one of the following:

  1. Leave things as-is, for the reasons mentioned, we won't be able to set the target blueprint anyway, so we already sorta handle this case.
  2. Add a new Error to nexus/reconfigurator/planning/src/blueprint_builder/builder.rs's Error, identifying PlanningInputOutOfDate. This seems possible if the inventory sees data that looks inconsistent with other data we read from the database. This seems fine to me - basically, a rip the cord, get out, stop planning more stuff, because we know we're out-of-date. On the other hand, it feels a little quirky, because we could have validated this before we started planning, so we could...
  3. Try to prevent blueprint planning when "PlanningInput" (read from the DB) disagrees with the inventory Collection. This wouldn't be too different from option (2), just attempting to do it before we start planning in earnest. Basically: "try to notice if a concurrent blueprint was set and we have inconsistent state". However, identifying "are these things consistent" might be complicated, and it might be a pain to have validation be far away from "where the collection/input values are used together".

My two cents: I think I'm down to do either option (1) or option (2)? I think (1) works fine because of our existing guards. I think (2) would also be fine, as long as the error isn't noisy - I think this is a "normal condition" and not an error worth notifying anyone about.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tl;dr: I think this behavior is fine, but I think we should better document why. I don't know that it's safe to assume that the internal DNS version in the planning input is up-to-date but I don't think that matters. I would add a comment along these lines:

The purpose of this check is to ensure that at all times, we have enough working internal DNS servers that are up to date enough that if the system powers off and cold starts, and even if there's a subsequent failure that prevents one of them from coming up, there remains at least one that can be used to get the control plane back up and running. So let's count how many up-to-date internal DNS servers we have and make sure that it matches the number we expect under normal operation. We'll only consider those that are at least as up-to-date as internal DNS was when we started planning this blueprint.

We could add:

(It's possible that internal DNS has changed again by a concurrent blueprint execution, but not by more than one version. (Each change to internal DNS requires a new target blueprint. We can see one change behind our backs if the current target -- the parent of the blueprint we're generating -- hadn't been executed when we started planning this one. But more than one change would require a new target blueprint, and that would mean this blueprint could never be made the target.) And one version cannot be so different that it would not work for cold start.)

but I don't think I'd bother -- it seems like too many hypotheticals on hypotheticals to be useful.


(I think all of this can be ignored; it's a long explanation of why I don't think it's true that if DNS changes after the planning input is created, then this blueprint will necessarily never be the target. But I don't think any of this matters because I don't think we need that assumption.)

First, I don't know if it's true that an internal DNS change would require a new blueprint. Even if it is, I don't love relying on that fact here because it's kind of an implicit assumption that relies on several unrelated behaviors. The logic would be something like:

  1. the contents of internal DNS are basically a pure function of the blueprint
  2. => changing internal DNS requires changing the current target blueprint
  3. changing the current target blueprint invalidates any blueprints created from any previous target
  4. => a change to internal DNS since we created this PlanningInput means that the current target blueprint has changed
  5. => a change to internal DNS since we created this PlanningInput means that the blueprint we're currently planning can never be the target

But there are some wrinkles here:

(1) is not quite true. There are at least two cases where internal DNS is not a pure function of the blueprint (see blueprint_internal_dns_config()):

  • If an upgrade happens, execution of the same blueprint might change the contents of internal DNS (that happens every time a new release adds DNS records for new or existing services, which has happened several times). This case probably doesn't matter though because we can't have such an upgrade during a planning run.
  • Records for scrimlet-specific services depend on what sleds are labeled scrimlet in the sled table. If sleds get physically moved, executing the same blueprint could change the addresses for some switch zone services. How could this happen during a planning run though? That leads to the next problem with this logic, which is that (2) is not true either.

(2) is not true because the contents of DNS changes not when the blueprint is created or made the target, but rather when it's executed. And if (2) is not true, neither are (4) or (5). I think you could have this sequence:

  1. The system is at DNS version 10 and all internal DNS servers are up to date.
  2. Blueprint 1 is created with an internal DNS change in it (e.g., deployed a new Nexus zone).
  3. Blueprint 1 is made the target.
  4. We start planning blueprint 2 based on blueprint 1 as its parent. First, we assemble a PlanningInput with the current DNS version from the database. It's version 10.
  5. Meanwhile, blueprint 1 is finally executed for the first time, causing the DNS configuration to change to version 11. All DNS servers are updated to version 11. An inventory collection is created that reflects that.
  6. Back in the planner background task, we see the latest inventory and find the current internal DNS version for each server is version 11. We've hit the case we're discussing here. [Note this assumes we grab the latest inventory collection after the latest internal DNS version. We could prevent this by always doing it in the other order, but then we have yet another implicit assumption involved.]
  7. We finish planning blueprint 2 and make it the target. This works fine because the target blueprint hasn't changed. Nonetheless, we did hit this case.

But I don't think any of this matters. The egregious situation we're trying to avoid is something like:

  • we start with all internal DNS servers at the current version
  • we rapidly expunge and re-add them all (imagine all in the same blueprint, or three sequential blueprints)
  • the rack loses power
  • on startup, all internal DNS servers have no idea what the contents of internal DNS should be and the control plane can't come up

This isn't a case of internal DNS being a little behind, but rather being completely empty. We don't need the servers to have the very latest contents of internal DNS. Strictly speaking, I think all we need is for it to contain correct addresses for enough CockroachDB zones for CockroachDB to form a quorum and for Nexus to find it.

We could fairly ask "how far behind can they be and it's still okay?" I'm not sure what the exact answer to that is, but I don't think we need to solve that problem today. That's imagining a much less likely case, something like:

  • we start with all internal DNS servers at the current version
  • we start planning this blueprint
  • we plan and execute a sequence of blueprints that changes a majority of the CockroachDB node IP addresses
  • we finish planning this blueprint and still make it the target (seems impossible because here we really have changed the target blueprint, not just DNS)
  • then we expunge this internal DNS zone
  • but the other two internal DNS zones never got the updates about the CockroachDB cluster changing
  • then the rack loses power

I admit this isn't a proof but there's enough that should be either impossible or highly unlikely here that I'm not worried about this for the foreseeable future.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack, thanks for the detailed response here.

I'll update the comment in this section.

@davepacheco davepacheco left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is good but I did have a few questions.

slot B details UNAVAILABLE: constructed via debug_assume_success()
last reconciled config: matches ledgered config
no information from NTP for this sled
Internal DNS generation: 1

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this issue is not new in this PR, but it seems wrong that this appears under the ledgered sled agent config. As I understand it, the inventory collector finds internal DNS zones from sled agent's config, but it queries those zones directly, not via sled agent. I wouldn't expect sled agent to need to know anything about internal DNS generations (aside from RSS). Shouldn't this information to be decoupled from the sled agent itself?

Also, looking at the code in display_internal_dns_status(), it looks like it will only report one internal DNS zone's generation, even if there are multiple on the same sled.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that it's a little weird to put this under the ledgered sled config, but doesn't it make sense to organize it "by sled"? This is from inventory - I think it makes sense to show "this is where this data is coming from", e.g., "the zone on this sled reports _____ generation from _____ zone".

I'm going to make this change in a separate PR, if that's okay: #8724

) {
if zone.zone_type.kind() == ZoneKind::InternalDns {
internal_dns_zones.insert(zone.id);
debug!(self.log, "Found internal dns zone in blueprint"; "id" => ?zone.id);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: there are a bunch of log lines here over 80 columns

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ugh, why is rustfmt not helping me...

Updated.

Comment on lines +1690 to +1725
info!(
self.log,
"Internal DNS zone shutdown check";
"total_internal_dns_zones" => internal_dns_zones.len(),
"synchronized_count" => synchronized_internal_dns_count,
"can_shutdown" => can_shutdown
);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My gut is to make this a warning if !can_shutdown but I don't feel strongly. I assume the real answer is to record this with the upcoming planner reports.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bias - I'd rather not have it be a warning, because IMO this is a "very normal operating condition", where e.g. we just happened to start planning while DNS is propagating during execution. I otherwise want to keep the spew of warning/error messages really low.

debug!(self.log, "Found internal dns zone in inventory"; "id" => ?status.zone_id);
if internal_dns_zones.contains(&status.zone_id)
&& status.generation
== self.input.internal_dns_version()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tl;dr: I think this behavior is fine, but I think we should better document why. I don't know that it's safe to assume that the internal DNS version in the planning input is up-to-date but I don't think that matters. I would add a comment along these lines:

The purpose of this check is to ensure that at all times, we have enough working internal DNS servers that are up to date enough that if the system powers off and cold starts, and even if there's a subsequent failure that prevents one of them from coming up, there remains at least one that can be used to get the control plane back up and running. So let's count how many up-to-date internal DNS servers we have and make sure that it matches the number we expect under normal operation. We'll only consider those that are at least as up-to-date as internal DNS was when we started planning this blueprint.

We could add:

(It's possible that internal DNS has changed again by a concurrent blueprint execution, but not by more than one version. (Each change to internal DNS requires a new target blueprint. We can see one change behind our backs if the current target -- the parent of the blueprint we're generating -- hadn't been executed when we started planning this one. But more than one change would require a new target blueprint, and that would mean this blueprint could never be made the target.) And one version cannot be so different that it would not work for cold start.)

but I don't think I'd bother -- it seems like too many hypotheticals on hypotheticals to be useful.


(I think all of this can be ignored; it's a long explanation of why I don't think it's true that if DNS changes after the planning input is created, then this blueprint will necessarily never be the target. But I don't think any of this matters because I don't think we need that assumption.)

First, I don't know if it's true that an internal DNS change would require a new blueprint. Even if it is, I don't love relying on that fact here because it's kind of an implicit assumption that relies on several unrelated behaviors. The logic would be something like:

  1. the contents of internal DNS are basically a pure function of the blueprint
  2. => changing internal DNS requires changing the current target blueprint
  3. changing the current target blueprint invalidates any blueprints created from any previous target
  4. => a change to internal DNS since we created this PlanningInput means that the current target blueprint has changed
  5. => a change to internal DNS since we created this PlanningInput means that the blueprint we're currently planning can never be the target

But there are some wrinkles here:

(1) is not quite true. There are at least two cases where internal DNS is not a pure function of the blueprint (see blueprint_internal_dns_config()):

  • If an upgrade happens, execution of the same blueprint might change the contents of internal DNS (that happens every time a new release adds DNS records for new or existing services, which has happened several times). This case probably doesn't matter though because we can't have such an upgrade during a planning run.
  • Records for scrimlet-specific services depend on what sleds are labeled scrimlet in the sled table. If sleds get physically moved, executing the same blueprint could change the addresses for some switch zone services. How could this happen during a planning run though? That leads to the next problem with this logic, which is that (2) is not true either.

(2) is not true because the contents of DNS changes not when the blueprint is created or made the target, but rather when it's executed. And if (2) is not true, neither are (4) or (5). I think you could have this sequence:

  1. The system is at DNS version 10 and all internal DNS servers are up to date.
  2. Blueprint 1 is created with an internal DNS change in it (e.g., deployed a new Nexus zone).
  3. Blueprint 1 is made the target.
  4. We start planning blueprint 2 based on blueprint 1 as its parent. First, we assemble a PlanningInput with the current DNS version from the database. It's version 10.
  5. Meanwhile, blueprint 1 is finally executed for the first time, causing the DNS configuration to change to version 11. All DNS servers are updated to version 11. An inventory collection is created that reflects that.
  6. Back in the planner background task, we see the latest inventory and find the current internal DNS version for each server is version 11. We've hit the case we're discussing here. [Note this assumes we grab the latest inventory collection after the latest internal DNS version. We could prevent this by always doing it in the other order, but then we have yet another implicit assumption involved.]
  7. We finish planning blueprint 2 and make it the target. This works fine because the target blueprint hasn't changed. Nonetheless, we did hit this case.

But I don't think any of this matters. The egregious situation we're trying to avoid is something like:

  • we start with all internal DNS servers at the current version
  • we rapidly expunge and re-add them all (imagine all in the same blueprint, or three sequential blueprints)
  • the rack loses power
  • on startup, all internal DNS servers have no idea what the contents of internal DNS should be and the control plane can't come up

This isn't a case of internal DNS being a little behind, but rather being completely empty. We don't need the servers to have the very latest contents of internal DNS. Strictly speaking, I think all we need is for it to contain correct addresses for enough CockroachDB zones for CockroachDB to form a quorum and for Nexus to find it.

We could fairly ask "how far behind can they be and it's still okay?" I'm not sure what the exact answer to that is, but I don't think we need to solve that problem today. That's imagining a much less likely case, something like:

  • we start with all internal DNS servers at the current version
  • we start planning this blueprint
  • we plan and execute a sequence of blueprints that changes a majority of the CockroachDB node IP addresses
  • we finish planning this blueprint and still make it the target (seems impossible because here we really have changed the target blueprint, not just DNS)
  • then we expunge this internal DNS zone
  • but the other two internal DNS zones never got the updates about the CockroachDB cluster changing
  • then the rack loses power

I admit this isn't a proof but there's enough that should be either impossible or highly unlikely here that I'm not worried about this for the foreseeable future.

Comment on lines +6514 to +6544
// If we're missing info from even a single zone, we
// will still refuse to update.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not because of the presence of a zone with no info, but rather because that means there aren't enough zones with info, right?

That is, if we deployed 5 Internal DNS zones and only required 3, this wouldn't be true. It's just that today we deploy the same number as are required, so one being absent means there aren't enough. Right?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's right. I'll re-word this.

// Manually update all zones except Internal DNS
//
// We just specified a new TUF repo, everything is going to shift from
// the install dataset to this new repo.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this reflect having updated all the zones, or is this the case where the TUF repo matches what's in the install dataset and the planner is just changing the config in a way that doesn't change the software that's running?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it's "just changing the config", but it's a little test-specific, because what we're doing here is:

  1. Updating the blueprint
  2. Calling update_collection_from_blueprint with that new blueprint

So we're forcing inventory to reflect what we're asking for in the blueprint.

@smklein
smklein merged commit cb110e2 into main Jul 31, 2025
@smklein
smklein deleted the planner-use-dns branch July 31, 2025 16:17
smklein added a commit that referenced this pull request Jul 31, 2025
Response to
#8683 (comment)

- Move this display outside "sled ledger", but keep co-located with sled
- Display results for all zones present, not just first zone present
- Identify zone UUID
@plotnick plotnick mentioned this pull request Aug 8, 2025
1 of 4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

check internal DNS status in planner before upgrading it

3 participants