@highstate/k8s 0.9.16 → 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 (95) 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/cluster-dns/index.js.map +1 -1
  37. package/dist/units/cluster-patch/index.js.map +1 -1
  38. package/dist/units/dns01-issuer/index.js +27 -23
  39. package/dist/units/dns01-issuer/index.js.map +1 -1
  40. package/dist/units/existing-cluster/index.js +11 -8
  41. package/dist/units/existing-cluster/index.js.map +1 -1
  42. package/dist/units/gateway-api/index.js +2 -2
  43. package/dist/units/gateway-api/index.js.map +1 -1
  44. package/package.json +40 -14
  45. package/src/cluster.ts +30 -22
  46. package/src/config-map.ts +195 -57
  47. package/src/container.ts +5 -5
  48. package/src/cron-job.ts +403 -31
  49. package/src/deployment.ts +260 -120
  50. package/src/dns01-solver.ts +10 -0
  51. package/src/gateway/backend.ts +2 -2
  52. package/src/gateway/gateway.ts +383 -0
  53. package/src/gateway/http-route.ts +17 -24
  54. package/src/gateway/index.ts +1 -0
  55. package/src/helm.ts +83 -53
  56. package/src/impl/gateway-route.ts +155 -0
  57. package/src/impl/tls-certificate.ts +33 -0
  58. package/src/index.ts +22 -67
  59. package/src/job.ts +393 -28
  60. package/src/namespace.ts +236 -99
  61. package/src/network-policy.ts +216 -165
  62. package/src/network.ts +2 -2
  63. package/src/pvc.ts +266 -65
  64. package/src/rbac.ts +218 -0
  65. package/src/scripting/bundle.ts +9 -20
  66. package/src/scripting/container.ts +1 -1
  67. package/src/scripting/environment.ts +5 -5
  68. package/src/secret.ts +200 -62
  69. package/src/service.ts +288 -158
  70. package/src/shared.ts +94 -67
  71. package/src/stateful-set.ts +270 -117
  72. package/src/tls.ts +344 -0
  73. package/src/units/cert-manager/index.ts +2 -3
  74. package/src/units/dns01-issuer/index.ts +30 -14
  75. package/src/units/existing-cluster/index.ts +10 -7
  76. package/src/units/gateway-api/index.ts +2 -2
  77. package/src/worker.ts +26 -0
  78. package/src/workload.ts +275 -171
  79. package/dist/chunk-5C2BJGES.js.map +0 -1
  80. package/dist/chunk-5TLC5BXR.js +0 -256
  81. package/dist/chunk-5TLC5BXR.js.map +0 -1
  82. package/dist/chunk-BBIY3KUN.js +0 -1557
  83. package/dist/chunk-BBIY3KUN.js.map +0 -1
  84. package/dist/chunk-OFFSHGC6.js.map +0 -1
  85. package/dist/chunk-TZHOUJRC.js +0 -202
  86. package/dist/chunk-TZHOUJRC.js.map +0 -1
  87. package/dist/chunk-YWRJ4EZM.js +0 -192
  88. package/dist/chunk-YWRJ4EZM.js.map +0 -1
  89. package/dist/deployment-XK3CDJOE.js +0 -6
  90. package/dist/stateful-set-7CAQWTV2.js +0 -6
  91. package/dist/units/access-point/index.js +0 -21
  92. package/dist/units/access-point/index.js.map +0 -1
  93. package/src/access-point.ts +0 -191
  94. package/src/units/access-point/index.ts +0 -19
  95. package/src/units/dns01-issuer/solver.ts +0 -23
