@highstate/k8s 0.9.18 → 0.9.19

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 (93) hide show
  1. package/dist/chunk-2EEHJZPD.js +13 -0
  2. package/dist/chunk-2EEHJZPD.js.map +1 -0
  3. package/dist/{chunk-OFFSHGC6.js → chunk-4JGXGN2L.js} +66 -48
  4. package/dist/chunk-4JGXGN2L.js.map +1 -0
  5. package/dist/chunk-A3XGSDIW.js +306 -0
  6. package/dist/chunk-A3XGSDIW.js.map +1 -0
  7. package/dist/chunk-IMTXUK2U.js +244 -0
  8. package/dist/chunk-IMTXUK2U.js.map +1 -0
  9. package/dist/chunk-JYNXQ3I3.js +287 -0
  10. package/dist/chunk-JYNXQ3I3.js.map +1 -0
  11. package/dist/{chunk-5C2BJGES.js → chunk-KDD6XUWM.js} +30 -23
  12. package/dist/chunk-KDD6XUWM.js.map +1 -0
  13. package/dist/chunk-NOFJC3EM.js +236 -0
  14. package/dist/chunk-NOFJC3EM.js.map +1 -0
  15. package/dist/chunk-NXSYCA3V.js +337 -0
  16. package/dist/chunk-NXSYCA3V.js.map +1 -0
  17. package/dist/chunk-SBC3TUIN.js +1513 -0
  18. package/dist/chunk-SBC3TUIN.js.map +1 -0
  19. package/dist/chunk-SI7X6N46.js +338 -0
  20. package/dist/chunk-SI7X6N46.js.map +1 -0
  21. package/dist/chunk-WGMJCZSK.js +360 -0
  22. package/dist/chunk-WGMJCZSK.js.map +1 -0
  23. package/dist/deployment-752P6JIT.js +8 -0
  24. package/dist/{deployment-XK3CDJOE.js.map → deployment-752P6JIT.js.map} +1 -1
  25. package/dist/highstate.manifest.json +8 -7
  26. package/dist/impl/gateway-route.js +123 -0
  27. package/dist/impl/gateway-route.js.map +1 -0
  28. package/dist/impl/tls-certificate.js +32 -0
  29. package/dist/impl/tls-certificate.js.map +1 -0
  30. package/dist/index.js +736 -208
  31. package/dist/index.js.map +1 -1
  32. package/dist/stateful-set-N64YVKR7.js +8 -0
  33. package/dist/{stateful-set-7CAQWTV2.js.map → stateful-set-N64YVKR7.js.map} +1 -1
  34. package/dist/units/cert-manager/index.js +11 -10
  35. package/dist/units/cert-manager/index.js.map +1 -1
  36. package/dist/units/dns01-issuer/index.js +27 -23
  37. package/dist/units/dns01-issuer/index.js.map +1 -1
  38. package/dist/units/existing-cluster/index.js +11 -8
  39. package/dist/units/existing-cluster/index.js.map +1 -1
  40. package/dist/units/gateway-api/index.js +2 -2
  41. package/dist/units/gateway-api/index.js.map +1 -1
  42. package/package.json +39 -13
  43. package/src/cluster.ts +30 -22
  44. package/src/config-map.ts +195 -57
  45. package/src/container.ts +5 -5
  46. package/src/cron-job.ts +403 -31
  47. package/src/deployment.ts +260 -120
  48. package/src/dns01-solver.ts +10 -0
  49. package/src/gateway/backend.ts +2 -2
  50. package/src/gateway/gateway.ts +383 -0
  51. package/src/gateway/http-route.ts +17 -24
  52. package/src/gateway/index.ts +1 -0
  53. package/src/helm.ts +83 -53
  54. package/src/impl/gateway-route.ts +155 -0
  55. package/src/impl/tls-certificate.ts +33 -0
  56. package/src/index.ts +22 -67
  57. package/src/job.ts +393 -28
  58. package/src/namespace.ts +236 -99
  59. package/src/network-policy.ts +216 -165
  60. package/src/network.ts +2 -2
  61. package/src/pvc.ts +266 -65
  62. package/src/rbac.ts +218 -0
  63. package/src/scripting/bundle.ts +9 -20
  64. package/src/scripting/container.ts +1 -1
  65. package/src/scripting/environment.ts +5 -5
  66. package/src/secret.ts +200 -62
  67. package/src/service.ts +288 -158
  68. package/src/shared.ts +94 -67
  69. package/src/stateful-set.ts +270 -117
  70. package/src/tls.ts +344 -0
  71. package/src/units/cert-manager/index.ts +2 -3
  72. package/src/units/dns01-issuer/index.ts +30 -14
  73. package/src/units/existing-cluster/index.ts +10 -7
  74. package/src/units/gateway-api/index.ts +2 -2
  75. package/src/worker.ts +26 -0
  76. package/src/workload.ts +275 -171
  77. package/dist/chunk-5C2BJGES.js.map +0 -1
  78. package/dist/chunk-5TLC5BXR.js +0 -256
  79. package/dist/chunk-5TLC5BXR.js.map +0 -1
  80. package/dist/chunk-BBIY3KUN.js +0 -1557
  81. package/dist/chunk-BBIY3KUN.js.map +0 -1
  82. package/dist/chunk-OFFSHGC6.js.map +0 -1
  83. package/dist/chunk-TZHOUJRC.js +0 -202
  84. package/dist/chunk-TZHOUJRC.js.map +0 -1
  85. package/dist/chunk-YWRJ4EZM.js +0 -192
  86. package/dist/chunk-YWRJ4EZM.js.map +0 -1
  87. package/dist/deployment-XK3CDJOE.js +0 -6
  88. package/dist/stateful-set-7CAQWTV2.js +0 -6
  89. package/dist/units/access-point/index.js +0 -21
  90. package/dist/units/access-point/index.js.map +0 -1
  91. package/src/access-point.ts +0 -191
  92. package/src/units/access-point/index.ts +0 -19
  93. package/src/units/dns01-issuer/solver.ts +0 -23
