kubernetes-fluent-client 1.5.0 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/dist/cli.d.ts +3 -0
  2. package/dist/cli.d.ts.map +1 -0
  3. package/dist/cli.js +39 -0
  4. package/dist/fetch.d.ts +1 -1
  5. package/dist/fetch.js +2 -2
  6. package/dist/fetch.test.js +1 -1
  7. package/dist/fluent/apply.js +1 -1
  8. package/dist/fluent/index.d.ts +1 -0
  9. package/dist/fluent/index.d.ts.map +1 -1
  10. package/dist/fluent/index.js +45 -3
  11. package/dist/fluent/types.d.ts +33 -21
  12. package/dist/fluent/types.d.ts.map +1 -1
  13. package/dist/fluent/types.js +1 -1
  14. package/dist/fluent/utils.d.ts +18 -7
  15. package/dist/fluent/utils.d.ts.map +1 -1
  16. package/dist/fluent/utils.js +19 -8
  17. package/dist/fluent/utils.test.js +1 -1
  18. package/dist/fluent/watch.d.ts +9 -2
  19. package/dist/fluent/watch.d.ts.map +1 -1
  20. package/dist/fluent/watch.js +19 -2
  21. package/dist/generate.d.ts +19 -0
  22. package/dist/generate.d.ts.map +1 -0
  23. package/dist/generate.js +165 -0
  24. package/dist/generate.test.d.ts +2 -0
  25. package/dist/generate.test.d.ts.map +1 -0
  26. package/dist/generate.test.js +256 -0
  27. package/dist/index.d.ts +1 -0
  28. package/dist/index.d.ts.map +1 -1
  29. package/dist/index.js +4 -1
  30. package/dist/kinds.d.ts +6 -0
  31. package/dist/kinds.d.ts.map +1 -1
  32. package/dist/kinds.js +53 -0
  33. package/dist/types.d.ts +1 -1
  34. package/dist/types.d.ts.map +1 -1
  35. package/package.json +13 -7
  36. package/src/cli.ts +44 -0
  37. package/src/fetch.test.ts +1 -1
  38. package/src/fetch.ts +2 -2
  39. package/src/fluent/apply.ts +1 -1
  40. package/src/fluent/index.ts +46 -4
  41. package/src/fluent/types.ts +34 -22
  42. package/src/fluent/utils.test.ts +1 -1
  43. package/src/fluent/utils.ts +19 -8
  44. package/src/fluent/watch.ts +22 -4
  45. package/src/generate.test.ts +266 -0
  46. package/src/generate.ts +189 -0
  47. package/src/index.ts +3 -0
  48. package/src/kinds.ts +53 -0
  49. package/src/types.ts +1 -1
