diff --git a/src/cache.ts b/src/cache.ts index 2ee8c4f80c..af5e5bc852 100644 --- a/src/cache.ts +++ b/src/cache.ts @@ -30,14 +30,23 @@ export class ListWatch implements ObjectCache, In private readonly callbackCache: { [key: string]: (ObjectCallback | ErrorCallback)[] } = {}; private request: AbortController | undefined; private stopped: boolean = false; + private readonly path: string; + private readonly watch: Watch; + private readonly listFn: ListPromise; + private readonly labelSelector?: string; public constructor( - private readonly path: string, - private readonly watch: Watch, - private readonly listFn: ListPromise, + path: string, + watch: Watch, + listFn: ListPromise, autoStart: boolean = true, - private readonly labelSelector?: string, + labelSelector?: string, ) { + this.path = path; + this.watch = watch; + this.listFn = listFn; + this.labelSelector = labelSelector; + this.callbackCache[ADD] = []; this.callbackCache[UPDATE] = []; this.callbackCache[DELETE] = []; diff --git a/src/config_types.ts b/src/config_types.ts index f628e1ad68..eed9e1b052 100644 --- a/src/config_types.ts +++ b/src/config_types.ts @@ -1,9 +1,11 @@ import fs from 'node:fs'; -export enum ActionOnInvalid { - THROW = 'throw', - FILTER = 'filter', -} +export const ActionOnInvalid = { + THROW: 'throw', + FILTER: 'filter', +} as const; + +export type ActionOnInvalid = (typeof ActionOnInvalid)[keyof typeof ActionOnInvalid]; export interface ConfigOptions { onInvalidEntry: ActionOnInvalid; diff --git a/src/object.ts b/src/object.ts index 958aaef5a5..52c98a7dec 100644 --- a/src/object.ts +++ b/src/object.ts @@ -59,7 +59,10 @@ export class KubernetesObjectApi { /** Cache resource API response. */ protected apiVersionResourceCache: Record = {}; - constructor(protected configuration: Configuration) {} + protected configuration: Configuration; + constructor(configuration: Configuration) { + this.configuration = configuration; + } /** * Create any Kubernetes resource. diff --git a/src/oidc_auth.ts b/src/oidc_auth.ts index 09f28a16ea..af5e0c1311 100644 --- a/src/oidc_auth.ts +++ b/src/oidc_auth.ts @@ -22,7 +22,10 @@ interface Client { } class OidcClient implements Client { - public constructor(readonly config: oidc.Configuration) {} + readonly config: oidc.Configuration; + public constructor(c: oidc.Configuration) { + this.config = c; + } public async refresh(token: string): Promise { const newToken = await oidc.refreshTokenGrant(this.config, token); diff --git a/src/patch.ts b/src/patch.ts index a4ff6de180..74c3d76297 100644 --- a/src/patch.ts +++ b/src/patch.ts @@ -6,13 +6,15 @@ * Additionally for Server-Side Apply https://kubernetes.io/docs/reference/using-api/server-side-apply/ * and https://kubernetes.io/docs/reference/using-api/server-side-apply/#api-implementation */ -export enum PatchStrategy { +export const PatchStrategy = { /** Diff-like JSON format. */ - JsonPatch = 'application/json-patch+json', + JsonPatch: 'application/json-patch+json', /** Simple merge. */ - MergePatch = 'application/merge-patch+json', + MergePatch: 'application/merge-patch+json', /** Merge with different strategies depending on field metadata. */ - StrategicMergePatch = 'application/strategic-merge-patch+json', + StrategicMergePatch: 'application/strategic-merge-patch+json', /** Server-Side Apply */ - ServerSideApply = 'application/apply-patch+yaml', -} + ServerSideApply: 'application/apply-patch+yaml', +} as const; + +export type PatchStrategy = (typeof PatchStrategy)[keyof typeof PatchStrategy]; diff --git a/src/top.ts b/src/top.ts index f88ad18195..aea8b292d8 100644 --- a/src/top.ts +++ b/src/top.ts @@ -11,44 +11,70 @@ import { } from './util.js'; export class ResourceUsage { - constructor( - public readonly Capacity: number | bigint, - public readonly RequestTotal: number | bigint, - public readonly LimitTotal: number | bigint, - ) {} + public readonly Capacity: number | bigint; + public readonly RequestTotal: number | bigint; + public readonly LimitTotal: number | bigint; + + constructor(Capacity: number | bigint, RequestTotal: number | bigint, LimitTotal: number | bigint) { + this.Capacity = Capacity; + this.RequestTotal = RequestTotal; + this.LimitTotal = LimitTotal; + } } export class CurrentResourceUsage { - constructor( - public readonly CurrentUsage: number | bigint, - public readonly RequestTotal: number | bigint, - public readonly LimitTotal: number | bigint, - ) {} + public readonly CurrentUsage: number | bigint; + public readonly RequestTotal: number | bigint; + public readonly LimitTotal: number | bigint; + + constructor(CurrentUsage: number | bigint, RequestTotal: number | bigint, LimitTotal: number | bigint) { + this.CurrentUsage = CurrentUsage; + this.RequestTotal = RequestTotal; + this.LimitTotal = LimitTotal; + } } export class NodeStatus { - constructor( - public readonly Node: V1Node, - public readonly CPU: ResourceUsage, - public readonly Memory: ResourceUsage, - ) {} + public readonly Node: V1Node; + public readonly CPU: ResourceUsage; + public readonly Memory: ResourceUsage; + + constructor(Node: V1Node, CPU: ResourceUsage, Memory: ResourceUsage) { + this.Node = Node; + this.CPU = CPU; + this.Memory = Memory; + } } export class ContainerStatus { - constructor( - public readonly Container: string, - public readonly CPUUsage: CurrentResourceUsage, - public readonly MemoryUsage: CurrentResourceUsage, - ) {} + public readonly Container: string; + public readonly CPUUsage: CurrentResourceUsage; + public readonly MemoryUsage: CurrentResourceUsage; + + constructor(Container: string, CPUUsage: CurrentResourceUsage, MemoryUsage: CurrentResourceUsage) { + this.Container = Container; + this.CPUUsage = CPUUsage; + this.MemoryUsage = MemoryUsage; + } } export class PodStatus { + public readonly Pod: V1Pod; + public readonly CPU: CurrentResourceUsage; + public readonly Memory: CurrentResourceUsage; + public readonly Containers: ContainerStatus[]; + constructor( - public readonly Pod: V1Pod, - public readonly CPU: CurrentResourceUsage, - public readonly Memory: CurrentResourceUsage, - public readonly Containers: ContainerStatus[], - ) {} + Pod: V1Pod, + CPU: CurrentResourceUsage, + Memory: CurrentResourceUsage, + Containers: ContainerStatus[], + ) { + this.Pod = Pod; + this.CPU = CPU; + this.Memory = Memory; + this.Containers = Containers; + } } export async function topNodes(api: CoreV1Api): Promise { diff --git a/src/util.ts b/src/util.ts index 9477223b9f..791d89c728 100644 --- a/src/util.ts +++ b/src/util.ts @@ -86,11 +86,15 @@ export function quantityToScalar(quantity: string): number | bigint { } export class ResourceStatus { - constructor( - public readonly request: bigint | number, - public readonly limit: bigint | number, - public readonly resourceType: string, - ) {} + public readonly request: bigint | number; + public readonly limit: bigint | number; + public readonly resourceType: string; + + constructor(request: bigint | number, limit: bigint | number, resourceType: string) { + this.request = request; + this.limit = limit; + this.resourceType = resourceType; + } } export function totalCPUForContainer(container: V1Container): ResourceStatus { diff --git a/src/web-socket-handler.ts b/src/web-socket-handler.ts index 5959201155..d0abf6bab1 100644 --- a/src/web-socket-handler.ts +++ b/src/web-socket-handler.ts @@ -174,20 +174,32 @@ export class WebSocketHandler implements WebSocketInterface { return () => ws; } + readonly config: KubeConfig; + readonly socketFactory?: ( + uri: string, + protocols: string[], + opts: WebSocket.ClientOptions, + ) => WebSocket.WebSocket; + readonly streams: StreamInterface; + // factory is really just for test injection public constructor( - readonly config: KubeConfig, - readonly socketFactory?: ( + kc: KubeConfig, + socketFactoryFn?: ( uri: string, protocols: string[], opts: WebSocket.ClientOptions, ) => WebSocket.WebSocket, - readonly streams: StreamInterface = { + streamsInterface: StreamInterface = { stdin: process.stdin, stdout: process.stdout, stderr: process.stderr, }, - ) {} + ) { + this.config = kc; + this.socketFactory = socketFactoryFn; + this.streams = streamsInterface; + } /** * Connect to a web socket endpoint.