package/src/job.ts CHANGED
@@ -1,55 +1,420 @@
1
+ import type { k8s } from "@highstate/library"
2
+ import type { Container } from "./container"
3
+ import type { NetworkPolicy } from "./network-policy"
4
+ import { getOrCreate, type UnitTerminal } from "@highstate/contract"
5
+ import {
6
+ type ComponentResourceOptions,
7
+ type Input,
8
+ type Inputs,
9
+ interpolate,
10
+ type Output,
11
+ output,
12
+ toPromise,
13
+ type Unwrap,
14
+ } from "@highstate/pulumi"
1
15
  import { batch, type types } from "@pulumi/kubernetes"
2
- import { ComponentResource, Output, output, type ComponentResourceOptions } from "@highstate/pulumi"
3
- import { mergeDeep, omit } from "remeda"
4
- import { commonExtraArgs, getProvider, mapMetadata } from "./shared"
5
- import { getWorkloadComponents, type WorkloadArgs } from "./workload"
16
+ import { deepmerge } from "deepmerge-ts"
17
+ import { omit } from "remeda"
18
+ import { Namespace } from "./namespace"
19
+ import { commonExtraArgs, getProvider, mapMetadata, type ScopedResourceArgs } from "./shared"
20
+ import {
21
+ getWorkloadComponents,
22
+ Workload,
23
+ type WorkloadArgs,
24
+ type WorkloadTerminalArgs,
25
+ } from "./workload"
6
26
 
