From 2281dcafb4724349a9f7b98d84af08b50dced1ba Mon Sep 17 00:00:00 2001 From: Morten Olsen Date: Fri, 24 Oct 2025 09:05:27 +0200 Subject: [PATCH] linting --- packages/k8s/src/config/config.ts | 5 ++- .../src/resources/resource/resource.custom.ts | 6 ++-- .../k8s/src/resources/resource/resource.ts | 2 +- .../k8s/src/resources/resources.service.ts | 4 +-- .../src/resources/server/server.ts | 2 +- .../src/resources/account/account.ts | 27 +++++++------- .../src/resources/dns-record/dns-record.ts | 17 +++++---- .../services/cloudflare/cloudflare.account.ts | 36 +++++++++---------- .../src/services/cloudflare/cloudflare.ts | 23 +++++++----- packages/resource-cloudflare/src/start.ts | 11 ++---- 10 files changed, 67 insertions(+), 66 deletions(-) diff --git a/packages/k8s/src/config/config.ts b/packages/k8s/src/config/config.ts index 8d2b118..05275d3 100644 --- a/packages/k8s/src/config/config.ts +++ b/packages/k8s/src/config/config.ts @@ -8,7 +8,6 @@ class K8sConfig { constructor() { this.#config = new KubeConfig(); this.#config.loadFromDefault(); - } public get kubeConfig() { @@ -17,7 +16,7 @@ class K8sConfig { public get objectsApi() { if (!this.#objectsApi) { - this.#objectsApi = this.#config.makeApiClient(KubernetesObjectApi) + this.#objectsApi = this.#config.makeApiClient(KubernetesObjectApi); } return this.#objectsApi; } @@ -31,7 +30,7 @@ class K8sConfig { public get extensionsApi() { if (!this.#extensionsApi) { - this.#extensionsApi = this.#config.makeApiClient(ApiextensionsV1Api) + this.#extensionsApi = this.#config.makeApiClient(ApiextensionsV1Api); } return this.#extensionsApi; } diff --git a/packages/k8s/src/resources/resource/resource.custom.ts b/packages/k8s/src/resources/resource/resource.custom.ts index 4744117..fd8da7b 100644 --- a/packages/k8s/src/resources/resource/resource.custom.ts +++ b/packages/k8s/src/resources/resource/resource.custom.ts @@ -2,14 +2,14 @@ import { z, type ZodType } from 'zod'; import { PatchStrategy, setHeaderOptions, type KubernetesObject } from '@kubernetes/client-node'; import { CronJob, CronTime } from 'cron'; import { CoalescingQueue } from '@morten-olsen/box-utils/coalescing-queue'; -import { FINALIZER } from '@morten-olsen/box-utils/consts'; +// import { FINALIZER } from '@morten-olsen/box-utils/consts'; import { NotReadyError } from '../../errors/errors.js'; - -import { Resource, type ResourceOptions } from './resource.js'; import { K8sConfig } from '../../config/config.js'; import type { ResourceClass } from '../resources.service.js'; +import { Resource, type ResourceOptions } from './resource.js'; + const customResourceStatusSchema = z.object({ observedGeneration: z.number().optional(), conditions: z diff --git a/packages/k8s/src/resources/resource/resource.ts b/packages/k8s/src/resources/resource/resource.ts index f8d09e6..00218d2 100644 --- a/packages/k8s/src/resources/resource/resource.ts +++ b/packages/k8s/src/resources/resource/resource.ts @@ -1,4 +1,4 @@ -import { ApiException, KubernetesObjectApi, PatchStrategy, type KubernetesObject } from '@kubernetes/client-node'; +import { ApiException, PatchStrategy, type KubernetesObject } from '@kubernetes/client-node'; import deepEqual from 'deep-equal'; import type { Services } from '@morten-olsen/box-utils/services'; import { EventEmitter } from '@morten-olsen/box-utils/event-emitter'; diff --git a/packages/k8s/src/resources/resources.service.ts b/packages/k8s/src/resources/resources.service.ts index c29972b..f185ac2 100644 --- a/packages/k8s/src/resources/resources.service.ts +++ b/packages/k8s/src/resources/resources.service.ts @@ -1,4 +1,4 @@ -import { ApiException, ApiextensionsV1Api, type KubernetesObject } from '@kubernetes/client-node'; +import { ApiException, type KubernetesObject } from '@kubernetes/client-node'; import type { ZodType } from 'zod'; import { EventEmitter } from '@morten-olsen/box-utils/event-emitter'; import type { Services } from '@morten-olsen/box-utils/services'; @@ -58,7 +58,7 @@ class ResourceService extends EventEmitter { resources: [], }); if ('dependsOn' in resource && Array.isArray(resource.dependsOn)) { - await this.register(...resource.dependsOn as ResourceClass[]); + await this.register(...(resource.dependsOn as ResourceClass[])); } const watcherService = this.#services.get(WatcherService); const watcher = watcherService.create({ diff --git a/packages/resource-authentik/src/resources/server/server.ts b/packages/resource-authentik/src/resources/server/server.ts index 5f7480f..0f4509c 100644 --- a/packages/resource-authentik/src/resources/server/server.ts +++ b/packages/resource-authentik/src/resources/server/server.ts @@ -31,7 +31,7 @@ class AuthentikServer extends CustomResource { ); throw new NotReadyError(); } - const { secret } = this.#secret.value; + // const { secret } = this.#secret.value; }; } diff --git a/packages/resource-cloudflare/src/resources/account/account.ts b/packages/resource-cloudflare/src/resources/account/account.ts index 1854748..b20c345 100644 --- a/packages/resource-cloudflare/src/resources/account/account.ts +++ b/packages/resource-cloudflare/src/resources/account/account.ts @@ -1,12 +1,19 @@ -import { CustomResource, NotReadyError, ResourceReference, Secret, type CustomResourceOptions } from "@morten-olsen/box-k8s"; -import { cloudflareAccountSchema } from "./account.schemas.js"; -import { API_VERSION } from "@morten-olsen/box-utils/consts"; +import { + CustomResource, + NotReadyError, + ResourceReference, + Secret, + type CustomResourceOptions, +} from '@morten-olsen/box-k8s'; +import { API_VERSION } from '@morten-olsen/box-utils/consts'; + +import { cloudflareAccountSchema } from './account.schemas.js'; class CloudflareAccountResource extends CustomResource { public static readonly apiVersion = API_VERSION; - public static readonly kind = "CloudflareAccount"; + public static readonly kind = 'CloudflareAccount'; public static readonly spec = cloudflareAccountSchema; - public static readonly scope = "Cluster"; + public static readonly scope = 'Cluster'; public static readonly dependsOn = [Secret]; #secret: ResourceReference; @@ -30,19 +37,15 @@ class CloudflareAccountResource extends CustomResource { this.#secret.current = this.#getSecret(); if (!this.token) { throw new NotReadyError('Token not found'); } - } + }; } export { CloudflareAccountResource }; diff --git a/packages/resource-cloudflare/src/resources/dns-record/dns-record.ts b/packages/resource-cloudflare/src/resources/dns-record/dns-record.ts index af506bd..a03421e 100644 --- a/packages/resource-cloudflare/src/resources/dns-record/dns-record.ts +++ b/packages/resource-cloudflare/src/resources/dns-record/dns-record.ts @@ -1,20 +1,20 @@ import { CustomResource, NotReadyError } from '@morten-olsen/box-k8s'; +import { API_VERSION } from '@morten-olsen/box-utils/consts'; import { CloudflareService } from '../../services/cloudflare/cloudflare.js'; +// import { CloudflareAccountResource } from '../account/account.js'; import { cloudflareDnsRecordSchema } from './dns-record.schemas.js'; -import { API_VERSION } from '@morten-olsen/box-utils/consts'; -import { CloudflareAccountResource } from '../account/account.js'; class CloudflareDnsRecordResource extends CustomResource { public static readonly apiVersion = API_VERSION; - public static readonly kind = "CloudflareDnsRecord"; + public static readonly kind = 'CloudflareDnsRecord'; public static readonly spec = cloudflareDnsRecordSchema; - public static readonly scope = "Namespaced"; - public static readonly dependsOn = [CloudflareAccountResource]; + public static readonly scope = 'Namespaced'; + // public static readonly dependsOn = [CloudflareAccountResource]; public get dnsId() { - return `homelab|${this.namespace}|${this.name}` + return `homelab|${this.namespace}|${this.name}`; } public reconcile = async () => { @@ -22,19 +22,18 @@ class CloudflareDnsRecordResource extends CustomResource { - if (!this.spec) { throw new NotReadyError('Missing spec'); } const service = this.services.get(CloudflareService); const { removeDnsRecord } = service.getAccount(this.spec.account); await removeDnsRecord(this.dnsId, this.spec.domain); - } + }; } export { CloudflareDnsRecordResource, cloudflareDnsRecordSchema }; diff --git a/packages/resource-cloudflare/src/services/cloudflare/cloudflare.account.ts b/packages/resource-cloudflare/src/services/cloudflare/cloudflare.account.ts index 40c9a02..8321297 100644 --- a/packages/resource-cloudflare/src/services/cloudflare/cloudflare.account.ts +++ b/packages/resource-cloudflare/src/services/cloudflare/cloudflare.account.ts @@ -1,19 +1,20 @@ -import type { Services } from "@morten-olsen/box-utils/services"; -import type { CloudflareAccountResource } from "../../resources/account/account.js" +import type { Services } from '@morten-olsen/box-utils/services'; import API from 'cloudflare'; -import type { Zone } from "cloudflare/resources/zones/zones.mjs"; -import type { z } from "@morten-olsen/box-k8s"; -import type { cloudflareDnsRecordSchema } from "../../resources/dns-record/dns-record.schemas.js"; +import type { Zone } from 'cloudflare/resources/zones/zones.mjs'; +import type { z } from '@morten-olsen/box-k8s'; + +import type { CloudflareAccountResource } from '../../resources/account/account.js'; +import type { cloudflareDnsRecordSchema } from '../../resources/dns-record/dns-record.schemas.js'; type CloudflareAccountOptions = { services: Services; resource: CloudflareAccountResource; -} +}; class CloudflareAccount { #options: CloudflareAccountOptions; #api?: API; - #zones: Map> + #zones: Map>; constructor(options: CloudflareAccountOptions) { this.#zones = new Map(); @@ -31,7 +32,7 @@ class CloudflareAccount { if (!this.#api) { this.#api = new API({ apiToken: this.token, - }) + }); } return this.#api; } @@ -39,10 +40,10 @@ class CloudflareAccount { #getZone = async (name: string) => { const zones = await this.api.zones.list({ name, - }) + }); const [zone] = zones.result; return zone; - } + }; public getZone = async (name: string) => { if (!this.#zones.has(name)) { @@ -50,7 +51,7 @@ class CloudflareAccount { } const current = this.#zones.get(name); return await current; - } + }; public getDnsRecord = async (id: string, domain: string) => { const zone = await this.getZone(domain); @@ -64,11 +65,11 @@ class CloudflareAccount { comment: { exact: id, }, - }) + }); const [dnsRecord] = dnsRecords.result; return dnsRecord; - } + }; public removeDnsRecord = async (id: string, domain: string) => { const zone = await this.getZone(domain); @@ -83,7 +84,7 @@ class CloudflareAccount { await this.api.dns.records.delete(record.id, { zone_id: zone.id, }); - } + }; public ensrureDnsRecord = async (id: string, options: z.infer) => { const { domain, subdomain, value, type, ttl = 1, proxy } = options; @@ -102,9 +103,8 @@ class CloudflareAccount { comment: id, ttl, proxied: proxy, - }) + }); } else { - await this.api.dns.records.update(current.id, { zone_id: zone.id, type, @@ -113,9 +113,9 @@ class CloudflareAccount { comment: id, ttl, proxied: proxy, - }) + }); } - } + }; } export { CloudflareAccount }; diff --git a/packages/resource-cloudflare/src/services/cloudflare/cloudflare.ts b/packages/resource-cloudflare/src/services/cloudflare/cloudflare.ts index 756e7a4..7a4f81e 100644 --- a/packages/resource-cloudflare/src/services/cloudflare/cloudflare.ts +++ b/packages/resource-cloudflare/src/services/cloudflare/cloudflare.ts @@ -1,7 +1,9 @@ -import type { Services } from "@morten-olsen/box-utils/services"; -import { CloudflareAccount } from "./cloudflare.account.js"; -import { ResourceService } from "@morten-olsen/box-k8s"; -import { CloudflareAccountResource } from "../../resources/account/account.js"; +import type { Services } from '@morten-olsen/box-utils/services'; +import { ResourceService } from '@morten-olsen/box-k8s'; + +import { CloudflareAccountResource } from '../../resources/account/account.js'; + +import { CloudflareAccount } from './cloudflare.account.js'; class CloudflareService { #services: Services; @@ -16,17 +18,20 @@ class CloudflareService { if (!this.#instances.has(name)) { const resourceService = this.#services.get(ResourceService); const resource = resourceService.get(CloudflareAccountResource, name); - this.#instances.set(name, new CloudflareAccount({ - resource, - services: this.#services, - })) + this.#instances.set( + name, + new CloudflareAccount({ + resource, + services: this.#services, + }), + ); } const current = this.#instances.get(name); if (!current) { throw new Error('Could not get cloudflare account'); } return current; - } + }; } export { CloudflareService }; diff --git a/packages/resource-cloudflare/src/start.ts b/packages/resource-cloudflare/src/start.ts index 77b7adb..277ed34 100644 --- a/packages/resource-cloudflare/src/start.ts +++ b/packages/resource-cloudflare/src/start.ts @@ -1,13 +1,8 @@ import { K8sOperator } from '@morten-olsen/box-k8s'; + import { CloudflareAccountResource } from './resources/account/account.js'; import { CloudflareDnsRecordResource } from './resources/dns-record/dns-record.js'; const operator = new K8sOperator(); -await operator.resources.install( - CloudflareAccountResource, - CloudflareDnsRecordResource, -) -await operator.resources.register( - CloudflareAccountResource, - CloudflareDnsRecordResource, -) +await operator.resources.install(CloudflareAccountResource, CloudflareDnsRecordResource); +await operator.resources.register(CloudflareAccountResource, CloudflareDnsRecordResource);