@highstate/k8s 0.19.1 → 0.21.1

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 (107) hide show
  1. package/dist/chunk-23vn2rdc.js +11 -0
  2. package/dist/chunk-2pfx13ay.js +11 -0
  3. package/dist/chunk-46ntav0c.js +299 -0
  4. package/dist/chunk-556pc9e6.js +155 -0
  5. package/dist/chunk-7kgjgcft.js +170 -0
  6. package/dist/{chunk-LGHFSXNT.js → chunk-9hs97f1q.js} +23 -17
  7. package/dist/chunk-aame3x1b.js +11 -0
  8. package/dist/chunk-b05q6fm2.js +37 -0
  9. package/dist/chunk-bmvc9d2d.js +11 -0
  10. package/dist/chunk-de82bbp2.js +7 -0
  11. package/dist/chunk-facs31cb.js +624 -0
  12. package/dist/chunk-h1b79v66.js +1425 -0
  13. package/dist/chunk-k4w9zpn5.js +215 -0
  14. package/dist/chunk-pqc6w52f.js +352 -0
  15. package/dist/chunk-qyshvz32.js +176 -0
  16. package/dist/chunk-tpfyj6fe.js +199 -0
  17. package/dist/chunk-z6bmpnm7.js +180 -0
  18. package/dist/highstate.manifest.json +3 -2
  19. package/dist/impl/dynamic-endpoint-resolver.js +91 -0
  20. package/dist/impl/gateway-route.js +226 -166
  21. package/dist/impl/tls-certificate.js +31 -31
  22. package/dist/index.js +293 -166
  23. package/dist/units/cert-manager/index.js +19 -14
  24. package/dist/units/cluster-patch/index.js +14 -13
  25. package/dist/units/dns01-issuer/index.js +82 -42
  26. package/dist/units/existing-cluster/index.js +59 -26
  27. package/dist/units/gateway-api/index.js +15 -16
  28. package/dist/units/reduced-access-cluster/index.js +32 -36
  29. package/package.json +23 -21
  30. package/src/cluster.ts +12 -8
  31. package/src/config-map.ts +15 -5
  32. package/src/container.ts +4 -2
  33. package/src/cron-job.ts +51 -5
  34. package/src/deployment.ts +49 -18
  35. package/src/gateway/backend.ts +3 -3
  36. package/src/gateway/gateway.ts +12 -56
  37. package/src/helm.ts +354 -22
  38. package/src/impl/dynamic-endpoint-resolver.ts +109 -0
  39. package/src/impl/gateway-route.ts +231 -57
  40. package/src/impl/tls-certificate.ts +8 -3
  41. package/src/index.ts +1 -0
  42. package/src/job.ts +38 -6
  43. package/src/kubectl.ts +166 -0
  44. package/src/namespace.ts +47 -3
  45. package/src/network-policy.ts +1 -1
  46. package/src/pvc.ts +12 -2
  47. package/src/rbac.ts +28 -5
  48. package/src/scripting/bundle.ts +21 -98
  49. package/src/scripting/environment.ts +4 -10
  50. package/src/secret.ts +15 -5
  51. package/src/service.ts +28 -6
  52. package/src/shared.ts +31 -3
  53. package/src/stateful-set.ts +49 -18
  54. package/src/tls.ts +31 -5
  55. package/src/units/cluster-patch/index.ts +5 -5
  56. package/src/units/dns01-issuer/index.ts +56 -12
  57. package/src/units/existing-cluster/index.ts +36 -15
  58. package/src/units/reduced-access-cluster/index.ts +6 -3
  59. package/src/worker.ts +4 -2
  60. package/src/workload.ts +474 -217
  61. package/LICENSE +0 -21
  62. package/dist/chunk-4G6LLC2X.js +0 -240
  63. package/dist/chunk-4G6LLC2X.js.map +0 -1
  64. package/dist/chunk-BR2CLUUD.js +0 -230
  65. package/dist/chunk-BR2CLUUD.js.map +0 -1
  66. package/dist/chunk-DCUMJSO6.js +0 -427
  67. package/dist/chunk-DCUMJSO6.js.map +0 -1
  68. package/dist/chunk-FE4SHRAJ.js +0 -286
  69. package/dist/chunk-FE4SHRAJ.js.map +0 -1
  70. package/dist/chunk-HH2JJELM.js +0 -13
  71. package/dist/chunk-HH2JJELM.js.map +0 -1
  72. package/dist/chunk-KMLRI5UZ.js +0 -155
  73. package/dist/chunk-KMLRI5UZ.js.map +0 -1
  74. package/dist/chunk-LGHFSXNT.js.map +0 -1
  75. package/dist/chunk-MIC2BHGS.js +0 -301
  76. package/dist/chunk-MIC2BHGS.js.map +0 -1
  77. package/dist/chunk-OBDQONMV.js +0 -401
  78. package/dist/chunk-OBDQONMV.js.map +0 -1
  79. package/dist/chunk-P2VOUU7E.js +0 -1626
  80. package/dist/chunk-P2VOUU7E.js.map +0 -1
  81. package/dist/chunk-PZ5AY32C.js +0 -9
  82. package/dist/chunk-PZ5AY32C.js.map +0 -1
  83. package/dist/chunk-RVB4WWZZ.js +0 -267
  84. package/dist/chunk-RVB4WWZZ.js.map +0 -1
  85. package/dist/chunk-TWBMG6TD.js +0 -315
  86. package/dist/chunk-TWBMG6TD.js.map +0 -1
  87. package/dist/chunk-VCXWCZ43.js +0 -279
  88. package/dist/chunk-VCXWCZ43.js.map +0 -1
  89. package/dist/chunk-YIJUVPU2.js +0 -297
  90. package/dist/chunk-YIJUVPU2.js.map +0 -1
  91. package/dist/cron-job-NX4HD4FI.js +0 -8
  92. package/dist/cron-job-NX4HD4FI.js.map +0 -1
  93. package/dist/deployment-O2LJ5WR5.js +0 -8
  94. package/dist/deployment-O2LJ5WR5.js.map +0 -1
  95. package/dist/impl/gateway-route.js.map +0 -1
  96. package/dist/impl/tls-certificate.js.map +0 -1
  97. package/dist/index.js.map +0 -1
  98. package/dist/job-SYME6Y43.js +0 -8
  99. package/dist/job-SYME6Y43.js.map +0 -1
  100. package/dist/stateful-set-VJYKTQ72.js +0 -8
  101. package/dist/stateful-set-VJYKTQ72.js.map +0 -1
  102. package/dist/units/cert-manager/index.js.map +0 -1
  103. package/dist/units/cluster-patch/index.js.map +0 -1
  104. package/dist/units/dns01-issuer/index.js.map +0 -1
  105. package/dist/units/existing-cluster/index.js.map +0 -1
  106. package/dist/units/gateway-api/index.js.map +0 -1
  107. package/dist/units/reduced-access-cluster/index.js.map +0 -1