7
- export type JobArgs = WorkloadArgs &
27
+ export type JobArgs = ScopedResourceArgs &
8
28
  Omit<Partial<types.input.batch.v1.JobSpec>, "template"> & {
9
29
  template?: {
10
30
  metadata?: types.input.meta.v1.ObjectMeta
11
31
  spec?: Partial<types.input.core.v1.PodSpec>
12
32
  }
33
+ } & WorkloadArgs
34
+
35
+ export type CreateOrGetJobArgs = JobArgs & {
36
+ /**
37
+ * The job entity to patch/retrieve.
38
+ */
39
+ existing: Input<k8s.ScopedResource> | undefined
40
+ }
41
+
42
+ /**
43
+ * Represents a Kubernetes Job resource with metadata and spec.
44
+ */
45
+ export abstract class Job extends Workload {
46
+ protected constructor(
47
+ type: string,
48
+ name: string,
49
+ args: Inputs,
50
+ opts: ComponentResourceOptions | undefined,
51
+
52
+ apiVersion: Output<string>,
53
+ kind: Output<string>,
54
+ terminalArgs: Output<Unwrap<WorkloadTerminalArgs>>,
55
+ containers: Output<Container[]>,
56
+ namespace: Output<Namespace>,
57
+ metadata: Output<types.output.meta.v1.ObjectMeta>,
58
+ networkPolicy: Output<NetworkPolicy | undefined>,
59
+
60
+ /**
61
+ * The spec of the underlying Kubernetes job.
62
+ */
63
+ readonly spec: Output<types.output.batch.v1.JobSpec>,
64
+
65
+ /**
66
+ * The status of the underlying Kubernetes job.
67
+ */
68
+ readonly status: Output<types.output.batch.v1.JobStatus>,
69
+ ) {
70
+ super(
71
+ type,
72
+ name,
73
+ args,
74
+ opts,
75
+ apiVersion,
76
+ kind,
77
+ terminalArgs,
78
+ containers,
79
+ namespace,
80
+ metadata,
81
+ networkPolicy,
82
+ )
13
83
  }
14
84
 
15
- const jobExtraArgs = [...commonExtraArgs, "container", "containers"] as const
85
+ /**
86
+ * The Highstate job entity.
87
+ */
88
+ get entity(): Output<k8s.ScopedResource> {
89
+ return output({
90
+ type: "job",
91
+ clusterId: this.cluster.id,
92
+ clusterName: this.cluster.name,
93
+ metadata: this.metadata,
94
+ })
95
+ }
96
+
97
+ protected getTerminalMeta(): Output<UnitTerminal["meta"]> {
98
+ return output({
99
+ title: "Job",
100
+ globalTitle: interpolate`Job | ${this.metadata.name}`,
101
+ description: "The shell inside the job.",
102
+ icon: "devicon:kubernetes",
103
+ })
104
+ }
105
+
106
+ protected get resourceType(): string {
107
+ return "job"
108
+ }
16
109
 
17
- export class Job extends ComponentResource {
18
110
  /**
19
- * The underlying Kubernetes job.
111
+ * Creates a new job.
20
112
  */
21
- public readonly job: Output<batch.v1.Job>
113
+ static create(name: string, args: JobArgs, opts?: ComponentResourceOptions): Job {
114
+ return new CreatedJob(name, args, opts)
115
+ }
22
116
 
23
- constructor(name: string, args: JobArgs, opts: ComponentResourceOptions) {
24
- super("highstate:k8s:Job", name, args, opts)
117
+ /**
118
+ * Creates a new job or patches an existing one.
119
+ *
120
+ * @param name The name of the resource. May not be the same as the job name.
121
+ * @param args The arguments to create or patch the job with.
122
+ * @param opts Optional resource options.
123
+ */
124
+ static createOrPatch(
125
+ name: string,
126
+ args: CreateOrGetJobArgs,
127
+ opts?: ComponentResourceOptions,
128
+ ): Job {
129
+ if (args.existing) {
130
+ return new JobPatch(name, {
131
+ ...args,
132
+ name: output(args.existing).metadata.name,
133
+ namespace: Namespace.forResourceAsync(args.existing, output(args.namespace).cluster),
134
+ })
135
+ }
136
+
137
+ return new CreatedJob(name, args, opts)
138
+ }
25
139
 
26
- const { podTemplate } = getWorkloadComponents(name, args, () => this, opts)
140
+ /**
141
+ * Creates a new job or gets an existing one.
142
+ *
143
+ * @param name The name of the resource. May not be the same as the job name. Will not be used when existing job is retrieved.
144
+ * @param args The arguments to create or get the job with.
145
+ * @param opts Optional resource options.
146
+ */
147
+ static async createOrGet(
148
+ name: string,
149
+ args: CreateOrGetJobArgs,
150
+ opts?: ComponentResourceOptions,
151
+ ): Promise<Job> {
152
+ if (args.existing) {
153
+ return await Job.forAsync(args.existing, output(args.namespace).cluster)
154
+ }
155
+
156
+ return new CreatedJob(name, args, opts)
157
+ }
158
+
159
+ /**
160
+ * Patches an existing job.
161
+ *
162
+ * Will throw an error if the job does not exist.
163
+ *
164
+ * @param name The name of the resource. May not be the same as the job name.
165
+ * @param args The arguments to patch the job with.
166
+ * @param opts Optional resource options.
167
+ */
168
+ static patch(name: string, args: JobArgs, opts?: ComponentResourceOptions): Job {
169
+ return new JobPatch(name, args, opts)
170
+ }
171
+
172
+ /**
173
+ * Wraps an existing Kubernetes job.
174
+ */
175
+ static wrap(name: string, args: WrappedJobArgs, opts?: ComponentResourceOptions): Job {
176
+ return new WrappedJob(name, args, opts)
177
+ }
178
+
179
+ /**
180
+ * Gets an existing job.
181
+ *
182
+ * Will throw an error if the job does not exist.
183
+ */
184
+ static get(name: string, args: ExternalJobArgs, opts?: ComponentResourceOptions): Job {
185
+ return new ExternalJob(name, args, opts)
186
+ }
187
+
188
+ private static readonly jobCache = new Map<string, Job>()
189
+
190
+ /**
191
+ * Gets an existing job for a given entity.
192
+ * Prefer this method over `get` when possible.
193
+ *
194
+ * It automatically names the resource with the following format: `{clusterName}.{namespace}.{name}.{clusterId}`.
195
+ *
196
+ * This method is idempotent and will return the same instance for the same entity.
197
+ *
198
+ * @param entity The entity to get the job for.
199
+ * @param cluster The cluster where the job is located.
200
+ */
201
+ static for(entity: k8s.ScopedResource, cluster: Input<k8s.Cluster>): Job {
202
+ return getOrCreate(
203
+ Job.jobCache,
204
+ `${entity.clusterName}.${entity.metadata.namespace}.${entity.metadata.name}.${entity.clusterId}`,
205
+ name => {
206
+ return Job.get(name, {
207
+ name: entity.metadata.name,
208
+ namespace: Namespace.forResource(entity, cluster),
209
+ })
210
+ },
211
+ )
212
+ }
213
+
214
+ /**
215
+ * Gets an existing job for a given entity.
216
+ * Prefer this method over `get` when possible.
217
+ *
218
+ * It automatically names the resource with the following format: `{clusterName}.{namespace}.{name}.{clusterId}`.
219
+ *
220
+ * This method is idempotent and will return the same instance for the same entity.
221
+ *
222
+ * @param entity The entity to get the job for.
223
+ * @param cluster The cluster where the job is located.
224
+ */
225
+ static async forAsync(
226
+ entity: Input<k8s.ScopedResource>,
227
+ cluster: Input<k8s.Cluster>,
228
+ ): Promise<Job> {
229
+ const resolvedEntity = await toPromise(entity)
230
+ return Job.for(resolvedEntity, cluster)
231
+ }
232
+ }
27
233
 
28
- this.job = output({ args, podTemplate }).apply(async ({ args, podTemplate }) => {
234
+ const jobExtraArgs = [...commonExtraArgs, "container", "containers"] as const
235
+
236
+ class CreatedJob extends Job {
237
+ constructor(name: string, args: JobArgs, opts?: ComponentResourceOptions) {
238
+ const { podTemplate, containers, networkPolicy } = getWorkloadComponents(
239
+ name,
240
+ args,
241
+ () => this,
242
+ opts,
243
+ )
244
+
245
+ const job = output(args.namespace).cluster.apply(cluster => {
29
246
  return new batch.v1.Job(
30
247
  name,
31
248
  {
32
249
  metadata: mapMetadata(args, name),
33
- spec: mergeDeep(
34
- {
35
- template: mergeDeep(
36
- {
37
- spec: {
38
- restartPolicy: "Never",
250
+ spec: output({ args, podTemplate }).apply(({ args, podTemplate }) => {
251
+ return deepmerge(
252
+ {
253
+ template: deepmerge(
254
+ {
255
+ spec: {
256
+ restartPolicy: "Never",
257
+ },
39
258
  },
40
- },
41
- podTemplate,
42
- ),
43
- } satisfies types.input.batch.v1.JobSpec,
44
- omit(args, jobExtraArgs) as types.input.batch.v1.JobSpec,
45
- ),
259
+ podTemplate,
260
+ ),
261
+ },
262
+ omit(args, jobExtraArgs) as types.input.batch.v1.JobSpec,
263
+ )
264
+ }),
46
265
  },
266
+ { ...opts, parent: this, provider: getProvider(cluster) },
267
+ )
268
+ })
269
+
270
+ super(
271
+ "highstate:k8s:Job",
272
+ name,
273
+ args,
274
+ opts,
275
+
276
+ job.apiVersion,
277
+ job.kind,
278
+ output(args.terminal ?? {}),
279
+ containers,
280
+ output(args.namespace),
281
+ job.metadata,
282
+ networkPolicy,
283
+
284
+ job.spec,
285
+ job.status,
286
+ )
287
+ }
288
+ }
289
+
290
+ class JobPatch extends Job {
291
+ constructor(name: string, args: JobArgs, opts?: ComponentResourceOptions) {
292
+ const { podTemplate, containers, networkPolicy } = getWorkloadComponents(
293
+ name,
294
+ args,
295
+ () => this,
296
+ opts,
297
+ )
298
+
299
+ const job = output(args.namespace).cluster.apply(cluster => {
300
+ return new batch.v1.JobPatch(
301
+ name,
47
302
  {
48
- ...opts,
49
- parent: this,
50
- provider: await getProvider(args.cluster),
303
+ metadata: mapMetadata(args, name),
304
+ spec: output({ args, podTemplate }).apply(({ args, podTemplate }) => {
305
+ return deepmerge(
306
+ { template: podTemplate } satisfies types.input.batch.v1.JobSpec,
307
+ omit(args, jobExtraArgs) as types.input.batch.v1.JobSpec,
308
+ )
309
+ }),
51
310
  },
311
+ { ...opts, parent: this, provider: getProvider(cluster) },
312
+ )
313
+ })
314
+
315
+ super(
316
+ "highstate:k8s:JobPatch",
317
+ name,
318
+ args,
319
+ opts,
320
+
321
+ job.apiVersion,
322
+ job.kind,
323
+ output(args.terminal ?? {}),
324
+ containers,
325
+ output(args.namespace),
326
+ job.metadata,
327
+ networkPolicy,
328
+
329
+ job.spec,
330
+ job.status,
331
+ )
332
+
333
+ this.registerOutputs({
334
+ metadata: this.metadata,
335
+ spec: this.spec,
336
+ status: this.status,
337
+ })
338
+ }
339
+ }
340
+
341
+ export type WrappedJobArgs = {
342
+ /**
343
+ * The underlying Kubernetes job to wrap.
344
+ */
345
+ job: Input<batch.v1.Job>
346
+
347
+ /**
348
+ * The namespace where the job is located.
349
+ */
350
+ namespace: Input<Namespace>
351
+
352
+ /**
353
+ * The args for the terminal to use.
354
+ */
355
+ terminal?: Input<WorkloadTerminalArgs>
356
+ }
357
+
358
+ class WrappedJob extends Job {
359
+ constructor(name: string, args: WrappedJobArgs, opts?: ComponentResourceOptions) {
360
+ super(
361
+ "highstate:k8s:WrappedJob",
362
+ name,
363
+ args,
364
+ opts,
365
+
366
+ output(args.job).apiVersion,
367
+ output(args.job).kind,
368
+ output(args.terminal ?? {}),
369
+ output([]),
370
+ output(args.namespace),
371
+ output(args.job).metadata,
372
+ output(undefined),
373
+
374
+ output(args.job).spec,
375
+ output(args.job).status,
376
+ )
377
+ }
378
+ }
379
+
380
+ export type ExternalJobArgs = {
381
+ /**
382
+ * The name of the job to get.
383
+ */
384
+ name: Input<string>
385
+
386
+ /**
387
+ * The namespace where the job is located.
388
+ */
389
+ namespace: Input<Namespace>
390
+ }
391
+
392
+ class ExternalJob extends Job {
393
+ constructor(name: string, args: ExternalJobArgs, opts?: ComponentResourceOptions) {
394
+ const job = output(args.namespace).cluster.apply(cluster => {
395
+ return batch.v1.Job.get(
396
+ name,
397
+ interpolate`${output(args.namespace).metadata.name}/${args.name}`,
398
+ { ...opts, parent: this, provider: getProvider(cluster) },
52
399
  )
53
400
  })
401
+
402
+ super(
403
+ "highstate:k8s:ExternalJob",
404
+ name,
405
+ args,
406
+ opts,
407
+
408
+ job.apiVersion,
409
+ job.kind,
410
+ output({}),
411
+ output([]),
412
+ output(args.namespace),
413
+ job.metadata,
414
+ output(undefined),
415
+
416
+ job.spec,
417
+ job.status,
418
+ )
54
419
  }
55
420
  }