Skip to content
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

Ensure volatile keys are preserved, when saving a network #1036

Merged
merged 1 commit into from
Dec 18, 2024
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
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");
});
});
Loading