mirror of
https://github.com/KevinMidboe/infra-map.git
synced 2026-01-22 00:55:53 +00:00
working nice. docker uses bun
This commit is contained in:
59
src/routes/cluster/[resource]/[uid]/+page.server.ts
Normal file
59
src/routes/cluster/[resource]/[uid]/+page.server.ts
Normal file
@@ -0,0 +1,59 @@
|
||||
import type { PageServerLoad } from './$types';
|
||||
import { getPods, getDaemons, getReplicas, getDeployments } from '$lib/server/kubernetes';
|
||||
import type { V1DaemonSet, V1Deployment, V1Pod } from '@kubernetes/client-node';
|
||||
|
||||
const AVAILABLE_RESOURCES = [
|
||||
'pod',
|
||||
'deployment',
|
||||
'daemonset',
|
||||
'cronjobs',
|
||||
'configmap',
|
||||
'replicaset'
|
||||
];
|
||||
|
||||
export const load: PageServerLoad = async ({ params }) => {
|
||||
const { resource, uid } = params;
|
||||
console.log('PARAMS:', params);
|
||||
|
||||
if (!AVAILABLE_RESOURCES.includes(resource)) {
|
||||
return {
|
||||
error: 'No resource ' + resource,
|
||||
resource: null
|
||||
};
|
||||
}
|
||||
console.log(uid);
|
||||
|
||||
let resources: V1Pod[];
|
||||
|
||||
switch (resource) {
|
||||
case 'pod':
|
||||
const podsResp: V1Pod[] = await getPods();
|
||||
resources = JSON.parse(JSON.stringify(podsResp));
|
||||
break;
|
||||
case 'daemonset':
|
||||
const daemonsResp: V1DaemonSet[] = await getDaemons();
|
||||
resources = JSON.parse(JSON.stringify(daemonsResp));
|
||||
break;
|
||||
case 'deployment':
|
||||
const deploymentResp: V1Deployment[] = await getDeployments();
|
||||
resources = JSON.parse(JSON.stringify(deploymentResp));
|
||||
break;
|
||||
case 'replicaset':
|
||||
console.log('replicas');
|
||||
const replicasResp: V1ReplicaSet[] = await getReplicas();
|
||||
console.log('replicas', replicasResp);
|
||||
resources = JSON.parse(JSON.stringify(replicasResp));
|
||||
break;
|
||||
default:
|
||||
console.log('no resources found');
|
||||
}
|
||||
|
||||
const singleResource = resources?.find((p) => p.metadata?.uid === uid);
|
||||
delete singleResource?.metadata?.managedFields;
|
||||
|
||||
return {
|
||||
resource: singleResource,
|
||||
kind: resource,
|
||||
error: null
|
||||
};
|
||||
};
|
||||
32
src/routes/cluster/[resource]/[uid]/+page.svelte
Normal file
32
src/routes/cluster/[resource]/[uid]/+page.svelte
Normal file
@@ -0,0 +1,32 @@
|
||||
<script lang="ts">
|
||||
import PageHeader from '$lib/components/PageHeader.svelte';
|
||||
import PodDescribe from '$lib/components/kube-describe/Pod.svelte';
|
||||
import DeploymentDescribe from '$lib/components/kube-describe/Deployment.svelte';
|
||||
import DaemonSetDescribe from '$lib/components/kube-describe/DaemonSet.svelte';
|
||||
import type { PageData } from './$types';
|
||||
import type { V1Pod } from '@kubernetes/client-node';
|
||||
|
||||
let { data }: { data: PageData } = $props();
|
||||
const { error, kind } = data;
|
||||
const { resource }: { pod: V1Pod | undefined } = data;
|
||||
</script>
|
||||
|
||||
<PageHeader>{kind || 'Resource'}: {resource?.metadata?.name || 'not found'}</PageHeader>
|
||||
|
||||
{#if error}
|
||||
<p>{error}</p>
|
||||
{/if}
|
||||
|
||||
{#if resource}
|
||||
{#if kind == 'pod'}
|
||||
<PodDescribe pod={resource} />
|
||||
{:else if kind == 'deployment' || kind == 'replicaset'}
|
||||
<DeploymentDescribe deployment={resource} />
|
||||
{:else if kind == 'daemonset'}
|
||||
<DaemonSetDescribe daemonset={resource} />
|
||||
{:else}
|
||||
<PodDescribe pod={resource} />
|
||||
{/if}
|
||||
{:else}
|
||||
<h2>404. '{kind}' resource not found!</h2>
|
||||
{/if}
|
||||
27
src/routes/cluster/[resource]/[uid]/logs/+server.ts
Normal file
27
src/routes/cluster/[resource]/[uid]/logs/+server.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { createLogStream } from '$lib/server/kubernetes';
|
||||
import { produce } from 'sveltekit-sse';
|
||||
|
||||
export function GET({ request }) {
|
||||
return produce(async function start({ emit }) {
|
||||
console.log('----- REQUEST -----');
|
||||
const url = new URL(request.url);
|
||||
const pod = url.searchParams.get('pod');
|
||||
const namespace = url.searchParams.get('namespace');
|
||||
const container = url.searchParams.get('container');
|
||||
|
||||
console.log('pod, namespace:', pod, namespace);
|
||||
const k8sLogs = createLogStream(pod, namespace, container);
|
||||
k8sLogs.start();
|
||||
const unsubscribe = k8sLogs.logEmitter.subscribe((msg: string) => {
|
||||
emit('message', msg);
|
||||
});
|
||||
|
||||
const { error } = emit('message', `the time is ${Date.now()}`);
|
||||
|
||||
if (error) {
|
||||
k8sLogs.stop();
|
||||
unsubscribe();
|
||||
return;
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user