talos/pkg/resources/runtime/kernel_params_status.go
Artem Chernyshev e08b4f8f9e feat: implement sysctl controllers
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>
2021-08-10 13:21:49 -07:00

91 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
import (
"fmt"
"github.com/cosi-project/runtime/pkg/resource"
"github.com/cosi-project/runtime/pkg/resource/meta"
)
// KernelParamStatusType is type of KernelParam resource.
const KernelParamStatusType = resource.Type("KernelParamStatuses.runtime.talos.dev")
// KernelParamStatus resource holds defined sysctl flags status.
type KernelParamStatus struct {
md resource.Metadata
spec KernelParamStatusSpec
}
// KernelParamStatusSpec describes status of the defined sysctls.
type KernelParamStatusSpec struct {
Current string `yaml:"current"`
Default string `yaml:"default"`
Unsupported bool `yaml:"unsupported"`
}
// NewKernelParamStatus initializes a KernelParamStatus resource.
func NewKernelParamStatus(namespace resource.Namespace, id resource.ID) *KernelParamStatus {
r := &KernelParamStatus{
md: resource.NewMetadata(namespace, KernelParamStatusType, id, resource.VersionUndefined),
spec: KernelParamStatusSpec{},
}
r.md.BumpVersion()
return r
}
// Metadata implements resource.Resource.
func (r *KernelParamStatus) Metadata() *resource.Metadata {
return &r.md
}
// Spec implements resource.Resource.
func (r *KernelParamStatus) Spec() interface{} {
return r.spec
}
func (r *KernelParamStatus) String() string {
return fmt.Sprintf("runtime.KernelParamStatus.(%q)", r.md.ID())
}
// DeepCopy implements resource.Resource.
func (r *KernelParamStatus) DeepCopy() resource.Resource {
return &KernelParamStatus{
md: r.md,
spec: r.spec,
}
}
// ResourceDefinition implements meta.ResourceDefinitionProvider interface.
func (r *KernelParamStatus) ResourceDefinition() meta.ResourceDefinitionSpec {
return meta.ResourceDefinitionSpec{
Type: KernelParamStatusType,
Aliases: []resource.Type{"Sysctls", "KernelParameters", "KernelParams"},
DefaultNamespace: NamespaceName,
PrintColumns: []meta.PrintColumn{
{
Name: "Current",
JSONPath: `{.current}`,
},
{
Name: "Default",
JSONPath: `{.default}`,
},
{
Name: "Unsupported",
JSONPath: `{.unsupported}`,
},
},
}
}
// TypedSpec allows to access the KernelParamStatusSpec with the proper type.
func (r *KernelParamStatus) TypedSpec() *KernelParamStatusSpec {
return &r.spec
}