mirror of
https://github.com/siderolabs/talos.git
synced 2025-10-30 16:01:12 +01:00
Fixed: https://github.com/talos-systems/talos/issues/3686 Replaced sequencer tasks for KSPP and Kubernetes required sysctl props by the ones set by controllers. KernelParam flow includes of 3 controllers and 2 resources: - `KernelParamConfigController` - handles user sysctls coming from v1alpha1 config. - `KernelParamDefaultsController` - handles our built-in KSPP and K8s required sysctls. - `KernelParamSpecController` - consumes `KernelParamSpec`s created by the previous two controllers, applies them and updates the corresponding `KernelParamStatus`. Signed-off-by: Artem Chernyshev <artem.0xD2@gmail.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/resources/config"
|
|
)
|
|
|
|
const (
|
|
fsFileMax = "fs.file-max"
|
|
)
|
|
|
|
type KernelParamSuite struct {
|
|
suite.Suite
|
|
|
|
state state.State
|
|
|
|
runtime *runtime.Runtime
|
|
wg sync.WaitGroup
|
|
|
|
ctx context.Context
|
|
ctxCancel context.CancelFunc
|
|
}
|
|
|
|
func (suite *KernelParamSuite) 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 *KernelParamSuite) startRuntime() {
|
|
suite.wg.Add(1)
|
|
|
|
go func() {
|
|
defer suite.wg.Done()
|
|
|
|
suite.Assert().NoError(suite.runtime.Run(suite.ctx))
|
|
}()
|
|
}
|
|
|
|
func (suite *KernelParamSuite) 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 *KernelParamSuite) 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)
|
|
}
|