@highstate/k8s 0.9.14 → 0.9.16

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 (60) hide show
  1. package/dist/{chunk-QLQ3QVGT.js → chunk-5C2BJGES.js} +17 -17
  2. package/dist/chunk-5C2BJGES.js.map +1 -0
  3. package/dist/{chunk-Y3LZSX7I.js → chunk-5TLC5BXR.js} +33 -31
  4. package/dist/chunk-5TLC5BXR.js.map +1 -0
  5. package/dist/chunk-BBIY3KUN.js +1557 -0
  6. package/dist/chunk-BBIY3KUN.js.map +1 -0
  7. package/dist/{chunk-5S4JPM4M.js → chunk-OFFSHGC6.js} +43 -32
  8. package/dist/chunk-OFFSHGC6.js.map +1 -0
  9. package/dist/chunk-PZ5AY32C.js +9 -0
  10. package/dist/chunk-PZ5AY32C.js.map +1 -0
  11. package/dist/{chunk-VL7Z5FJQ.js → chunk-TZHOUJRC.js} +29 -20
  12. package/dist/chunk-TZHOUJRC.js.map +1 -0
  13. package/dist/{chunk-6L67WIZW.js → chunk-YWRJ4EZM.js} +29 -20
  14. package/dist/chunk-YWRJ4EZM.js.map +1 -0
  15. package/dist/deployment-XK3CDJOE.js +6 -0
  16. package/dist/deployment-XK3CDJOE.js.map +1 -0
  17. package/dist/highstate.manifest.json +8 -8
  18. package/dist/index.js +39 -138
  19. package/dist/index.js.map +1 -1
  20. package/dist/stateful-set-7CAQWTV2.js +6 -0
  21. package/dist/stateful-set-7CAQWTV2.js.map +1 -0
  22. package/dist/units/access-point/index.js +7 -6
  23. package/dist/units/access-point/index.js.map +1 -1
  24. package/dist/units/cert-manager/index.js +11 -14
  25. package/dist/units/cert-manager/index.js.map +1 -1
  26. package/dist/units/cluster-dns/index.js +9 -8
  27. package/dist/units/cluster-dns/index.js.map +1 -1
  28. package/dist/units/cluster-patch/index.js +9 -8
  29. package/dist/units/cluster-patch/index.js.map +1 -1
  30. package/dist/units/dns01-issuer/index.js +9 -14
  31. package/dist/units/dns01-issuer/index.js.map +1 -1
  32. package/dist/units/existing-cluster/index.js +12 -19
  33. package/dist/units/existing-cluster/index.js.map +1 -1
  34. package/dist/units/gateway-api/index.js +8 -10
  35. package/dist/units/gateway-api/index.js.map +1 -1
  36. package/package.json +19 -10
  37. package/src/cluster.ts +14 -9
  38. package/src/deployment.ts +34 -0
  39. package/src/helm.ts +38 -2
  40. package/src/network-policy.ts +2 -5
  41. package/src/shared.ts +17 -0
  42. package/src/stateful-set.ts +34 -0
  43. package/src/units/cluster-dns/index.ts +1 -1
  44. package/src/units/cluster-patch/index.ts +1 -1
  45. package/src/units/existing-cluster/index.ts +1 -1
  46. package/src/workload.ts +22 -3
  47. package/dist/chunk-5S4JPM4M.js.map +0 -1
  48. package/dist/chunk-6L67WIZW.js.map +0 -1
  49. package/dist/chunk-QLQ3QVGT.js.map +0 -1
  50. package/dist/chunk-SARVLQZY.js +0 -876
  51. package/dist/chunk-SARVLQZY.js.map +0 -1
  52. package/dist/chunk-VL7Z5FJQ.js.map +0 -1
  53. package/dist/chunk-WEKIQRCZ.js +0 -792
  54. package/dist/chunk-WEKIQRCZ.js.map +0 -1
  55. package/dist/chunk-Y3LZSX7I.js.map +0 -1
  56. package/dist/deployment-QTPBNKO5.js +0 -10
  57. package/dist/deployment-QTPBNKO5.js.map +0 -1
  58. package/dist/stateful-set-K4GV7ZTK.js +0 -10
  59. package/dist/stateful-set-K4GV7ZTK.js.map +0 -1
  60. package/src/custom.ts +0 -104
