From 1d8c754abb98fcb5d697608c300fdc2f32a25915 Mon Sep 17 00:00:00 2001 From: Utku Ozdemir Date: Fri, 20 Dec 2024 13:05:54 +0100 Subject: [PATCH] fix: do not preserve extensions on Talos agent mode If Talos is in agent mode, we should avoid preserving the list of extensions for the actual Talos installation, as the `metal-agent` extension breaks the Talos installation. Signed-off-by: Utku Ozdemir --- .../omni/internal/talos/schematic.go | 20 +++++++ .../controllers/omni/machine_status_test.go | 52 ++++++++++++++----- 2 files changed, 60 insertions(+), 12 deletions(-) diff --git a/internal/backend/runtime/omni/controllers/omni/internal/talos/schematic.go b/internal/backend/runtime/omni/controllers/omni/internal/talos/schematic.go index b22e3ac7..55280468 100644 --- a/internal/backend/runtime/omni/controllers/omni/internal/talos/schematic.go +++ b/internal/backend/runtime/omni/controllers/omni/internal/talos/schematic.go @@ -11,6 +11,7 @@ import ( "strings" "github.com/cosi-project/runtime/pkg/safe" + "github.com/siderolabs/go-pointer" "github.com/siderolabs/image-factory/pkg/constants" "github.com/siderolabs/image-factory/pkg/schematic" "github.com/siderolabs/talos/pkg/machinery/client" @@ -51,10 +52,17 @@ func GetSchematicInfo(ctx context.Context, c *client.Client, defaultKernelArgs [ fullID string rawSchematic = &schematic.Schematic{} manifest string + inAgentMode bool ) err = items.ForEachErr(func(status *runtime.ExtensionStatus) error { name := status.TypedSpec().Metadata.Name + if name == "metal-agent" { + inAgentMode = true + + return nil + } + if name == constants.SchematicIDExtensionName { // skip the meta extension fullID = status.TypedSpec().Metadata.Version @@ -83,6 +91,18 @@ func GetSchematicInfo(ctx context.Context, c *client.Client, defaultKernelArgs [ return SchematicInfo{}, err } + if inAgentMode { + id, idErr := pointer.To(schematic.Schematic{}).ID() + if idErr != nil { + return SchematicInfo{}, fmt.Errorf("failed to calculate extensions schematic ID: %w", idErr) + } + + return SchematicInfo{ + ID: id, + FullID: id, + }, nil + } + exts = extensions.MapNames(exts) if fullID == "" && len(exts) > 0 { diff --git a/internal/backend/runtime/omni/controllers/omni/machine_status_test.go b/internal/backend/runtime/omni/controllers/omni/machine_status_test.go index fafe574d..95bca64d 100644 --- a/internal/backend/runtime/omni/controllers/omni/machine_status_test.go +++ b/internal/backend/runtime/omni/controllers/omni/machine_status_test.go @@ -328,17 +328,6 @@ func (suite *MachineStatusSuite) TestMachineSchematic() { }).ID() suite.Require().NoError(err) - machine := omni.NewMachine(resources.DefaultNamespace, testID) - spec := machine.TypedSpec().Value - - spec.Connected = true - spec.ManagementAddress = suite.socketConnectionString - - suite.Require().NoError(suite.state.Create(suite.ctx, machine)) - - defaultSchematic, err := (&schematic.Schematic{}).ID() - suite.Require().NoError(err) - for _, tt := range []struct { expected *specs.MachineStatusSpec_Schematic name string @@ -408,11 +397,50 @@ func (suite *MachineStatusSuite) TestMachineSchematic() { KernelArgs: kernelArgs, }, }, + { + name: "agent mode empty list", + extensions: []*runtime.ExtensionStatusSpec{ + { + Metadata: extensions.Metadata{ + Name: constants.SchematicIDExtensionName, + Description: "0", + Version: "full-id", + }, + }, + { + Metadata: extensions.Metadata{ + Name: "metal-agent", + Description: "1", + }, + }, + { + Metadata: extensions.Metadata{ + Name: "hello-world-service", + Description: "2", + }, + }, + }, + expected: &specs.MachineStatusSpec_Schematic{ + Id: defaultSchematic, + InitialSchematic: defaultSchematic, + FullId: defaultSchematic, + }, + }, } { suite.T().Run(tt.name, func(t *testing.T) { ctx, cancel := context.WithTimeout(suite.ctx, time.Second*5) defer cancel() + id := "test-" + tt.name + + machine := omni.NewMachine(resources.DefaultNamespace, id) + spec := machine.TypedSpec().Value + + spec.Connected = true + spec.ManagementAddress = suite.socketConnectionString + + suite.Require().NoError(suite.state.Create(suite.ctx, machine)) + rtestutils.DestroyAll[*runtime.ExtensionStatus](ctx, t, suite.machineService.state) for _, spec := range tt.extensions { @@ -424,7 +452,7 @@ func (suite *MachineStatusSuite) TestMachineSchematic() { suite.Require().NoError(suite.machineService.state.Create(ctx, res)) } - rtestutils.AssertResources(ctx, t, suite.state, []string{testID}, func(status *omni.MachineStatus, assert *assert.Assertions) { + rtestutils.AssertResources(ctx, t, suite.state, []string{id}, func(status *omni.MachineStatus, assert *assert.Assertions) { assert.EqualValues(tt.expected, status.TypedSpec().Value.Schematic) }) })