package/src/cron-job.ts CHANGED
@@ -1,13 +1,14 @@
1
1
  import type { UnitTerminal } from "@highstate/contract"
2
- import type { k8s } from "@highstate/library"
3
2
  import type { Container } from "./container"
4
3
  import type { NetworkPolicy } from "./network-policy"
5
4
  import { getOrCreate } from "@highstate/contract"
5
+ import { k8s } from "@highstate/library"
6
6
  import {
7
7
  type ComponentResourceOptions,
8
8
  type Input,
9
9
  type Inputs,
10
10
  interpolate,
11
+ makeEntityOutput,
11
12
  type Output,
12
13
  output,
13
14
  toPromise,
@@ -19,6 +20,7 @@ import { omit } from "remeda"
19
20
  import { Namespace } from "./namespace"
20
21
  import { commonExtraArgs, getProvider, mapMetadata, type ScopedResourceArgs } from "./shared"
21
22
  import {
23
+ filterPatchOwnedContainersInTemplate,
22
24
  getWorkloadComponents,
23
25
  Workload,
24
26
  type WorkloadArgs,
@@ -96,7 +98,17 @@ export abstract class CronJob extends Workload {
96
98
  * The Highstate cron job entity.
97
99
  */
98
100
  get entity(): Output<k8s.CronJob> {
99
- return output(this.entityBase)
101
+ return makeEntityOutput({
102
+ entity: k8s.cronJobEntity,
103
+ identity: this.metadata.uid,
104
+ meta: {
105
+ title: this.metadata.name,
106
+ },
107
+ value: {
108
+ ...this.entityBase,
109
+ spec: this.spec.jobTemplate.spec,
110
+ },
111
+ })
100
112
  }
101
113
 
102
114
  protected getTerminalMeta(): Output<UnitTerminal["meta"]> {
@@ -313,7 +325,7 @@ class CronJobPatch extends CronJob {
313
325
  {
314
326
  metadata: mapMetadata(args, name),
315
327
  spec: output({ args, podTemplate }).apply(({ args, podTemplate }) => {
316
- return deepmerge(
328
+ const spec = deepmerge(
317
329
  {
318
330
  jobTemplate: {
319
331
  spec: {
@@ -323,7 +335,16 @@ class CronJobPatch extends CronJob {
323
335
  schedule: args.schedule!,
324
336
  } satisfies types.input.batch.v1.CronJobSpec,
325
337
  omit(args, cronJobExtraArgs) as types.input.batch.v1.CronJobSpec,
326
- )
338
+ ) as Unwrap<types.input.batch.v1.CronJobSpec>
339
+
340
+ if (spec.jobTemplate?.spec?.template) {
341
+ spec.jobTemplate.spec.template = filterPatchOwnedContainersInTemplate(
342
+ spec.jobTemplate.spec.template,
343
+ podTemplate,
344
+ )
345
+ }
346
+
347
+ return spec
327
348
  }),
328
349
  },
329
350
  {
@@ -334,6 +355,31 @@ class CronJobPatch extends CronJob {
334
355
  )
335
356
  })
336
357
 
358
+ const filteredSpec = output({ spec: cronJob.spec, podTemplate }).apply(
359
+ ({ spec, podTemplate }) => {
360
+ const template = spec.jobTemplate?.spec?.template
361
+ if (!template) {
362
+ return spec
363
+ }
364
+
365
+ const filteredTemplate = filterPatchOwnedContainersInTemplate(
366
+ template as Unwrap<types.input.core.v1.PodTemplateSpec>,
367
+ podTemplate,
368
+ ) as types.output.core.v1.PodTemplateSpec
369
+
370
+ return {
371
+ ...spec,
372
+ jobTemplate: {
373
+ ...spec.jobTemplate,
374
+ spec: {
375
+ ...spec.jobTemplate.spec,
376
+ template: filteredTemplate,
377
+ },
378
+ },
379
+ }
380
+ },
381
+ ) as Output<types.output.batch.v1.CronJobSpec>
382
+
337
383
  super(
338
384
  "highstate:k8s:CronJobPatch",
339
385
  name,
@@ -344,7 +390,7 @@ class CronJobPatch extends CronJob {
344
390
  output(args.terminal ?? {}),
345
391
  containers,
346
392
  networkPolicy,
347
- cronJob.spec,
393
+ filteredSpec,
348
394
  cronJob.status,
349
395
  )
350
396
  }
package/src/deployment.ts CHANGED
@@ -1,14 +1,15 @@
1
1
  import type { AccessPointRoute } from "@highstate/common"
2
- import type { k8s } from "@highstate/library"
3
2
  import type { Container } from "./container"
4
3
  import type { NetworkPolicy } from "./network-policy"
5
4
  import type { Service } from "./service"
6
5
  import { getOrCreate, type UnitTerminal } from "@highstate/contract"
6
+ import { k8s } from "@highstate/library"
7
7
  import {
8
8
  type ComponentResourceOptions,
9
9
  type Input,
10
10
  type Inputs,
11
11
  interpolate,
12
+ makeEntityOutput,
12
13
  type Output,
13
14
  output,
14
15
  toPromise,
@@ -20,14 +21,15 @@ import { omit } from "remeda"
20
21
  import { Namespace } from "./namespace"
21
22
  import { getProvider, mapMetadata } from "./shared"
22
23
  import {
23
- ExposableWorkload,
24
- type ExposableWorkloadArgs,
25
- exposableWorkloadExtraArgs,
26
- getExposableWorkloadComponents,
24
+ filterPatchOwnedContainersInTemplate,
25
+ getWorkloadServiceComponents,
26
+ Workload,
27
+ type WorkloadServiceArgs,
27
28
  type WorkloadTerminalArgs,
29
+ workloadServiceExtraArgs,
28
30
  } from "./workload"
29
31
 
30
- export type DeploymentArgs = Omit<ExposableWorkloadArgs, "existing"> &
32
+ export type DeploymentArgs = Omit<WorkloadServiceArgs, "existing"> &
31
33
  Omit<Partial<types.input.apps.v1.DeploymentSpec>, "template"> & {
32
34
  template?: {
33
35
  metadata?: types.input.meta.v1.ObjectMeta
@@ -42,7 +44,7 @@ export type CreateOrGetDeploymentArgs = DeploymentArgs & {
42
44
  existing: Input<k8s.Deployment> | undefined
43
45
  }
44
46
 
45
- export abstract class Deployment extends ExposableWorkload {
47
+ export abstract class Deployment extends Workload {
46
48
  static readonly apiVersion = "apps/v1"
47
49
  static readonly kind = "Deployment"
48
50
 
@@ -107,10 +109,17 @@ export abstract class Deployment extends ExposableWorkload {
107
109
  get entity(): Output<k8s.Deployment> {
108
110
  const service = this._service.apply(service => service?.entity)
109
111
 
110
- return output({
111
- ...this.entityBase,
112
- service,
113
- endpoints: service.apply(svc => output(svc?.endpoints ?? [])),
112
+ return makeEntityOutput({
113
+ entity: k8s.deploymentEntity,
114
+ identity: this.metadata.uid,
115
+ meta: {
116
+ title: this.metadata.name,
117
+ },
118
+ value: {
119
+ ...this.entityBase,
120
+ service,
121
+ spec: this.spec,
122
+ },
114
123
  })
115
124
  }
116
125
 
@@ -249,7 +258,7 @@ export abstract class Deployment extends ExposableWorkload {
249
258
  class CreatedDeployment extends Deployment {
250
259
  constructor(name: string, args: DeploymentArgs, opts?: ComponentResourceOptions) {
251
260
  const { labels, podTemplate, networkPolicy, containers, service, routes } =
252
- getExposableWorkloadComponents(name, args, () => this, opts)
261
+ getWorkloadServiceComponents(name, args, () => this, opts)
253
262
 
254
263
  const deployment = output(args.namespace).cluster.apply(cluster => {
255
264
  return new apps.v1.Deployment(
@@ -262,7 +271,7 @@ class CreatedDeployment extends Deployment {
262
271
  template: podTemplate,
263
272
  selector: { matchLabels: labels },
264
273
  },
265
- omit(args, exposableWorkloadExtraArgs),
274
+ omit(args, workloadServiceExtraArgs),
266
275
  ) as types.input.apps.v1.DeploymentSpec
267
276
  }),
268
277
  },
@@ -295,7 +304,7 @@ class CreatedDeployment extends Deployment {
295
304
  class DeploymentPatch extends Deployment {
296
305
  constructor(name: string, args: DeploymentArgs, opts?: ComponentResourceOptions) {
297
306
  const { podTemplate, networkPolicy, containers, service, routes } =
298
- getExposableWorkloadComponents(name, args, () => this, opts, true)
307
+ getWorkloadServiceComponents(name, args, () => this, opts, true)
299
308
 
300
309
  const deployment = output(args.namespace).cluster.apply(cluster => {
301
310
  return new apps.v1.DeploymentPatch(
@@ -303,10 +312,16 @@ class DeploymentPatch extends Deployment {
303
312
  {
304
313
  metadata: mapMetadata(args, name),
305
314
  spec: output({ args, podTemplate }).apply(({ args, podTemplate }) => {
306
- return deepmerge(
315
+ const spec = deepmerge(
307
316
  { template: podTemplate },
308
- omit(args, exposableWorkloadExtraArgs),
309
- ) as types.input.apps.v1.DeploymentSpec
317
+ omit(args, workloadServiceExtraArgs),
318
+ ) as Unwrap<types.input.apps.v1.DeploymentSpec>
319
+
320
+ if (spec.template) {
321
+ spec.template = filterPatchOwnedContainersInTemplate(spec.template, podTemplate)
322
+ }
323
+
324
+ return spec
310
325
  }),
311
326
  },
312
327
  {
@@ -317,6 +332,22 @@ class DeploymentPatch extends Deployment {
317
332
  )
318
333
  })
319
334
 
335
+ const filteredSpec = output({ spec: deployment.spec, podTemplate }).apply(
336
+ ({ spec, podTemplate }) => {
337
+ if (!spec.template) {
338
+ return spec
339
+ }
340
+
341
+ return {
342
+ ...spec,
343
+ template: filterPatchOwnedContainersInTemplate(
344
+ spec.template as Unwrap<types.input.core.v1.PodTemplateSpec>,
345
+ podTemplate,
346
+ ) as types.output.core.v1.PodTemplateSpec,
347
+ }
348
+ },
349
+ ) as Output<types.output.apps.v1.DeploymentSpec>
350
+
320
351
  super(
321
352
  "highstate:k8s:DeploymentPatch",
322
353
  name,
@@ -332,7 +363,7 @@ class DeploymentPatch extends Deployment {
332
363
  service,
333
364
  routes,
334
365
 
335
- deployment.spec,
366
+ filteredSpec,
336
367
  deployment.status,
337
368
  )
338
369
  }
@@ -24,12 +24,12 @@ export interface ServiceBackendRef {
24
24
  /**
25
25
  * The name of the service being referenced.
26
26
  */
27
- service: Input<core.v1.Service>
27
+ service: Input<core.v1.Service | Service>
28
28
 
29
29
  /**
30
30
  * The port of the service being referenced.
31
31
  */
32
- port: Input<number>
32
+ port?: Input<number>
33
33
  }
34
34
 
35
35
  export type BackendRef = FullBackendRef | ServiceBackendRef | Service
@@ -49,7 +49,7 @@ export function resolveBackendRef(ref: BackendRef): Output<Unwrap<FullBackendRef
49
49
  return output({
50
50
  name: service.metadata.name,
51
51
  namespace: service.metadata.namespace,
52
- port: ref.port,
52
+ port: ref.port ?? service.spec.ports[0].port,
53
53
  })
54
54
  }
55
55
 
@@ -1,15 +1,15 @@
1
- import type { k8s, network } from "@highstate/library"
2
1
  import type { types } from "@pulumi/kubernetes"
3
- import type { SetRequired } from "type-fest"
4
2
  import { parseEndpoint } from "@highstate/common"
5
3
  import { getOrCreate } from "@highstate/contract"
6
4
  import { gateway, type types as gwTypes } from "@highstate/gateway-api"
5
+ import { k8s, type network } from "@highstate/library"
7
6
  import {
8
7
  type ComponentResourceOptions,
9
8
  type Input,
10
9
  type InputArray,
11
10
  type Inputs,
12
11
  interpolate,
12
+ makeEntityOutput,
13
13
  type Output,
14
14
  output,
15
15
  toPromise,
@@ -81,7 +81,16 @@ export abstract class Gateway extends NamespacedResource {
81
81
  * The Highstate gateway entity.
82
82
  */
83
83
  get entity(): Output<k8s.Gateway> {
84
- return output(this.entityBase)
84
+ return makeEntityOutput({
85
+ entity: k8s.gatewayEntity,
86
+ identity: this.metadata.uid,
87
+ meta: {
88
+ title: this.metadata.name,
89
+ },
90
+ value: {
91
+ ...this.entityBase,
92
+ },
93
+ })
85
94
  }
86
95
 
87
96
  /**
@@ -217,59 +226,6 @@ export abstract class Gateway extends NamespacedResource {
217
226
 
218
227
  return Gateway.for(resolvedEntity, output(cluster))
219
228
  }
220
-
221
- /**
222
- * Creates a gateway with the provided name/namespace/cluster only once.
223
- *
224
- * It automatically names the resource with the following format: `{name}.{namespace}.{clusterName}.{clusterId}`.
225
- *
226
- * On subsequent calls the gateway is patched with the union of existing and requested listeners.
227
- * Only the listeners field is modified to avoid altering other spec fields.
228
- *
229
- * @param name The name of the gateway to create.
230
- * @param args The arguments to create the gateway with.
231
- * @param opts Optional resource options.
232
- */
233
- static async createOnce(
234
- args: SetRequired<GatewayArgs, "name">,
235
- opts?: ComponentResourceOptions,
236
- ): Promise<Gateway> {
237
- const { name, namespace, cluster } = await toPromise({
238
- name: args.name,
239
- namespace: output(args.namespace).metadata.name,
240
- cluster: output(args.namespace).cluster,
241
- })
242
-
243
- const fullName = `${name}.${namespace}.${cluster.name}.${cluster.id}`
244
-
245
- const existing = Gateway.gatewayCache.get(fullName)
246
- if (existing) {
247
- Gateway.patch(
248
- fullName,
249
- {
250
- name,
251
- namespace: args.namespace,
252
- listeners: args.listeners,
253
- },
254
- opts,
255
- )
256
-
257
- return existing
258
- }
259
-
260
- const created = Gateway.create(
261
- fullName,
262
- {
263
- ...args,
264
- name,
265
- namespace: args.namespace,
266
- },
267
- opts,
268
- )
269
-
270
- Gateway.gatewayCache.set(fullName, created)
271
- return created
272
- }
273
229
  }
274
230
 
275
231
  class CreatedGateway extends Gateway {