Skip to content

Commit

Permalink
Allow root disk device to have a custom name (#913)
Browse files Browse the repository at this point in the history
## Done

- Allow root disk device to have a custom name

## QA

1. Run the LXD-UI:
- On the demo server via the link posted by @webteam-app below. This is
only available for PRs created by collaborators of the repo. Ask
@mas-who or @edlerd for access.
- With a local copy of this branch, [build and run as described in the
docs](../CONTRIBUTING.md#setting-up-for-development).
2. Perform the following QA steps:
- create an instance where the root storage is overridden / set on the
instance itself
- edit instance in yaml editor, rename root device from "root" to
another name, i.e. "rooty-root", save changes
- ensure the guided forms (devices > disk) display the root device
properly and custom volumes work as expected.
  • Loading branch information
edlerd authored Sep 18, 2024
2 parents a8f5c73 + 771d4af commit 1eff361
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
7 changes: 5 additions & 2 deletions src/components/forms/DiskDeviceFormCustom.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ import { getConfigurationRowBase } from "components/ConfigurationRow";
import DetachDiskDeviceBtn from "pages/instances/actions/DetachDiskDeviceBtn";
import classnames from "classnames";
import { LxdStorageVolume } from "types/storage";
import { isDiskDeviceMountPointMissing } from "util/instanceValidation";
import {
isDiskDeviceMountPointMissing,
isRootDisk,
} from "util/instanceValidation";
import { ensureEditMode } from "util/instanceEdit";
import { getExistingDeviceNames } from "util/devices";
import { LxdProfile } from "types/profile";
Expand All @@ -29,7 +32,7 @@ interface Props {
const DiskDeviceFormCustom: FC<Props> = ({ formik, project, profiles }) => {
const readOnly = (formik.values as EditInstanceFormValues).readOnly;
const customVolumes = formik.values.devices
.filter((device) => device.name !== "root" && device.type === "disk")
.filter((item) => item.type === "disk" && !isRootDisk(item))
.map((device) => device as FormDiskDevice);

const focusField = (name: string) => {
Expand Down
8 changes: 3 additions & 5 deletions src/components/forms/DiskDeviceFormRoot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import DiskSizeSelector from "components/forms/DiskSizeSelector";
import { LxdStoragePool } from "types/storage";
import { LxdProfile } from "types/profile";
import { removeDevice } from "util/formDevices";
import { hasNoRootDisk } from "util/instanceValidation";
import { hasNoRootDisk, isRootDisk } from "util/instanceValidation";
import { ensureEditMode } from "util/instanceEdit";

interface Props {
Expand All @@ -29,9 +29,7 @@ const DiskDeviceFormRoot: FC<Props> = ({
profiles,
}) => {
const readOnly = (formik.values as EditInstanceFormValues).readOnly;
const rootIndex = formik.values.devices.findIndex(
(item) => item.type === "disk" && item.name === "root",
);
const rootIndex = formik.values.devices.findIndex(isRootDisk);
const hasRootStorage = rootIndex !== -1;
const formRootDevice = formik.values.devices[
rootIndex
Expand All @@ -46,7 +44,7 @@ const DiskDeviceFormRoot: FC<Props> = ({
const copy = [...formik.values.devices];
copy.push({
type: "disk",
name: "root",
name: inheritValue?.name ? inheritValue.name : "root",
path: "/",
pool: inheritValue ? inheritValue.pool : (pools[0]?.name ?? undefined),
});
Expand Down
5 changes: 4 additions & 1 deletion src/util/configInheritance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,10 @@ export const getInheritedRootStorage = (
.find((item) => (item.device as LxdDiskDevice).path === "/");

if (rootDisk) {
return [rootDisk.device as LxdDiskDevice, rootDisk.source];
return [
{ ...rootDisk.device, name: rootDisk.key } as LxdDiskDevice,
rootDisk.source,
];
}

return [null, "LXD"];
Expand Down
6 changes: 5 additions & 1 deletion src/util/instanceValidation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@ export const hasNoRootDisk = (
return missingRoot(values.devices) && !inheritsRoot(values, profiles);
};

export const isRootDisk = (device: FormDevice): device is FormDiskDevice => {
return device.type === "disk" && device.path === "/" && !device.source;
};

const missingRoot = (devices: FormDevice[]): boolean => {
return !devices.some((item) => item.type === "disk" && item.name === "root");
return !devices.some(isRootDisk);
};

const inheritsRoot = (
Expand Down

0 comments on commit 1eff361

Please sign in to comment.