Skip to content

Commit

Permalink
refactor: track infra machine install status via a counter
Browse files Browse the repository at this point in the history
With this change, we change the way we track whether Talos is installed on the disk or not in the bare-metal infra provider.

Previously, it worked like the following:
- Omni, when observing some specific type of events on SideroLink, set the `installed` flag on the dedicated `MachineState` resource to true.
- The provider, after wiping disks of a machine, set that flag to false.

This method went against the "single owner per resource" principle and was not leveraging COSI runtime and controller-based logic. Furthermore, it made the contract between Omni and the provider more complex since it was yet another resource.

Instead, now, we do the following:
- Every time we observe those specific types of events on SideroLink, we increment a counter field on the `infra.Machine` resource.
- When the provider wipes a machine, it persists this counter value at the time of wipe internally.
- To detect whether Talos is installed or not, the provider compares the internally stored counter value vs the value on the `infra.Machine`. It is "installed" only if the counter value on the `infra.Machine` is bigger than the internally stored one (it means we observed an installation after the last wipe).

Signed-off-by: Utku Ozdemir <[email protected]>
  • Loading branch information
utkuozdemir committed Jan 27, 2025
1 parent c6b7dd3 commit fd888ab
Show file tree
Hide file tree
Showing 28 changed files with 510 additions and 391 deletions.
132 changes: 80 additions & 52 deletions client/api/omni/specs/infra.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions client/api/omni/specs/infra.proto
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ message InfraMachineSpec {
string extra_kernel_args = 6;
string requested_reboot_id = 7;
bool cordoned = 8;

// InstallEventId is a counter, incremented each time Omni receives an event over SideroLink that indicates there is Talos installation on the disk.
//
// This value is then used by the infra provider to make the decision whether Talos is installed or not.
// It is able to track the installation state by:
// - Storing a copy of the value of this counter internally after wiping a machine.
// - Comparing the value of this counter with the stored value to determine if Talos is installed:
// It is installed if the value of the counter is greater than the stored value.
uint64 install_event_id = 9;
}

message InfraMachineStateSpec {
Expand All @@ -68,6 +77,7 @@ message InfraMachineStatusSpec {
bool ready_to_use = 2;
string last_reboot_id = 3;
google.protobuf.Timestamp last_reboot_timestamp = 4;
bool installed = 5;
}

message InfraProviderStatusSpec {
Expand Down
68 changes: 68 additions & 0 deletions client/api/omni/specs/infra_vtproto.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion client/pkg/omni/resources/infra/infra.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import "github.com/siderolabs/omni/client/pkg/omni/resources/registry"
func init() {
registry.MustRegisterResource(MachineRequestType, &MachineRequest{})
registry.MustRegisterResource(MachineRequestStatusType, &MachineRequestStatus{})
registry.MustRegisterResource(InfraMachineStateType, &MachineState{})
registry.MustRegisterResource(InfraMachineType, &Machine{})
registry.MustRegisterResource(InfraMachineStatusType, &MachineStatus{})
registry.MustRegisterResource(InfraProviderStatusType, &ProviderStatus{})
Expand Down
4 changes: 4 additions & 0 deletions client/pkg/omni/resources/infra/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ func (MachineExtension) ResourceDefinition() meta.ResourceDefinitionSpec {
Name: "Cordoned",
JSONPath: "{.cordoned}",
},
{
Name: "Install Event ID",
JSONPath: "{.installeventid}",
},
},
}
}
Loading

0 comments on commit fd888ab

Please sign in to comment.