@highstate/k8s 0.20.0 → 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 (81) 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-ADHZK6V2.js → chunk-9hs97f1q.js} +13 -11
  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 -3
  19. package/dist/impl/dynamic-endpoint-resolver.js +82 -81
  20. package/dist/impl/gateway-route.js +131 -168
  21. package/dist/impl/tls-certificate.js +31 -32
  22. package/dist/index.js +245 -201
  23. package/dist/units/cert-manager/index.js +19 -13
  24. package/dist/units/cluster-patch/index.js +9 -8
  25. package/dist/units/dns01-issuer/index.js +44 -41
  26. package/dist/units/existing-cluster/index.js +25 -13
  27. package/dist/units/gateway-api/index.js +15 -16
  28. package/dist/units/reduced-access-cluster/index.js +28 -32
  29. package/package.json +21 -21
  30. package/src/cron-job.ts +26 -1
  31. package/src/deployment.ts +17 -1
  32. package/src/job.ts +15 -1
  33. package/src/scripting/bundle.ts +21 -98
  34. package/src/scripting/environment.ts +2 -9
  35. package/src/shared.ts +1 -1
  36. package/src/stateful-set.ts +17 -1
  37. package/src/workload.ts +31 -14
  38. package/LICENSE +0 -21
  39. package/dist/chunk-23X5SXQG.js +0 -301
  40. package/dist/chunk-23X5SXQG.js.map +0 -1
  41. package/dist/chunk-ADHZK6V2.js.map +0 -1
  42. package/dist/chunk-BTAEFJ5N.js +0 -291
  43. package/dist/chunk-BTAEFJ5N.js.map +0 -1
  44. package/dist/chunk-HH2JJELM.js +0 -13
  45. package/dist/chunk-HH2JJELM.js.map +0 -1
  46. package/dist/chunk-IXE3OKB4.js +0 -249
  47. package/dist/chunk-IXE3OKB4.js.map +0 -1
  48. package/dist/chunk-OG2OPX7B.js +0 -333
  49. package/dist/chunk-OG2OPX7B.js.map +0 -1
  50. package/dist/chunk-P26SQ2ZB.js +0 -393
  51. package/dist/chunk-P26SQ2ZB.js.map +0 -1
  52. package/dist/chunk-PG27ZY2H.js +0 -319
  53. package/dist/chunk-PG27ZY2H.js.map +0 -1
  54. package/dist/chunk-PZYGZSN5.js +0 -54
  55. package/dist/chunk-PZYGZSN5.js.map +0 -1
  56. package/dist/chunk-S77TE7UC.js +0 -309
  57. package/dist/chunk-S77TE7UC.js.map +0 -1
  58. package/dist/chunk-SZKOAHNX.js +0 -1804
  59. package/dist/chunk-SZKOAHNX.js.map +0 -1
  60. package/dist/chunk-TOLFVF4S.js +0 -889
  61. package/dist/chunk-TOLFVF4S.js.map +0 -1
  62. package/dist/chunk-TVKT3ZYX.js +0 -423
  63. package/dist/chunk-TVKT3ZYX.js.map +0 -1
  64. package/dist/cron-job-RKB2HYTO.js +0 -7
  65. package/dist/cron-job-RKB2HYTO.js.map +0 -1
  66. package/dist/deployment-T35TUOL2.js +0 -7
  67. package/dist/deployment-T35TUOL2.js.map +0 -1
  68. package/dist/impl/dynamic-endpoint-resolver.js.map +0 -1
  69. package/dist/impl/gateway-route.js.map +0 -1
  70. package/dist/impl/tls-certificate.js.map +0 -1
  71. package/dist/index.js.map +0 -1
  72. package/dist/job-PE4AKOHB.js +0 -7
  73. package/dist/job-PE4AKOHB.js.map +0 -1
  74. package/dist/stateful-set-LUIRHQJY.js +0 -7
  75. package/dist/stateful-set-LUIRHQJY.js.map +0 -1
  76. package/dist/units/cert-manager/index.js.map +0 -1
  77. package/dist/units/cluster-patch/index.js.map +0 -1
  78. package/dist/units/dns01-issuer/index.js.map +0 -1
  79. package/dist/units/existing-cluster/index.js.map +0 -1
  80. package/dist/units/gateway-api/index.js.map +0 -1
  81. package/dist/units/reduced-access-cluster/index.js.map +0 -1