@@ -0,0 +1,383 @@
1
+ import type { k8s, network } from "@highstate/library"
2
+ import type { types } from "@pulumi/kubernetes"
3
+ import type { SetRequired } from "type-fest"
4
+ import { parseL3Endpoint } from "@highstate/common"
5
+ import { getOrCreate } from "@highstate/contract"
6
+ import { gateway, type types as gwTypes } from "@highstate/gateway-api"
7
+ import {
8
+ ComponentResource,
9
+ type ComponentResourceOptions,
10
+ type Input,
11
+ type InputArray,
12
+ type Inputs,
13
+ interpolate,
14
+ type Output,
15
+ output,
16
+ toPromise,
17
+ } from "@highstate/pulumi"
18
+ import { deepmerge } from "deepmerge-ts"
19
+ import { omit } from "remeda"
20
+ import { Namespace } from "../namespace"
21
+ import { commonExtraArgs, getProvider, mapMetadata, type ScopedResourceArgs } from "../shared"
22
+
23
+ export type GatewayArgs = ScopedResourceArgs & {
24
+ /**
25
+ * The FQDN to configure the listeners for.
26
+ */
27
+ fqdn?: Input<string>
28
+
29
+ /**
30
+ * The FQDNs to configure the listeners for.
31
+ */
32
+ fqdns?: InputArray<string>
33
+ } & gwTypes.input.gateway.v1.GatewaySpec
34
+
35
+ export type CreateOrGetGatewayArgs = GatewayArgs & {
36
+ /**
37
+ * The gateway entity to patch/retrieve.
38
+ */
39
+ existing: Input<k8s.Gateway> | undefined
40
+ }
41
+
42
+ const gatewayExtraArgs = [...commonExtraArgs, "fqdn", "fqdns"] as const
43
+
44
+ /**
45
+ * Represents a Kubernetes Gateway resource.
46
+ */
47
+ export abstract class Gateway extends ComponentResource {
48
+ protected constructor(
49
+ type: string,
50
+ name: string,
51
+ args: Inputs,
52
+ opts: ComponentResourceOptions | undefined,
53
+
54
+ /**
55
+ * The namespace where the gateway is located.
56
+ */
57
+ readonly namespace: Output<Namespace>,
58
+
59
+ /**
60
+ * The metadata of the underlying Kubernetes gateway.
61
+ */
62
+ readonly metadata: Output<types.output.meta.v1.ObjectMeta>,
63
+
64
+ /**
65
+ * The spec of the underlying Gateway resource.
66
+ */
67
+ readonly spec: Output<gwTypes.output.gateway.v1.GatewaySpec>,
68
+
69
+ /**
70
+ * The status of the underlying Gateway resource.
71
+ */
72
+ readonly status: Output<gwTypes.output.gateway.v1.GatewayStatus>,
73
+ ) {
74
+ super(type, name, args, opts)
75
+ }
76
+
77
+ /**
78
+ * The cluster where the gateway is located.
79
+ */
80
+ get cluster(): Output<k8s.Cluster> {
81
+ return this.namespace.cluster
82
+ }
83
+
84
+ /**
85
+ * The Highstate gateway entity.
86
+ */
87
+ get entity(): Output<k8s.Gateway> {
88
+ return output({
89
+ type: "gateway",
90
+ clusterId: this.cluster.id,
91
+ clusterName: this.cluster.name,
92
+ metadata: this.metadata,
93
+ })
94
+ }
95
+
96
+ /**
97
+ * Returns the endpoints L3 endpoints on which the gateway is exposed.
98
+ */
99
+ get endpoints(): Output<network.L3Endpoint[]> {
100
+ return this.status.addresses.apply(addresses => {
101
+ if (!addresses) {
102
+ return []
103
+ }
104
+
105
+ return addresses.map(address => parseL3Endpoint(address.value))
106
+ })
107
+ }
108
+
109
+ /**
110
+ * Creates a new gateway.
111
+ */
112
+ static create(name: string, args: GatewayArgs, opts?: ComponentResourceOptions): Gateway {
113
+ return new CreatedGateway(name, args, opts)
114
+ }
115
+
116
+ /**
117
+ * Creates a new gateway or patches an existing one.
118
+ *
119
+ * @param name The name of the resource. May not be the same as the gateway name.
120
+ * @param args The arguments to create or patch the gateway with.
121
+ * @param opts Optional resource options.
122
+ */
123
+ static createOrPatch(
124
+ name: string,
125
+ args: CreateOrGetGatewayArgs,
126
+ opts?: ComponentResourceOptions,
127
+ ): Gateway {
128
+ if (args.existing) {
129
+ return new GatewayPatch(name, {
130
+ ...args,
131
+ name: output(args.existing).metadata.name,
132
+ namespace: Namespace.forResourceAsync(args.existing, output(args.namespace).cluster),
133
+ })
134
+ }
135
+
136
+ return new CreatedGateway(name, args, opts)
137
+ }
138
+
139
+ /**
140
+ * Creates a new gateway or gets an existing one.
141
+ *
142
+ * @param name The name of the resource. May not be the same as the gateway name. Will not be used when existing gateway is retrieved.
143
+ * @param args The arguments to create or get the gateway with.
144
+ * @param opts Optional resource options.
145
+ */
146
+ static async createOrGet(
147
+ name: string,
148
+ args: CreateOrGetGatewayArgs,
149
+ opts?: ComponentResourceOptions,
150
+ ): Promise<Gateway> {
151
+ if (args.existing) {
152
+ return await Gateway.forAsync(args.existing, output(args.namespace).cluster)
153
+ }
154
+
155
+ return new CreatedGateway(name, args, opts)
156
+ }
157
+
158
+ /**
159
+ * Patches an existing gateway.
160
+ *
161
+ * Will throw an error if the gateway does not exist.
162
+ *
163
+ * @param name The name of the resource. May not be the same as the gateway name.
164
+ * @param args The arguments to patch the gateway with.
165
+ * @param opts Optional resource options.
166
+ */
167
+ static patch(name: string, args: GatewayArgs, opts?: ComponentResourceOptions): Gateway {
168
+ return new GatewayPatch(name, args, opts)
169
+ }
170
+
171
+ /**
172
+ * Wraps an existing Kubernetes gateway.
173
+ */
174
+ static wrap(name: string, args: WrappedGatewayArgs, opts?: ComponentResourceOptions): Gateway {
175
+ return new WrappedGateway(name, args, opts)
176
+ }
177
+
178
+ /**
179
+ * Gets an existing gateway.
180
+ *
181
+ * Will throw an error if the gateway does not exist.
182
+ */
183
+ static get(name: string, args: ExternalGatewayArgs, opts?: ComponentResourceOptions): Gateway {
184
+ return new ExternalGateway(name, args, opts)
185
+ }
186
+
187
+ private static readonly gatewayCache = new Map<string, Gateway>()
188
+
189
+ /**
190
+ * Gets an existing gateway for a given entity.
191
+ * Prefer this method over `get` when possible.
192
+ *
193
+ * It automatically names the resource with the following format: `{clusterName}.{namespace}.{gatewayName}.{clusterId}`.
194
+ *
195
+ * This method is idempotent and will return the same instance for the same entity.
196
+ *
197
+ * @param entity The entity to get the gateway for.
198
+ * @param cluster The cluster where the gateway is located.
199
+ */
200
+ static for(entity: k8s.Gateway, cluster: Input<k8s.Cluster>): Gateway {
201
+ return getOrCreate(
202
+ Gateway.gatewayCache,
203
+ `${entity.clusterName}.${entity.metadata.namespace}.${entity.metadata.name}.${entity.clusterId}`,
204
+ name => {
205
+ return Gateway.get(name, {
206
+ name: entity.metadata.name,
207
+ namespace: Namespace.forResourceAsync(entity, cluster),
208
+ })
209
+ },
210
+ )
211
+ }
212
+
213
+ /**
214
+ * Gets an existing gateway for a given entity.
215
+ * Prefer this method over `get` when possible.
216
+ *
217
+ * It automatically names the resource with the following format: `{clusterName}.{namespace}.{gatewayName}.{clusterId}`.
218
+ *
219
+ * This method is idempotent and will return the same instance for the same entity.
220
+ *
221
+ * @param entity The entity to get the gateway for.
222
+ * @param cluster The cluster where the gateway is located.
223
+ */
224
+ static async forAsync(entity: Input<k8s.Gateway>, cluster: Input<k8s.Cluster>): Promise<Gateway> {
225
+ const resolvedEntity = await toPromise(entity)
226
+
227
+ return Gateway.for(resolvedEntity, output(cluster))
228
+ }
229
+
230
+ /**
231
+ * Creates a gateway with the provided name/namespace/cluster only once.
232
+ *
233
+ * It automatically names the resource with the following format: `{name}.{namespace}.{clusterName}.{clusterId}`.
234
+ *
235
+ * This method is idempotent and will return the same instance for the same name/namespace/cluster.
236
+ *
237
+ * @param name The name of the gateway to create.
238
+ * @param args The arguments to create the gateway with.
239
+ * @param opts Optional resource options.
240
+ */
241
+ static async createOnce(
242
+ args: SetRequired<GatewayArgs, "name">,
243
+ opts?: ComponentResourceOptions,
244
+ ): Promise<Gateway> {
245
+ const { name, namespace, cluster } = await toPromise({
246
+ name: args.name,
247
+ namespace: output(args.namespace).metadata.name,
248
+ cluster: output(args.namespace).cluster,
249
+ })
250
+
251
+ const fullName = `${name}.${namespace}.${cluster.name}.${cluster.id}`
252
+
253
+ return getOrCreate(Gateway.gatewayCache, name, () =>
254
+ Gateway.create(
255
+ fullName,
256
+ {
257
+ ...args,
258
+ name,
259
+ namespace: args.namespace,
260
+ },
261
+ opts,
262
+ ),
263
+ )
264
+ }
265
+ }
266
+
267
+ class CreatedGateway extends Gateway {
268
+ constructor(name: string, args: GatewayArgs, opts?: ComponentResourceOptions) {
269
+ const gatewayResource = output(args.namespace).cluster.apply(cluster => {
270
+ return new gateway.v1.Gateway(
271
+ name,
272
+ {
273
+ metadata: mapMetadata(args, name),
274
+ spec: deepmerge({}, omit(args, gatewayExtraArgs)),
275
+ },
276
+ { ...opts, parent: this, provider: getProvider(cluster) },
277
+ )
278
+ })
279
+
280
+ super(
281
+ "highstate:k8s:Gateway",
282
+ name,
283
+ args,
284
+ opts,
285
+
286
+ output(args.namespace),
287
+ gatewayResource.metadata as Output<types.output.meta.v1.ObjectMeta>,
288
+ gatewayResource.spec,
289
+ gatewayResource.status,
290
+ )
291
+ }
292
+ }
293
+
294
+ class GatewayPatch extends Gateway {
295
+ constructor(name: string, args: GatewayArgs, opts?: ComponentResourceOptions) {
296
+ const gatewayResource = output(args.namespace).cluster.apply(cluster => {
297
+ return new gateway.v1.GatewayPatch(
298
+ name,
299
+ {
300
+ metadata: mapMetadata(args, name),
301
+ spec: deepmerge({}, omit(args, gatewayExtraArgs)),
302
+ },
303
+ { ...opts, parent: this, provider: getProvider(cluster) },
304
+ )
305
+ })
306
+
307
+ super(
308
+ "highstate:k8s:GatewayPatch",
309
+ name,
310
+ args,
311
+ opts,
312
+
313
+ output(args.namespace),
314
+ gatewayResource.metadata as Output<types.output.meta.v1.ObjectMeta>,
315
+ gatewayResource.spec,
316
+ gatewayResource.status,
317
+ )
318
+ }
319
+ }
320
+
321
+ export type WrappedGatewayArgs = {
322
+ /**
323
+ * The underlying Kubernetes gateway to wrap.
324
+ */
325
+ gateway: Input<gateway.v1.Gateway>
326
+
327
+ /**
328
+ * The namespace where the gateway is located.
329
+ */
330
+ namespace: Input<Namespace>
331
+ }
332
+
333
+ class WrappedGateway extends Gateway {
334
+ constructor(name: string, args: WrappedGatewayArgs, opts?: ComponentResourceOptions) {
335
+ super(
336
+ "highstate:k8s:WrappedGateway",
337
+ name,
338
+ args,
339
+ opts,
340
+
341
+ output(args.namespace),
342
+ output(args.gateway).metadata as Output<types.output.meta.v1.ObjectMeta>,
343
+ output(args.gateway).spec,
344
+ output(args.gateway).status,
345
+ )
346
+ }
347
+ }
348
+
349
+ export type ExternalGatewayArgs = {
350
+ /**
351
+ * The name of the gateway to get.
352
+ */
353
+ name: Input<string>
354
+
355
+ /**
356
+ * The namespace of the gateway to get.
357
+ */
358
+ namespace: Input<Namespace>
359
+ }
360
+
361
+ class ExternalGateway extends Gateway {
362
+ constructor(name: string, args: ExternalGatewayArgs, opts?: ComponentResourceOptions) {
363
+ const gatewayResource = output(args.namespace).cluster.apply(cluster => {
364
+ return gateway.v1.Gateway.get(
365
+ name,
366
+ interpolate`${output(args.namespace).metadata.name}/${args.name}`,
367
+ { ...opts, parent: this, provider: getProvider(cluster) },
368
+ )
369
+ })
370
+
371
+ super(
372
+ "highstate:k8s:ExternalGateway",
373
+ name,
374
+ args,
375
+ opts,
376
+
377
+ output(args.namespace),
378
+ gatewayResource.metadata as Output<types.output.meta.v1.ObjectMeta>,
379
+ gatewayResource.spec,
380
+ gatewayResource.status,
381
+ )
382
+ }
383
+ }
@@ -1,22 +1,25 @@
1
+ import type { Gateway } from "./gateway"
1
2
  import {
2
3
  ComponentResource,
3
4
  normalize,
5
+ normalizeInputs,
6
+ normalizeInputsAndMap,
4
7
  output,
5
- Output,
8
+ type Output,
6
9
  type ComponentResourceOptions,
7
10
  type Input,
8
11
  type InputArray,
9
12
  } from "@highstate/pulumi"
