mirror of
https://github.com/siderolabs/talos.git
synced 2025-09-16 19:31:13 +02:00
Fixes #4693 Machine configuration change plus very simple controllers which transform config into the module spec and finally load modules. There's no support for advanced features like module params and aliases, but we can add it later. Signed-off-by: Andrey Smirnov <andrey.smirnov@talos-systems.com>
103 lines
2.4 KiB
Go
103 lines
2.4 KiB
Go
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
package runtime_test
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"log"
|
|
"sync"
|
|
"time"
|
|
|
|
"github.com/cosi-project/runtime/pkg/controller/runtime"
|
|
"github.com/cosi-project/runtime/pkg/resource"
|
|
"github.com/cosi-project/runtime/pkg/state"
|
|
"github.com/cosi-project/runtime/pkg/state/impl/inmem"
|
|
"github.com/cosi-project/runtime/pkg/state/impl/namespaced"
|
|
"github.com/stretchr/testify/suite"
|
|
"github.com/talos-systems/go-retry/retry"
|
|
|
|
"github.com/talos-systems/talos/pkg/logging"
|
|
"github.com/talos-systems/talos/pkg/machinery/config/types/v1alpha1"
|
|
"github.com/talos-systems/talos/pkg/machinery/resources/config"
|
|
)
|
|
|
|
const (
|
|
fsFileMax = "fs.file-max"
|
|
)
|
|
|
|
type RuntimeSuite struct {
|
|
suite.Suite
|
|
|
|
state state.State
|
|
|
|
runtime *runtime.Runtime
|
|
wg sync.WaitGroup
|
|
|
|
ctx context.Context
|
|
ctxCancel context.CancelFunc
|
|
}
|
|
|
|
func (suite *RuntimeSuite) SetupTest() {
|
|
suite.ctx, suite.ctxCancel = context.WithTimeout(context.Background(), 3*time.Minute)
|
|
|
|
suite.state = state.WrapCore(namespaced.NewState(inmem.Build))
|
|
|
|
var err error
|
|
|
|
logger := logging.Wrap(log.Writer())
|
|
|
|
suite.runtime, err = runtime.NewRuntime(suite.state, logger)
|
|
suite.Require().NoError(err)
|
|
}
|
|
|
|
func (suite *RuntimeSuite) startRuntime() {
|
|
suite.wg.Add(1)
|
|
|
|
go func() {
|
|
defer suite.wg.Done()
|
|
|
|
suite.Assert().NoError(suite.runtime.Run(suite.ctx))
|
|
}()
|
|
}
|
|
|
|
func (suite *RuntimeSuite) assertResource(md resource.Metadata, compare func(res resource.Resource) bool) func() error {
|
|
return func() error {
|
|
r, err := suite.state.Get(suite.ctx, md)
|
|
if err != nil {
|
|
if state.IsNotFoundError(err) {
|
|
return retry.ExpectedError(err)
|
|
}
|
|
|
|
return err
|
|
}
|
|
|
|
if !compare(r) {
|
|
return fmt.Errorf("resource is not equal to the expected one")
|
|
}
|
|
|
|
return nil
|
|
}
|
|
}
|
|
|
|
func (suite *RuntimeSuite) TearDownTest() {
|
|
suite.T().Log("tear down")
|
|
|
|
suite.ctxCancel()
|
|
|
|
suite.wg.Wait()
|
|
|
|
// trigger updates in resources to stop watch loops
|
|
err := suite.state.Create(context.Background(), config.NewMachineConfig(&v1alpha1.Config{
|
|
ConfigVersion: "v1alpha1",
|
|
MachineConfig: &v1alpha1.MachineConfig{},
|
|
}))
|
|
if state.IsConflictError(err) {
|
|
err = suite.state.Destroy(context.Background(), config.NewMachineConfig(nil).Metadata())
|
|
}
|
|
|
|
suite.Assert().NoError(err)
|
|
}
|