@@ -0,0 +1,189 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // SPDX-FileCopyrightText: 2023-Present The Kubernetes Fluent Client Authors
3
+
4
+ import { loadAllYaml } from "@kubernetes/client-node";
5
+ import * as fs from "fs";
6
+ import * as path from "path";
7
+ import {
8
+ FetchingJSONSchemaStore,
9
+ InputData,
10
+ JSONSchemaInput,
11
+ TargetLanguage,
12
+ quicktype,
13
+ } from "quicktype-core";
14
+
15
+ import { fetch } from "./fetch";
16
+ import { K8s } from "./fluent";
17
+ import { CustomResourceDefinition } from "./upstream";
18
+
19
+ export interface GenerateOptions {
20
+ /** The source URL, yaml file path or K8s CRD name */
21
+ source: string;
22
+ /** The output directory path */
23
+ directory?: string;
24
+ /** Disable kubernetes-fluent-client wrapping */
25
+ plain?: boolean;
26
+ /** The language to generate types in */
27
+ language?: string | TargetLanguage;
28
+ }
29
+
30
+ /**
31
+ * Converts a CustomResourceDefinition to TypeScript types
32
+ *
33
+ * @param crd The CustomResourceDefinition to convert
34
+ * @param opts The options to use when converting
35
+ * @returns A promise that resolves when the CustomResourceDefinition has been converted
36
+ */
37
+ async function convertCRDtoTS(
38
+ crd: CustomResourceDefinition,
39
+ opts: GenerateOptions,
40
+ ): Promise<Record<string, string[]>> {
41
+ // Get the name of the kind
42
+ const name = crd.spec.names.kind;
43
+
44
+ const results: Record<string, string[]> = {};
45
+
46
+ for (const match of crd.spec.versions) {
47
+ // Get the schema from the matched version
48
+ const schema = JSON.stringify(match?.schema?.openAPIV3Schema);
49
+
50
+ // Create a new JSONSchemaInput
51
+ const schemaInput = new JSONSchemaInput(new FetchingJSONSchemaStore());
52
+
53
+ // Add the schema to the input
54
+ await schemaInput.addSource({ name, schema });
55
+
56
+ // Create a new InputData object
57
+ const inputData = new InputData();
58
+ inputData.addInput(schemaInput);
59
+
60
+ // Generate the types
61
+ const out = await quicktype({
62
+ inputData,
63
+ lang: opts.language || "ts",
64
+ rendererOptions: { "just-types": "true" },
65
+ });
66
+
67
+ let processedLines = out.lines;
68
+
69
+ // If using typescript, remove the line containing `[property: string]: any;`
70
+ if (opts.language === "ts" || opts.language === "typescript") {
71
+ processedLines = out.lines.filter(line => !line.includes("[property: string]: any;"));
72
+ }
73
+
74
+ // If the language is TypeScript and plain is not specified, wire up the fluent client
75
+ if (opts.language === "ts" && !opts.plain) {
76
+ processedLines.unshift(
77
+ // Add warning that the file is auto-generated
78
+ `// This file is auto-generated by kubernetes-fluent-client, do not edit manually\n`,
79
+ // Add the imports before any other lines
80
+ `import { GenericKind, RegisterKind } from "kubernetes-fluent-client";\n`,
81
+ );
82
+
83
+ // Replace the interface with a named class that extends GenericKind
84
+ const entryIdx = processedLines.findIndex(line =>
85
+ line.includes(`export interface ${name} {`),
86
+ );
87
+
88
+ // Replace the interface with a named class that extends GenericKind
89
+ processedLines[entryIdx] = `export class ${name} extends GenericKind {`;
90
+
91
+ // Add the RegisterKind call
92
+ processedLines.push(`RegisterKind(${name}, {`);
93
+ processedLines.push(` group: "${crd.spec.group}",`);
94
+ processedLines.push(` version: "${match.name}",`);
95
+ processedLines.push(` kind: "${name}",`);
96
+ processedLines.push(`});`);
97
+ }
98
+
99
+ const finalContents = processedLines.join("\n");
100
+ const fileName = `${name.toLowerCase()}-${match.name.toLowerCase()}`;
101
+
102
+ // If an output file is specified, write the output to the file
103
+ if (opts.directory) {
104
+ // Create the directory if it doesn't exist
105
+ fs.mkdirSync(opts.directory, { recursive: true });
106
+
107
+ // Write the file
108
+ const filePath = path.join(opts.directory, `${fileName}.${opts.language}`);
109
+ fs.writeFileSync(filePath, finalContents);
110
+ }
111
+
112
+ // Add the results to the array
113
+ results[fileName] = processedLines;
114
+ }
115
+
116
+ return results;
117
+ }
118
+
119
+ /**
120
+ * Reads a CustomResourceDefinition from a file, the cluster or the internet
121
+ *
122
+ * @param source The source to read from (file path, cluster or URL)
123
+ * @returns A promise that resolves when the CustomResourceDefinition has been read
124
+ */
125
+ async function readOrFetchCrd(source: string): Promise<CustomResourceDefinition[]> {
126
+ const filePath = path.join(process.cwd(), source);
127
+
128
+ // First try to read the source as a file
129
+ try {
130
+ if (fs.existsSync(filePath)) {
131
+ const payload = fs.readFileSync(filePath, "utf8");
132
+ return loadAllYaml(payload) as CustomResourceDefinition[];
133
+ }
134
+ } catch (e) {
135
+ // Ignore errors
136
+ }
137
+
138
+ // Next try to parse the source as a URL
139
+ try {
140
+ const url = new URL(source);
141
+
142
+ // If the source is a URL, fetch it
143
+ if (url.protocol === "http:" || url.protocol === "https:") {
144
+ const { ok, data } = await fetch<string>(source);
145
+
146
+ // If the request failed, throw an error
147
+ if (!ok) {
148
+ throw new Error(`Failed to fetch ${source}: ${data}`);
149
+ }
150
+
151
+ return loadAllYaml(data) as CustomResourceDefinition[];
152
+ }
153
+ } catch (e) {
154
+ // Ignore errors
155
+ }
156
+
157
+ // Finally, if the source is not a file or URL, try to read it as a CustomResourceDefinition from the cluster
158
+ try {
159
+ return [await K8s(CustomResourceDefinition).Get(source)];
160
+ } catch (e) {
161
+ throw new Error(`Failed to read ${source} as a file, url or K8s CRD: ${e}`);
162
+ }
163
+ }
164
+
165
+ /**
166
+ * Generate TypeScript types from a K8s CRD
167
+ *
168
+ * @param opts The options to use when generating
169
+ * @returns A promise that resolves when the TypeScript types have been generated
170
+ */
171
+ export async function generate(opts: GenerateOptions) {
172
+ const crds = await readOrFetchCrd(opts.source);
173
+ const results: Record<string, string[]> = {};
174
+
175
+ for (const crd of crds) {
176
+ if (!crd || crd.kind !== "CustomResourceDefinition" || !crd.spec?.versions?.length) {
177
+ // Ignore empty and non-CRD objects
178
+ continue;
179
+ }
180
+
181
+ // Add the results to the record
182
+ const out = await convertCRDtoTS(crd, opts);
183
+ for (const key of Object.keys(out)) {
184
+ results[key] = out[key];
185
+ }
186
+ }
187
+
188
+ return results;
189
+ }
package/src/index.ts CHANGED
@@ -19,6 +19,9 @@ export { K8s } from "./fluent";
19
19
  // Export helpers for working with K8s types
