Skip to content

Commit

Permalink
fix(networks) ensure volatile keys are preserved, when saving a netwo…
Browse files Browse the repository at this point in the history
…rk. see canonical/lxd#14531

Signed-off-by: David Edler <[email protected]>
  • Loading branch information
edlerd committed Dec 18, 2024
1 parent b6832ba commit 9e9c0d9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
4 changes: 1 addition & 3 deletions src/pages/networks/forms/NetworkForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,7 @@ export const toNetwork = (values: NetworkFormValues): Partial<LxdNetwork> => {
const excludeConfigKeys = getHandledNetworkConfigKeys();
const missingConfigFields = Object.fromEntries(
Object.entries(values.bareNetwork?.config ?? {}).filter(
(e) =>
!excludeConfigKeys.has(e[0] as keyof LxdNetworkConfig) &&
!e[0].startsWith("volatile"),
(e) => !excludeConfigKeys.has(e[0] as keyof LxdNetworkConfig),
),
);

Expand Down
1 change: 1 addition & 0 deletions src/types/network.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export interface LxdNetworkConfig {
network?: string;
parent?: string;
[key: `user.${string}`]: string;
[key: `volatile.${string}`]: string;
}

export interface LxdNetwork {
Expand Down
15 changes: 15 additions & 0 deletions src/util/networkForm.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,19 @@ describe("conversion to form values and back with toNetworkFormValues and toNetw

expect(payload.config?.["user.key"]).toBe("custom-config-value");
});

it("preserves volatile keys in network config", () => {
const network = {
devices: {},
config: {
"user.key": "custom-config-value",
"volatile.network.ipv4.address": "1.2.3.4",
},
} as unknown as LxdNetwork;

const formValues = toNetworkFormValues(network);
const payload = toNetwork(formValues);

expect(payload.config?.["volatile.network.ipv4.address"]).toBe("1.2.3.4");
});
});

0 comments on commit 9e9c0d9

Please sign in to comment.