10
- import { gateway, types } from "@highstate/gateway-api"
13
+ import { gateway, type types } from "@highstate/gateway-api"
11
14
  import { map, pipe } from "remeda"
12
- import { getProvider, mapMetadata, type CommonArgs } from "../shared"
15
+ import { getProvider, mapMetadata, type ScopedResourceArgs } from "../shared"
13
16
  import { resolveBackendRef, type BackendRef } from "./backend"
14
17
 
15
- export type HttpRouteArgs = Omit<CommonArgs, "namespace"> & {
18
+ export type HttpRouteArgs = Omit<ScopedResourceArgs, "namespace"> & {
16
19
  /**
17
20
  * The gateway to associate with the route.
18
21
  */
19
- gateway: Input<gateway.v1.Gateway>
22
+ gateway: Input<Gateway>
20
23
 
21
24
  /**
22
25
  * The alias for `hostnames: [hostname]`.
@@ -77,30 +80,24 @@ export class HttpRoute extends ComponentResource {
77
80
  constructor(name: string, args: HttpRouteArgs, opts?: ComponentResourceOptions) {
78
81
  super("highstate:k8s:HttpRoute", name, args, opts)
79
82
 
80
- this.route = output({
81
- args,
82
- gatewayNamespace: output(args.gateway).metadata.namespace,
83
- }).apply(async ({ args, gatewayNamespace }) => {
83
+ this.route = output(args.gateway).cluster.apply(cluster => {
84
84
  return new gateway.v1.HTTPRoute(
85
85
  name,
86
86
  {
87
- metadata: mapMetadata(
88
- {
89
- ...args,
90
- namespace: gatewayNamespace as string,
91
- },
92
- name,
93
- ),
87
+ metadata: mapMetadata(args, name).apply(metadata => ({
88
+ ...metadata,
89
+ namespace: output(args.gateway).namespace.metadata.name,
90
+ })),
94
91
  spec: {
95
- hostnames: normalize(args.hostname, args.hostnames),
92
+ hostnames: normalizeInputs(args.hostname, args.hostnames),
96
93
 
97
94
  parentRefs: [
98
95
  {
99
- name: args.gateway.metadata.name as Output<string>,
96
+ name: output(args.gateway).metadata.name,
100
97
  },
101
98
  ],
102
99
 
103
- rules: normalize(args.rule, args.rules).map(rule => ({
100
+ rules: normalizeInputsAndMap(args.rule, args.rules, rule => ({
104
101
  timeouts: rule.timeouts,
105
102
 
106
103
  matches: pipe(
@@ -114,11 +111,7 @@ export class HttpRoute extends ComponentResource {
114
111
  })),
115
112
  } satisfies types.input.gateway.v1.HTTPRouteSpec,
116
113
  },
117
- {
118
- ...opts,
119
- parent: this,
120
- provider: await getProvider(args.cluster),
121
- },
114
+ { ...opts, parent: this, provider: getProvider(cluster) },
122
115
  )
123
116
  })
124
117
  }
@@ -1,2 +1,3 @@
1
1
  export * from "./backend"
2
2
  export * from "./http-route"
3
+ export * from "./gateway"