20
20
  export { RegisterKind, modelToGroupVersionKind } from "./kinds";
21
21
 
22
+ // Export the GenericKind interface for CRD registration
23
+ export { GenericKind } from "./types";
24
+
22
25
  export * from "./types";
23
26
 
24
27
  export * as K8sClientNode from "@kubernetes/client-node";
package/src/kinds.ts CHANGED
@@ -10,6 +10,7 @@ const gvkMap: Record<string, GroupVersionKind> = {
10
10
  * Events have a limited retention time and triggers and messages may evolve with time. Event consumers should not
11
11
  * rely on the timing of an event with a given Reason reflecting a consistent underlying trigger, or the continued
12
12
  * existence of events with that Reason. Events should be treated as informative, best-effort, supplemental data.
13
+ *
13
14
  * @see {@link https://kubernetes.io/docs/reference/kubernetes-api/cluster-resources/event-v1/}
14
15
  */
15
16
  CoreV1Event: {
@@ -21,6 +22,7 @@ const gvkMap: Record<string, GroupVersionKind> = {
21
22
  /**
22
23
  * Represents a K8s ClusterRole resource.
23
24
  * ClusterRole is a set of permissions that can be bound to a user or group in a cluster-wide scope.
25
+ *
24
26
  * @see {@link https://kubernetes.io/docs/reference/access-authn-authz/rbac/#role-and-clusterrole}
25
27
  */
26
28
  V1ClusterRole: {
@@ -31,6 +33,7 @@ const gvkMap: Record<string, GroupVersionKind> = {
31
33
  /**
32
34
  * Represents a K8s ClusterRoleBinding resource.
33
35
  * ClusterRoleBinding binds a ClusterRole to a user or group in a cluster-wide scope.
36
+ *
34
37
  * @see {@link https://kubernetes.io/docs/reference/access-authn-authz/rbac/#rolebinding-and-clusterrolebinding}
35
38
  */
36
39
  V1ClusterRoleBinding: {
@@ -41,6 +44,7 @@ const gvkMap: Record<string, GroupVersionKind> = {
41
44
  /**
42
45
  * Represents a K8s Role resource.
43
46
  * Role is a set of permissions that can be bound to a user or group in a namespace scope.
47
+ *
44
48
  * @see {@link https://kubernetes.io/docs/reference/access-authn-authz/rbac/#role-and-clusterrole}
45
49
  */
46
50
  V1Role: {
@@ -51,6 +55,7 @@ const gvkMap: Record<string, GroupVersionKind> = {
51
55
  /**
52
56
  * Represents a K8s RoleBinding resource.
53
57
  * RoleBinding binds a Role to a user or group in a namespace scope.
58
+ *
54
59
  * @see {@link https://kubernetes.io/docs/reference/access-authn-authz/rbac/#rolebinding-and-clusterrolebinding}
55
60
  */
56
61
  V1RoleBinding: {
@@ -61,6 +66,7 @@ const gvkMap: Record<string, GroupVersionKind> = {
61
66
  /**
62
67
  * Represents a K8s ConfigMap resource.
63
68
  * ConfigMap holds configuration data for pods to consume.
69
+ *
64
70
  * @see {@link https://kubernetes.io/docs/concepts/configuration/configmap/}
65
71
  */
66
72
  V1ConfigMap: {
@@ -72,6 +78,7 @@ const gvkMap: Record<string, GroupVersionKind> = {
72
78
  /**
73
79
  * Represents a K8s Endpoints resource.
74
80
  * Endpoints expose a service's IP addresses and ports to other resources.
81
+ *
75
82
  * @see {@link https://kubernetes.io/docs/concepts/services-networking/service/#endpoints}
76
83
  */
77
84
  V1Endpoint: {
@@ -84,6 +91,7 @@ const gvkMap: Record<string, GroupVersionKind> = {
84
91
  /**
85
92
  * Represents a K8s LimitRange resource.
86
93
  * LimitRange enforces constraints on the resource consumption of objects in a namespace.
94
+ *
87
95
  * @see {@link https://kubernetes.io/docs/concepts/policy/limit-range/}
88
96
  */
89
97
  V1LimitRange: {
@@ -95,6 +103,7 @@ const gvkMap: Record<string, GroupVersionKind> = {
95
103
  /**
96
104
  * Represents a K8s Namespace resource.
97
105
  * Namespace is a way to divide cluster resources between multiple users.
106
+ *
98
107
  * @see {@link https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/}
99
108
  */
100
109
  V1Namespace: {
@@ -106,6 +115,7 @@ const gvkMap: Record<string, GroupVersionKind> = {
106
115
  /**
107
116
  * Represents a K8s Node resource.
108
117
  * Node is a worker machine in Kubernetes.
118
+ *
109
119
  * @see {@link https://kubernetes.io/docs/concepts/architecture/nodes/}
110
120
  */
111
121
  V1Node: {
@@ -117,6 +127,7 @@ const gvkMap: Record<string, GroupVersionKind> = {
117
127
  /**
118
128
  * Represents a K8s PersistentVolumeClaim resource.
119
129
  * PersistentVolumeClaim is a user's request for and claim to a persistent volume.
130
+ *
120
131
  * @see {@link https://kubernetes.io/docs/concepts/storage/persistent-volumes/#persistentvolumeclaims}
121
132
  */
122
133
  V1PersistentVolumeClaim: {
@@ -128,6 +139,7 @@ const gvkMap: Record<string, GroupVersionKind> = {
128
139
  /**
129
140
  * Represents a K8s PersistentVolume resource.
130
141
  * PersistentVolume is a piece of storage in the cluster that has been provisioned by an administrator.
142
+ *
131
143
  * @see {@link https://kubernetes.io/docs/concepts/storage/persistent-volumes/}
132
144
  */
133
145
  V1PersistentVolume: {
@@ -139,6 +151,7 @@ const gvkMap: Record<string, GroupVersionKind> = {
139
151
  /**
140
152
  * Represents a K8s Pod resource.
141
153
  * Pod is the smallest and simplest unit in the Kubernetes object model.
154
+ *
142
155
  * @see {@link https://kubernetes.io/docs/concepts/workloads/pods/}
143
156
  */
144
157
  V1Pod: {
@@ -149,6 +162,7 @@ const gvkMap: Record<string, GroupVersionKind> = {
149
162
  /**
150
163
  * Represents a K8s PodTemplate resource.
151
164
  * PodTemplate is an object that describes the pod that will be created from a higher level abstraction.
165
+ *
152
166
  * @see {@link https://kubernetes.io/docs/concepts/workloads/controllers/#pod-template}
153
167
  */
154
168
  V1PodTemplate: {
@@ -160,6 +174,7 @@ const gvkMap: Record<string, GroupVersionKind> = {
160
174
  /**
161
175
  * Represents a K8s ReplicationController resource.
162
176
  * ReplicationController ensures that a specified number of pod replicas are running at any given time.
177
+ *
163
178
  * @see {@link https://kubernetes.io/docs/concepts/workloads/controllers/replicationcontroller/}
164
179
  */
165
180
  V1ReplicationController: {
@@ -171,6 +186,7 @@ const gvkMap: Record<string, GroupVersionKind> = {
171
186
  /**
172
187
  * Represents a K8s ResourceQuota resource.
173
188
  * ResourceQuota provides constraints that limit resource consumption per namespace.
189
+ *
174
190
  * @see {@link https://kubernetes.io/docs/concepts/policy/resource-quotas/}
175
191
  */
176
192
  V1ResourceQuota: {
@@ -182,6 +198,7 @@ const gvkMap: Record<string, GroupVersionKind> = {
182
198
  /**
183
199
  * Represents a K8s Secret resource.
184
200
  * Secret holds secret data of a certain type.
201
+ *
185
202
  * @see {@link https://kubernetes.io/docs/concepts/configuration/secret/}
186
203
  */
187
204
  V1Secret: {
@@ -193,6 +210,7 @@ const gvkMap: Record<string, GroupVersionKind> = {
193
210
  /**
194
211
  * Represents a K8s ServiceAccount resource.
195
212
  * ServiceAccount is an identity that processes in a pod can use to access the Kubernetes API.
213
+ *
196
214
  * @see {@link https://kubernetes.io/docs/tasks/configure-pod-container/configure-service-account/}
197
215
  */
198
216
  V1ServiceAccount: {
@@ -204,6 +222,7 @@ const gvkMap: Record<string, GroupVersionKind> = {
204
222
  /**
205
223
  * Represents a K8s Service resource.
206
224
  * Service is an abstraction which defines a logical set of Pods and a policy by which to access them.
225
+ *
207
226
  * @see {@link https://kubernetes.io/docs/concepts/services-networking/service/}
208
227
  */
209
228
  V1Service: {
@@ -215,6 +234,7 @@ const gvkMap: Record<string, GroupVersionKind> = {
215
234
  /**
216
235
  * Represents a K8s MutatingWebhookConfiguration resource.
217
236
  * MutatingWebhookConfiguration configures a mutating admission webhook.
237
+ *
218
238
  * @see {@link https://kubernetes.io/docs/reference/access-authn-authz/extensible-admission-controllers/#configure-admission-webhooks-on-the-fly}
219
239
  */
220
240
  V1MutatingWebhookConfiguration: {
@@ -226,6 +246,7 @@ const gvkMap: Record<string, GroupVersionKind> = {
226
246
  /**
227
247
  * Represents a K8s ValidatingWebhookConfiguration resource.
228
248
  * ValidatingWebhookConfiguration configures a validating admission webhook.
249
+ *
229
250
  * @see {@link https://kubernetes.io/docs/reference/access-authn-authz/extensible-admission-controllers/#configure-admission-webhooks-on-the-fly}
230
251
  */
231
252
  V1ValidatingWebhookConfiguration: {
@@ -236,6 +257,7 @@ const gvkMap: Record<string, GroupVersionKind> = {
236
257
  /**
237
258
  * Represents a K8s CustomResourceDefinition resource.
238
259
  * CustomResourceDefinition is a custom resource in a Kubernetes cluster.
260
+ *
239
261
  * @see {@link https://kubernetes.io/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions/}
240
262
  */
241
263
  V1CustomResourceDefinition: {
@@ -247,6 +269,7 @@ const gvkMap: Record<string, GroupVersionKind> = {
247
269
  /**
248
270
  * Represents a K8s APIService resource.
249
271
  * APIService represents a server for a particular API version and group.
272
+ *
250
273
  * @see {@link https://kubernetes.io/docs/tasks/access-kubernetes-api/setup-extension-api-server/}
251
274
  */
252
275
  V1APIService: {
@@ -258,6 +281,7 @@ const gvkMap: Record<string, GroupVersionKind> = {
258
281
  /**
259
282
  * Represents a K8s ControllerRevision resource.
260
283
  * ControllerRevision is used to manage the history of a StatefulSet or DaemonSet.
284
+ *
261
285
  * @see {@link https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/#revision-history}
262
286
  */
263
287
  V1ControllerRevision: {
@@ -269,6 +293,7 @@ const gvkMap: Record<string, GroupVersionKind> = {
269
293
  /**
270
294
  * Represents a K8s DaemonSet resource.
271
295
  * DaemonSet ensures that all (or some) nodes run a copy of a Pod.
296
+ *
272
297
  * @see {@link https://kubernetes.io/docs/concepts/workloads/controllers/daemonset/}
273
298
  */
274
299
  V1DaemonSet: {
@@ -280,6 +305,7 @@ const gvkMap: Record<string, GroupVersionKind> = {
280
305
  /**
281
306
  * Represents a K8s Deployment resource.
282
307
  * Deployment provides declarative updates for Pods and ReplicaSets.
308
+ *
283
309
  * @see {@link https://kubernetes.io/docs/concepts/workloads/controllers/deployment/}
284
310
  */
285
311
  V1Deployment: {
@@ -291,6 +317,7 @@ const gvkMap: Record<string, GroupVersionKind> = {
291
317
  /**
292
318
  * Represents a K8s ReplicaSet resource.
293
319
  * ReplicaSet ensures that a specified number of pod replicas are running at any given time.
320
+ *
294
321
  * @see {@link https://kubernetes.io/docs/concepts/workloads/controllers/replicaset/}
295
322
  */
296
323
  V1ReplicaSet: {
@@ -302,6 +329,7 @@ const gvkMap: Record<string, GroupVersionKind> = {
302
329
  /**
303
330
  * Represents a K8s StatefulSet resource.
304
331
  * StatefulSet is used to manage stateful applications.
332
+ *
305
333
  * @see {@link https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/}
306
334
  */
307
335
  V1StatefulSet: {
@@ -313,6 +341,7 @@ const gvkMap: Record<string, GroupVersionKind> = {
313
341
  /**
314
342
  * Represents a K8s TokenReview resource.
315
343
  * TokenReview attempts to authenticate a token to a known user.
344
+ *
316
345
  * @see {@link https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.20/#tokenreview-v1-authentication-k8s-io}
317
346
  */
318
347
  V1TokenReview: {
@@ -324,6 +353,7 @@ const gvkMap: Record<string, GroupVersionKind> = {
324
353
  /**
325
354
  * Represents a K8s LocalSubjectAccessReview resource.
326
355
  * LocalSubjectAccessReview checks whether a specific user can perform a specific action in a specific namespace.
356
+ *
327
357
  * @see {@link https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.20/#localsubjectaccessreview-v1-authorization-k8s-io}
328
358
  */
329
359
  V1LocalSubjectAccessReview: {
@@ -335,6 +365,7 @@ const gvkMap: Record<string, GroupVersionKind> = {
335
365
  /**
336
366
  * Represents a K8s SelfSubjectAccessReview resource.
337
367
  * SelfSubjectAccessReview checks whether the current user can perform a specific action.
368
+ *
338
369
  * @see {@link https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.20/#selfsubjectaccessreview-v1-authorization-k8s-io}
339
370
  */
340
371
  V1SelfSubjectAccessReview: {
@@ -346,6 +377,7 @@ const gvkMap: Record<string, GroupVersionKind> = {
346
377
  /**
347
378
  * Represents a K8s SelfSubjectRulesReview resource.
348
379
  * SelfSubjectRulesReview lists the permissions a specific user has within a namespace.
380
+ *
349
381
  * @see {@link https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.20/#selfsubjectrulesreview-v1-authorization-k8s-io}
350
382
  */
351
383
  V1SelfSubjectRulesReview: {
@@ -357,6 +389,7 @@ const gvkMap: Record<string, GroupVersionKind> = {
357
389
  /**
358
390
  * Represents a K8s SubjectAccessReview resource.
359
391
  * SubjectAccessReview checks whether a specific user can perform a specific action.
392
+ *
360
393
  * @see {@link https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.20/#subjectaccessreview-v1-authorization-k8s-io}
361
394
  */
362
395
  V1SubjectAccessReview: {
@@ -368,6 +401,7 @@ const gvkMap: Record<string, GroupVersionKind> = {
368
401
  /**
369
402
  * Represents a K8s HorizontalPodAutoscaler resource.
370
403
  * HorizontalPodAutoscaler automatically scales the number of Pods in a replication controller, deployment, or replica set.
404
+ *
371
405
  * @see {@link https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/}
372
406
  */
373
407
  V1HorizontalPodAutoscaler: {
@@ -379,6 +413,7 @@ const gvkMap: Record<string, GroupVersionKind> = {
379
413
  /**
380
414
  * Represents a K8s CronJob resource.
381
415
  * CronJob manages time-based jobs, specifically those that run periodically and complete after a successful execution.
416
+ *
382
417
  * @see {@link https://kubernetes.io/docs/concepts/workloads/controllers/cron-jobs/}
383
418
  */
384
419
  V1CronJob: {
@@ -390,6 +425,7 @@ const gvkMap: Record<string, GroupVersionKind> = {
390
425
  /**
391
426
  * Represents a K8s Job resource.
392
427
  * Job represents the configuration of a single job.
428
+ *
393
429
  * @see {@link https://kubernetes.io/docs/concepts/workloads/controllers/job/}
394
430
  */
395
431
  V1Job: {
@@ -401,6 +437,7 @@ const gvkMap: Record<string, GroupVersionKind> = {
401
437
  /**
402
438
  * Represents a K8s CertificateSigningRequest resource.
403
439
  * CertificateSigningRequest represents a certificate signing request.
440
+ *
404
441
  * @see {@link https://kubernetes.io/docs/reference/access-authn-authz/certificate-signing-requests/}
405
442
  */
406
443
  V1CertificateSigningRequest: {
@@ -412,6 +449,7 @@ const gvkMap: Record<string, GroupVersionKind> = {
412
449
  /**
413
450
  * Represents a K8s EndpointSlice resource.
414
451
  * EndpointSlice represents a scalable set of network endpoints for a Kubernetes Service.
452
+ *
415
453
  * @see {@link https://kubernetes.io/docs/concepts/services-networking/endpoint-slices/}
416
454
  */
417
455
  V1EndpointSlice: {
@@ -423,6 +461,7 @@ const gvkMap: Record<string, GroupVersionKind> = {
423
461
  /**
424
462
  * Represents a K8s IngressClass resource.
425
463
  * IngressClass represents the class of the Ingress, referenced by the Ingress spec.
464
+ *
426
465
  * @see {@link https://kubernetes.io/docs/concepts/services-networking/ingress/}
427
466
  */
428
467
  V1IngressClass: {
@@ -434,6 +473,7 @@ const gvkMap: Record<string, GroupVersionKind> = {
434
473
  /**
435
474
  * Represents a K8s Ingress resource.
436
475
  * Ingress exposes HTTP and HTTPS routes from outside the cluster to services within the cluster.
476
+ *
437
477
  * @see {@link https://kubernetes.io/docs/concepts/services-networking/ingress/}
438
478
  */
439
479
  V1Ingress: {
@@ -446,6 +486,7 @@ const gvkMap: Record<string, GroupVersionKind> = {
446
486
  /**
447
487
  * Represents a K8s NetworkPolicy resource.
448
488
  * NetworkPolicy defines a set of rules for how pods communicate with each other.
489
+ *
449
490
  * @see {@link https://kubernetes.io/docs/concepts/services-networking/network-policies/}
450
491
  */
451
492
  V1NetworkPolicy: {
@@ -457,6 +498,7 @@ const gvkMap: Record<string, GroupVersionKind> = {
457
498
  /**
458
499
  * Represents a K8s RuntimeClass resource.
459
500
  * RuntimeClass is a cluster-scoped resource that surfaces container runtime properties to the control plane.
501
+ *
460
502
  * @see {@link https://kubernetes.io/docs/concepts/containers/runtime-class/}
461
503
  */
462
504
  V1RuntimeClass: {
@@ -468,6 +510,7 @@ const gvkMap: Record<string, GroupVersionKind> = {
468
510
  /**
469
511
  * Represents a K8s PodDisruptionBudget resource.
470
512
  * PodDisruptionBudget is an API object that limits the number of pods of a replicated application that are down simultaneously.
513
+ *
471
514
  * @see {@link https://kubernetes.io/docs/concepts/workloads/pods/disruptions/}
472
515
  */
473
516
  V1PodDisruptionBudget: {
@@ -479,6 +522,7 @@ const gvkMap: Record<string, GroupVersionKind> = {
479
522
  /**
480
523
  * Represents a K8s VolumeAttachment resource.
481
524
  * VolumeAttachment captures the intent to attach or detach the specified volume to/from the specified node.
525
+ *
482
526
  * @see {@link https://kubernetes.io/docs/concepts/storage/storage-classes/}
483
527
  */
484
528
  V1VolumeAttachment: {
@@ -490,6 +534,7 @@ const gvkMap: Record<string, GroupVersionKind> = {
490
534
  /**
491
535
  * Represents a K8s CSIDriver resource.
492
536
  * CSIDriver captures information about a Container Storage Interface (CSI) volume driver.
537
+ *
493
538
  * @see {@link https://kubernetes.io/docs/concepts/storage/volumes/}
494
539
  */
495
540
  V1CSIDriver: {
@@ -501,6 +546,7 @@ const gvkMap: Record<string, GroupVersionKind> = {
501
546
  /**
502
547
  * Represents a K8s CSIStorageCapacity resource.
503
548
  * CSIStorageCapacity stores the reported storage capacity of a CSI node or storage class.
549
+ *
504
550
  * @see {@link https://kubernetes.io/docs/concepts/storage/csi/}
505
551
  */
506
552
  V1CSIStorageCapacity: {
@@ -512,6 +558,7 @@ const gvkMap: Record<string, GroupVersionKind> = {
512
558
  /**
513
559
  * Represents a K8s StorageClass resource.
514
560
  * StorageClass is a cluster-scoped resource that provides a way for administrators to describe the classes of storage they offer.
561
+ *
515
562
  * @see {@link https://kubernetes.io/docs/concepts/storage/storage-classes/}
516
563
  */
517
564
  V1StorageClass: {
@@ -521,6 +568,12 @@ const gvkMap: Record<string, GroupVersionKind> = {
521
568
  },
522
569
  };
523
570
 
571
+ /**
572
+ * Converts a model name to a GroupVersionKind
573
+ *
574
+ * @param key The name of the model
575
+ * @returns The GroupVersionKind for the model
576
+ */
524
577
  export function modelToGroupVersionKind(key: string): GroupVersionKind {
525
578
  return gvkMap[key];
526
579
  }
package/src/types.ts CHANGED
@@ -24,7 +24,7 @@ export class GenericKind implements KubernetesObject {
24
24
  /**
25
25
  * GroupVersionKind unambiguously identifies a kind. It doesn't anonymously include GroupVersion
26
26
  * to avoid automatic coercion. It doesn't use a GroupVersion to avoid custom marshalling
27
- **/
27
+ */
28
28
  export interface GroupVersionKind {
29
29
  /** The K8s resource kind, e..g "Pod". */
30
30
  readonly kind: string;