Skip to content

Commit

Permalink
fix: do not preserve extensions on Talos agent mode
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
utkuozdemir committed Dec 20, 2024
1 parent 1f81400 commit 1d8c754
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
})
})
Expand Down

0 comments on commit 1d8c754

Please sign in to comment.