Skip to content

Commit ff8ec79

Browse files
authored
Merge pull request #2302 from brendandburns/erasable
Revisions needed for no non-erasable types
2 parents a282df5 + 24c6144 commit ff8ec79

File tree

8 files changed

+111
-50
lines changed

8 files changed

+111
-50
lines changed

src/cache.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,23 @@ export class ListWatch<T extends KubernetesObject> implements ObjectCache<T>, In
3030
private readonly callbackCache: { [key: string]: (ObjectCallback<T> | ErrorCallback)[] } = {};
3131
private request: AbortController | undefined;
3232
private stopped: boolean = false;
33+
private readonly path: string;
34+
private readonly watch: Watch;
35+
private readonly listFn: ListPromise<T>;
36+
private readonly labelSelector?: string;
3337

3438
public constructor(
35-
private readonly path: string,
36-
private readonly watch: Watch,
37-
private readonly listFn: ListPromise<T>,
39+
path: string,
40+
watch: Watch,
41+
listFn: ListPromise<T>,
3842
autoStart: boolean = true,
39-
private readonly labelSelector?: string,
43+
labelSelector?: string,
4044
) {
45+
this.path = path;
46+
this.watch = watch;
47+
this.listFn = listFn;
48+
this.labelSelector = labelSelector;
49+
4150
this.callbackCache[ADD] = [];
4251
this.callbackCache[UPDATE] = [];
4352
this.callbackCache[DELETE] = [];

src/config_types.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import fs from 'node:fs';
22

3-
export enum ActionOnInvalid {
4-
THROW = 'throw',
5-
FILTER = 'filter',
6-
}
3+
export const ActionOnInvalid = {
4+
THROW: 'throw',
5+
FILTER: 'filter',
6+
} as const;
7+
8+
export type ActionOnInvalid = (typeof ActionOnInvalid)[keyof typeof ActionOnInvalid];
79

810
export interface ConfigOptions {
911
onInvalidEntry: ActionOnInvalid;

src/object.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,10 @@ export class KubernetesObjectApi {
5959
/** Cache resource API response. */
6060
protected apiVersionResourceCache: Record<string, V1APIResourceList> = {};
6161

62-
constructor(protected configuration: Configuration) {}
62+
protected configuration: Configuration;
63+
constructor(configuration: Configuration) {
64+
this.configuration = configuration;
65+
}
6366

6467
/**
6568
* Create any Kubernetes resource.

src/oidc_auth.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ interface Client {
2222
}
2323

2424
class OidcClient implements Client {
25-
public constructor(readonly config: oidc.Configuration) {}
25+
readonly config: oidc.Configuration;
26+
public constructor(c: oidc.Configuration) {
27+
this.config = c;
28+
}
2629

2730
public async refresh(token: string): Promise<Token> {
2831
const newToken = await oidc.refreshTokenGrant(this.config, token);

src/patch.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@
66
* Additionally for Server-Side Apply https://kubernetes.io/docs/reference/using-api/server-side-apply/
77
* and https://kubernetes.io/docs/reference/using-api/server-side-apply/#api-implementation
88
*/
9-
export enum PatchStrategy {
9+
export const PatchStrategy = {
1010
/** Diff-like JSON format. */
11-
JsonPatch = 'application/json-patch+json',
11+
JsonPatch: 'application/json-patch+json',
1212
/** Simple merge. */
13-
MergePatch = 'application/merge-patch+json',
13+
MergePatch: 'application/merge-patch+json',
1414
/** Merge with different strategies depending on field metadata. */
15-
StrategicMergePatch = 'application/strategic-merge-patch+json',
15+
StrategicMergePatch: 'application/strategic-merge-patch+json',
1616
/** Server-Side Apply */
17-
ServerSideApply = 'application/apply-patch+yaml',
18-
}
17+
ServerSideApply: 'application/apply-patch+yaml',
18+
} as const;
19+
20+
export type PatchStrategy = (typeof PatchStrategy)[keyof typeof PatchStrategy];

src/top.ts

Lines changed: 51 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,44 +11,70 @@ import {
1111
} from './util.js';
1212

1313
export class ResourceUsage {
14-
constructor(
15-
public readonly Capacity: number | bigint,
16-
public readonly RequestTotal: number | bigint,
17-
public readonly LimitTotal: number | bigint,
18-
) {}
14+
public readonly Capacity: number | bigint;
15+
public readonly RequestTotal: number | bigint;
16+
public readonly LimitTotal: number | bigint;
17+
18+
constructor(Capacity: number | bigint, RequestTotal: number | bigint, LimitTotal: number | bigint) {
19+
this.Capacity = Capacity;
20+
this.RequestTotal = RequestTotal;
21+
this.LimitTotal = LimitTotal;
22+
}
1923
}
2024

2125
export class CurrentResourceUsage {
22-
constructor(
23-
public readonly CurrentUsage: number | bigint,
24-
public readonly RequestTotal: number | bigint,
25-
public readonly LimitTotal: number | bigint,
26-
) {}
26+
public readonly CurrentUsage: number | bigint;
27+
public readonly RequestTotal: number | bigint;
28+
public readonly LimitTotal: number | bigint;
29+
30+
constructor(CurrentUsage: number | bigint, RequestTotal: number | bigint, LimitTotal: number | bigint) {
31+
this.CurrentUsage = CurrentUsage;
32+
this.RequestTotal = RequestTotal;
33+
this.LimitTotal = LimitTotal;
34+
}
2735
}
2836

2937
export class NodeStatus {
30-
constructor(
31-
public readonly Node: V1Node,
32-
public readonly CPU: ResourceUsage,
33-
public readonly Memory: ResourceUsage,
34-
) {}
38+
public readonly Node: V1Node;
39+
public readonly CPU: ResourceUsage;
40+
public readonly Memory: ResourceUsage;
41+
42+
constructor(Node: V1Node, CPU: ResourceUsage, Memory: ResourceUsage) {
43+
this.Node = Node;
44+
this.CPU = CPU;
45+
this.Memory = Memory;
46+
}
3547
}
3648

3749
export class ContainerStatus {
38-
constructor(
39-
public readonly Container: string,
40-
public readonly CPUUsage: CurrentResourceUsage,
41-
public readonly MemoryUsage: CurrentResourceUsage,
42-
) {}
50+
public readonly Container: string;
51+
public readonly CPUUsage: CurrentResourceUsage;
52+
public readonly MemoryUsage: CurrentResourceUsage;
53+
54+
constructor(Container: string, CPUUsage: CurrentResourceUsage, MemoryUsage: CurrentResourceUsage) {
55+
this.Container = Container;
56+
this.CPUUsage = CPUUsage;
57+
this.MemoryUsage = MemoryUsage;
58+
}
4359
}
4460

4561
export class PodStatus {
62+
public readonly Pod: V1Pod;
63+
public readonly CPU: CurrentResourceUsage;
64+
public readonly Memory: CurrentResourceUsage;
65+
public readonly Containers: ContainerStatus[];
66+
4667
constructor(
47-
public readonly Pod: V1Pod,
48-
public readonly CPU: CurrentResourceUsage,
49-
public readonly Memory: CurrentResourceUsage,
50-
public readonly Containers: ContainerStatus[],
51-
) {}
68+
Pod: V1Pod,
69+
CPU: CurrentResourceUsage,
70+
Memory: CurrentResourceUsage,
71+
Containers: ContainerStatus[],
72+
) {
73+
this.Pod = Pod;
74+
this.CPU = CPU;
75+
this.Memory = Memory;
76+
this.Containers = Containers;
77+
}
5278
}
5379

5480
export async function topNodes(api: CoreV1Api): Promise<NodeStatus[]> {

src/util.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,15 @@ export function quantityToScalar(quantity: string): number | bigint {
8686
}
8787

8888
export class ResourceStatus {
89-
constructor(
90-
public readonly request: bigint | number,
91-
public readonly limit: bigint | number,
92-
public readonly resourceType: string,
93-
) {}
89+
public readonly request: bigint | number;
90+
public readonly limit: bigint | number;
91+
public readonly resourceType: string;
92+
93+
constructor(request: bigint | number, limit: bigint | number, resourceType: string) {
94+
this.request = request;
95+
this.limit = limit;
96+
this.resourceType = resourceType;
97+
}
9498
}
9599

96100
export function totalCPUForContainer(container: V1Container): ResourceStatus {

src/web-socket-handler.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,20 +174,32 @@ export class WebSocketHandler implements WebSocketInterface {
174174
return () => ws;
175175
}
176176

177+
readonly config: KubeConfig;
178+
readonly socketFactory?: (
179+
uri: string,
180+
protocols: string[],
181+
opts: WebSocket.ClientOptions,
182+
) => WebSocket.WebSocket;
183+
readonly streams: StreamInterface;
184+
177185
// factory is really just for test injection
178186
public constructor(
179-
readonly config: KubeConfig,
180-
readonly socketFactory?: (
187+
kc: KubeConfig,
188+
socketFactoryFn?: (
181189
uri: string,
182190
protocols: string[],
183191
opts: WebSocket.ClientOptions,
184192
) => WebSocket.WebSocket,
185-
readonly streams: StreamInterface = {
193+
streamsInterface: StreamInterface = {
186194
stdin: process.stdin,
187195
stdout: process.stdout,
188196
stderr: process.stderr,
189197
},
190-
) {}
198+
) {
199+
this.config = kc;
200+
this.socketFactory = socketFactoryFn;
201+
this.streams = streamsInterface;
202+
}
191203

192204
/**
193205
* Connect to a web socket endpoint.

0 commit comments

Comments
 (0)