mirror of
https://github.com/YuzuZensai/Minikura.git
synced 2026-09-13 18:59:25 +00:00
✨ feat: topology, and improves handling
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
import type * as k8s from "@kubernetes/client-node";
|
||||
import type { CustomResourceSummary } from "@minikura/api";
|
||||
import { getAge } from "@minikura/shared/errors";
|
||||
import { BaseK8sOperations } from "./base.operations";
|
||||
|
||||
interface CustomResourceItem {
|
||||
kind?: string;
|
||||
metadata?: {
|
||||
name?: string;
|
||||
namespace?: string;
|
||||
creationTimestamp?: string;
|
||||
labels?: Record<string, string>;
|
||||
};
|
||||
spec?: Record<string, unknown>;
|
||||
status?: { phase?: string; [key: string]: unknown };
|
||||
}
|
||||
|
||||
interface CustomResourceList {
|
||||
items?: CustomResourceItem[];
|
||||
}
|
||||
|
||||
export class CustomResourceOperations extends BaseK8sOperations {
|
||||
constructor(
|
||||
private customObjectsApi: k8s.CustomObjectsApi,
|
||||
namespace: string
|
||||
) {
|
||||
super(namespace);
|
||||
}
|
||||
|
||||
async listCustomResources(
|
||||
group: string,
|
||||
version: string,
|
||||
plural: string
|
||||
): Promise<CustomResourceSummary[]> {
|
||||
return this.executeOperation(async () => {
|
||||
const response = await this.customObjectsApi.listNamespacedCustomObject({
|
||||
group,
|
||||
version,
|
||||
namespace: this.namespace,
|
||||
plural,
|
||||
});
|
||||
|
||||
const items = (response as unknown as CustomResourceList).items || [];
|
||||
|
||||
return items.map((item) => ({
|
||||
name: item.metadata?.name ?? "",
|
||||
namespace: item.metadata?.namespace ?? this.namespace,
|
||||
age: getAge(item.metadata?.creationTimestamp),
|
||||
labels: item.metadata?.labels,
|
||||
spec: item.spec ?? {},
|
||||
status: item.status ?? {},
|
||||
}));
|
||||
}, `Failed to fetch custom resources (${plural})`);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user