Skip to content

Commit

Permalink
chore: rewrite MachineStatus to use QController
Browse files Browse the repository at this point in the history
This rewrite should improve performance of the controller drastically.
Fixes: #281

Signed-off-by: Artem Chernyshev <artem.chernyshev@talos-systems.com>
  • Loading branch information
Unix4ever committed Jun 4, 2024
1 parent ed26122 commit 800762d
Show file tree
Hide file tree
Showing 8 changed files with 334 additions and 274 deletions.
4 changes: 4 additions & 0 deletions cmd/integration-test/pkg/tests/talos.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ func clearConnectionRefused(ctx context.Context, t *testing.T, c *talosclient.Cl
return retry.ExpectedError(err)
}

if strings.Contains(err.Error(), "connection reset by peer") {
return retry.ExpectedError(err)
}

return err
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package machine
import (
"context"
"fmt"
"time"

"github.com/cosi-project/runtime/pkg/resource"
"github.com/cosi-project/runtime/pkg/resource/meta"
Expand Down Expand Up @@ -41,6 +42,9 @@ func forEachResource[T resource.Resource](

// QueryRegisteredTypes gets all registered types from the meta namespace.
func QueryRegisteredTypes(ctx context.Context, st state.State) (map[resource.Type]struct{}, error) {
ctx, cancel := context.WithTimeout(ctx, time.Second*5)
defer cancel()

// query all resources to start watching only resources that are defined for running version of talos
resources, err := safe.StateList[*meta.ResourceDefinition](ctx, st, resource.NewMetadata(meta.NamespaceName, meta.ResourceDefinitionType, "", resource.VersionUndefined))
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,6 @@ func (spec CollectTaskSpec) RunTask(ctx context.Context, logger *zap.Logger, not

registeredTypes, err := QueryRegisteredTypes(ctx, c.COSI)
if err != nil {
// this is the first request to the Talos API
// if it fails we handle it and update the machine status with the request error
if !spec.sendInfo(ctx, Info{}, notifyCh, err) {
return nil
}

return err
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ func (task *Task[T, S]) runWithRestarts(ctx context.Context) {

// finished without an error
if err == nil {
task.logger.Info("task finished")

return
}

Expand Down
Loading

0 comments on commit 800762d

Please sign in to comment.