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,
'io' => $model->io,
'memory' => $model->memory,
'oom_disabled' => $model->oom_disabled,
'oom_killer' => !$model->oom_disabled,
'swap' => $model->swap,
'threads' => $model->threads,
],

View file

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

View file

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

View file

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

View file

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

View file

@ -40,7 +40,7 @@ function transform<T>(
export default class Transformers {
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 || {};
return {
@ -56,7 +56,7 @@ export default class Transformers {
allocationId: attributes.allocation_id,
eggId: attributes.egg_id,
nestId: attributes.nest_id,
limits: { ...limits, oomDisabled: oom_disabled },
limits: { ...limits, oomKiller: oom_killer },
featureLimits: attributes.feature_limits,
container: attributes.container,
createdAt: new Date(attributes.created_at),

View file

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

View file

@ -23,10 +23,6 @@ export default () => {
const submit = (values: Values, { setSubmitting, setFieldValue }: FormikHelpers<Values>) => {
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)
.then(() => {
// setServer({ ...server, ...s });
@ -58,7 +54,7 @@ export default () => {
threads: server.limits.threads || '',
// This value is inverted to have the switch be on when the
// OOM Killer is enabled, rather than when disabled.
oomDisabled: !server.limits.oomDisabled,
oomKiller: server.limits.oomKiller,
},
featureLimits: {
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`}>
<FormikSwitch
name={'limits.oomDisabled'}
name={'limits.oomKiller'}
label={'Out of Memory Killer'}
description={
'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 FlashMessageRender from '@/components/FlashMessageRender';
import SpinnerOverlay from '@/components/elements/SpinnerOverlay';
import type { DetailedHTMLProps, HTMLAttributes } from 'react';
import tw from 'twin.macro';
import FlashMessageRender from '@/components/FlashMessageRender';
import SpinnerOverlay from '@/components/elements/SpinnerOverlay';
type Props = Readonly<
React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement> & {
DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement> & {
title?: string;
borderColor?: string;
showFlashes?: string | boolean;