Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: do not preserve extensions on Talos agent mode #799

Merged
merged 1 commit into from
Dec 20, 2024
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
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{
frezbo marked this conversation as resolved.
Show resolved Hide resolved
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))

Comment on lines +434 to +443
Copy link
Member Author

Choose a reason for hiding this comment

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

Moved this here to create a different machine ID each time - otherwise MachineStatus preserves the initial schematic, and my new test was giving different results when it was run in isolation vs when it was run together with other tests.

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