New settings/KindGate renders the store's per-kind loading/error state where the form would be: a skeleton while loading, ReadError with Retry on a failed read. Wired into Tools, SystemModels, SystemRepos, SchedulingPolicy, ContainerRuntime, OrgAlerts, Instructions, Plugins, SystemTasks, UpdateSettings, IdentityGrants, OrgModels, Channels and Authentication pages, which no longer render blank until the draft exists.
194 lines
8.1 KiB
Vue
194 lines
8.1 KiB
Vue
<script setup lang="ts">
|
|
import { Alert, AlertDescription } from "@/components/ui/alert";
|
|
import ApplyStatusRows from "./ApplyStatusRows.vue";
|
|
import { computed, onMounted } from "vue";
|
|
import { storeToRefs } from "pinia";
|
|
import { TriangleAlert } from "@lucide/vue";
|
|
|
|
import PageHeader from "@/base/PageHeader.vue";
|
|
import { DurationInput } from "@/components/ui/duration-input";
|
|
import { parseGoDuration } from "@/components/ui/duration-input/duration";
|
|
import { Field, FieldContent, FieldDescription, FieldError, FieldGroup, FieldLabel } from "@/components/ui/field";
|
|
import { Input } from "@/components/ui/input";
|
|
import {
|
|
NumberField,
|
|
NumberFieldContent,
|
|
NumberFieldDecrement,
|
|
NumberFieldIncrement,
|
|
NumberFieldInput,
|
|
} from "@/components/ui/number-field";
|
|
import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group";
|
|
import { resourcesForPage, useSettingsStore } from "@/stores/settings";
|
|
import DraftHint from "./DraftHint.vue";
|
|
import HistoryLink from "./HistoryLink.vue";
|
|
import KindGate from "./KindGate.vue";
|
|
import { fieldInvalid } from "./settings-form";
|
|
|
|
const KIND = "container-runtime-policies";
|
|
const EXECUTION_KIND = "workflow-execution-settings";
|
|
// The server's own default when execution settings predate the task limit.
|
|
const DEFAULT_TASK_RUNTIME_SECONDS = 4 * 60 * 60;
|
|
|
|
// The stored document is containerRuntimePolicies on the wire: snake_case keys
|
|
// and durations as Go duration strings.
|
|
interface ContainerRuntime {
|
|
image: string;
|
|
max_concurrency: number;
|
|
max_uptime: string;
|
|
volume_ttl: string;
|
|
pull_policy: string;
|
|
network: string;
|
|
}
|
|
|
|
const store = useSettingsStore();
|
|
const { catalog, catalogError } = storeToRefs(store);
|
|
onMounted(store.load);
|
|
|
|
const resources = computed(() => resourcesForPage(catalog.value, "containers"));
|
|
const form = computed(() => store.formFor(KIND));
|
|
const runtime = computed(() => store.draftValue(KIND) as ContainerRuntime | undefined);
|
|
const error = computed(() => store.pageErrorFor(KIND));
|
|
|
|
const pullPolicies = [
|
|
{ value: "missing", label: "If missing" },
|
|
{ value: "always", label: "Always" },
|
|
];
|
|
|
|
// The daemon kills a container at max uptime, so a task limit longer than it
|
|
// can never be reached. Mirrors the warning archied logs when it applies them.
|
|
const uptimeWarning = computed(() => {
|
|
const uptime = parseGoDuration(runtime.value?.max_uptime ?? "");
|
|
if (!uptime) return "";
|
|
const execution = store.draftValue(EXECUTION_KIND) as { max_task_runtime_seconds?: number | null } | undefined;
|
|
const limitSeconds = execution?.max_task_runtime_seconds ?? DEFAULT_TASK_RUNTIME_SECONDS;
|
|
if (limitSeconds > 0 && limitSeconds * 1000 <= uptime) return "";
|
|
const limit = limitSeconds > 0 ? `the ${formatHours(limitSeconds)} task limit` : "the task limit, which is off";
|
|
return `Shorter than ${limit}, so containers are killed before a task can finish.`;
|
|
});
|
|
|
|
function formatHours(seconds: number): string {
|
|
return seconds % 3600 === 0 ? `${seconds / 3600}h` : `${Math.round(seconds / 60)}m`;
|
|
}
|
|
</script>
|
|
|
|
<template>
|
|
<div>
|
|
<PageHeader title="Container runtime">
|
|
<HistoryLink :kinds="resources.map((r) => r.kind)" />
|
|
</PageHeader>
|
|
<ApplyStatusRows v-for="resource in resources" :key="resource.kind" :kind="resource.kind" class="mb-4" />
|
|
|
|
<Alert v-if="catalogError || error" variant="destructive" class="mb-4"><AlertDescription>{{ catalogError || error }}</AlertDescription></Alert>
|
|
|
|
<KindGate v-if="!form" :kind="KIND" />
|
|
<FieldGroup v-if="form" class="@container/field-group">
|
|
<form.Field v-slot="{ field }" name="image">
|
|
<Field orientation="responsive" :data-invalid="fieldInvalid(field)">
|
|
<FieldContent><FieldLabel for="cr-image">Image</FieldLabel></FieldContent>
|
|
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
|
|
<Input
|
|
id="cr-image"
|
|
:model-value="field.state.value"
|
|
class="font-mono"
|
|
:aria-invalid="fieldInvalid(field)"
|
|
@blur="field.handleBlur"
|
|
@update:model-value="field.handleChange"
|
|
/>
|
|
<DraftHint :kind="KIND" path="image" />
|
|
</div>
|
|
</Field>
|
|
</form.Field>
|
|
|
|
<form.Field v-slot="{ field }" name="pull_policy">
|
|
<Field orientation="responsive">
|
|
<FieldContent><FieldLabel>Pull policy</FieldLabel></FieldContent>
|
|
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
|
|
<ToggleGroup
|
|
type="single"
|
|
variant="outline"
|
|
size="sm"
|
|
:model-value="field.state.value || 'missing'"
|
|
aria-label="Pull policy"
|
|
@update:model-value="(value) => { if (value) field.handleChange(value); }"
|
|
>
|
|
<ToggleGroupItem v-for="option in pullPolicies" :key="option.value" :value="option.value">{{ option.label }}</ToggleGroupItem>
|
|
</ToggleGroup>
|
|
<DraftHint :kind="KIND" path="pull_policy" />
|
|
</div>
|
|
</Field>
|
|
</form.Field>
|
|
|
|
<form.Field v-slot="{ field }" name="max_concurrency">
|
|
<Field orientation="responsive">
|
|
<FieldContent>
|
|
<FieldLabel>Max concurrency</FieldLabel>
|
|
<FieldDescription>0 = no limit.</FieldDescription>
|
|
</FieldContent>
|
|
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
|
|
<NumberField :model-value="field.state.value" :min="0" class="w-32" @update:model-value="field.handleChange">
|
|
<NumberFieldContent>
|
|
<NumberFieldDecrement />
|
|
<NumberFieldInput class="font-mono" aria-label="Max concurrency" />
|
|
<NumberFieldIncrement />
|
|
</NumberFieldContent>
|
|
</NumberField>
|
|
<DraftHint :kind="KIND" path="max_concurrency" />
|
|
</div>
|
|
</Field>
|
|
</form.Field>
|
|
|
|
<form.Field v-slot="{ field }" name="max_uptime">
|
|
<Field orientation="responsive" :data-invalid="fieldInvalid(field)">
|
|
<FieldContent><FieldLabel for="cr-uptime">Max uptime</FieldLabel></FieldContent>
|
|
<div class="flex min-w-0 flex-col gap-2 @md/field-group:flex-1">
|
|
<FieldDescription v-if="uptimeWarning" class="flex items-start gap-1.5 text-warn" role="status">
|
|
<TriangleAlert class="mt-0.5 size-3.5 shrink-0" />
|
|
<span>{{ uptimeWarning }}</span>
|
|
</FieldDescription>
|
|
<div class="flex flex-wrap items-center gap-3">
|
|
<DurationInput
|
|
id="cr-uptime"
|
|
:model-value="field.state.value"
|
|
:units="['m', 'h']"
|
|
:aria-invalid="fieldInvalid(field)"
|
|
@update:model-value="field.handleChange"
|
|
/>
|
|
<DraftHint :kind="KIND" path="max_uptime" />
|
|
</div>
|
|
<FieldError v-if="fieldInvalid(field)" :errors="field.state.meta.errors" />
|
|
</div>
|
|
</Field>
|
|
</form.Field>
|
|
|
|
<form.Field v-slot="{ field }" name="volume_ttl">
|
|
<Field orientation="responsive">
|
|
<FieldContent><FieldLabel for="cr-ttl">Volume retention</FieldLabel></FieldContent>
|
|
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
|
|
<DurationInput id="cr-ttl" :model-value="field.state.value" :units="['h']" @update:model-value="field.handleChange" />
|
|
<DraftHint :kind="KIND" path="volume_ttl" />
|
|
</div>
|
|
</Field>
|
|
</form.Field>
|
|
|
|
<form.Field v-slot="{ field }" name="network">
|
|
<Field orientation="responsive">
|
|
<FieldContent>
|
|
<FieldLabel for="cr-network">Network</FieldLabel>
|
|
<FieldDescription>Empty: auto-detect.</FieldDescription>
|
|
</FieldContent>
|
|
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
|
|
<Input
|
|
id="cr-network"
|
|
:model-value="field.state.value"
|
|
class="max-w-sm font-mono"
|
|
@blur="field.handleBlur"
|
|
@update:model-value="field.handleChange"
|
|
/>
|
|
<DraftHint :kind="KIND" path="network" />
|
|
</div>
|
|
</Field>
|
|
</form.Field>
|
|
</FieldGroup>
|
|
</div>
|
|
</template>
|