Skip to content

Commit 5f55c05

Browse files
committed
fix: use the correct res order for the cluster operations in the UI
The way resources were ordered was making config patch being created before machine set node resources. That kind of order makes Omni code racy and it might install Talos to the wrong disk for example. Signed-off-by: Artem Chernyshev <[email protected]>
1 parent 029ec05 commit 5f55c05

File tree

4 files changed

+27
-9
lines changed

4 files changed

+27
-9
lines changed

frontend/src/components/common/Form/JsonForm.vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,6 @@ watch(jsonSchema, renderSchema);
165165
166166
renderSchema();
167167
168-
console.log(modelValue.value)
169168
updateErrors(modelValue.value);
170169
171170
const uiSchema = computed(() => {

frontend/src/states/cluster-management/index.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ import yaml from "js-yaml";
4545
import { withRuntime, withSelectors } from "@/api/options";
4646
import { Runtime } from "@/api/common/omni.pb";
4747

48+
export const typesOrder = {
49+
[ClusterType]: 4,
50+
[ConfigPatchType]: 3,
51+
[MachineSetType]: 2,
52+
[MachineSetNodeType]: 1
53+
};
54+
4855
const dec2hex = (dec: number) => {
4956
return dec.toString(16).padStart(2, "0");
5057
}
@@ -333,7 +340,7 @@ export class State {
333340
cluster.spec.backup_configuration = undefined;
334341
}
335342

336-
const resources: Resource[] = [
343+
let resources: Resource[] = [
337344
cluster,
338345
];
339346

@@ -461,6 +468,16 @@ export class State {
461468
}, ms.metadata.id));
462469
}
463470

471+
resources = resources.sort((a: Resource, b: Resource) => {
472+
if (typesOrder[a.metadata.type!] > typesOrder[b.metadata.type!]) {
473+
return -1;
474+
} else if (typesOrder[a.metadata.type!] < typesOrder[b.metadata.type!]) {
475+
return 1;
476+
}
477+
478+
return 0;
479+
});
480+
464481
if (!this.baseResources) {
465482
return resources;
466483
}

frontend/test/unit/clusterManageState.spec.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import { Resource } from "../../src/api/grpc";
77
import { ClusterSpec, ConfigPatchSpec, MachineSetNodeSpec, MachineSetSpec, MachineSetSpecMachineAllocationType, MachineSetSpecUpdateStrategy } from "../../src/api/omni/specs/omni.pb";
88
import { ClusterType, ConfigPatchType, DefaultNamespace, LabelCluster, LabelClusterMachine, LabelControlPlaneRole, LabelMachineSet, LabelWorkerRole, MachineSetNodeType, MachineSetType } from "../../src/api/resources";
9-
import { Cluster, initState, MachineSet, PatchID, state } from "../../src/states/cluster-management";
9+
import { Cluster, initState, MachineSet, PatchID, state, typesOrder } from "../../src/states/cluster-management";
1010

1111
import { describe, expect, test } from "bun:test";
1212

@@ -358,7 +358,7 @@ describe("cluster-management-state", () => {
358358
state.value.cluster = tt.cluster;
359359

360360
if (tt.machineSets) {
361-
for (let i = 0; i < tt.machineSets.length ?? 0; i++) {
361+
for (let i = 0; i < tt.machineSets.length; i++) {
362362
const machineSet = tt.machineSets[i];
363363

364364
if (state.value.machineSets.length <= i) {
@@ -386,12 +386,16 @@ describe("cluster-management-state", () => {
386386
empty[key] = {};
387387
}
388388

389+
for (let i = 1; i < resources.length; i++) {
390+
expect(typesOrder[resources[i-1].metadata.type],
391+
`${resources[i].metadata.type} is not expected after ${resources[i-1].metadata.type}`,
392+
).toBeGreaterThanOrEqual(typesOrder[resources[i].metadata.type]);
393+
}
394+
389395
for (const res of resources) {
390396
const expected = tt.expectedResources?.[res.metadata.type!]?.[res.metadata.id!];
391397

392-
console.log(`should have resource ${res.metadata.type}/${res.metadata.id}`);
393-
394-
expect(expected).toBeDefined();
398+
expect(expected, `should have resource ${res.metadata.type}/${res.metadata.id}`).toBeDefined();
395399

396400
delete tt.expectedResources?.[res.metadata.type!]?.[res.metadata.id!];
397401

frontend/test/unit/watch.spec.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ class fakeStream extends EventTarget {
2020
private reject?: (value: Error | PromiseLike<void>) => void;
2121

2222
public run(...args: any[]): Promise<void> {
23-
console.log("starting fake stream", ...args);
24-
2523
this.dispatchEvent(new Event("run"));
2624

2725
return new Promise<void>(

0 commit comments

Comments
 (0)