@@ -1,1804 +0,0 @@
1
- import { isEndpointFromCluster, mapServiceToLabelSelector, Service, mapContainerPortToServicePort } from './chunk-OG2OPX7B.js';
2
- import { commonExtraArgs, NamespacedResource, Namespace, mapMetadata, getProvider, Secret, mapSelectorLikeToSelector, getProviderAsync, mapNamespaceNameToSelector, getNamespaceName, images_exports, getClusterKubeconfigContent } from './chunk-TOLFVF4S.js';
3
- import { z, getOrCreate, trimIndentation } from '@highstate/contract';
4
- import { k8s } from '@highstate/library';
5
- import { ComponentResource, makeEntityOutput, output, toPromise, interpolate, normalize, normalizeInputs, makeFileOutput } from '@highstate/pulumi';
6
- import { core, networking } from '@pulumi/kubernetes';
7
- import { deepmerge } from 'deepmerge-ts';
8
- import { omit, concat, map, groupBy, isNonNullish, mergeDeep, uniqueBy, flat, merge, unique, filter } from 'remeda';
9
- import { ImplementationMediator, parseEndpoint, addressToCidr, endpointToString, l3EndpointToCidr, AccessPointRoute, mergeEndpoints } from '@highstate/common';
10
- import { output as output$1, interpolate as interpolate$1 } from '@pulumi/pulumi';
11
- import { sha256 } from 'crypto-hash';
12
-
13
- var ConfigMap = class _ConfigMap extends NamespacedResource {
14
- constructor(type, name, args, opts, metadata, namespace, data) {
15
- super(type, name, args, opts, metadata, namespace);
16
- this.data = data;
17
- }
18
- static apiVersion = "v1";
19
- static kind = "ConfigMap";
20
- /**
21
- * The Highstate config map entity.
22
- */
23
- get entity() {
24
- return makeEntityOutput({
25
- entity: k8s.configMapEntity,
26
- identity: this.metadata.uid,
27
- meta: {
28
- title: this.metadata.name
29
- },
30
- value: {
31
- ...this.entityBase
32
- }
33
- });
34
- }
35
- /**
36
- * Creates a new config map.
37
- */
38
- static create(name, args, opts) {
39
- return new CreatedConfigMap(name, args, opts);
40
- }
41
- /**
42
- * Creates a new config map or patches an existing one.
43
- *
44
- * @param name The name of the resource. May not be the same as the config map name.
45
- * @param args The arguments to create or patch the config map with.
46
- * @param opts Optional resource options.
47
- */
48
- static createOrPatch(name, args, opts) {
49
- if (args.existing) {
50
- return new ConfigMapPatch(name, {
51
- ...args,
52
- name: output(args.existing).metadata.name
53
- });
54
- }
55
- return new CreatedConfigMap(name, args, opts);
56
- }
57
- /**
58
- * Creates a new config map or gets an existing one.
59
- *
60
- * @param name The name of the resource. May not be the same as the config map name. Will not be used when existing config map is retrieved.
61
- * @param args The arguments to create or get the config map with.
62
- * @param opts Optional resource options.
63
- */
64
- static async createOrGet(name, args, opts) {
65
- if (args.existing) {
66
- return await _ConfigMap.forAsync(args.existing, output(args.namespace).cluster);
67
- }
68
- return new CreatedConfigMap(name, args, opts);
69
- }
70
- /**
71
- * Patches an existing config map.
72
- *
73
- * Will throw an error if the config map does not exist.
74
- *
75
- * @param name The name of the resource. May not be the same as the config map name.
76
- * @param args The arguments to patch the config map with.
77
- * @param opts Optional resource options.
78
- */
79
- static patch(name, args, opts) {
80
- return new ConfigMapPatch(name, args, opts);
81
- }
82
- /**
83
- * Wraps an existing Kubernetes config map.
84
- */
85
- static wrap(name, args, opts) {
86
- return new WrappedConfigMap(name, args, opts);
87
- }
88
- /**
89
- * Gets an existing config map.
90
- *
91
- * Will throw an error if the config map does not exist.
92
- */
93
- static get(name, args, opts) {
94
- return new ExternalConfigMap(name, args, opts);
95
- }
96
- static configMapCache = /* @__PURE__ */ new Map();
97
- /**
98
- * Gets an existing config map for a given entity.
99
- * Prefer this method over `get` when possible.
100
- *
101
- * It automatically names the resource with the following format: `{clusterName}.{namespace}.{name}.{clusterId}`.
102
- *
103
- * This method is idempotent and will return the same instance for the same entity.
104
- *
105
- * @param entity The entity to get the config map for.
106
- * @param cluster The cluster where the config map is located.
107
- */
108
- static for(entity, cluster) {
109
- return getOrCreate(
110
- _ConfigMap.configMapCache,
111
- `${entity.clusterName}.${entity.metadata.namespace}.${entity.metadata.name}.${entity.clusterId}`,
112
- (name) => {
113
- return _ConfigMap.get(name, {
114
- name: entity.metadata.name,
115
- namespace: Namespace.forResource(entity, cluster)
116
- });
117
- }
118
- );
119
- }
120
- /**
121
- * Gets an existing config map for a given entity.
122
- * Prefer this method over `get` when possible.
123
- *
124
- * It automatically names the resource with the following format: `{clusterName}.{namespace}.{name}.{clusterId}`.
125
- *
126
- * This method is idempotent and will return the same instance for the same entity.
127
- *
128
- * @param entity The entity to get the config map for.
129
- * @param cluster The cluster where the config map is located.
130
- */
131
- static async forAsync(entity, cluster) {
132
- const resolvedEntity = await toPromise(entity);
133
- return _ConfigMap.for(resolvedEntity, cluster);
134
- }
135
- };
136
- var CreatedConfigMap = class extends ConfigMap {
137
- constructor(name, args, opts) {
138
- const configMap = output(args.namespace).cluster.apply((cluster) => {
139
- return new core.v1.ConfigMap(
140
- name,
141
- {
142
- metadata: mapMetadata(args, name),
143
- data: args.data
144
- },
145
- {
146
- ...opts,
147
- parent: this,
148
- provider: getProvider(cluster)
149
- }
150
- );
151
- });
152
- super(
153
- "highstate:k8s:ConfigMap",
154
- name,
155
- args,
156
- opts,
157
- configMap.metadata,
158
- output(args.namespace),
159
- configMap.data
160
- );
161
- }
162
- };
163
- var ConfigMapPatch = class extends ConfigMap {
164
- constructor(name, args, opts) {
165
- const configMap = output(args.namespace).cluster.apply((cluster) => {
166
- return new core.v1.ConfigMapPatch(
167
- name,
168
- {
169
- metadata: mapMetadata(args, name),
170
- data: args.data
171
- },
172
- {
173
- ...opts,
174
- parent: this,
175
- provider: getProvider(cluster)
176
- }
177
- );
178
- });
179
- super(
180
- "highstate:k8s:ConfigMapPatch",
181
- name,
182
- args,
183
- opts,
184
- configMap.metadata,
185
- output(args.namespace),
186
- configMap.data
187
- );
188
- }
189
- };
190
- var WrappedConfigMap = class extends ConfigMap {
191
- constructor(name, args, opts) {
192
- super(
193
- "highstate:k8s:WrappedConfigMap",
194
- name,
195
- args,
196
- opts,
197
- output(args.configMap).metadata,
198
- output(args.namespace),
199
- output(args.configMap).data
200
- );
201
- }
202
- };
203
- var ExternalConfigMap = class extends ConfigMap {
204
- constructor(name, args, opts) {
205
- const configMap = output(args.namespace).cluster.apply((cluster) => {
206
- return core.v1.ConfigMap.get(
207
- name,
208
- interpolate`${output(args.namespace).metadata.name}/${args.name}`,
209
- { ...opts, parent: this, provider: getProvider(cluster) }
210
- );
211
- });
212
- super(
213
- "highstate:k8s:ExternalConfigMap",
214
- name,
215
- args,
216
- opts,
217
- configMap.metadata,
218
- output(args.namespace),
219
- configMap.data
220
- );
221
- }
222
- };
223
- var extraPersistentVolumeClaimArgs = [...commonExtraArgs, "size"];
224
- var PersistentVolumeClaim = class _PersistentVolumeClaim extends NamespacedResource {
225
- constructor(type, name, args, opts, metadata, namespace, spec, status) {
226
- super(type, name, args, opts, metadata, namespace);
227
- this.spec = spec;
228
- this.status = status;
229
- }
230
- static apiVersion = "v1";
231
- static kind = "PersistentVolumeClaim";
232
- /**
233
- * The Highstate PVC entity.
234
- */
235
- get entity() {
236
- return makeEntityOutput({
237
- entity: k8s.persistentVolumeClaimEntity,
238
- identity: this.metadata.uid,
239
- meta: {
240
- title: this.metadata.name
241
- },
242
- value: {
243
- ...this.entityBase
244
- }
245
- });
246
- }
247
- /**
248
- * Creates a new PVC.
249
- */
250
- static create(name, args, opts) {
251
- return new CreatedPersistentVolumeClaim(name, args, opts);
252
- }
253
- /**
254
- * Creates a new PVC or patches an existing one.
255
- *
256
- * @param name The name of the resource. May not be the same as the PVC name.
257
- * @param args The arguments to create or patch the PVC with.
258
- * @param opts Optional resource options.
259
- */
260
- static createOrPatch(name, args, opts) {
261
- if (args.existing) {
262
- return new PersistentVolumeClaimPatch(name, {
263
- ...args,
264
- name: output(args.existing).metadata.name
265
- });
266
- }
267
- return new CreatedPersistentVolumeClaim(name, args, opts);
268
- }
269
- /**
270
- * Creates a new PVC or gets an existing one.
271
- *
272
- * @param name The name of the resource. May not be the same as the PVC name. Will not be used when existing PVC is retrieved.
273
- * @param args The arguments to create or get the PVC with.
274
- * @param opts Optional resource options.
275
- */
276
- static async createOrGet(name, args, opts) {
277
- if (args.existing) {
278
- return await _PersistentVolumeClaim.forAsync(args.existing, output(args.namespace).cluster);
279
- }
280
- return new CreatedPersistentVolumeClaim(name, args, opts);
281
- }
282
- /**
283
- * Patches an existing PVC.
284
- *
285
- * Will throw an error if the PVC does not exist.
286
- *
287
- * @param name The name of the resource. May not be the same as the PVC name.
288
- * @param args The arguments to patch the PVC with.
289
- * @param opts Optional resource options.
290
- */
291
- static patch(name, args, opts) {
292
- return new PersistentVolumeClaimPatch(name, args, opts);
293
- }
294
- /**
295
- * Wraps an existing Kubernetes PVC.
296
- */
297
- static wrap(name, args, opts) {
298
- return new WrappedPersistentVolumeClaim(name, args, opts);
299
- }
300
- /**
301
- * Gets an existing PVC.
302
- *
303
- * Will throw an error if the PVC does not exist.
304
- */
305
- static get(name, args, opts) {
306
- return new ExternalPersistentVolumeClaim(name, args, opts);
307
- }
308
- static pvcCache = /* @__PURE__ */ new Map();
309
- /**
310
- * Gets an existing PVC for a given entity.
311
- * Prefer this method over `get` when possible.
312
- *
313
- * It automatically names the resource with the following format: `{clusterName}.{namespace}.{name}.{clusterId}`.
314
- *
315
- * This method is idempotent and will return the same instance for the same entity.
316
- *
317
- * @param entity The entity to get the PVC for.
318
- * @param cluster The cluster where the PVC is located.
319
- */
320
- static for(entity, cluster) {
321
- return getOrCreate(
322
- _PersistentVolumeClaim.pvcCache,
323
- `${entity.clusterName}.${entity.metadata.namespace}.${entity.metadata.name}.${entity.clusterId}`,
324
- (name) => {
325
- return _PersistentVolumeClaim.get(name, {
326
- name: entity.metadata.name,
327
- namespace: Namespace.forResource(entity, cluster)
328
- });
329
- }
330
- );
331
- }
332
- /**
333
- * Gets an existing PVC for a given entity.
334
- * Prefer this method over `get` when possible.
335
- *
336
- * It automatically names the resource with the following format: `{clusterName}.{namespace}.{name}.{clusterId}`.
337
- *
338
- * This method is idempotent and will return the same instance for the same entity.
339
- *
340
- * @param entity The entity to get the PVC for.
341
- * @param cluster The cluster where the PVC is located.
342
- */
343
- static async forAsync(entity, cluster) {
344
- const resolvedEntity = await toPromise(entity);
345
- return _PersistentVolumeClaim.for(resolvedEntity, cluster);
346
- }
347
- };
348
- var CreatedPersistentVolumeClaim = class extends PersistentVolumeClaim {
349
- constructor(name, args, opts) {
350
- const pvc = output(args.namespace).cluster.apply((cluster) => {
351
- return new core.v1.PersistentVolumeClaim(
352
- name,
353
- {
354
- metadata: mapMetadata(args, name),
355
- spec: output(args).apply((args2) => {
356
- return deepmerge(
357
- {
358
- accessModes: ["ReadWriteOnce"],
359
- resources: {
360
- requests: {
361
- storage: args2.size ?? "100Mi"
362
- }
363
- }
364
- },
365
- omit(args2, extraPersistentVolumeClaimArgs)
366
- );
367
- })
368
- },
369
- {
370
- ...opts,
371
- parent: this,
372
- provider: getProvider(cluster)
373
- }
374
- );
375
- });
376
- super(
377
- "highstate:k8s:PersistentVolumeClaim",
378
- name,
379
- args,
380
- opts,
381
- pvc.metadata,
382
- output(args.namespace),
383
- pvc.spec,
384
- pvc.status
385
- );
386
- }
387
- };
388
- var PersistentVolumeClaimPatch = class extends PersistentVolumeClaim {
389
- constructor(name, args, opts) {
390
- const pvc = output(args.namespace).cluster.apply((cluster) => {
391
- return new core.v1.PersistentVolumeClaimPatch(
392
- name,
393
- {
394
- metadata: mapMetadata(args, name),
395
- spec: output(args).apply((args2) => {
396
- return deepmerge(
397
- {
398
- accessModes: ["ReadWriteOnce"],
399
- resources: {
400
- requests: {
401
- storage: args2.size ?? "100Mi"
402
- }
403
- }
404
- },
405
- omit(args2, extraPersistentVolumeClaimArgs)
406
- );
407
- })
408
- },
409
- {
410
- ...opts,
411
- parent: this,
412
- provider: getProvider(cluster)
413
- }
414
- );
415
- });
416
- super(
417
- "highstate:k8s:PersistentVolumeClaimPatch",
418
- name,
419
- args,
420
- opts,
421
- pvc.metadata,
422
- output(args.namespace),
423
- pvc.spec,
424
- pvc.status
425
- );
426
- }
427
- };
428
- var WrappedPersistentVolumeClaim = class extends PersistentVolumeClaim {
429
- constructor(name, args, opts) {
430
- super(
431
- "highstate:k8s:WrappedPersistentVolumeClaim",
432
- name,
433
- args,
434
- opts,
435
- output(args.pvc).metadata,
436
- output(args.namespace),
437
- output(args.pvc).spec,
438
- output(args.pvc).status
439
- );
440
- }
441
- };
442
- var ExternalPersistentVolumeClaim = class extends PersistentVolumeClaim {
443
- constructor(name, args, opts) {
444
- const pvc = output(args.namespace).cluster.apply((cluster) => {
445
- return core.v1.PersistentVolumeClaim.get(
446
- name,
447
- interpolate`${output(args.namespace).metadata.name}/${args.name}`,
448
- { ...opts, parent: this, provider: getProvider(cluster) }
449
- );
450
- });
451
- super(
452
- "highstate:k8s:ExternalPersistentVolumeClaim",
453
- name,
454
- args,
455
- opts,
456
- pvc.metadata,
457
- output(args.namespace),
458
- pvc.spec,
459
- pvc.status
460
- );
461
- }
462
- };
463
- function getAutoVolumeName(workloadName, index) {
464
- if (index === 0) {
465
- return `${workloadName}-data`;
466
- }
467
- return `${workloadName}-data-${index}`;
468
- }
469
- var containerExtraArgs = [
470
- "port",
471
- "volumeMount",
472
- "volume",
473
- "environment",
474
- "environmentSource",
475
- "environmentSources"
476
- ];
477
- function getFallbackContainerName(name, index) {
478
- if (index === 0) {
479
- return name;
480
- }
481
- return `${name}-${index}`;
482
- }
483
- function mapContainerToRaw(container, cluster, fallbackName) {
484
- const containerName = container.name ?? fallbackName;
485
- const spec = {
486
- ...omit(container, containerExtraArgs),
487
- name: containerName,
488
- ports: normalize(container.port, container.ports),
489
- volumeMounts: map(normalize(container.volumeMount, container.volumeMounts), mapVolumeMount),
490
- env: concat(
491
- container.environment ? mapContainerEnvironment(container.environment) : [],
492
- container.env ?? []
493
- ),
494
- envFrom: concat(
495
- map(
496
- normalize(container.environmentSource, container.environmentSources),
497
- mapEnvironmentSource
498
- ),
499
- container.envFrom ?? []
500
- )
501
- };
502
- if (container.enableTun) {
503
- spec.securityContext ??= {};
504
- spec.securityContext.capabilities ??= {};
505
- spec.securityContext.capabilities.add = ["NET_ADMIN"];
506
- if (cluster.quirks?.tunDevicePolicy?.type === "plugin") {
507
- spec.resources ??= {};
508
- spec.resources.limits ??= {};
509
- spec.resources.limits[cluster.quirks.tunDevicePolicy.resourceName] = cluster.quirks.tunDevicePolicy.resourceValue;
510
- } else {
511
- spec.volumeMounts ??= [];
512
- spec.volumeMounts.push({
513
- name: "tun-device",
514
- mountPath: "/dev/net/tun",
515
- readOnly: false
516
- });
517
- }
518
- }
519
- return spec;
520
- }
521
- function mapContainerEnvironment(environment) {
522
- const envVars = [];
523
- for (const [name, value] of Object.entries(environment)) {
524
- if (!value) {
525
- continue;
526
- }
527
- if (typeof value === "string") {
528
- envVars.push({ name, value });
529
- continue;
530
- }
531
- if ("secret" in value) {
532
- envVars.push({
533
- name,
534
- valueFrom: {
535
- secretKeyRef: {
536
- name: value.secret.metadata.name,
537
- key: value.key
538
- }
539
- }
540
- });
541
- continue;
542
- }
543
- if ("configMap" in value) {
544
- envVars.push({
545
- name,
546
- valueFrom: {
547
- configMapKeyRef: {
548
- name: value.configMap.metadata.name,
549
- key: value.key
550
- }
551
- }
552
- });
553
- continue;
554
- }
555
- envVars.push({ name, valueFrom: value });
556
- }
557
- return envVars;
558
- }
559
- function mapVolumeMount(volumeMount) {
560
- if ("volume" in volumeMount) {
561
- return omit(
562
- {
563
- ...volumeMount,
564
- name: output(volumeMount.volume).apply(mapWorkloadVolume).apply((volume) => output(volume.name))
565
- },
566
- ["volume"]
567
- );
568
- }
569
- return {
570
- ...volumeMount,
571
- name: volumeMount.name
572
- };
573
- }
574
- function mapEnvironmentSource(envFrom) {
575
- if (envFrom instanceof core.v1.ConfigMap || envFrom instanceof ConfigMap) {
576
- return {
577
- configMapRef: {
578
- name: envFrom.metadata.name
579
- }
580
- };
581
- }
582
- if (envFrom instanceof core.v1.Secret || envFrom instanceof Secret) {
583
- return {
584
- secretRef: {
585
- name: envFrom.metadata.name
586
- }
587
- };
588
- }
589
- return envFrom;
590
- }
591
- function mapWorkloadVolume(volume) {
592
- if (volume instanceof PersistentVolumeClaim) {
593
- return {
594
- name: volume.metadata.name,
595
- persistentVolumeClaim: {
596
- claimName: volume.metadata.name
597
- }
598
- };
599
- }
600
- if (volume instanceof Secret) {
601
- return {
602
- name: volume.metadata.name,
603
- secret: {
604
- secretName: volume.metadata.name
605
- }
606
- };
607
- }
608
- if (volume instanceof ConfigMap) {
609
- return {
610
- name: volume.metadata.name,
611
- configMap: {
612
- name: volume.metadata.name
613
- }
614
- };
615
- }
616
- if (core.v1.PersistentVolumeClaim.isInstance(volume)) {
617
- return {
618
- name: volume.metadata.name,
619
- persistentVolumeClaim: {
620
- claimName: volume.metadata.name
621
- }
622
- };
623
- }
624
- if (core.v1.ConfigMap.isInstance(volume)) {
625
- return {
626
- name: volume.metadata.name,
627
- configMap: {
628
- name: volume.metadata.name
629
- }
630
- };
631
- }
632
- if (core.v1.Secret.isInstance(volume)) {
633
- return {
634
- name: volume.metadata.name,
635
- secret: {
636
- secretName: volume.metadata.name
637
- }
638
- };
639
- }
640
- return volume;
641
- }
642
- function getWorkloadVolumeResourceUuid(volume) {
643
- if (volume instanceof PersistentVolumeClaim) {
644
- return volume.metadata.uid;
645
- }
646
- if (volume instanceof Secret) {
647
- return volume.metadata.uid;
648
- }
649
- if (volume instanceof ConfigMap) {
650
- return volume.metadata.uid;
651
- }
652
- if (core.v1.PersistentVolumeClaim.isInstance(volume)) {
653
- return volume.metadata.uid;
654
- }
655
- if (core.v1.ConfigMap.isInstance(volume)) {
656
- return volume.metadata.uid;
657
- }
658
- if (core.v1.Secret.isInstance(volume)) {
659
- return volume.metadata.uid;
660
- }
661
- return output(void 0);
662
- }
663
-
664
- // src/network.ts
665
- function getBestEndpoint(endpoints, cluster) {
666
- if (!endpoints.length) {
667
- return void 0;
668
- }
669
- if (endpoints.length === 1) {
670
- return endpoints[0];
671
- }
672
- if (cluster) {
673
- const clusterEndpoint = endpoints.find(
674
- (endpoint) => isEndpointFromCluster(endpoint, cluster) && endpoint.metadata["k8s.service"].isInternal
675
- );
676
- if (clusterEndpoint) {
677
- return clusterEndpoint;
678
- }
679
- }
680
- const publicEndpoint = endpoints.find((endpoint) => endpoint.metadata["iana.scope"] === "global");
681
- if (publicEndpoint) {
682
- return publicEndpoint;
683
- }
684
- return endpoints[0];
685
- }
686
- function requireBestEndpoint(endpoints, cluster) {
687
- const endpoint = getBestEndpoint(endpoints, cluster);
688
- if (!endpoint) {
689
- throw new Error(`No best endpoint found for cluster "${cluster.name}" (${cluster.id})`);
690
- }
691
- return endpoint;
692
- }
693
- var networkPolicyMediator = new ImplementationMediator(
694
- "network-policy",
695
- z.object({ name: z.string(), args: z.custom() }),
696
- z.instanceof(ComponentResource)
697
- );
698
- var NetworkPolicy = class _NetworkPolicy extends ComponentResource {
699
- /**
700
- * The underlying network policy resource.
701
- */
702
- networkPolicy;
703
- constructor(name, args, opts) {
704
- super("k8s:network-policy", name, args, opts);
705
- const normalizedArgs = output(args).apply(async (args2) => {
706
- const ingressRules = normalize(args2.ingressRule, args2.ingressRules);
707
- const egressRules = normalize(args2.egressRule, args2.egressRules);
708
- const cluster = await toPromise(args2.namespace.cluster);
709
- const extraEgressRules = [];
710
- if (args2.allowKubeDns) {
711
- extraEgressRules.push({
712
- namespaces: ["kube-system"],
713
- namespaceSelectors: [],
714
- selectors: [{ matchLabels: { "k8s-app": "kube-dns" } }],
715
- ports: [{ port: 53, protocol: "UDP" }],
716
- all: false,
717
- clusterPods: false,
718
- cidrs: [],
719
- fqdns: [],
720
- services: []
721
- });
722
- }
723
- return {
724
- ...args2,
725
- podSelector: args2.selector ? mapSelectorLikeToSelector(args2.selector) : {},
726
- cluster,
727
- isolateEgress: args2.isolateEgress ?? false,
728
- isolateIngress: args2.isolateIngress ?? false,
729
- allowKubeApiServer: args2.allowKubeApiServer ?? false,
730
- ingressRules: ingressRules.flatMap((rule) => {
731
- const endpoints = normalize(rule?.fromEndpoint, rule?.fromEndpoints);
732
- const parsedEndpoints = endpoints.map((endpoint) => parseEndpoint(endpoint));
733
- const endpointsNamespaces = groupBy(parsedEndpoints, (endpoint) => {
734
- const namespace = isEndpointFromCluster(endpoint, cluster) ? endpoint.metadata["k8s.service"].namespace : "";
735
- return namespace;
736
- });
737
- const l3OnlyRule = endpointsNamespaces[""] ? _NetworkPolicy.getRuleFromEndpoint(void 0, endpointsNamespaces[""], cluster) : void 0;
738
- const otherRules = Object.entries(endpointsNamespaces).filter(([key]) => key !== "").map(([, endpoints2]) => {
739
- return _NetworkPolicy.getRuleFromEndpoint(void 0, endpoints2, cluster);
740
- });
741
- return [
742
- {
743
- all: rule.fromAll ?? false,
744
- clusterPods: rule.fromClusterPods ?? false,
745
- cidrs: normalize(rule.fromCidr, rule.fromCidrs).concat(l3OnlyRule?.cidrs ?? []),
746
- fqdns: [],
747
- services: normalize(rule.fromService, rule.fromServices),
748
- namespaces: normalize(rule.fromNamespace, rule.fromNamespaces),
749
- namespaceSelectors: normalize(
750
- rule.fromNamespaceSelector,
751
- rule.fromNamespaceSelectors
752
- ),
753
- selectors: normalize(rule.fromSelector, rule.fromSelectors),
754
- ports: normalize(rule.toPort, rule.toPorts)
755
- },
756
- ...otherRules
757
- ].filter((rule2) => !_NetworkPolicy.isEmptyRule(rule2));
758
- }),
759
- egressRules: egressRules.flatMap((rule) => {
760
- const endpoints = normalize(rule?.toEndpoint, rule?.toEndpoints);
761
- const parsedEndpoints = endpoints.map((endpoint) => parseEndpoint(endpoint));
762
- const endpointsByPortsAnsNamespaces = groupBy(parsedEndpoints, (endpoint) => {
763
- const namespace = isEndpointFromCluster(endpoint, cluster) ? endpoint.metadata["k8s.service"].namespace : "";
764
- const port = isEndpointFromCluster(endpoint, cluster) ? endpoint.metadata["k8s.service"].targetPort : endpoint.level !== 3 ? endpoint.port : void 0;
765
- return `${port ?? "0"}:${namespace}`;
766
- });
767
- const l3OnlyRule = endpointsByPortsAnsNamespaces["0:"] ? _NetworkPolicy.getRuleFromEndpoint(
768
- void 0,
769
- endpointsByPortsAnsNamespaces["0:"],
770
- cluster
771
- ) : void 0;
772
- const otherRules = Object.entries(endpointsByPortsAnsNamespaces).filter(([key]) => key !== "0:").map(([key, endpoints2]) => {
773
- const [port] = key.split(":");
774
- const portNumber = parseInt(port, 10);
775
- const portValue = Number.isNaN(portNumber) ? port : portNumber;
776
- return _NetworkPolicy.getRuleFromEndpoint(portValue, endpoints2, cluster);
777
- });
778
- return [
779
- {
780
- all: rule.toAll ?? false,
781
- clusterPods: rule.toClusterPods ?? false,
782
- cidrs: normalize(rule.toCidr, rule.toCidrs).concat(l3OnlyRule?.cidrs ?? []),
783
- fqdns: normalize(rule.toFqdn, rule.toFqdns).concat(l3OnlyRule?.fqdns ?? []),
784
- services: normalize(rule.toService, rule.toServices),
785
- namespaces: normalize(rule.toNamespace, rule.toNamespaces),
786
- namespaceSelectors: normalize(rule.toNamespaceSelector, rule.toNamespaceSelectors),
787
- selectors: normalize(rule.toSelector, rule.toSelectors),
788
- ports: normalize(rule.toPort, rule.toPorts)
789
- },
790
- ...otherRules
791
- ].filter((rule2) => !_NetworkPolicy.isEmptyRule(rule2));
792
- }).concat(extraEgressRules)
793
- };
794
- });
795
- this.networkPolicy = output(
796
- normalizedArgs.apply(async (args2) => {
797
- const cluster = args2.cluster;
798
- if (cluster.networkPolicyImplRef) {
799
- return networkPolicyMediator.call(cluster.networkPolicyImplRef, {
800
- name,
801
- args: args2
802
- });
803
- }
804
- const nativePolicy = new NativeNetworkPolicy(name, args2, {
805
- ...opts,
806
- parent: this,
807
- provider: await getProviderAsync(output(args2.namespace).cluster)
808
- });
809
- return nativePolicy.networkPolicy;
810
- })
811
- );
812
- }
813
- static getRuleFromEndpoint(port, endpoints, cluster) {
814
- const ports = port ? [
815
- {
816
- port,
817
- protocol: endpoints[0].level !== 3 ? endpoints[0].protocol?.toUpperCase() : void 0
818
- }
819
- ] : [];
820
- const cidrs = endpoints.filter((endpoint) => !isEndpointFromCluster(endpoint, cluster)).map((endpoint) => endpoint.address ? addressToCidr(endpoint.address) : null).filter(isNonNullish);
821
- const fqdns = endpoints.filter((endpoint) => endpoint.type === "hostname").map((endpoint) => endpoint.hostname);
822
- const selectors = endpoints.filter((endpoint) => isEndpointFromCluster(endpoint, cluster)).map((endpoint) => endpoint.metadata["k8s.service"].selector);
823
- const namespace = endpoints.filter((endpoint) => isEndpointFromCluster(endpoint, cluster)).map((endpoint) => endpoint.metadata["k8s.service"].namespace)[0];
824
- return {
825
- all: false,
826
- clusterPods: false,
827
- cidrs,
828
- fqdns,
829
- services: [],
830
- namespaces: namespace ? [namespace] : [],
831
- namespaceSelectors: [],
832
- selectors,
833
- ports
834
- };
835
- }
836
- static isEmptyRule(rule) {
837
- return !rule.all && !rule.clusterPods && rule.cidrs.length === 0 && rule.fqdns.length === 0 && rule.services.length === 0 && rule.namespaces.length === 0 && rule.namespaceSelectors.length === 0 && rule.selectors.length === 0 && rule.ports.length === 0;
838
- }
839
- /**
840
- * Creates network policy to isolate the namespace by denying all traffic to/from it.
841
- *
842
- * Automatically names the policy as: `isolate-namespace.{clusterName}.{namespace}.{clusterId}`.
843
- *
844
- * @param namespace The namespace to isolate.
845
- * @param opts Optional resource options.
846
- */
847
- static async isolateNamespace(namespace, opts) {
848
- const name = await toPromise(output(namespace).metadata.name);
849
- const cluster = await toPromise(output(namespace).cluster);
850
- return new _NetworkPolicy(
851
- `isolate-namespace.${cluster.name}.${name}.${cluster.id}`,
852
- {
853
- namespace,
854
- description: "By default, deny all traffic to/from the namespace.",
855
- isolateEgress: true,
856
- isolateIngress: true
857
- },
858
- opts
859
- );
860
- }
861
- /**
862
- * Creates network policy to allow all traffic inside the namespace (pod to pod within same namespace).
863
- *
864
- * Automatically names the policy as: `allow-inside-namespace.{clusterName}.{namespace}.{clusterId}`.
865
- *
866
- * @param namespace The namespace to create the policy in.
867
- * @param opts Optional resource options.
868
- */
869
- static async allowInsideNamespace(namespace, opts) {
870
- const nsName = await toPromise(output(namespace).metadata.name);
871
- const cluster = await toPromise(output(namespace).cluster);
872
- return new _NetworkPolicy(
873
- `allow-inside-namespace.${cluster.name}.${nsName}.${cluster.id}`,
874
- {
875
- namespace,
876
- description: "Allow all traffic inside the namespace.",
877
- ingressRule: { fromNamespace: namespace },
878
- egressRule: { toNamespace: namespace }
879
- },
880
- opts
881
- );
882
- }
883
- /**
884
- * Creates network policy to allow traffic from the namespace to the Kubernetes API server.
885
- *
886
- * Automatically names the policy as: `allow-kube-api-server.{clusterName}.{namespace}.{clusterId}`.
887
- *
888
- * @param namespace The namespace to create the policy in.
889
- * @param opts Optional resource options.
890
- */
891
- static async allowKubeApiServer(namespace, opts) {
892
- const nsName = await toPromise(output(namespace).metadata.name);
893
- const cluster = await toPromise(output(namespace).cluster);
894
- return new _NetworkPolicy(
895
- `allow-kube-api-server.${cluster.name}.${nsName}.${cluster.id}`,
896
- {
897
- namespace,
898
- description: "Allow all traffic to the Kubernetes API server from the namespace.",
899
- allowKubeApiServer: true
900
- },
901
- opts
902
- );
903
- }
904
- /**
905
- * Creates network policy to allow egress DNS traffic (UDP 53) required for name resolution.
906
- *
907
- * Automatically names the policy as: `allow-kube-dns.{clusterName}.{namespace}.{clusterId}`.
908
- *
909
- * @param namespace The namespace to create the policy in.
910
- * @param opts Optional resource options.
911
- */
912
- static async allowKubeDns(namespace, opts) {
913
- const nsName = await toPromise(output(namespace).metadata.name);
914
- const cluster = await toPromise(output(namespace).cluster);
915
- return new _NetworkPolicy(
916
- `allow-kube-dns.${cluster.name}.${nsName}.${cluster.id}`,
917
- {
918
- namespace,
919
- description: "Allow all traffic to the Kubernetes DNS server from the namespace.",
920
- allowKubeDns: true
921
- },
922
- opts
923
- );
924
- }
925
- /**
926
- * Creates network policy to allow all egress traffic from the namespace.
927
- *
928
- * Automatically names the policy as: `allow-all-egress.{clusterName}.{namespace}.{clusterId}`.
929
- *
930
- * @param namespace The namespace to create the policy in.
931
- * @param opts Optional resource options.
932
- */
933
- static async allowAllEgress(namespace, opts) {
934
- const nsName = await toPromise(output(namespace).metadata.name);
935
- const cluster = await toPromise(output(namespace).cluster);
936
- return new _NetworkPolicy(
937
- `allow-all-egress.${cluster.name}.${nsName}.${cluster.id}`,
938
- {
939
- namespace,
940
- description: "Allow all egress traffic from the namespace.",
941
- egressRule: { toAll: true }
942
- },
943
- opts
944
- );
945
- }
946
- /**
947
- * Creates network policy to allow all ingress traffic to the namespace.
948
- *
949
- * Automatically names the policy as: `allow-all-ingress.{clusterName}.{namespace}.{clusterId}`.
950
- *
951
- * @param namespace The namespace to create the policy in.
952
- * @param opts Optional resource options.
953
- */
954
- static async allowAllIngress(namespace, opts) {
955
- const nsName = await toPromise(output(namespace).metadata.name);
956
- const cluster = await toPromise(output(namespace).cluster);
957
- return new _NetworkPolicy(
958
- `allow-all-ingress.${cluster.name}.${nsName}.${cluster.id}`,
959
- {
960
- namespace,
961
- description: "Allow all ingress traffic to the namespace.",
962
- ingressRule: { fromAll: true }
963
- },
964
- opts
965
- );
966
- }
967
- /**
968
- * Creates network policy to allow egress traffic to a specific L3/L4 endpoint.
969
- *
970
- * Automatically names the policy as: `allow-egress-to-<endpoint>.{clusterName}.{namespace}.{clusterId}`.
971
- *
972
- * @param namespace The namespace to create the policy in.
973
- * @param endpoint The endpoint to allow egress to.
974
- * @param opts Optional resource options.
975
- */
976
- static async allowEgressToEndpoint(namespace, endpoint, opts) {
977
- const parsedEndpoint = parseEndpoint(endpoint);
978
- const endpointStr = endpointToString(parsedEndpoint).replace(/:/g, "-");
979
- const nsName = await toPromise(output(namespace).metadata.name);
980
- const cluster = await toPromise(output(namespace).cluster);
981
- return new _NetworkPolicy(
982
- `allow-egress-to-${endpointStr}.${cluster.name}.${nsName}.${cluster.id}`,
983
- {
984
- namespace,
985
- description: `Allow egress traffic to "${endpointToString(parsedEndpoint)}" from the namespace.`,
986
- egressRule: { toEndpoint: endpoint }
987
- },
988
- opts
989
- );
990
- }
991
- /**
992
- * Creates network policy to allow egress traffic to the best endpoint among provided candidates.
993
- *
994
- * Automatically names the policy as: `allow-egress-to-<bestEndpoint>.{clusterName}.{namespace}.{clusterId}`.
995
- *
996
- * @param namespace The namespace to create the policy in.
997
- * @param endpoints The candidate endpoints to select from.
998
- * @param opts Optional resource options.
999
- */
1000
- static async allowEgressToBestEndpoint(namespace, endpoints, opts) {
1001
- const cluster = await toPromise(output(namespace).cluster);
1002
- const resolvedEndpoints = await toPromise(output(endpoints));
1003
- const bestEndpoint = requireBestEndpoint(
1004
- resolvedEndpoints.map((endpoint) => parseEndpoint(endpoint)),
1005
- cluster
1006
- );
1007
- return await _NetworkPolicy.allowEgressToEndpoint(namespace, bestEndpoint, opts);
1008
- }
1009
- /**
1010
- * Creates network policy to allow ingress traffic from a specific L3/L4 endpoint.
1011
- *
1012
- * Automatically names the policy as: `allow-ingress-from-<endpoint>.{clusterName}.{namespace}.{clusterId}`.
1013
- *
1014
- * @param namespace The namespace to create the policy in.
1015
- * @param endpoint The endpoint to allow ingress from.
1016
- * @param opts Optional resource options.
1017
- */
1018
- static async allowIngressFromEndpoint(namespace, endpoint, opts) {
1019
- const parsedEndpoint = parseEndpoint(endpoint);
1020
- const endpointStr = endpointToString(parsedEndpoint).replace(/:/g, "-");
1021
- const nsName = await toPromise(output(namespace).metadata.name);
1022
- const cluster = await toPromise(output(namespace).cluster);
1023
- return new _NetworkPolicy(
1024
- `allow-ingress-from-${endpointStr}.${cluster.name}.${nsName}.${cluster.id}`,
1025
- {
1026
- namespace,
1027
- description: interpolate`Allow ingress traffic from "${endpointToString(parsedEndpoint)}" to the namespace.`,
1028
- ingressRule: { fromEndpoint: endpoint }
1029
- },
1030
- opts
1031
- );
1032
- }
1033
- };
1034
- var NativeNetworkPolicy = class _NativeNetworkPolicy extends ComponentResource {
1035
- /**
1036
- * The underlying native network policy resource.
1037
- */
1038
- networkPolicy;
1039
- constructor(name, args, opts) {
1040
- super("k8s:native-network-policy", name, args, opts);
1041
- const ingress = _NativeNetworkPolicy.createIngressRules(args);
1042
- const egress = _NativeNetworkPolicy.createEgressRules(args);
1043
- const policyTypes = [];
1044
- if (ingress.length > 0 || args.isolateIngress) {
1045
- policyTypes.push("Ingress");
1046
- }
1047
- if (egress.length > 0 || args.isolateEgress) {
1048
- policyTypes.push("Egress");
1049
- }
1050
- this.networkPolicy = new networking.v1.NetworkPolicy(
1051
- name,
1052
- {
1053
- metadata: mergeDeep(mapMetadata(args, name), {
1054
- annotations: args.description ? { "kubernetes.io/description": args.description } : void 0
1055
- }),
1056
- spec: {
1057
- podSelector: args.podSelector,
1058
- ingress,
1059
- egress,
1060
- policyTypes
1061
- }
1062
- },
1063
- { ...opts, parent: this }
1064
- );
1065
- }
1066
- static fallbackIpBlock = {
1067
- cidr: "0.0.0.0/0",
1068
- except: ["10.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16"]
1069
- };
1070
- static fallbackDnsRule = {
1071
- to: [
1072
- {
1073
- namespaceSelector: { matchLabels: { "kubernetes.io/metadata.name": "kube-system" } },
1074
- podSelector: { matchLabels: { "k8s-app": "kube-dns" } }
1075
- }
1076
- ],
1077
- ports: [{ port: 53, protocol: "UDP" }]
1078
- };
1079
- static createIngressRules(args) {
1080
- return uniqueBy(
1081
- args.ingressRules.map((rule) => ({
1082
- from: rule.all ? [] : rule.clusterPods ? [{ namespaceSelector: {} }] : _NativeNetworkPolicy.createRulePeers(rule),
1083
- ports: _NativeNetworkPolicy.mapPorts(rule.ports)
1084
- })),
1085
- (rule) => JSON.stringify(rule)
1086
- );
1087
- }
1088
- static createEgressRules(args) {
1089
- const extraRules = [];
1090
- const needKubeDns = args.egressRules.some((rule) => rule.fqdns.length > 0);
1091
- if (needKubeDns) {
1092
- extraRules.push(_NativeNetworkPolicy.fallbackDnsRule);
1093
- }
1094
- const needFallback = args.egressRules.some(
1095
- (rule) => rule.fqdns.some((fqdn) => !fqdn.endsWith(".cluster.local"))
1096
- );
1097
- if (needFallback) {
1098
- extraRules.push({ to: [{ ipBlock: _NativeNetworkPolicy.fallbackIpBlock }] });
1099
- }
1100
- if (args.allowKubeApiServer) {
1101
- const { quirks, apiEndpoints } = args.cluster;
1102
- if (quirks?.fallbackKubeApiAccess) {
1103
- extraRules.push({
1104
- to: [{ ipBlock: { cidr: `${quirks?.fallbackKubeApiAccess.serverIp}/32` } }],
1105
- ports: [{ port: quirks?.fallbackKubeApiAccess.serverPort, protocol: "TCP" }]
1106
- });
1107
- } else {
1108
- const rules = apiEndpoints.filter((endpoint) => endpoint.type !== "hostname").map((endpoint) => ({
1109
- to: [{ ipBlock: { cidr: l3EndpointToCidr(endpoint) } }],
1110
- ports: [{ port: endpoint.port, protocol: "TCP" }]
1111
- }));
1112
- extraRules.push(...rules);
1113
- }
1114
- }
1115
- return uniqueBy(
1116
- args.egressRules.map((rule) => {
1117
- return {
1118
- to: rule.all ? [] : rule.clusterPods ? [{ namespaceSelector: {} }] : _NativeNetworkPolicy.createRulePeers(rule),
1119
- ports: _NativeNetworkPolicy.mapPorts(rule.ports)
1120
- };
1121
- }).filter((rule) => rule.to !== void 0).concat(extraRules),
1122
- (rule) => JSON.stringify(rule)
1123
- );
1124
- }
1125
- static createRulePeers(args) {
1126
- const peers = uniqueBy(
1127
- [
1128
- ..._NativeNetworkPolicy.createCidrPeers(args),
1129
- ..._NativeNetworkPolicy.createServicePeers(args),
1130
- ..._NativeNetworkPolicy.createSelectorPeers(args)
1131
- ],
1132
- (peer) => JSON.stringify(peer)
1133
- );
1134
- return peers.length > 0 ? peers : void 0;
1135
- }
1136
- static createCidrPeers(args) {
1137
- return args.cidrs.map((cidr) => ({ ipBlock: { cidr } }));
1138
- }
1139
- static createServicePeers(args) {
1140
- return args.services.map((service) => {
1141
- const selector = mapServiceToLabelSelector(service);
1142
- return {
1143
- namespaceSelector: mapNamespaceNameToSelector(service.metadata.namespace),
1144
- podSelector: selector
1145
- };
1146
- });
1147
- }
1148
- static createSelectorPeers(args) {
1149
- const selectorPeers = args.selectors.map((selector) => ({
1150
- podSelector: mapSelectorLikeToSelector(selector)
1151
- }));
1152
- const namespacePeers = [
1153
- ...args.namespaces.map(_NativeNetworkPolicy.createNamespacePeer),
1154
- ...args.namespaceSelectors.map(_NativeNetworkPolicy.createNamespaceSelectorPeer)
1155
- ];
1156
- if (namespacePeers.length === 0) {
1157
- return selectorPeers;
1158
- }
1159
- if (selectorPeers.length === 0) {
1160
- return namespacePeers;
1161
- }
1162
- return flat(
1163
- selectorPeers.map((selectorPeer) => {
1164
- return namespacePeers.map((namespacePeer) => merge(selectorPeer, namespacePeer));
1165
- })
1166
- );
1167
- }
1168
- static createNamespacePeer(namespace) {
1169
- const namespaceName = getNamespaceName(namespace);
1170
- const namespaceSelector = mapNamespaceNameToSelector(namespaceName);
1171
- return { namespaceSelector };
1172
- }
1173
- static createNamespaceSelectorPeer(selector) {
1174
- return {
1175
- namespaceSelector: mapSelectorLikeToSelector(selector)
1176
- };
1177
- }
1178
- static mapPorts(ports) {
1179
- return ports.map((port) => {
1180
- if ("port" in port) {
1181
- return {
1182
- port: port.port,
1183
- protocol: port.protocol ?? "TCP"
1184
- };
1185
- }
1186
- return {
1187
- port: port.range[0],
1188
- endPort: port.range[1],
1189
- protocol: port.protocol ?? "TCP"
1190
- };
1191
- });
1192
- }
1193
- };
1194
-
1195
- // src/pod.ts
1196
- var podSpecDefaults = {
1197
- automountServiceAccountToken: false
1198
- };
1199
- var workloadExtraArgs = [...commonExtraArgs, "container", "containers"];
1200
- function filterPatchOwnedContainersInTemplate(template, ownedTemplate) {
1201
- const ownedContainerNames = unique(
1202
- (ownedTemplate.spec?.containers ?? []).map((container) => container.name).filter(isNonNullish)
1203
- );
1204
- const ownedInitContainerNames = unique(
1205
- (ownedTemplate.spec?.initContainers ?? []).map((container) => container.name).filter(isNonNullish)
1206
- );
1207
- const filterByOwnedNames = (source, ownedNames) => {
1208
- if (!source || source.length === 0 || ownedNames.length === 0) {
1209
- return void 0;
1210
- }
1211
- const filtered = source.filter(
1212
- (container) => container.name ? ownedNames.includes(container.name) : false
1213
- );
1214
- return filtered.length > 0 ? filtered : void 0;
1215
- };
1216
- const containers = filterByOwnedNames(template.spec?.containers, ownedContainerNames);
1217
- const initContainers = filterByOwnedNames(template.spec?.initContainers, ownedInitContainerNames);
1218
- const {
1219
- containers: _containers,
1220
- initContainers: _initContainers,
1221
- ...restSpec
1222
- } = template.spec ?? {};
1223
- const spec = {
1224
- ...restSpec,
1225
- ...containers ? { containers } : {},
1226
- ...initContainers ? { initContainers } : {}
1227
- };
1228
- return {
1229
- ...template,
1230
- spec
1231
- };
1232
- }
1233
- var workloadServiceExtraArgs = [
1234
- ...workloadExtraArgs,
1235
- "service",
1236
- "route",
1237
- "routes"
1238
- ];
1239
- function getWorkloadComponents(name, args, parent, opts, isForPatch) {
1240
- const labels = isForPatch ? void 0 : { "app.kubernetes.io/name": name };
1241
- const containers = output$1(args).apply((args2) => normalize(args2.container, args2.containers));
1242
- const initContainers = output$1(args).apply(
1243
- (args2) => normalize(args2.initContainer, args2.initContainers)
1244
- );
1245
- const rawVolumes = output$1({ containers, initContainers }).apply(
1246
- ({ containers: containers2, initContainers: initContainers2 }) => {
1247
- const containerVolumes = [...containers2, ...initContainers2].flatMap(
1248
- (container) => normalize(container.volume, container.volumes)
1249
- );
1250
- const containerVolumeMounts = containers2.flatMap((container) => {
1251
- return normalize(container.volumeMount, container.volumeMounts).map((volumeMount) => {
1252
- return "volume" in volumeMount ? volumeMount.volume : void 0;
1253
- }).filter(Boolean);
1254
- });
1255
- return output$1([...containerVolumes, ...containerVolumeMounts]);
1256
- }
1257
- );
1258
- const volumes = rawVolumes.apply((rawVolumes2) => {
1259
- return output$1(rawVolumes2.map(mapWorkloadVolume)).apply(uniqueBy((volume) => volume.name));
1260
- });
1261
- const podSpec = output$1({
1262
- cluster: output$1(args.namespace).cluster,
1263
- containers,
1264
- initContainers,
1265
- volumes
1266
- }).apply(({ cluster, containers: containers2, initContainers: initContainers2, volumes: volumes2 }) => {
1267
- const spec = {
1268
- volumes: volumes2,
1269
- containers: containers2.map(
1270
- (container, index) => mapContainerToRaw(container, cluster, getFallbackContainerName(name, index))
1271
- ),
1272
- initContainers: initContainers2.map(
1273
- (container, index) => mapContainerToRaw(container, cluster, getFallbackContainerName(`init-${name}`, index))
1274
- ),
1275
- ...podSpecDefaults
1276
- };
1277
- if (containers2.some((container) => container.enableTun) && cluster.quirks?.tunDevicePolicy?.type !== "plugin") {
1278
- spec.volumes = output$1(spec.volumes).apply((volumes3) => [
1279
- ...volumes3 ?? [],
1280
- {
1281
- name: "tun-device",
1282
- hostPath: {
1283
- path: "/dev/net/tun"
1284
- }
1285
- }
1286
- ]);
1287
- }
1288
- return spec;
1289
- });
1290
- const dependencyHash = rawVolumes.apply((rawVolumes2) => {
1291
- return output$1(rawVolumes2.map(getWorkloadVolumeResourceUuid)).apply(filter(isNonNullish)).apply(unique()).apply((ids) => sha256(ids.join(",")));
1292
- });
1293
- const podTemplate = output$1({ podSpec, dependencyHash }).apply(({ podSpec: podSpec2, dependencyHash: dependencyHash2 }) => {
1294
- return {
1295
- metadata: {
1296
- labels,
1297
- annotations: {
1298
- // to trigger a redeployment when the volumes change
1299
- // we embed a hash as annotation name (not value) to allow patching without conflicts
1300
- [`highstate.io/dependency-hash-${dependencyHash2.slice(32)}`]: "1"
1301
- }
1302
- },
1303
- spec: podSpec2
1304
- };
1305
- });
1306
- const networkPolicy = output$1({ containers }).apply(({ containers: containers2 }) => {
1307
- if (isForPatch) {
1308
- return output$1(void 0);
1309
- }
1310
- const allowedEndpoints = containers2.flatMap((container) => container.allowedEndpoints ?? []);
1311
- if (allowedEndpoints.length === 0 && !args.networkPolicy) {
1312
- return output$1(void 0);
1313
- }
1314
- return output$1(
1315
- new NetworkPolicy(
1316
- name,
1317
- {
1318
- namespace: args.namespace,
1319
- selector: labels,
1320
- description: `Network policy for "${name}"`,
1321
- ...args.networkPolicy,
1322
- egressRules: output$1(args.networkPolicy?.egressRules).apply((egressRules) => [
1323
- ...egressRules ?? [],
1324
- ...allowedEndpoints.length > 0 ? [{ toEndpoints: allowedEndpoints }] : []
1325
- ])
1326
- },
1327
- { ...opts, parent: parent() }
1328
- )
1329
- );
1330
- });
1331
- return { labels, containers, volumes, podSpec, podTemplate, networkPolicy };
1332
- }
1333
- function getWorkloadServiceComponents(name, args, parent, opts, isForPatch) {
1334
- const { labels, containers, volumes, podSpec, podTemplate, networkPolicy } = getWorkloadComponents(name, args, parent, opts, isForPatch);
1335
- const service = output$1({
1336
- existing: args.existing,
1337
- serviceArgs: args.service,
1338
- containers
1339
- }).apply(({ existing, serviceArgs, containers: containers2 }) => {
1340
- if (!args.service && !args.route && !args.routes) {
1341
- return void 0;
1342
- }
1343
- if (existing?.service) {
1344
- return Service.for(existing.service, output$1(args.namespace).cluster);
1345
- }
1346
- if (existing) {
1347
- return void 0;
1348
- }
1349
- const ports = containers2.flatMap((container) => normalize(container.port, container.ports));
1350
- return Service.create(name, {
1351
- ...serviceArgs,
1352
- selector: labels,
1353
- namespace: args.namespace,
1354
- ports: (
1355
- // allow to completely override the ports
1356
- !serviceArgs?.port && !serviceArgs?.ports ? ports.map(mapContainerPortToServicePort) : serviceArgs?.ports
1357
- )
1358
- });
1359
- });
1360
- const routes = output$1({
1361
- routesArgs: normalizeInputs(args.route, args.routes),
1362
- service,
1363
- namespace: output$1(args.namespace)
1364
- }).apply(async ({ routesArgs, service: service2, namespace }) => {
1365
- if (!routesArgs.length || !service2) {
1366
- return [];
1367
- }
1368
- if (args.existing) {
1369
- return [];
1370
- }
1371
- const serviceEndpoints = await toPromise(service2.endpoints);
1372
- const servicePorts = await toPromise(service2.spec.ports);
1373
- const resolveServiceEndpoints = async (servicePort, routeName) => {
1374
- if (serviceEndpoints.length === 0) {
1375
- throw new Error(`No endpoints found for workload service in route "${routeName}"`);
1376
- }
1377
- let resolvedServicePort;
1378
- if (servicePort != null) {
1379
- const requestedServicePort = await toPromise(servicePort);
1380
- if (typeof requestedServicePort === "string") {
1381
- const namedPort = servicePorts?.find((port) => port.name === requestedServicePort);
1382
- if (!namedPort) {
1383
- throw new Error(
1384
- `Named port "${requestedServicePort}" not found for workload service in route "${routeName}"`
1385
- );
1386
- }
1387
- resolvedServicePort = namedPort.port;
1388
- } else {
1389
- resolvedServicePort = requestedServicePort;
1390
- }
1391
- } else {
1392
- resolvedServicePort = serviceEndpoints[0]?.port;
1393
- }
1394
- if (resolvedServicePort == null) {
1395
- throw new Error(
1396
- `Unable to resolve service port for workload service in route "${routeName}"`
1397
- );
1398
- }
1399
- const filteredEndpoints = serviceEndpoints.filter(
1400
- (endpoint) => endpoint.port === resolvedServicePort
1401
- );
1402
- if (filteredEndpoints.length === 0) {
1403
- throw new Error(
1404
- `No endpoints with port ${resolvedServicePort} found for workload service in route "${routeName}"`
1405
- );
1406
- }
1407
- return filteredEndpoints;
1408
- };
1409
- return await Promise.all(
1410
- routesArgs.map(async (routeArgs, index) => {
1411
- const routeName = `${name}.${index}`;
1412
- const routeRules = await toPromise(routeArgs.rules);
1413
- const routeRuleValues = Object.values(routeRules ?? {});
1414
- const needsDefaultBackend = routeRuleValues.length === 0 || routeRuleValues.some((rule) => rule.servicePort == null);
1415
- const defaultServiceEndpoints = needsDefaultBackend ? await resolveServiceEndpoints(routeArgs.servicePort, routeName) : void 0;
1416
- const resolvedRules = routeRules ? await Promise.all(
1417
- Object.entries(routeRules).map(async ([ruleName, rule]) => {
1418
- const ruleServiceEndpoints = await resolveServiceEndpoints(
1419
- rule.servicePort ?? routeArgs.servicePort,
1420
- `${routeName}:${ruleName}`
1421
- );
1422
- return [
1423
- ruleName,
1424
- {
1425
- ...omit(rule, ["servicePort"]),
1426
- backend: {
1427
- endpoints: ruleServiceEndpoints
1428
- }
1429
- }
1430
- ];
1431
- })
1432
- ) : void 0;
1433
- const resolvedRulesInput = resolvedRules ? Object.fromEntries(resolvedRules) : void 0;
1434
- return new AccessPointRoute(routeName, {
1435
- ...omit(routeArgs, ["servicePort", "rules"]),
1436
- ...defaultServiceEndpoints ? {
1437
- backend: {
1438
- endpoints: defaultServiceEndpoints
1439
- }
1440
- } : {},
1441
- rules: resolvedRulesInput,
1442
- metadata: {
1443
- ...routeArgs.metadata ?? {},
1444
- "k8s.namespace": namespace
1445
- }
1446
- });
1447
- })
1448
- );
1449
- });
1450
- return { labels, containers, volumes, podSpec, podTemplate, networkPolicy, service, routes };
1451
- }
1452
- var Workload = class extends NamespacedResource {
1453
- constructor(type, name, args, opts, metadata, namespace, terminalArgs, containers, podTemplate, networkPolicy, _service = output$1(void 0), routes = output$1([])) {
1454
- super(type, name, args, opts, metadata, namespace);
1455
- this.name = name;
1456
- this.terminalArgs = terminalArgs;
1457
- this.containers = containers;
1458
- this.podTemplate = podTemplate;
1459
- this.networkPolicy = networkPolicy;
1460
- this._service = _service;
1461
- this.routes = routes;
1462
- }
1463
- set terminal(_value) {
1464
- }
1465
- set logsTerminal(_value) {
1466
- }
1467
- // biome-ignore lint/correctness/noUnusedPrivateClassMembers: for pulumi which for some reason tries to copy all properties
1468
- set terminals(_value) {
1469
- }
1470
- // biome-ignore lint/correctness/noUnusedPrivateClassMembers: for pulumi which for some reason tries to copy all properties
1471
- set optionalService(_value) {
1472
- }
1473
- // biome-ignore lint/correctness/noUnusedPrivateClassMembers: for pulumi which for some reason tries to copy all properties
1474
- set service(_value) {
1475
- }
1476
- // biome-ignore lint/correctness/noUnusedPrivateClassMembers: for pulumi which for some reason tries to copy all properties
1477
- set selector(_value) {
1478
- }
1479
- /**
1480
- * The service associated with the workload.
1481
- */
1482
- get optionalService() {
1483
- return this._service;
1484
- }
1485
- /**
1486
- * The service associated with the workload.
1487
- *
1488
- * Will throw an error if the service is not available.
1489
- */
1490
- get service() {
1491
- return this._service.apply((service) => {
1492
- if (!service) {
1493
- throw new Error(`The service of the workload "${this.name}" is not available.`);
1494
- }
1495
- return service;
1496
- });
1497
- }
1498
- /**
1499
- * The merged and deduplicated L3 endpoints of all routes.
1500
- */
1501
- get endpoints() {
1502
- return this.routes.apply(
1503
- (routes) => output$1(routes.map((route) => route.route.endpoints)).apply((endpoints) => flat(endpoints)).apply(mergeEndpoints)
1504
- );
1505
- }
1506
- /**
1507
- * The selector matching pods created from this workload's template labels.
1508
- */
1509
- get selector() {
1510
- return this.podTemplate.apply((template) => ({
1511
- matchLabels: template.metadata?.labels
1512
- }));
1513
- }
1514
- /**
1515
- * The instance terminal to interact with the workload's pods.
1516
- */
1517
- get terminal() {
1518
- const containerName = this.podTemplate.spec.containers.apply((containers) => containers[0].name);
1519
- const shell = this.terminalArgs.apply((args) => args.shell ?? "bash");
1520
- const podLabelSelector = this.templateMetadata.apply((meta) => meta.labels ?? {}).apply(
1521
- (labels) => Object.entries(labels).map(([key, value]) => `${key}=${value}`).join(",")
1522
- );
1523
- return output$1({
1524
- name: this.metadata.name,
1525
- meta: this.getTerminalMeta(),
1526
- spec: {
1527
- image: images_exports["terminal-kubectl"].image,
1528
- command: ["bash", "/welcome.sh"],
1529
- files: {
1530
- "/kubeconfig": makeFileOutput({
1531
- name: "kubeconfig",
1532
- content: getClusterKubeconfigContent(this.cluster),
1533
- isSecret: true
1534
- }),
1535
- "/welcome.sh": makeFileOutput({
1536
- name: "welcome.sh",
1537
- content: interpolate$1`
1538
- #!/bin/bash
1539
- set -euo pipefail
1540
-
1541
- NAMESPACE="${this.metadata.namespace}"
1542
- RESOURCE_TYPE="${this.kind.toLowerCase()}"
1543
- RESOURCE_NAME="${this.metadata.name}"
1544
- CONTAINER_NAME="${containerName}"
1545
- SHELL="${shell}"
1546
- LABEL_SELECTOR="${podLabelSelector}"
1547
-
1548
- echo "Connecting to $RESOURCE_TYPE \\"$RESOURCE_NAME\\" in namespace \\"$NAMESPACE\\""
1549
-
1550
- # get all pods for this workload
1551
- PODS=$(kubectl get pods -n "$NAMESPACE" -l "$LABEL_SELECTOR" -o jsonpath='{.items[*].metadata.name}' 2>/dev/null || echo "")
1552
-
1553
- if [ -z "$PODS" ]; then
1554
- echo "No pods found"
1555
- exit 1
1556
- fi
1557
-
1558
- # convert space-separated string to array
1559
- read -ra POD_ARRAY <<< "$PODS"
1560
-
1561
- if [ \${#POD_ARRAY[@]} -eq 1 ]; then
1562
- # single pod found, connect directly
1563
- SELECTED_POD="\${POD_ARRAY[0]}"
1564
- echo "Found single pod: $SELECTED_POD"
1565
- else
1566
- # multiple pods found, use fzf for selection
1567
- echo "Found \${#POD_ARRAY[@]} pods. Please select one."
1568
-
1569
- SELECTED_POD=$(printf '%s\n' "\${POD_ARRAY[@]}" | fzf --prompt="Select pod: " --height 10 --border --info=inline)
1570
-
1571
- if [ -z "$SELECTED_POD" ]; then
1572
- echo "No pod selected"
1573
- exit 1
1574
- fi
1575
-
1576
- echo "Selected pod: $SELECTED_POD"
1577
- fi
1578
-
1579
- # execute into the selected pod
1580
- exec kubectl exec -it -n "$NAMESPACE" "$SELECTED_POD" -c "$CONTAINER_NAME" -- "$SHELL"
1581
- `.apply(trimIndentation)
1582
- })
1583
- },
1584
- env: {
1585
- KUBECONFIG: "/kubeconfig"
1586
- }
1587
- }
1588
- });
1589
- }
1590
- /**
1591
- * The instance terminal to view the workload's logs.
1592
- */
1593
- get logsTerminal() {
1594
- const containerName = this.podTemplate.spec.containers.apply((containers) => containers[0].name);
1595
- const podLabelSelector = this.templateMetadata.apply((meta) => meta.labels ?? {}).apply(
1596
- (labels) => Object.entries(labels).map(([key, value]) => `${key}=${value}`).join(",")
1597
- );
1598
- return output$1({
1599
- name: interpolate$1`${this.metadata.name}.logs`,
1600
- meta: output$1(this.getTerminalMeta()).apply((meta) => ({
1601
- ...meta,
1602
- title: `${meta.title} Logs`,
1603
- globalTitle: `${meta.globalTitle} | Logs`,
1604
- description: `The logs of ${meta.title.toLowerCase()}.`
1605
- })),
1606
- spec: {
1607
- image: images_exports["terminal-kubectl"].image,
1608
- command: ["bash", "/welcome.sh"],
1609
- files: {
1610
- "/kubeconfig": makeFileOutput({
1611
- name: "kubeconfig",
1612
- content: getClusterKubeconfigContent(this.cluster),
1613
- isSecret: true
1614
- }),
1615
- "/welcome.sh": makeFileOutput({
1616
- name: "welcome.sh",
1617
- content: interpolate$1`
1618
- #!/bin/bash
1619
- set -euo pipefail
1620
-
1621
- NAMESPACE="${this.metadata.namespace}"
1622
- RESOURCE_TYPE="${this.kind.toLowerCase()}"
1623
- RESOURCE_NAME="${this.metadata.name}"
1624
- CONTAINER_NAME="${containerName}"
1625
- LABEL_SELECTOR="${podLabelSelector}"
1626
-
1627
- echo "Connecting to logs of $RESOURCE_TYPE \"$RESOURCE_NAME\" in namespace \"$NAMESPACE\""
1628
-
1629
- # get all pods for this workload
1630
- PODS=$(kubectl get pods -n "$NAMESPACE" -l "$LABEL_SELECTOR" -o jsonpath='{.items[*].metadata.name}' 2>/dev/null || echo "")
1631
-
1632
- if [ -z "$PODS" ]; then
1633
- echo "No pods found"
1634
- exit 1
1635
- fi
1636
-
1637
- # convert space-separated string to array
1638
- read -ra POD_ARRAY <<< "$PODS"
1639
-
1640
- if [ \${#POD_ARRAY[@]} -eq 1 ]; then
1641
- # single pod found, connect directly
1642
- SELECTED_POD="\${POD_ARRAY[0]}"
1643
- echo "Found single pod: $SELECTED_POD"
1644
- else
1645
- # multiple pods found, use fzf for selection
1646
- echo "Found \${#POD_ARRAY[@]} pods. Please select one."
1647
-
1648
- SELECTED_POD=$(printf '%s\n' "\${POD_ARRAY[@]}" | fzf --prompt="Select pod: " --height 10 --border --info=inline)
1649
-
1650
- if [ -z "$SELECTED_POD" ]; then
1651
- echo "No pod selected"
1652
- exit 1
1653
- fi
1654
-
1655
- echo "Selected pod: $SELECTED_POD"
1656
- fi
1657
-
1658
- # stream logs for the selected pod
1659
- exec kubectl logs -f -n "$NAMESPACE" "$SELECTED_POD" -c "$CONTAINER_NAME"
1660
- `.apply(trimIndentation)
1661
- })
1662
- },
1663
- env: {
1664
- KUBECONFIG: "/kubeconfig"
1665
- }
1666
- }
1667
- });
1668
- }
1669
- /**
1670
- * The instance terminals to interact with the workload's pods and view its logs.
1671
- */
1672
- get terminals() {
1673
- return [this.logsTerminal, this.terminal];
1674
- }
1675
- /**
1676
- * Creates a terminal with a custom command.
1677
- *
1678
- * @param meta The metadata for the terminal.
1679
- * @param command The command to run in the terminal.
1680
- * @param spec Additional spec options for the terminal.
1681
- */
1682
- createTerminal(name, meta, command, spec) {
1683
- const containerName = this.podTemplate.spec.containers.apply((containers) => containers[0].name);
1684
- return output$1({
1685
- name,
1686
- meta: output$1(this.getTerminalMeta()).apply((currentMeta) => ({
1687
- ...currentMeta,
1688
- ...meta
1689
- })),
1690
- spec: {
1691
- image: images_exports["terminal-kubectl"].image,
1692
- command: output$1(command).apply((command2) => [
1693
- "exec",
1694
- "kubectl",
1695
- "exec",
1696
- "-it",
1697
- "-n",
1698
- this.metadata.namespace,
1699
- interpolate$1`${this.kind.toLowerCase()}/${this.metadata.name}`,
1700
- "-c",
1701
- containerName,
1702
- "--",
1703
- ...command2
1704
- ]),
1705
- files: {
1706
- "/kubeconfig": makeFileOutput({
1707
- name: "kubeconfig",
1708
- content: getClusterKubeconfigContent(this.cluster),
1709
- isSecret: true
1710
- }),
1711
- ...spec?.files
1712
- },
1713
- env: {
1714
- KUBECONFIG: "/kubeconfig",
1715
- ...spec?.env
1716
- }
1717
- }
1718
- });
1719
- }
1720
- /**
1721
- * Creates a generic workload or patches the existing one.
1722
- */
1723
- static createOrPatchGeneric(name, args, opts) {
1724
- return output$1(args).apply(async (args2) => {
1725
- if (args2.existing?.kind === "Deployment") {
1726
- const { Deployment } = await import('./deployment-T35TUOL2.js');
1727
- return Deployment.patch(
1728
- name,
1729
- {
1730
- ...deepmerge(args2, args2.deployment),
1731
- name: args2.existing.metadata.name,
1732
- namespace: Namespace.forResourceAsync(args2.existing, output$1(args2.namespace).cluster)
1733
- },
1734
- opts
1735
- );
1736
- }
1737
- if (args2.existing?.kind === "StatefulSet") {
1738
- const { StatefulSet } = await import('./stateful-set-LUIRHQJY.js');
1739
- return StatefulSet.patch(
1740
- name,
1741
- {
1742
- ...deepmerge(args2, args2.statefulSet),
1743
- name: args2.existing.metadata.name,
1744
- namespace: Namespace.forResourceAsync(args2.existing, output$1(args2.namespace).cluster)
1745
- },
1746
- opts
1747
- );
1748
- }
1749
- if (args2.existing?.kind === "Job") {
1750
- const { Job } = await import('./job-PE4AKOHB.js');
1751
- return Job.patch(
1752
- name,
1753
- {
1754
- ...deepmerge(args2, args2.job),
1755
- name: args2.existing.metadata.name,
1756
- namespace: Namespace.forResourceAsync(args2.existing, output$1(args2.namespace).cluster)
1757
- },
1758
- opts
1759
- );
1760
- }
1761
- if (args2.existing?.kind === "CronJob") {
1762
- const { CronJob } = await import('./cron-job-RKB2HYTO.js');
1763
- return CronJob.patch(
1764
- name,
1765
- {
1766
- ...deepmerge(args2, args2.cronJob),
1767
- name: args2.existing.metadata.name,
1768
- namespace: Namespace.forResourceAsync(args2.existing, output$1(args2.namespace).cluster)
1769
- },
1770
- opts
1771
- );
1772
- }
1773
- if (args2.defaultType === "Deployment") {
1774
- const { Deployment } = await import('./deployment-T35TUOL2.js');
1775
- const deploymentArgs = deepmerge(
1776
- omit(args2, ["defaultType", "existing", "deployment", "statefulSet", "job", "cronJob"]),
1777
- args2.deployment ?? {}
1778
- );
1779
- return Deployment.create(name, deploymentArgs, opts);
1780
- }
1781
- if (args2.defaultType === "StatefulSet") {
1782
- const { StatefulSet } = await import('./stateful-set-LUIRHQJY.js');
1783
- const statefulSetArgs = deepmerge(
1784
- omit(args2, ["defaultType", "existing", "deployment", "statefulSet", "job", "cronJob"]),
1785
- args2.statefulSet ?? {}
1786
- );
1787
- return StatefulSet.create(name, statefulSetArgs, opts);
1788
- }
1789
- if (args2.defaultType === "Job") {
1790
- const { Job } = await import('./job-PE4AKOHB.js');
1791
- return Job.create(name, deepmerge(args2, args2.job), opts);
1792
- }
1793
- if (args2.defaultType === "CronJob") {
1794
- const { CronJob } = await import('./cron-job-RKB2HYTO.js');
1795
- return CronJob.create(name, deepmerge(args2, args2.cronJob), opts);
1796
- }
1797
- throw new Error(`Unknown workload type: ${args2.defaultType}`);
1798
- });
1799
- }
1800
- };
1801
-
1802
- export { ConfigMap, NativeNetworkPolicy, NetworkPolicy, PersistentVolumeClaim, Workload, filterPatchOwnedContainersInTemplate, getAutoVolumeName, getBestEndpoint, getFallbackContainerName, getWorkloadComponents, getWorkloadServiceComponents, getWorkloadVolumeResourceUuid, mapContainerEnvironment, mapContainerToRaw, mapEnvironmentSource, mapVolumeMount, mapWorkloadVolume, networkPolicyMediator, podSpecDefaults, requireBestEndpoint, workloadExtraArgs, workloadServiceExtraArgs };
1803
- //# sourceMappingURL=chunk-SZKOAHNX.js.map
1804
- //# sourceMappingURL=chunk-SZKOAHNX.js.map