@@ -1,876 +0,0 @@
1
- import {
2
- HttpRoute,
3
- NetworkPolicy,
4
- Service,
5
- mapContainerPortToServicePort
6
- } from "./chunk-WEKIQRCZ.js";
7
- import {
8
- commonExtraArgs,
9
- getProvider,
10
- mapMetadata,
11
- resourceIdToString,
12
- withPatchName
13
- } from "./chunk-Y3LZSX7I.js";
14
-
15
- // src/pvc.ts
16
- import { core } from "@pulumi/kubernetes";
17
- import {
18
- ComponentResource,
19
- output
20
- } from "@highstate/pulumi";
21
- import { deepmerge } from "deepmerge-ts";
22
- import { omit } from "remeda";
23
- var extraPersistentVolumeClaimArgs = [...commonExtraArgs, "size"];
24
- var PersistentVolumeClaim = class extends ComponentResource {
25
- constructor(type, name, args, opts, cluster, metadata, spec, status) {
26
- super(type, name, args, opts);
27
- this.cluster = cluster;
28
- this.metadata = metadata;
29
- this.spec = spec;
30
- this.status = status;
31
- }
32
- /**
33
- * The Highstate PVC entity.
34
- */
35
- get entity() {
36
- return output({
37
- type: "k8s.persistent-volume-claim",
38
- clusterId: this.cluster.id,
39
- metadata: this.metadata
40
- });
41
- }
42
- static create(name, args, opts) {
43
- return new CreatedPersistentVolumeClaim(name, args, opts);
44
- }
45
- static of(name, entity, cluster, opts) {
46
- return new ExternalPersistentVolumeClaim(name, output(entity).metadata, cluster, opts);
47
- }
48
- static createOrGet(name, args, opts) {
49
- if (!args.existing) {
50
- return new CreatedPersistentVolumeClaim(name, args, opts);
51
- }
52
- return new ExternalPersistentVolumeClaim(
53
- name,
54
- output(args.existing).metadata,
55
- args.cluster,
56
- opts
57
- );
58
- }
59
- };
60
- var CreatedPersistentVolumeClaim = class extends PersistentVolumeClaim {
61
- constructor(name, args, opts) {
62
- const pvc = output(args).apply(async (args2) => {
63
- return new core.v1.PersistentVolumeClaim(
64
- name,
65
- {
66
- metadata: mapMetadata(args2, name),
67
- spec: deepmerge(
68
- {
69
- accessModes: ["ReadWriteOnce"],
70
- resources: {
71
- requests: {
72
- storage: args2.size ?? "100Mi"
73
- }
74
- }
75
- },
76
- omit(args2, extraPersistentVolumeClaimArgs)
77
- )
78
- },
79
- {
80
- ...opts,
81
- parent: this,
82
- provider: await getProvider(args2.cluster)
83
- }
84
- );
85
- });
86
- super(
87
- "k8s:PersistentVolumeClaim",
88
- name,
89
- args,
90
- opts,
91
- output(args.cluster),
92
- pvc.metadata,
93
- pvc.spec,
94
- pvc.status
95
- );
96
- }
97
- };
98
- var ExternalPersistentVolumeClaim = class extends PersistentVolumeClaim {
99
- constructor(name, id, cluster, opts) {
100
- const pvc = output(id).apply(async (id2) => {
101
- return core.v1.PersistentVolumeClaim.get(
102
- //
103
- name,
104
- resourceIdToString(id2),
105
- {
106
- ...opts,
107
- parent: this,
108
- provider: await getProvider(cluster)
109
- }
110
- );
111
- });
112
- super(
113
- "highstate:k8s:ExternalPersistentVolumeClaim",
114
- name,
115
- { id, cluster },
116
- opts,
117
- output(cluster),
118
- pvc.metadata,
119
- pvc.spec,
120
- pvc.status
121
- );
122
- }
123
- };
124
-
125
- // src/secret.ts
126
- import { core as core2 } from "@pulumi/kubernetes";
127
- import {
128
- ComponentResource as ComponentResource2,
129
- output as output2
130
- } from "@pulumi/pulumi";
131
- var Secret = class extends ComponentResource2 {
132
- constructor(type, name, args, opts, cluster, metadata, data, stringData) {
133
- super(type, name, args, opts);
134
- this.cluster = cluster;
135
- this.metadata = metadata;
136
- this.data = data;
137
- this.stringData = stringData;
138
- }
139
- /**
140
- * Creates a new secret.
141
- */
142
- static create(name, args, opts) {
143
- return new CreatedSecret(name, args, opts);
144
- }
145
- /**
146
- * Creates a new secret or patches an existing one.
147
- *
148
- * Will throw an error if the secret does not exist when `args.resource` is provided.
149
- */
150
- static createOrPatch(name, args, opts) {
151
- if (!args.existing) {
152
- return new CreatedSecret(name, args, opts);
153
- }
154
- return new SecretPatch(
155
- name,
156
- {
157
- ...args,
158
- name: withPatchName("secret", args.existing, args.cluster),
159
- namespace: output2(args.existing).metadata.namespace
160
- },
161
- opts
162
- );
163
- }
164
- /**
165
- * Gets an existing secret.
166
- *
167
- * Will throw an error if the secret does not exist.
168
- */
169
- static get(name, id, cluster, opts) {
170
- return new ExternalSecret(name, id, cluster, opts);
171
- }
172
- };
173
- var CreatedSecret = class extends Secret {
174
- constructor(name, args, opts) {
175
- const secret = output2(args).apply(async (args2) => {
176
- return new core2.v1.Secret(
177
- name,
178
- {
179
- metadata: mapMetadata(args2, name),
180
- data: args2.data,
181
- stringData: args2.stringData,
182
- type: args2.type,
183
- immutable: args2.immutable
184
- },
185
- {
186
- ...opts,
187
- parent: this,
188
- provider: await getProvider(args2.cluster)
189
- }
190
- );
191
- });
192
- super(
193
- "highstate:k8s:Secret",
194
- name,
195
- args,
196
- opts,
197
- output2(args.cluster),
198
- secret.metadata,
199
- secret.data,
200
- secret.stringData
201
- );
202
- }
203
- };
204
- var SecretPatch = class extends Secret {
205
- constructor(name, args, opts) {
206
- const secret = output2(args).apply(async (args2) => {
207
- return new core2.v1.SecretPatch(
208
- name,
209
- {
210
- metadata: mapMetadata(args2, name),
211
- data: args2.data,
212
- stringData: args2.stringData,
213
- type: args2.type,
214
- immutable: args2.immutable
215
- },
216
- {
217
- ...opts,
218
- parent: this,
219
- provider: await getProvider(args2.cluster)
220
- }
221
- );
222
- });
223
- super(
224
- "highstate:k8s:SecretPatch",
225
- name,
226
- args,
227
- opts,
228
- output2(args.cluster),
229
- secret.metadata,
230
- secret.data,
231
- secret.stringData
232
- );
233
- }
234
- };
235
- var ExternalSecret = class extends Secret {
236
- constructor(name, id, cluster, opts) {
237
- const secret = output2(id).apply(async (realName) => {
238
- return core2.v1.Secret.get(
239
- //
240
- name,
241
- realName,
242
- {
243
- ...opts,
244
- parent: this,
245
- provider: await getProvider(cluster)
246
- }
247
- );
248
- });
249
- super(
250
- "highstate:k8s:ExternalSecret",
251
- name,
252
- { id, cluster },
253
- opts,
254
- output2(cluster),
255
- secret.metadata,
256
- secret.data,
257
- secret.stringData
258
- );
259
- }
260
- };
261
-
262
- // src/config-map.ts
263
- import { core as core3 } from "@pulumi/kubernetes";
264
- import {
265
- ComponentResource as ComponentResource3,
266
- output as output3
267
- } from "@pulumi/pulumi";
268
- var ConfigMap = class extends ComponentResource3 {
269
- constructor(type, name, args, opts, cluster, metadata, data) {
270
- super(type, name, args, opts);
271
- this.cluster = cluster;
272
- this.metadata = metadata;
273
- this.data = data;
274
- }
275
- /**
276
- * Creates a new config map.
277
- */
278
- static create(name, args, opts) {
279
- return new CreatedConfigMap(name, args, opts);
280
- }
281
- /**
282
- * Creates a new config map or patches an existing one.
283
- *
284
- * Will throw an error if the config map does not exist when `args.resource` is provided.
285
- */
286
- static createOrPatch(name, args, opts) {
287
- if (!args.existing) {
288
- return new CreatedConfigMap(name, args, opts);
289
- }
290
- return new ConfigMapPatch(
291
- name,
292
- {
293
- ...args,
294
- name: withPatchName("configmap", args.existing, args.cluster),
295
- namespace: output3(args.existing).metadata.namespace
296
- },
297
- opts
298
- );
299
- }
300
- /**
301
- * Gets an existing config map.
302
- *
303
- * Will throw an error if the config map does not exist.
304
- */
305
- static get(name, id, cluster, opts) {
306
- return new ExternalConfigMap(name, id, cluster, opts);
307
- }
308
- };
309
- var CreatedConfigMap = class extends ConfigMap {
310
- constructor(name, args, opts) {
311
- const configMap = output3(args).apply(async (args2) => {
312
- return new core3.v1.ConfigMap(
313
- name,
314
- {
315
- metadata: mapMetadata(args2, name),
316
- data: args2.data
317
- },
318
- {
319
- ...opts,
320
- parent: this,
321
- provider: await getProvider(args2.cluster)
322
- }
323
- );
324
- });
325
- super(
326
- "highstate:k8s:ConfigMap",
327
- name,
328
- args,
329
- opts,
330
- output3(args.cluster),
331
- configMap.metadata,
332
- configMap.data
333
- );
334
- }
335
- };
336
- var ConfigMapPatch = class extends ConfigMap {
337
- constructor(name, args, opts) {
338
- const configMap = output3(args).apply(async (args2) => {
339
- return new core3.v1.ConfigMapPatch(
340
- name,
341
- {
342
- metadata: mapMetadata(args2, name),
343
- data: args2.data
344
- },
345
- {
346
- ...opts,
347
- parent: this,
348
- provider: await getProvider(args2.cluster)
349
- }
350
- );
351
- });
352
- super(
353
- "highstate:k8s:ConfigMapPatch",
354
- name,
355
- args,
356
- opts,
357
- output3(args.cluster),
358
- configMap.metadata,
359
- configMap.data
360
- );
361
- }
362
- };
363
- var ExternalConfigMap = class extends ConfigMap {
364
- constructor(name, id, cluster, opts) {
365
- const configMap = output3(id).apply(async (realName) => {
366
- return core3.v1.ConfigMap.get(name, realName, {
367
- ...opts,
368
- parent: this,
369
- provider: await getProvider(cluster)
370
- });
371
- });
372
- super(
373
- "highstate:k8s:ExternalConfigMap",
374
- name,
375
- { id, cluster },
376
- opts,
377
- output3(cluster),
378
- configMap.metadata,
379
- configMap.data
380
- );
381
- }
382
- };
383
-
384
- // src/container.ts
385
- import { core as core4 } from "@pulumi/kubernetes";
386
- import {
387
- normalize,
388
- output as output4
389
- } from "@highstate/pulumi";
390
- import { concat, map, omit as omit2 } from "remeda";
391
- var containerExtraArgs = [
392
- "port",
393
- "volumeMount",
394
- "volume",
395
- "environment",
396
- "environmentSource",
397
- "environmentSources"
398
- ];
399
- function mapContainerToRaw(container, cluster, fallbackName) {
400
- const containerName = container.name ?? fallbackName;
401
- const spec = {
402
- ...omit2(container, containerExtraArgs),
403
- name: containerName,
404
- ports: normalize(container.port, container.ports),
405
- volumeMounts: map(normalize(container.volumeMount, container.volumeMounts), mapVolumeMount),
406
- env: concat(
407
- container.environment ? mapContainerEnvironment(container.environment) : [],
408
- container.env ?? []
409
- ),
410
- envFrom: concat(
411
- map(
412
- normalize(container.environmentSource, container.environmentSources),
413
- mapEnvironmentSource
414
- ),
415
- container.envFrom ?? []
416
- )
417
- };
418
- if (container.enableTun) {
419
- spec.securityContext ??= {};
420
- spec.securityContext.capabilities ??= {};
421
- spec.securityContext.capabilities.add = ["NET_ADMIN"];
422
- if (cluster.quirks?.tunDevicePolicy?.type === "plugin") {
423
- spec.resources ??= {};
424
- spec.resources.limits ??= {};
425
- spec.resources.limits[cluster.quirks.tunDevicePolicy.resourceName] = cluster.quirks.tunDevicePolicy.resourceValue;
426
- } else {
427
- spec.volumeMounts ??= [];
428
- spec.volumeMounts.push({
429
- name: "tun-device",
430
- mountPath: "/dev/net/tun",
431
- readOnly: false
432
- });
433
- }
434
- }
435
- return spec;
436
- }
437
- function mapContainerEnvironment(environment) {
438
- const envVars = [];
439
- for (const [name, value] of Object.entries(environment)) {
440
- if (!value) {
441
- continue;
442
- }
443
- if (typeof value === "string") {
444
- envVars.push({ name, value });
445
- continue;
446
- }
447
- if ("secret" in value) {
448
- envVars.push({
449
- name,
450
- valueFrom: {
451
- secretKeyRef: {
452
- name: value.secret.metadata.name,
453
- key: value.key
454
- }
455
- }
456
- });
457
- continue;
458
- }
459
- if ("configMap" in value) {
460
- envVars.push({
461
- name,
462
- valueFrom: {
463
- configMapKeyRef: {
464
- name: value.configMap.metadata.name,
465
- key: value.key
466
- }
467
- }
468
- });
469
- continue;
470
- }
471
- envVars.push({ name, valueFrom: value });
472
- }
473
- return envVars;
474
- }
475
- function mapVolumeMount(volumeMount) {
476
- if ("volume" in volumeMount) {
477
- return omit2(
478
- {
479
- ...volumeMount,
480
- name: output4(volumeMount.volume).apply(mapWorkloadVolume).apply((volume) => output4(volume.name))
481
- },
482
- ["volume"]
483
- );
484
- }
485
- return {
486
- ...volumeMount,
487
- name: volumeMount.name
488
- };
489
- }
490
- function mapEnvironmentSource(envFrom) {
491
- if (envFrom instanceof core4.v1.ConfigMap) {
492
- return {
493
- configMapRef: {
494
- name: envFrom.metadata.name
495
- }
496
- };
497
- }
498
- if (envFrom instanceof core4.v1.Secret) {
499
- return {
500
- secretRef: {
501
- name: envFrom.metadata.name
502
- }
503
- };
504
- }
505
- return envFrom;
506
- }
507
- function mapWorkloadVolume(volume) {
508
- if (volume instanceof PersistentVolumeClaim) {
509
- return {
510
- name: volume.metadata.name,
511
- persistentVolumeClaim: {
512
- claimName: volume.metadata.name
513
- }
514
- };
515
- }
516
- if (volume instanceof Secret) {
517
- return {
518
- name: volume.metadata.name,
519
- secret: {
520
- secretName: volume.metadata.name
521
- }
522
- };
523
- }
524
- if (volume instanceof ConfigMap) {
525
- return {
526
- name: volume.metadata.name,
527
- configMap: {
528
- name: volume.metadata.name
529
- }
530
- };
531
- }
532
- if (core4.v1.PersistentVolumeClaim.isInstance(volume)) {
533
- return {
534
- name: volume.metadata.name,
535
- persistentVolumeClaim: {
536
- claimName: volume.metadata.name
537
- }
538
- };
539
- }
540
- if (core4.v1.ConfigMap.isInstance(volume)) {
541
- return {
542
- name: volume.metadata.name,
543
- configMap: {
544
- name: volume.metadata.name
545
- }
546
- };
547
- }
548
- if (core4.v1.Secret.isInstance(volume)) {
549
- return {
550
- name: volume.metadata.name,
551
- secret: {
552
- secretName: volume.metadata.name
553
- }
554
- };
555
- }
556
- return volume;
557
- }
558
- function getWorkloadVolumeResourceUuid(volume) {
559
- if (volume instanceof PersistentVolumeClaim) {
560
- return volume.metadata.uid;
561
- }
562
- if (volume instanceof Secret) {
563
- return volume.metadata.uid;
564
- }
565
- if (volume instanceof ConfigMap) {
566
- return volume.metadata.uid;
567
- }
568
- if (core4.v1.PersistentVolumeClaim.isInstance(volume)) {
569
- return volume.metadata.uid;
570
- }
571
- if (core4.v1.ConfigMap.isInstance(volume)) {
572
- return volume.metadata.uid;
573
- }
574
- if (core4.v1.Secret.isInstance(volume)) {
575
- return volume.metadata.uid;
576
- }
577
- return output4(void 0);
578
- }
579
-
580
- // src/workload.ts
581
- import {
582
- normalize as normalize2
583
- } from "@highstate/pulumi";
584
- import {
585
- ComponentResource as ComponentResource4,
586
- interpolate,
587
- output as output5
588
- } from "@pulumi/pulumi";
589
- import { filter, isNonNullish, unique, uniqueBy } from "remeda";
590
- import { deepmerge as deepmerge2 } from "deepmerge-ts";
591
- import { sha256 } from "crypto-hash";
592
-
593
- // src/pod.ts
594
- var podSpecDefaults = {
595
- automountServiceAccountToken: false
596
- };
597
-
598
- // src/workload.ts
599
- var workloadExtraArgs = [...commonExtraArgs, "container", "containers"];
600
- var exposableWorkloadExtraArgs = [...workloadExtraArgs, "service", "httpRoute"];
601
- function getWorkloadComponents(name, args, parent, opts) {
602
- const labels = {
603
- "app.kubernetes.io/name": name
604
- };
605
- const containers = output5(args).apply((args2) => normalize2(args2.container, args2.containers));
606
- const rawVolumes = containers.apply((containers2) => {
607
- const containerVolumes = containers2.flatMap(
608
- (container) => normalize2(container.volume, container.volumes)
609
- );
610
- const containerVolumeMounts = containers2.flatMap((container) => {
611
- return normalize2(container.volumeMount, container.volumeMounts).map((volumeMount) => {
612
- return "volume" in volumeMount ? volumeMount.volume : void 0;
613
- }).filter(Boolean);
614
- });
615
- return output5([...containerVolumes, ...containerVolumeMounts]);
616
- });
617
- const volumes = rawVolumes.apply((rawVolumes2) => {
618
- return output5(rawVolumes2.map(mapWorkloadVolume)).apply(uniqueBy((volume) => volume.name));
619
- });
620
- const podSpec = output5({ args, containers, volumes }).apply(({ args: args2, containers: containers2, volumes: volumes2 }) => {
621
- const spec = {
622
- volumes: volumes2,
623
- containers: containers2.map((container) => mapContainerToRaw(container, args2.cluster, name)),
624
- ...podSpecDefaults
625
- };
626
- if (containers2.some((container) => container.enableTun) && args2.cluster.quirks?.tunDevicePolicy?.type !== "plugin") {
627
- spec.volumes = output5(spec.volumes).apply((volumes3) => [
628
- ...volumes3 ?? [],
629
- {
630
- name: "tun-device",
631
- hostPath: {
632
- path: "/dev/net/tun"
633
- }
634
- }
635
- ]);
636
- }
637
- return spec;
638
- });
639
- const dependencyHash = rawVolumes.apply((rawVolumes2) => {
640
- return output5(rawVolumes2.map(getWorkloadVolumeResourceUuid)).apply(filter(isNonNullish)).apply(unique()).apply((ids) => sha256(ids.join(",")));
641
- });
642
- const podTemplate = output5({ podSpec, dependencyHash }).apply(({ podSpec: podSpec2, dependencyHash: dependencyHash2 }) => {
643
- return {
644
- metadata: {
645
- labels,
646
- annotations: {
647
- "highstate.io/dependency-hash": dependencyHash2
648
- }
649
- },
650
- spec: podSpec2
651
- };
652
- });
653
- const networkPolicy = output5({ args, containers }).apply(({ args: args2, containers: containers2 }) => {
654
- const allowedEndpoints = containers2.flatMap((container) => container.allowedEndpoints ?? []);
655
- if (allowedEndpoints.length === 0 && !args2.networkPolicy) {
656
- return output5(void 0);
657
- }
658
- return NetworkPolicy.create(
659
- name,
660
- {
661
- cluster: args2.cluster,
662
- namespace: args2.namespace,
663
- selector: labels,
664
- ...args2.networkPolicy,
665
- egressRules: [
666
- ...args2.networkPolicy?.egressRules ?? [],
667
- ...allowedEndpoints.length > 0 ? [{ toEndpoints: allowedEndpoints }] : []
668
- ]
669
- },
670
- { ...opts, parent: parent() }
671
- );
672
- });
673
- return { labels, containers, volumes, podSpec, podTemplate, networkPolicy };
674
- }
675
- function getExposableWorkloadComponents(name, args, parent, opts) {
676
- const { labels, containers, volumes, podSpec, podTemplate, networkPolicy } = getWorkloadComponents(name, args, parent, opts);
677
- const service = output5({ args, containers }).apply(async ({ args: args2, containers: containers2 }) => {
678
- if (!args2.service && !args2.httpRoute) {
679
- return void 0;
680
- }
681
- if (args2.existing?.service) {
682
- return Service.of(name, args2.existing.service, args2.cluster, { ...opts, parent: parent() });
683
- }
684
- if (args2.existing) {
685
- return void 0;
686
- }
687
- const ports = containers2.flatMap((container) => normalize2(container.port, container.ports));
688
- return Service.create(
689
- name,
690
- {
691
- ...args2.service,
692
- selector: labels,
693
- cluster: args2.cluster,
694
- namespace: args2.namespace,
695
- ports: (
696
- // allow to completely override the ports
697
- !args2.service?.port && !args2.service?.ports ? ports.map(mapContainerPortToServicePort) : args2.service?.ports
698
- )
699
- },
700
- {
701
- ...opts,
702
- parent: parent(),
703
- provider: await getProvider(args2.cluster)
704
- }
705
- );
706
- });
707
- const httpRoute = output5({
708
- args,
709
- service
710
- }).apply(async ({ args: args2, service: service2 }) => {
711
- if (!args2.httpRoute || !service2) {
712
- return void 0;
713
- }
714
- if (args2.existing) {
715
- return void 0;
716
- }
717
- return new HttpRoute(
718
- name,
719
- {
720
- ...args2.httpRoute,
721
- cluster: args2.cluster,
722
- rule: {
723
- backend: service2
724
- }
725
- },
726
- {
727
- ...opts,
728
- parent: parent(),
729
- provider: await getProvider(args2.cluster)
730
- }
731
- );
732
- });
733
- return { labels, containers, volumes, podSpec, podTemplate, networkPolicy, service, httpRoute };
734
- }
735
- var Workload = class extends ComponentResource4 {
736
- constructor(type, name, args, opts, resourceType, cluster, metadata, networkPolicy) {
737
- super(type, name, args, opts);
738
- this.name = name;
739
- this.args = args;
740
- this.resourceType = resourceType;
741
- this.cluster = cluster;
742
- this.metadata = metadata;
743
- this.networkPolicy = networkPolicy;
744
- }
745
- /**
746
- * The instance terminal to interact with the deployment.
747
- */
748
- get terminal() {
749
- const containerName = output5(this.args).apply((args) => {
750
- const containers = normalize2(args.container, args.containers);
751
- return containers[0]?.name ?? this.name;
752
- });
753
- return output5({
754
- name: this.metadata.name,
755
- title: this.metadata.name,
756
- image: "ghcr.io/exeteres/highstate/terminal-kubectl",
757
- command: [
758
- "exec",
759
- "kubectl",
760
- "exec",
761
- "-it",
762
- "-n",
763
- this.metadata.namespace,
764
- interpolate`${this.resourceType}/${this.metadata.name}`,
765
- "-c",
766
- containerName,
767
- "--",
768
- this.args.terminalShell ?? "bash"
769
- ],
770
- files: {
771
- "/kubeconfig": this.cluster.kubeconfig
772
- },
773
- env: {
774
- KUBECONFIG: "/kubeconfig"
775
- }
776
- });
777
- }
778
- };
779
- var ExposableWorkload = class extends Workload {
780
- constructor(type, name, args, opts, resourceType, cluster, metadata, networkPolicy, _service, _httpRoute) {
781
- super(type, name, args, opts, resourceType, cluster, metadata, networkPolicy);
782
- this.name = name;
783
- this._service = _service;
784
- this._httpRoute = _httpRoute;
785
- }
786
- /**
787
- * The service associated with the workload.
788
- */
789
- get optionalService() {
790
- return this._service;
791
- }
792
- /**
793
- * The HTTP route associated with the workload.
794
- */
795
- get optionalHttpRoute() {
796
- return this._httpRoute;
797
- }
798
- /**
799
- * The service associated with the workload.
800
- *
801
- * Will throw an error if the service is not available.
802
- */
803
- get service() {
804
- return this._service.apply((service) => {
805
- if (!service) {
806
- throw new Error(`The service of the workload "${this.name}" is not available.`);
807
- }
808
- return service;
809
- });
810
- }
811
- /**
812
- * The HTTP route associated with the workload.
813
- *
814
- * Will throw an error if the HTTP route is not available.
815
- */
816
- get httpRoute() {
817
- return this._httpRoute.apply((httpRoute) => {
818
- if (!httpRoute) {
819
- throw new Error(`The HTTP route of the workload "${this.name}" is not available.`);
820
- }
821
- return httpRoute;
822
- });
823
- }
824
- /**
825
- * Creates a generic workload or patches the existing one.
826
- */
827
- static createOrPatchGeneric(name, args, opts) {
828
- return output5(args).apply(async (args2) => {
829
- if (args2.existing?.type === "k8s.deployment") {
830
- const { Deployment } = await import("./deployment-QTPBNKO5.js");
831
- return Deployment.patch(
832
- name,
833
- {
834
- ...deepmerge2(args2, args2.deployment),
835
- name: args2.existing.metadata.name,
836
- namespace: args2.existing.metadata.namespace
837
- },
838
- opts
839
- );
840
- }
841
- if (args2.existing?.type === "k8s.stateful-set") {
842
- const { StatefulSet } = await import("./stateful-set-K4GV7ZTK.js");
843
- return StatefulSet.patch(
844
- name,
845
- {
846
- ...deepmerge2(args2, args2.statefulSet),
847
- name: args2.existing.metadata.name,
848
- namespace: args2.existing.metadata.namespace
849
- },
850
- opts
851
- );
852
- }
853
- if (args2.type === "Deployment") {
854
- const { Deployment } = await import("./deployment-QTPBNKO5.js");
855
- return Deployment.create(name, deepmerge2(args2, args2.deployment), opts);
856
- }
857
- if (args2.type === "StatefulSet") {
858
- const { StatefulSet } = await import("./stateful-set-K4GV7ZTK.js");
859
- return StatefulSet.create(name, deepmerge2(args2, args2.statefulSet), opts);
860
- }
861
- throw new Error(`Unknown workload type: ${args2.type}`);
862
- });
863
- }
864
- };
865
-
866
- export {
867
- PersistentVolumeClaim,
868
- Secret,
869
- ConfigMap,
870
- exposableWorkloadExtraArgs,
871
- getWorkloadComponents,
872
- getExposableWorkloadComponents,
873
- Workload,
874
- ExposableWorkload
875
- };
876
- //# sourceMappingURL=chunk-SARVLQZY.js.map