ui(admin): fix oom killer setting toggle

This commit is contained in:
Matthew Penner 2023-01-17 11:43:26 -07:00
parent f6cf4a1236
commit 450fba00bc
No known key found for this signature in database
10 changed files with 18 additions and 23 deletions

View file

@ -64,7 +64,7 @@ class ServerTransformer extends Transformer
'disk' => $model->disk, 'disk' => $model->disk,
'io' => $model->io, 'io' => $model->io,
'memory' => $model->memory, 'memory' => $model->memory,
'oom_disabled' => $model->oom_disabled, 'oom_killer' => !$model->oom_disabled,
'swap' => $model->swap, 'swap' => $model->swap,
'threads' => $model->threads, 'threads' => $model->threads,
], ],

View file

@ -18,7 +18,7 @@ interface ServerLimits {
io: number; io: number;
cpu: number; cpu: number;
threads: string | null; threads: string | null;
oomDisabled: boolean; oomKiller: boolean;
} }
export interface ServerVariable extends EggVariable { export interface ServerVariable extends EggVariable {

View file

@ -15,7 +15,7 @@ export interface CreateServerRequest {
io: number; io: number;
cpu: number; cpu: number;
threads: string; threads: string;
oomDisabled: boolean; oomKiller: boolean;
}; };
featureLimits: { featureLimits: {
@ -55,7 +55,7 @@ export default (r: CreateServerRequest, include: string[] = []): Promise<Server>
memory: r.limits.memory, memory: r.limits.memory,
swap: r.limits.swap, swap: r.limits.swap,
threads: r.limits.threads, threads: r.limits.threads,
oom_killer: r.limits.oomDisabled, oom_killer: r.limits.oomKiller,
}, },
feature_limits: { feature_limits: {

View file

@ -55,7 +55,7 @@ export interface Server {
io: number; io: number;
cpu: number; cpu: number;
threads: string | null; threads: string | null;
oomDisabled: boolean; oomKiller: boolean;
}; };
featureLimits: { featureLimits: {
@ -105,7 +105,7 @@ export const rawDataToServer = ({ attributes }: FractalResponseData): Server =>
io: attributes.limits.io, io: attributes.limits.io,
cpu: attributes.limits.cpu, cpu: attributes.limits.cpu,
threads: attributes.limits.threads, threads: attributes.limits.threads,
oomDisabled: attributes.limits.oom_disabled, oomKiller: attributes.limits.oom_killer,
}, },
featureLimits: { featureLimits: {

View file

@ -13,7 +13,7 @@ export interface Values {
io: number; io: number;
cpu: number; cpu: number;
threads: string; threads: string;
oomDisabled: boolean; oomKiller: boolean;
}; };
featureLimits: { featureLimits: {
@ -43,7 +43,7 @@ export default (id: number, server: Partial<Values>, include: string[] = []): Pr
io: server.limits?.io, io: server.limits?.io,
cpu: server.limits?.cpu, cpu: server.limits?.cpu,
threads: server.limits?.threads, threads: server.limits?.threads,
oom_killer: server.limits?.oomDisabled, oom_killer: server.limits?.oomKiller,
}, },
feature_limits: { feature_limits: {

View file

@ -40,7 +40,7 @@ function transform<T>(
export default class Transformers { export default class Transformers {
static toServer = ({ attributes }: FractalResponseData): Server => { static toServer = ({ attributes }: FractalResponseData): Server => {
const { oom_disabled, ...limits } = attributes.limits; const { oom_killer, ...limits } = attributes.limits;
const { allocations, egg, nest, node, user, variables } = attributes.relationships || {}; const { allocations, egg, nest, node, user, variables } = attributes.relationships || {};
return { return {
@ -56,7 +56,7 @@ export default class Transformers {
allocationId: attributes.allocation_id, allocationId: attributes.allocation_id,
eggId: attributes.egg_id, eggId: attributes.egg_id,
nestId: attributes.nest_id, nestId: attributes.nest_id,
limits: { ...limits, oomDisabled: oom_disabled }, limits: { ...limits, oomKiller: oom_killer },
featureLimits: attributes.feature_limits, featureLimits: attributes.feature_limits,
container: attributes.container, container: attributes.container,
createdAt: new Date(attributes.created_at), createdAt: new Date(attributes.created_at),

View file

@ -195,9 +195,7 @@ export default () => {
io: 500, io: 500,
cpu: 0, cpu: 0,
threads: '', threads: '',
// This value is inverted to have the switch be on when the oomKiller: true,
// OOM Killer is enabled, rather than when disabled.
oomDisabled: false,
}, },
featureLimits: { featureLimits: {
allocations: 1, allocations: 1,

View file

@ -23,10 +23,6 @@ export default () => {
const submit = (values: Values, { setSubmitting, setFieldValue }: FormikHelpers<Values>) => { const submit = (values: Values, { setSubmitting, setFieldValue }: FormikHelpers<Values>) => {
clearFlashes('server'); clearFlashes('server');
// This value is inverted to have the switch be on when the
// OOM Killer is enabled, rather than when disabled.
values.limits.oomDisabled = !values.limits.oomDisabled;
updateServer(server.id, values) updateServer(server.id, values)
.then(() => { .then(() => {
// setServer({ ...server, ...s }); // setServer({ ...server, ...s });
@ -58,7 +54,7 @@ export default () => {
threads: server.limits.threads || '', threads: server.limits.threads || '',
// This value is inverted to have the switch be on when the // This value is inverted to have the switch be on when the
// OOM Killer is enabled, rather than when disabled. // OOM Killer is enabled, rather than when disabled.
oomDisabled: !server.limits.oomDisabled, oomKiller: server.limits.oomKiller,
}, },
featureLimits: { featureLimits: {
allocations: server.featureLimits.allocations, allocations: server.featureLimits.allocations,

View file

@ -60,7 +60,7 @@ export default () => {
/> />
<div css={tw`xl:col-span-2 bg-neutral-800 border border-neutral-900 shadow-inner p-4 rounded`}> <div css={tw`xl:col-span-2 bg-neutral-800 border border-neutral-900 shadow-inner p-4 rounded`}>
<FormikSwitch <FormikSwitch
name={'limits.oomDisabled'} name={'limits.oomKiller'}
label={'Out of Memory Killer'} label={'Out of Memory Killer'}
description={ description={
'Enabling the Out of Memory Killer may cause server processes to exit unexpectedly.' 'Enabling the Out of Memory Killer may cause server processes to exit unexpectedly.'

View file

@ -1,10 +1,11 @@
import * as React from 'react'; import type { DetailedHTMLProps, HTMLAttributes } from 'react';
import FlashMessageRender from '@/components/FlashMessageRender';
import SpinnerOverlay from '@/components/elements/SpinnerOverlay';
import tw from 'twin.macro'; import tw from 'twin.macro';
import FlashMessageRender from '@/components/FlashMessageRender';
import SpinnerOverlay from '@/components/elements/SpinnerOverlay';
type Props = Readonly< type Props = Readonly<
React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement> & { DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement> & {
title?: string; title?: string;
borderColor?: string; borderColor?: string;
showFlashes?: string | boolean; showFlashes?: string | boolean;