mirror of
https://github.com/siderolabs/omni.git
synced 2025-08-06 17:46:59 +02:00
Some checks failed
default / default (push) Has been cancelled
default / e2e-backups (push) Has been cancelled
default / e2e-forced-removal (push) Has been cancelled
default / e2e-omni-upgrade (push) Has been cancelled
default / e2e-scaling (push) Has been cancelled
default / e2e-short (push) Has been cancelled
default / e2e-short-secureboot (push) Has been cancelled
default / e2e-templates (push) Has been cancelled
default / e2e-upgrades (push) Has been cancelled
default / e2e-workload-proxy (push) Has been cancelled
- Bump some deps, namely cosi-runtime and Talos machinery. - Update `auditState` to implement the new methods in COSI's `state.State`. - Bump default Talos and Kubernetes versions to their latest. - Rekres, which brings Go 1.24.5. Also update it in go.mod files. - Fix linter errors coming from new linters. Signed-off-by: Utku Ozdemir <utku.ozdemir@siderolabs.com>
154 lines
3.8 KiB
Go
154 lines
3.8 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 (
|
|
"fmt"
|
|
|
|
"github.com/cosi-project/runtime/pkg/resource"
|
|
"github.com/google/uuid"
|
|
"github.com/hashicorp/go-multierror"
|
|
"github.com/siderolabs/gen/pair"
|
|
|
|
"github.com/siderolabs/omni/client/pkg/constants"
|
|
"github.com/siderolabs/omni/client/pkg/omni/resources/omni"
|
|
)
|
|
|
|
// MachineIDList is a list of Machine UUIDs.
|
|
type MachineIDList []MachineID
|
|
|
|
// MachineID is a Machine UUID.
|
|
type MachineID string
|
|
|
|
// KindMachine is a Machine model kind.
|
|
const KindMachine = "Machine"
|
|
|
|
// Machine provides customization for a specific machine.
|
|
type Machine struct { //nolint:govet
|
|
Meta `yaml:",inline"`
|
|
SystemExtensions `yaml:",inline"`
|
|
|
|
// Machine name (ID).
|
|
Name MachineID `yaml:"name"`
|
|
|
|
// Descriptors are the user descriptors to apply to the cluster.
|
|
Descriptors Descriptors `yaml:",inline"`
|
|
|
|
// Locked locks the machine, so no config updates, upgrades and downgrades will be performed on the machine.
|
|
Locked bool `yaml:"locked,omitempty"`
|
|
|
|
// Install specification.
|
|
Install MachineInstall `yaml:"install,omitempty"`
|
|
|
|
// ClusterMachine patches.
|
|
Patches PatchList `yaml:"patches,omitempty"`
|
|
}
|
|
|
|
// MachineInstall provides machine install configuration.
|
|
type MachineInstall struct {
|
|
// Disk device name.
|
|
Disk string `yaml:"disk"`
|
|
}
|
|
|
|
// Validate the list of machines.
|
|
func (l MachineIDList) Validate() error {
|
|
var multiErr error
|
|
|
|
for _, id := range l {
|
|
multiErr = joinErrors(multiErr, id.Validate())
|
|
}
|
|
|
|
return multiErr
|
|
}
|
|
|
|
// Validate the model.
|
|
func (id MachineID) Validate() error {
|
|
if _, err := uuid.Parse(string(id)); err != nil {
|
|
return fmt.Errorf("invalid machine ID %q: %w", id, err)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// Validate the model.
|
|
func (install *MachineInstall) Validate() error {
|
|
return nil
|
|
}
|
|
|
|
// Validate the model.
|
|
func (machine *Machine) Validate() error {
|
|
var multiErr error
|
|
|
|
if machine.Name == "" {
|
|
multiErr = multierror.Append(multiErr, fmt.Errorf("name is required for machine"))
|
|
}
|
|
|
|
if err := machine.Descriptors.Validate(); err != nil {
|
|
multiErr = multierror.Append(multiErr, err)
|
|
}
|
|
|
|
multiErr = joinErrors(multiErr, machine.Name.Validate(), machine.Install.Validate(), machine.Patches.Validate())
|
|
if multiErr != nil {
|
|
return fmt.Errorf("machine %q is invalid: %w", machine.Name, multiErr)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// Translate the model.
|
|
func (machine *Machine) Translate(ctx TranslateContext) ([]resource.Resource, error) {
|
|
var resourceList []resource.Resource
|
|
|
|
if machine.Install.Disk != "" {
|
|
patch := Patch{
|
|
Name: "install-disk",
|
|
Inline: map[string]any{
|
|
"machine": map[string]any{
|
|
"install": map[string]any{
|
|
"disk": machine.Install.Disk,
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
patchResource, err := patch.Translate(
|
|
fmt.Sprintf("cm-%s", machine.Name),
|
|
constants.PatchWeightInstallDisk,
|
|
pair.MakePair(omni.LabelCluster, ctx.ClusterName),
|
|
pair.MakePair(omni.LabelClusterMachine, string(machine.Name)),
|
|
pair.MakePair(omni.LabelSystemPatch, ""),
|
|
)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
resourceList = append(resourceList, patchResource)
|
|
}
|
|
|
|
patches, err := machine.Patches.Translate(
|
|
fmt.Sprintf("cm-%s", machine.Name),
|
|
constants.PatchBaseWeightClusterMachine,
|
|
pair.MakePair(omni.LabelCluster, ctx.ClusterName),
|
|
pair.MakePair(omni.LabelClusterMachine, string(machine.Name)),
|
|
)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
resourceList = append(resourceList, patches...)
|
|
|
|
schematicConfigurations := machine.translate(
|
|
ctx,
|
|
string(machine.Name),
|
|
pair.MakePair(omni.LabelClusterMachine, string(machine.Name)),
|
|
)
|
|
|
|
return append(resourceList, schematicConfigurations...), nil
|
|
}
|
|
|
|
func init() {
|
|
register[Machine](KindMachine)
|
|
}
|