2026-02-17 18:12:02 +07:00
|
|
|
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>;
|
2026-08-13 03:29:17 +07:00
|
|
|
annotations?: Record<string, string>;
|
2026-02-17 18:12:02 +07:00
|
|
|
};
|
|
|
|
|
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,
|
2026-08-13 03:29:17 +07:00
|
|
|
annotations: item.metadata?.annotations,
|
2026-02-17 18:12:02 +07:00
|
|
|
spec: item.spec ?? {},
|
|
|
|
|
status: item.status ?? {},
|
|
|
|
|
}));
|
|
|
|
|
}, `Failed to fetch custom resources (${plural})`);
|
|
|
|
|
}
|
|
|
|
|
}
|