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