Skip to content

fix: remove machine set allocation source option #1161

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
535 changes: 236 additions & 299 deletions client/api/omni/specs/omni.pb.go

Large diffs are not rendered by default.

11 changes: 1 addition & 10 deletions client/api/omni/specs/omni.proto
Original file line number Diff line number Diff line change
Expand Up @@ -710,22 +710,13 @@ message MachineSetSpec {
Unlimited = 1;
}

enum Source {
// MachineClass allocates the machines from a machine class.
MachineClass = 0;
// MachineRequestSet allocates the machines from a machine request set.
MachineRequestSet = 1;
}

// Name defines the machine class/machine request set id to select the machines from.
string name = 1;
// MachineCount defines fixed amount of the machines to allocated from the machine class/request set.
uint32 machine_count = 2;
// AllocationType defines special constants for the amount of machines to be allocated.
Type allocation_type = 3;
// Source defines the source where to get the machines from.
// It can be either a machine class or a machine request set.
Source source = 4;
reserved 4;
}

// BootstrapSpec defines the bootstrap spec for the control plane machine set.
Expand Down
31 changes: 0 additions & 31 deletions client/api/omni/specs/omni_vtproto.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion client/pkg/template/internal/models/machineset.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,6 @@ func (machineset *MachineSet) translate(ctx TranslateContext, nameSuffix, roleLa
Name: machineset.MachineClass.Name,
MachineCount: machineset.MachineClass.Size.Value,
AllocationType: machineset.MachineClass.Size.AllocationType,
Source: specs.MachineSetSpec_MachineAllocation_MachineClass,
}
} else {
for _, machineID := range machineset.Machines {
Expand Down
5 changes: 0 additions & 5 deletions client/pkg/template/operations/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,11 +246,6 @@ func transformMachineSetToModel(machineSet *omni.MachineSet, nodes []*omni.Machi
AllocationType: allocationConfig.GetAllocationType(),
},
}

// TODO: for MCP we'll have a special flag defined, should support machine request set allocation mode export after we implement it
if allocationConfig.Source != specs.MachineSetSpec_MachineAllocation_MachineClass {
return models.MachineSet{}, fmt.Errorf("unsupported machine allocation source in the machine set %s", machineSet.Metadata().ID())
}
} else {
machineIDs = xslices.Map(nodes, func(node *omni.MachineSetNode) models.MachineID {
return models.MachineID(node.Metadata().ID())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ spec:
name: mc1
machinecount: 0
allocationtype: 1
source: 0
bootstrapspec: null
---

Expand Down Expand Up @@ -143,7 +142,6 @@ spec:
name: mc2
machinecount: 1
allocationtype: 0
source: 0
bootstrapspec: null
---

Expand Down
2 changes: 0 additions & 2 deletions client/pkg/template/testdata/cluster3-resources.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,6 @@ spec:
name: test
machinecount: 1
allocationtype: 0
source: 0
---
metadata:
namespace: default
Expand All @@ -303,4 +302,3 @@ spec:
name: test
machinecount: 0
allocationtype: 1
source: 0
6 changes: 0 additions & 6 deletions frontend/src/api/omni/specs/omni.pb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,6 @@ export enum MachineSetSpecMachineAllocationType {
Unlimited = 1,
}

export enum MachineSetSpecMachineAllocationSource {
MachineClass = 0,
MachineRequestSet = 1,
}

export enum TalosUpgradeStatusSpecPhase {
Unknown = 0,
Upgrading = 1,
Expand Down Expand Up @@ -525,7 +520,6 @@ export type MachineSetSpecMachineAllocation = {
name?: string
machine_count?: number
allocation_type?: MachineSetSpecMachineAllocationType
source?: MachineSetSpecMachineAllocationSource
}

export type MachineSetSpecBootstrapSpec = {
Expand Down
6 changes: 1 addition & 5 deletions frontend/src/states/cluster-management/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
MachineSetNodeSpec,
MachineSetSpec,
MachineSetSpecBootstrapSpec,
MachineSetSpecMachineAllocationSource,
MachineSetSpecMachineAllocationType,
MachineSetSpecUpdateStrategy,
MachineSetSpecUpdateStrategyConfig
Expand Down Expand Up @@ -92,7 +91,6 @@ export interface MachineSet {
machineAllocation?: {
name: string
size: number | "unlimited"
source: MachineSetSpecMachineAllocationSource
}
machines: Record<string, MachineSetNode>
patches: Record<string, ConfigPatch>
Expand Down Expand Up @@ -398,7 +396,6 @@ export class State {
if (machineSet.machineAllocation) {
ms.spec.machine_allocation = {
name: machineSet.machineAllocation.name,
source: machineSet.machineAllocation.source,
}

switch (machineSet.machineAllocation.size) {
Expand Down Expand Up @@ -562,7 +559,7 @@ export class State {

if (ms.machineAllocation) {
if (ms.machineAllocation.size === "unlimited") {
return `All From ${ms.machineAllocation.source === MachineSetSpecMachineAllocationSource.MachineClass ? 'Class' : 'Request Set'} "${ms.machineAllocation.name}"`;
return `All From Class "${ms.machineAllocation.name}"`;
}

count += ms.machineAllocation.size as number;
Expand Down Expand Up @@ -701,7 +698,6 @@ export const populateExisting = async (clusterName: string) => {
machineSet.machineAllocation = {
name: allocationCfg.name!,
size: allocationCfg.allocation_type === MachineSetSpecMachineAllocationType.Unlimited ? "unlimited" : allocationCfg.machine_count ?? 0,
source: allocationCfg.source ?? MachineSetSpecMachineAllocationSource.MachineClass,
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ import IconButton from "@/components/common/Button/IconButton.vue";
import pluralize from "pluralize";
import { LabelWorkerRole, PatchBaseWeightMachineSet } from "@/api/resources";
import MachineSetConfigEdit from "../../Modals/MachineSetConfigEdit.vue";
import { MachineSetSpecMachineAllocationSource, MachineClassSpec } from "@/api/omni/specs/omni.pb";
import { MachineClassSpec } from "@/api/omni/specs/omni.pb";

const emit = defineEmits(["update:modelValue"]);

Expand Down Expand Up @@ -140,7 +140,6 @@ watch([sourceName, machineCount, useMachineClasses, patches, allMachines], () =>
const mc = useMachineClasses.value && sourceName.value !== undefined ? {
name: sourceName.value,
size: allMachines.value ? 'unlimited' : machineCount.value,
source: MachineSetSpecMachineAllocationSource.MachineClass,
} : undefined;

const machineSet: MachineSet = {
Expand Down
6 changes: 1 addition & 5 deletions frontend/test/unit/clusterManageState.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// included in the LICENSE file.

import { Resource } from "../../src/api/grpc";
import { ClusterSpec, ConfigPatchSpec, MachineSetNodeSpec, MachineSetSpec, MachineSetSpecMachineAllocationSource, MachineSetSpecMachineAllocationType, MachineSetSpecUpdateStrategy } from "../../src/api/omni/specs/omni.pb";
import { ClusterSpec, ConfigPatchSpec, MachineSetNodeSpec, MachineSetSpec, MachineSetSpecMachineAllocationType, MachineSetSpecUpdateStrategy } from "../../src/api/omni/specs/omni.pb";
import { ClusterType, ConfigPatchType, DefaultNamespace, LabelCluster, LabelClusterMachine, LabelControlPlaneRole, LabelMachineSet, LabelWorkerRole, MachineSetNodeType, MachineSetType } from "../../src/api/resources";
import { Cluster, initState, MachineSet, PatchID, state } from "../../src/states/cluster-management";

Expand Down Expand Up @@ -79,7 +79,6 @@ describe("cluster-management-state", () => {
machineAllocation: {
name: "mc1",
size: "unlimited",
source: MachineSetSpecMachineAllocationSource.MachineClass,
},
machines: {
node4: {
Expand All @@ -95,7 +94,6 @@ describe("cluster-management-state", () => {
machineAllocation: {
name: "mc2",
size: 3,
source: MachineSetSpecMachineAllocationSource.MachineClass,
},
patches: {
[PatchID.Default]: {
Expand Down Expand Up @@ -176,7 +174,6 @@ describe("cluster-management-state", () => {
machine_allocation: {
name: "mc1",
allocation_type: MachineSetSpecMachineAllocationType.Unlimited,
source: MachineSetSpecMachineAllocationSource.MachineClass,
},
machine_class: undefined,
}
Expand All @@ -194,7 +191,6 @@ describe("cluster-management-state", () => {
machine_allocation: {
name: "mc2",
machine_count: 3,
source: MachineSetSpecMachineAllocationSource.MachineClass,
},
machine_class: undefined
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"github.com/siderolabs/gen/xerrors"
"go.uber.org/zap"

"github.com/siderolabs/omni/client/api/omni/specs"
"github.com/siderolabs/omni/client/pkg/omni/resources"
"github.com/siderolabs/omni/client/pkg/omni/resources/omni"
"github.com/siderolabs/omni/internal/backend/runtime/omni/controllers/omni/internal/mappers"
Expand Down Expand Up @@ -47,10 +46,6 @@ func NewMachineProvisionController() *MachineProvisionController {
return xerrors.NewTaggedf[qtransform.DestroyOutputTag]("machine set doesn't use automatic machine allocation")
}

if machineAllocation.Source != specs.MachineSetSpec_MachineAllocation_MachineClass {
return xerrors.NewTaggedf[qtransform.DestroyOutputTag]("machine allocation doesn't use machine classes")
}

clusterName, ok := machineSet.Metadata().Labels().Get(omni.LabelCluster)
if !ok {
return fmt.Errorf("machine set doesn't have cluster label")
Expand Down Expand Up @@ -128,8 +123,7 @@ func NewMachineProvisionController() *MachineProvisionController {
for machineSet := range machineSets.All() {
allocation := omni.GetMachineAllocation(machineSet)

if allocation == nil || allocation.Name != res.Metadata().ID() ||
allocation.Source != specs.MachineSetSpec_MachineAllocation_MachineClass {
if allocation == nil || allocation.Name != res.Metadata().ID() {
continue
}

Expand Down
51 changes: 18 additions & 33 deletions internal/backend/runtime/omni/controllers/omni/machine_set_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,54 +236,39 @@ func (ctrl *MachineSetNodeController) getMachineAllocation(ctx context.Context,
return nil, nil //nolint:nilnil
}

var manualAllocation bool

switch machineAllocation.Source {
case specs.MachineSetSpec_MachineAllocation_MachineClass:
machineClass, err := safe.ReaderGet[*omni.MachineClass](ctx, r, omni.NewMachineClass(resources.DefaultNamespace, machineAllocation.Name).Metadata())
if err != nil {
return nil, err
}

if machineClass.TypedSpec().Value.AutoProvision != nil {
selectors = append(selectors, resource.LabelQuery{
Terms: []resource.LabelTerm{
{
Key: omni.LabelMachineRequestSet,
Op: resource.LabelOpEqual,
Value: []string{machineSet.Metadata().ID()},
},
},
})

break
}

selectors, err = labels.ParseSelectors(machineClass.TypedSpec().Value.MatchLabels)
if err != nil {
return nil, err
}
machineClass, err := safe.ReaderGet[*omni.MachineClass](ctx, r, omni.NewMachineClass(resources.DefaultNamespace, machineAllocation.Name).Metadata())
if err != nil {
return nil, err
}

manualAllocation = true
case specs.MachineSetSpec_MachineAllocation_MachineRequestSet:
if machineClass.TypedSpec().Value.AutoProvision != nil {
selectors = append(selectors, resource.LabelQuery{
Terms: []resource.LabelTerm{
{
Key: omni.LabelMachineRequestSet,
Op: resource.LabelOpEqual,
Value: []string{machineAllocation.Name},
Value: []string{machineSet.Metadata().ID()},
},
},
})
default:
return nil, nil //nolint:nilnil

return &allocationConfig{
selectors: selectors,
allocationType: machineAllocation.AllocationType,
machineCount: machineAllocation.MachineCount,
}, nil
}

selectors, err = labels.ParseSelectors(machineClass.TypedSpec().Value.MatchLabels)
if err != nil {
return nil, err
}

return &allocationConfig{
selectors: selectors,
allocationType: machineAllocation.AllocationType,
machineCount: machineAllocation.MachineCount,
manual: manualAllocation,
manual: true,
}, nil
}

Expand Down
Loading
Loading