Utku Ozdemir 01bf663854
feat: support kernel args management in cluster templates
Implement kernel args support in cluster templates.

Managing kernel args via templates is opt-in: only and only if the `kernelArgs` YAML key is defined on a `Cluster`, `ControlPlane`, `Worker` or `Machine`, the matching `KernelArgs` resource will be created/updated.

Lower levels override higher levels (Cluster -> MachineSet -> Machine).

Unlike other cluster template managed resources, they will never be destroyed, i.e, when they are removed from a template (removed completely, as in, `kernelArgs` key doesn't exist) or when `omnictl cluster template delete` is run. They instead will get updated to have the annotation `omni.sidero.dev/managed-by-cluster-templates` removed from them.

Add the new flag `--include-kernel-args` to the `omnictl cluster template export` command to optionally include them in the exported template. Note: when this flag is set, `kernelArgs` key is always included at per-machine level, not pulled up even if they are the same for all machines in a machine set or a cluster.

Update the frontend, specifically the kernel args update screen to warn the user if kernel args for that machine is managed by templates, similar to what we do for clusters.

Signed-off-by: Utku Ozdemir <utku.ozdemir@siderolabs.com>
2026-01-07 12:48:53 +01:00

43 lines
1.2 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 models
import (
"github.com/cosi-project/runtime/pkg/resource"
"github.com/siderolabs/omni/client/pkg/omni/resources/omni"
)
// KernelArgs is a wrapper type for the kernel args, which can be specified at a Cluster, MachineSet, or Machine level in cluster templates.
//
// This type needs to be included in the models as an inline YAML, e.g., via `yaml:",inline"`.
type KernelArgs struct {
Value *[]string `yaml:"kernelArgs,omitempty"`
}
// Get returns the kernel args value and whether they are actually defined.
func (ka *KernelArgs) Get() (args []string, defined bool) {
if ka.Value != nil {
return *ka.Value, true
}
return nil, false
}
// Set sets the kernel args value.
func (ka *KernelArgs) Set(args []string) {
ka.Value = &args
}
func buildKernelArgsResource(id MachineID, args []string) *omni.KernelArgs {
kernelArgsRes := omni.NewKernelArgs(resource.ID(id))
kernelArgsRes.Metadata().Annotations().Set(omni.ResourceManagedByClusterTemplates, "")
kernelArgsRes.TypedSpec().Value.Args = args
return kernelArgsRes
}