Skip to content

Commit

Permalink
fix: do not use created time of the ClusterMachineTalosVersion in sort
Browse files Browse the repository at this point in the history
Sort by the creation time of the `MachineSetNode` instead.
As the creation time of the `ClusterMachineTalosVersion` doesn't
replicate the creation time of the `MachineSetNode` anymore.

Signed-off-by: Artem Chernyshev <artem.chernyshev@talos-systems.com>
  • Loading branch information
Unix4ever committed Jun 20, 2024
1 parent 61b0e4c commit 11f7edb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"errors"
"fmt"
"slices"
"time"

"github.com/cosi-project/runtime/pkg/controller"
"github.com/cosi-project/runtime/pkg/controller/generic/qtransform"
Expand Down Expand Up @@ -167,16 +168,22 @@ func updateMachines(
) (string, error) {
var machineToUpdate *omni.ClusterMachineTalosVersion

slices.SortStableFunc(machinesToUpdate, func(a, b *omni.ClusterMachineTalosVersion) int {
return a.Metadata().Created().Compare(b.Metadata().Created())
})

lockedMachines := map[resource.ID]struct{}{}
creationTimes := map[resource.ID]time.Time{}

machineSetNodes.ForEach(func(machine *omni.MachineSetNode) {
if _, locked := machine.Metadata().Annotations().Get(omni.MachineLocked); locked {
lockedMachines[machine.Metadata().ID()] = struct{}{}
}

creationTimes[machine.Metadata().ID()] = machine.Metadata().Created()
})

slices.SortStableFunc(machinesToUpdate, func(a, b *omni.ClusterMachineTalosVersion) int {
aCreated := creationTimes[a.Metadata().ID()]
bCreated := creationTimes[b.Metadata().ID()]

return aCreated.Compare(bCreated)
})

for _, machine := range machinesToUpdate {
Expand Down Expand Up @@ -248,6 +255,7 @@ func reconcileTalosUpdateStatus(ctx context.Context, r controller.ReaderWriter,
var (
machinesToUpdate []*omni.ClusterMachineTalosVersion
configsReady = true
schematicsReady = true
err error
)

Expand All @@ -274,6 +282,8 @@ func reconcileTalosUpdateStatus(ctx context.Context, r controller.ReaderWriter,
if xerrors.TagIs[skipMachine](err) {
logger.Warn("machine is skipped due to no schematic information", zap.Error(err), zap.String("machine", machine.Metadata().ID()))

schematicsReady = false

continue
}

Expand Down Expand Up @@ -339,6 +349,10 @@ func reconcileTalosUpdateStatus(ctx context.Context, r controller.ReaderWriter,
}
}

if !schematicsReady {
return xerrors.NewTaggedf[qtransform.SkipReconcileTag]("schematics not ready on some machines")
}

upgradeStatus.Metadata().Labels().Set(omni.LabelCluster, cluster.Metadata().ID())

if len(machinesToUpdate) == 0 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func (suite *TalosUpgradeStatusSuite) TestReconcile() {
expectedSchematic = "c6ee5f479027e5ca84e5518c3a56d62e2283b6d30a5846e6295aa7113735df40"
}

rtestutils.AssertResource[*omni.ClusterMachineTalosVersion](suite.ctx, suite.T(), suite.state, machines[i].Metadata().ID(),
rtestutils.AssertResource(suite.ctx, suite.T(), suite.state, machines[i].Metadata().ID(),
func(r *omni.ClusterMachineTalosVersion, assertion *assert.Assertions) {
assertion.Equal(expectedSchematic, r.TypedSpec().Value.SchematicId)
},
Expand Down

0 comments on commit 11f7edb

Please sign in to comment.