| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- import type { K8sClient } from '$lib/server/k8s';
- import { K8sResource } from '$lib/server/resources/k8s';
- import type { StackCR } from '$lib/types/custom-resources';
- import type { ResourceEvent } from '$lib/types/events';
- import type { CoreResources } from '$lib/types/workspace';
- import type { StackResources } from './types';
- class K8sStackResourceImpl extends K8sResource<StackCR> {
- constructor(k8sClient: K8sClient, namespace: string) {
- super(
- k8sClient,
- namespace,
- {
- group: 'locostack.com',
- version: 'v1alpha1',
- namespace,
- resource: 'stacks',
- },
- [],
- );
- }
- }
- class K8sStackResources implements StackResources {
- #stackResources: K8sStackResourceImpl;
- constructor(k8sClient: K8sClient, namespace: string) {
- this.#stackResources = new K8sStackResourceImpl(k8sClient, namespace);
- }
- subscribe(handler: (event: ResourceEvent) => void): () => void {
- return this.#stackResources.subscribe(handler);
- }
- async getStacks(): Promise<StackCR[]> {
- return this.#stackResources.getResources();
- }
- async getStackResources(stackId: string): Promise<CoreResources> {
- return this.#stackResources.getCoreResources(stackId);
- }
- async getStackStatus(stackId: string): Promise<StackCR['status'] | undefined> {
- return this.#stackResources.getResourceStatus<StackCR['status']>(stackId);
- }
- async applyStack(cr: StackCR): Promise<void> {
- await this.#stackResources.apply(cr);
- }
- async deleteStack(id: string): Promise<void> {
- await this.#stackResources.remove(id);
- }
- }
- export { K8sStackResources };
|