@highstate/k8s 0.9.8 → 0.9.10
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.
- package/dist/{chunk-YEH2UAPS.js → chunk-3B5DTLGG.js} +2 -2
- package/dist/{chunk-JBGQQVTZ.js → chunk-7R2VAXVL.js} +24 -4
- package/dist/chunk-7R2VAXVL.js.map +1 -0
- package/dist/{chunk-YTCZBMAL.js → chunk-FF3GFWG3.js} +2 -2
- package/dist/chunk-OP75IMU7.js +766 -0
- package/dist/chunk-OP75IMU7.js.map +1 -0
- package/dist/{chunk-UNVUOHHB.js → chunk-R43VRICF.js} +163 -448
- package/dist/chunk-R43VRICF.js.map +1 -0
- package/dist/deployment-E3ZTF2IS.js +10 -0
- package/dist/highstate.manifest.json +8 -8
- package/dist/index.js +27 -11
- package/dist/index.js.map +1 -1
- package/dist/stateful-set-NTU7QKC7.js +10 -0
- package/dist/units/cert-manager/index.js +2 -2
- package/package.json +9 -9
- package/src/config-map.ts +180 -0
- package/src/container.ts +12 -1
- package/src/cron-job.ts +8 -1
- package/src/helm.ts +35 -2
- package/src/index.ts +1 -0
- package/src/job.ts +8 -1
- package/src/scripting/bundle.ts +7 -5
- package/src/secret.ts +4 -0
- package/src/service.ts +1 -0
- package/dist/chunk-J6O3TE56.js +0 -347
- package/dist/chunk-J6O3TE56.js.map +0 -1
- package/dist/chunk-JBGQQVTZ.js.map +0 -1
- package/dist/chunk-UNVUOHHB.js.map +0 -1
- package/dist/deployment-TFCMSEGW.js +0 -10
- package/dist/stateful-set-2OEPSK44.js +0 -10
- /package/dist/{chunk-YEH2UAPS.js.map → chunk-3B5DTLGG.js.map} +0 -0
- /package/dist/{chunk-YTCZBMAL.js.map → chunk-FF3GFWG3.js.map} +0 -0
- /package/dist/{deployment-TFCMSEGW.js.map → deployment-E3ZTF2IS.js.map} +0 -0
- /package/dist/{stateful-set-2OEPSK44.js.map → stateful-set-NTU7QKC7.js.map} +0 -0
@@ -1,18 +1,13 @@
|
|
1
1
|
import {
|
2
2
|
HttpRoute,
|
3
|
+
NetworkPolicy,
|
3
4
|
Service,
|
4
|
-
|
5
|
-
|
6
|
-
mapContainerPortToServicePort,
|
7
|
-
mapServiceToLabelSelector
|
8
|
-
} from "./chunk-J6O3TE56.js";
|
5
|
+
mapContainerPortToServicePort
|
6
|
+
} from "./chunk-OP75IMU7.js";
|
9
7
|
import {
|
10
8
|
commonExtraArgs,
|
11
9
|
getProvider,
|
12
10
|
mapMetadata,
|
13
|
-
mapNamespaceLikeToNamespaceName,
|
14
|
-
mapNamespaceNameToSelector,
|
15
|
-
mapSelectorLikeToSelector,
|
16
11
|
resourceIdToString,
|
17
12
|
withPatchName
|
18
13
|
} from "./chunk-HTQP2NB4.js";
|
@@ -183,7 +178,9 @@ var CreatedSecret = class extends Secret {
|
|
183
178
|
{
|
184
179
|
metadata: mapMetadata(args2, name),
|
185
180
|
data: args2.data,
|
186
|
-
stringData: args2.stringData
|
181
|
+
stringData: args2.stringData,
|
182
|
+
type: args2.type,
|
183
|
+
immutable: args2.immutable
|
187
184
|
},
|
188
185
|
{
|
189
186
|
...opts,
|
@@ -212,7 +209,9 @@ var SecretPatch = class extends Secret {
|
|
212
209
|
{
|
213
210
|
metadata: mapMetadata(args2, name),
|
214
211
|
data: args2.data,
|
215
|
-
stringData: args2.stringData
|
212
|
+
stringData: args2.stringData,
|
213
|
+
type: args2.type,
|
214
|
+
immutable: args2.immutable
|
216
215
|
},
|
217
216
|
{
|
218
217
|
...opts,
|
@@ -260,9 +259,131 @@ var ExternalSecret = class extends Secret {
|
|
260
259
|
}
|
261
260
|
};
|
262
261
|
|
263
|
-
// src/
|
262
|
+
// src/config-map.ts
|
264
263
|
import { core as core3 } from "@pulumi/kubernetes";
|
265
|
-
import {
|
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 { normalize, output as output4 } from "@highstate/pulumi";
|
266
387
|
import { concat, map, omit as omit2 } from "remeda";
|
267
388
|
var containerExtraArgs = [
|
268
389
|
"port",
|
@@ -353,7 +474,7 @@ function mapVolumeMount(volumeMount) {
|
|
353
474
|
return omit2(
|
354
475
|
{
|
355
476
|
...volumeMount,
|
356
|
-
name:
|
477
|
+
name: output4(volumeMount.volume).apply(mapWorkloadVolume).apply((volume) => output4(volume.name))
|
357
478
|
},
|
358
479
|
["volume"]
|
359
480
|
);
|
@@ -364,14 +485,14 @@ function mapVolumeMount(volumeMount) {
|
|
364
485
|
};
|
365
486
|
}
|
366
487
|
function mapEnvironmentSource(envFrom) {
|
367
|
-
if (envFrom instanceof
|
488
|
+
if (envFrom instanceof core4.v1.ConfigMap) {
|
368
489
|
return {
|
369
490
|
configMapRef: {
|
370
491
|
name: envFrom.metadata.name
|
371
492
|
}
|
372
493
|
};
|
373
494
|
}
|
374
|
-
if (envFrom instanceof
|
495
|
+
if (envFrom instanceof core4.v1.Secret) {
|
375
496
|
return {
|
376
497
|
secretRef: {
|
377
498
|
name: envFrom.metadata.name
|
@@ -397,7 +518,15 @@ function mapWorkloadVolume(volume) {
|
|
397
518
|
}
|
398
519
|
};
|
399
520
|
}
|
400
|
-
if (
|
521
|
+
if (volume instanceof ConfigMap) {
|
522
|
+
return {
|
523
|
+
name: volume.metadata.name,
|
524
|
+
configMap: {
|
525
|
+
name: volume.metadata.name
|
526
|
+
}
|
527
|
+
};
|
528
|
+
}
|
529
|
+
if (core4.v1.PersistentVolumeClaim.isInstance(volume)) {
|
401
530
|
return {
|
402
531
|
name: volume.metadata.name,
|
403
532
|
persistentVolumeClaim: {
|
@@ -405,7 +534,7 @@ function mapWorkloadVolume(volume) {
|
|
405
534
|
}
|
406
535
|
};
|
407
536
|
}
|
408
|
-
if (
|
537
|
+
if (core4.v1.ConfigMap.isInstance(volume)) {
|
409
538
|
return {
|
410
539
|
name: volume.metadata.name,
|
411
540
|
configMap: {
|
@@ -413,7 +542,7 @@ function mapWorkloadVolume(volume) {
|
|
413
542
|
}
|
414
543
|
};
|
415
544
|
}
|
416
|
-
if (
|
545
|
+
if (core4.v1.Secret.isInstance(volume)) {
|
417
546
|
return {
|
418
547
|
name: volume.metadata.name,
|
419
548
|
secret: {
|
@@ -424,430 +553,16 @@ function mapWorkloadVolume(volume) {
|
|
424
553
|
return volume;
|
425
554
|
}
|
426
555
|
|
427
|
-
// src/network-policy.ts
|
428
|
-
import { networking } from "@pulumi/kubernetes";
|
429
|
-
import {
|
430
|
-
ComponentResource as ComponentResource3,
|
431
|
-
interpolate,
|
432
|
-
normalize as normalize2,
|
433
|
-
output as output4
|
434
|
-
} from "@highstate/pulumi";
|
435
|
-
import { capitalize, flat, groupBy, merge, mergeDeep, uniqueBy } from "remeda";
|
436
|
-
import "@highstate/library";
|
437
|
-
import {
|
438
|
-
l34EndpointToString,
|
439
|
-
l3EndpointToCidr,
|
440
|
-
parseL34Endpoint
|
441
|
-
} from "@highstate/common";
|
442
|
-
var NetworkPolicy = class _NetworkPolicy extends ComponentResource3 {
|
443
|
-
/**
|
444
|
-
* The underlying network policy resource.
|
445
|
-
*/
|
446
|
-
networkPolicy;
|
447
|
-
constructor(name, args, opts) {
|
448
|
-
super("k8s:network-policy", name, args, opts);
|
449
|
-
const normalizedArgs = output4(args).apply((args2) => {
|
450
|
-
const ingressRules = normalize2(args2.ingressRule, args2.ingressRules);
|
451
|
-
const egressRules = normalize2(args2.egressRule, args2.egressRules);
|
452
|
-
const extraEgressRules = [];
|
453
|
-
if (args2.allowKubeDns) {
|
454
|
-
extraEgressRules.push({
|
455
|
-
namespaces: ["kube-system"],
|
456
|
-
selectors: [{ matchLabels: { "k8s-app": "kube-dns" } }],
|
457
|
-
ports: [{ port: 53, protocol: "UDP" }],
|
458
|
-
all: false,
|
459
|
-
cidrs: [],
|
460
|
-
fqdns: [],
|
461
|
-
services: []
|
462
|
-
});
|
463
|
-
}
|
464
|
-
return {
|
465
|
-
...args2,
|
466
|
-
podSelector: args2.selector ? mapSelectorLikeToSelector(args2.selector) : {},
|
467
|
-
isolateEgress: args2.isolateEgress ?? false,
|
468
|
-
isolateIngress: args2.isolateIngress ?? false,
|
469
|
-
allowKubeApiServer: args2.allowKubeApiServer ?? false,
|
470
|
-
ingressRules: ingressRules.flatMap((rule) => {
|
471
|
-
const endpoints = normalize2(
|
472
|
-
args2.ingressRule?.fromEndpoint,
|
473
|
-
args2.ingressRule?.fromEndpoints
|
474
|
-
);
|
475
|
-
const parsedEndpoints = endpoints.map(parseL34Endpoint);
|
476
|
-
const endpointsByPortsAndNamespaces = groupBy(parsedEndpoints, (endpoint) => {
|
477
|
-
const namespace = isFromCluster(endpoint, args2.cluster) ? endpoint.metadata.k8sService.namespace : "";
|
478
|
-
const port = isFromCluster(endpoint, args2.cluster) ? endpoint.metadata.k8sService.targetPort : endpoint.port;
|
479
|
-
return `${port ?? "0"}:${namespace}`;
|
480
|
-
});
|
481
|
-
const l3OnlyRule = endpointsByPortsAndNamespaces["0:"] ? _NetworkPolicy.getRuleFromEndpoint(
|
482
|
-
void 0,
|
483
|
-
endpointsByPortsAndNamespaces["0:"],
|
484
|
-
args2.cluster
|
485
|
-
) : void 0;
|
486
|
-
const otherRules = Object.entries(endpointsByPortsAndNamespaces).filter(([key]) => key !== "0:").map(([key, endpoints2]) => {
|
487
|
-
const [port] = key.split(":");
|
488
|
-
const portNumber = parseInt(port, 10);
|
489
|
-
const portValue = isNaN(portNumber) ? port : portNumber;
|
490
|
-
return _NetworkPolicy.getRuleFromEndpoint(portValue, endpoints2, args2.cluster);
|
491
|
-
});
|
492
|
-
return [
|
493
|
-
{
|
494
|
-
all: rule.fromAll ?? false,
|
495
|
-
cidrs: normalize2(rule.fromCidr, rule.fromCidrs).concat(l3OnlyRule?.cidrs ?? []),
|
496
|
-
fqdns: [],
|
497
|
-
services: normalize2(rule.fromService, rule.fromServices),
|
498
|
-
namespaces: normalize2(rule.fromNamespace, rule.fromNamespaces),
|
499
|
-
selectors: normalize2(rule.fromSelector, rule.fromSelectors),
|
500
|
-
ports: normalize2(rule.toPort, rule.toPorts)
|
501
|
-
},
|
502
|
-
...otherRules
|
503
|
-
].filter((rule2) => !_NetworkPolicy.isEmptyRule(rule2));
|
504
|
-
}),
|
505
|
-
egressRules: egressRules.flatMap((rule) => {
|
506
|
-
const endpoints = normalize2(args2.egressRule?.toEndpoint, args2.egressRule?.toEndpoints);
|
507
|
-
const parsedEndpoints = endpoints.map(parseL34Endpoint);
|
508
|
-
const endpointsByPortsAnsNamespaces = groupBy(parsedEndpoints, (endpoint) => {
|
509
|
-
const namespace = isFromCluster(endpoint, args2.cluster) ? endpoint.metadata.k8sService.namespace : "";
|
510
|
-
const port = isFromCluster(endpoint, args2.cluster) ? endpoint.metadata.k8sService.targetPort : endpoint.port;
|
511
|
-
return `${port ?? "0"}:${namespace}`;
|
512
|
-
});
|
513
|
-
const l3OnlyRule = endpointsByPortsAnsNamespaces["0:"] ? _NetworkPolicy.getRuleFromEndpoint(
|
514
|
-
void 0,
|
515
|
-
endpointsByPortsAnsNamespaces["0:"],
|
516
|
-
args2.cluster
|
517
|
-
) : void 0;
|
518
|
-
const otherRules = Object.entries(endpointsByPortsAnsNamespaces).filter(([key]) => key !== "0:").map(([key, endpoints2]) => {
|
519
|
-
const [port] = key.split(":");
|
520
|
-
const portNumber = parseInt(port, 10);
|
521
|
-
const portValue = isNaN(portNumber) ? port : portNumber;
|
522
|
-
return _NetworkPolicy.getRuleFromEndpoint(portValue, endpoints2, args2.cluster);
|
523
|
-
});
|
524
|
-
return [
|
525
|
-
{
|
526
|
-
all: rule.toAll ?? false,
|
527
|
-
cidrs: normalize2(rule.toCidr, rule.toCidrs).concat(l3OnlyRule?.cidrs ?? []),
|
528
|
-
fqdns: normalize2(rule.toFqdn, rule.toFqdns).concat(l3OnlyRule?.fqdns ?? []),
|
529
|
-
services: normalize2(rule.toService, rule.toServices),
|
530
|
-
namespaces: normalize2(rule.toNamespace, rule.toNamespaces),
|
531
|
-
selectors: normalize2(rule.toSelector, rule.toSelectors),
|
532
|
-
ports: normalize2(rule.toPort, rule.toPorts)
|
533
|
-
},
|
534
|
-
...otherRules
|
535
|
-
].filter((rule2) => !_NetworkPolicy.isEmptyRule(rule2));
|
536
|
-
}).concat(extraEgressRules)
|
537
|
-
};
|
538
|
-
});
|
539
|
-
this.networkPolicy = output4(
|
540
|
-
normalizedArgs.apply(async (args2) => {
|
541
|
-
return output4(
|
542
|
-
this.create(name, args2, {
|
543
|
-
...opts,
|
544
|
-
parent: this,
|
545
|
-
provider: await getProvider(args2.cluster)
|
546
|
-
})
|
547
|
-
);
|
548
|
-
})
|
549
|
-
);
|
550
|
-
}
|
551
|
-
static mapCidrFromEndpoint(result) {
|
552
|
-
if (result.type === "ipv4") {
|
553
|
-
return `${result.address}/32`;
|
554
|
-
}
|
555
|
-
return `${result.address}/128`;
|
556
|
-
}
|
557
|
-
static getRuleFromEndpoint(port, endpoints, cluster) {
|
558
|
-
const ports = port ? [{ port, protocol: endpoints[0].protocol?.toUpperCase() }] : [];
|
559
|
-
const cidrs = endpoints.filter((endpoint) => !isFromCluster(endpoint, cluster)).filter((endpoint) => endpoint.type === "ipv4" || endpoint.type === "ipv6").map(_NetworkPolicy.mapCidrFromEndpoint);
|
560
|
-
const fqdns = endpoints.filter((endpoint) => endpoint.type === "hostname").map((endpoint) => endpoint.hostname);
|
561
|
-
const selectors = endpoints.filter((endpoint) => isFromCluster(endpoint, cluster)).map((endpoint) => endpoint.metadata.k8sService.selector);
|
562
|
-
const namespace = endpoints.filter((endpoint) => isFromCluster(endpoint, cluster)).map((endpoint) => getServiceMetadata(endpoint)?.namespace)[0];
|
563
|
-
return {
|
564
|
-
all: false,
|
565
|
-
cidrs,
|
566
|
-
fqdns,
|
567
|
-
services: [],
|
568
|
-
namespaces: namespace ? [namespace] : [],
|
569
|
-
selectors,
|
570
|
-
ports
|
571
|
-
};
|
572
|
-
}
|
573
|
-
static isEmptyRule(rule) {
|
574
|
-
return !rule.all && rule.cidrs.length === 0 && rule.fqdns.length === 0 && rule.services.length === 0 && rule.namespaces.length === 0 && rule.selectors.length === 0 && rule.ports.length === 0;
|
575
|
-
}
|
576
|
-
static create(name, args, opts) {
|
577
|
-
return output4(args).apply(async (args2) => {
|
578
|
-
const cni = args2.cluster.cni;
|
579
|
-
if (cni === "other") {
|
580
|
-
return new NativeNetworkPolicy(name, args2, opts);
|
581
|
-
}
|
582
|
-
const implName = `${capitalize(cni)}NetworkPolicy`;
|
583
|
-
const implModule = await import(`@highstate/${cni}`);
|
584
|
-
const implClass = implModule[implName];
|
585
|
-
if (!implClass) {
|
586
|
-
throw new Error(`No implementation found for ${cni}`);
|
587
|
-
}
|
588
|
-
return new implClass(name, args2, opts);
|
589
|
-
});
|
590
|
-
}
|
591
|
-
static isolate(namespace, cluster, opts) {
|
592
|
-
return _NetworkPolicy.create(
|
593
|
-
"isolate",
|
594
|
-
{
|
595
|
-
namespace,
|
596
|
-
cluster,
|
597
|
-
description: "By default, deny all traffic to/from the namespace.",
|
598
|
-
isolateEgress: true,
|
599
|
-
isolateIngress: true
|
600
|
-
},
|
601
|
-
opts
|
602
|
-
);
|
603
|
-
}
|
604
|
-
static allowInsideNamespace(namespace, cluster, opts) {
|
605
|
-
return _NetworkPolicy.create(
|
606
|
-
"allow-inside-namespace",
|
607
|
-
{
|
608
|
-
namespace,
|
609
|
-
cluster,
|
610
|
-
description: "Allow all traffic inside the namespace.",
|
611
|
-
selector: {},
|
612
|
-
ingressRule: { fromNamespace: namespace },
|
613
|
-
egressRule: { toNamespace: namespace }
|
614
|
-
},
|
615
|
-
opts
|
616
|
-
);
|
617
|
-
}
|
618
|
-
static allowKubeApiServer(namespace, cluster, opts) {
|
619
|
-
return _NetworkPolicy.create(
|
620
|
-
"allow-kube-api-server",
|
621
|
-
{
|
622
|
-
namespace,
|
623
|
-
cluster,
|
624
|
-
description: "Allow all traffic to the Kubernetes API server from the namespace.",
|
625
|
-
allowKubeApiServer: true
|
626
|
-
},
|
627
|
-
opts
|
628
|
-
);
|
629
|
-
}
|
630
|
-
static allowKubeDns(namespace, cluster, opts) {
|
631
|
-
return _NetworkPolicy.create(
|
632
|
-
"allow-kube-dns",
|
633
|
-
{
|
634
|
-
namespace,
|
635
|
-
cluster,
|
636
|
-
description: "Allow all traffic to the Kubernetes DNS server from the namespace.",
|
637
|
-
allowKubeDns: true
|
638
|
-
},
|
639
|
-
opts
|
640
|
-
);
|
641
|
-
}
|
642
|
-
static allowAllEgress(namespace, cluster, opts) {
|
643
|
-
return _NetworkPolicy.create(
|
644
|
-
"allow-all-egress",
|
645
|
-
{
|
646
|
-
namespace,
|
647
|
-
cluster,
|
648
|
-
description: "Allow all egress traffic from the namespace.",
|
649
|
-
egressRule: { toAll: true }
|
650
|
-
},
|
651
|
-
opts
|
652
|
-
);
|
653
|
-
}
|
654
|
-
static allowAllIngress(namespace, cluster, opts) {
|
655
|
-
return _NetworkPolicy.create(
|
656
|
-
"allow-all-ingress",
|
657
|
-
{
|
658
|
-
namespace,
|
659
|
-
cluster,
|
660
|
-
description: "Allow all ingress traffic to the namespace.",
|
661
|
-
ingressRule: { fromAll: true }
|
662
|
-
},
|
663
|
-
opts
|
664
|
-
);
|
665
|
-
}
|
666
|
-
static allowEgressToEndpoint(endpoint, namespace, cluster, opts) {
|
667
|
-
const parsedEndpoint = parseL34Endpoint(endpoint);
|
668
|
-
return _NetworkPolicy.create(
|
669
|
-
`allow-egress-to-${l34EndpointToString(parsedEndpoint)}`,
|
670
|
-
{
|
671
|
-
namespace,
|
672
|
-
cluster,
|
673
|
-
description: interpolate`Allow egress traffic to "${l34EndpointToString(parsedEndpoint)}" from the namespace.`,
|
674
|
-
egressRule: { toEndpoint: endpoint }
|
675
|
-
},
|
676
|
-
opts
|
677
|
-
);
|
678
|
-
}
|
679
|
-
static allowIngressFromEndpoint(endpoint, namespace, cluster, opts) {
|
680
|
-
const parsedEndpoint = parseL34Endpoint(endpoint);
|
681
|
-
return _NetworkPolicy.create(
|
682
|
-
`allow-ingress-from-${l34EndpointToString(parsedEndpoint)}`,
|
683
|
-
{
|
684
|
-
namespace,
|
685
|
-
cluster,
|
686
|
-
description: interpolate`Allow ingress traffic from "${l34EndpointToString(parsedEndpoint)}" to the namespace.`,
|
687
|
-
ingressRule: { fromEndpoint: endpoint }
|
688
|
-
},
|
689
|
-
opts
|
690
|
-
);
|
691
|
-
}
|
692
|
-
};
|
693
|
-
var NativeNetworkPolicy = class _NativeNetworkPolicy extends NetworkPolicy {
|
694
|
-
create(name, args, opts) {
|
695
|
-
const ingress = _NativeNetworkPolicy.createIngressRules(args);
|
696
|
-
const egress = _NativeNetworkPolicy.createEgressRules(args);
|
697
|
-
const policyTypes = [];
|
698
|
-
if (ingress.length > 0 || args.isolateIngress) {
|
699
|
-
policyTypes.push("Ingress");
|
700
|
-
}
|
701
|
-
if (egress.length > 0 || args.isolateEgress) {
|
702
|
-
policyTypes.push("Egress");
|
703
|
-
}
|
704
|
-
return new networking.v1.NetworkPolicy(
|
705
|
-
name,
|
706
|
-
{
|
707
|
-
metadata: mergeDeep(mapMetadata(args, name), {
|
708
|
-
annotations: args.description ? { "kubernetes.io/description": args.description } : void 0
|
709
|
-
}),
|
710
|
-
spec: {
|
711
|
-
podSelector: args.podSelector,
|
712
|
-
ingress,
|
713
|
-
egress,
|
714
|
-
policyTypes
|
715
|
-
}
|
716
|
-
},
|
717
|
-
opts
|
718
|
-
);
|
719
|
-
}
|
720
|
-
static fallbackIpBlock = {
|
721
|
-
cidr: "0.0.0.0/0",
|
722
|
-
except: ["10.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16"]
|
723
|
-
};
|
724
|
-
static fallbackDnsRule = {
|
725
|
-
to: [
|
726
|
-
{
|
727
|
-
namespaceSelector: { matchLabels: { "kubernetes.io/metadata.name": "kube-system" } },
|
728
|
-
podSelector: { matchLabels: { "k8s-app": "kube-dns" } }
|
729
|
-
}
|
730
|
-
],
|
731
|
-
ports: [{ port: 53, protocol: "UDP" }]
|
732
|
-
};
|
733
|
-
static createIngressRules(args) {
|
734
|
-
return uniqueBy(
|
735
|
-
args.ingressRules.map((rule) => ({
|
736
|
-
from: rule.all ? [] : _NativeNetworkPolicy.createRulePeers(rule),
|
737
|
-
ports: _NativeNetworkPolicy.mapPorts(rule.ports)
|
738
|
-
})),
|
739
|
-
(rule) => JSON.stringify(rule)
|
740
|
-
);
|
741
|
-
}
|
742
|
-
static createEgressRules(args) {
|
743
|
-
const extraRules = [];
|
744
|
-
const needKubeDns = args.egressRules.some((rule) => rule.fqdns.length > 0);
|
745
|
-
if (needKubeDns) {
|
746
|
-
extraRules.push(_NativeNetworkPolicy.fallbackDnsRule);
|
747
|
-
}
|
748
|
-
const needFallback = args.egressRules.some(
|
749
|
-
(rule) => rule.fqdns.some((fqdn) => !fqdn.endsWith(".cluster.local"))
|
750
|
-
);
|
751
|
-
if (needFallback) {
|
752
|
-
extraRules.push({ to: [{ ipBlock: _NativeNetworkPolicy.fallbackIpBlock }] });
|
753
|
-
}
|
754
|
-
if (args.allowKubeApiServer) {
|
755
|
-
const { quirks, apiEndpoints } = args.cluster;
|
756
|
-
if (quirks?.fallbackKubeApiAccess) {
|
757
|
-
extraRules.push({
|
758
|
-
to: [{ ipBlock: { cidr: `${quirks?.fallbackKubeApiAccess.serverIp}/32` } }],
|
759
|
-
ports: [{ port: quirks?.fallbackKubeApiAccess.serverPort, protocol: "TCP" }]
|
760
|
-
});
|
761
|
-
} else {
|
762
|
-
const rules = apiEndpoints.filter((endpoint) => endpoint.type !== "hostname").map((endpoint) => ({
|
763
|
-
to: [{ ipBlock: { cidr: l3EndpointToCidr(endpoint) } }],
|
764
|
-
ports: [{ port: endpoint.port, protocol: "TCP" }]
|
765
|
-
}));
|
766
|
-
extraRules.push(...rules);
|
767
|
-
}
|
768
|
-
}
|
769
|
-
return uniqueBy(
|
770
|
-
args.egressRules.map((rule) => {
|
771
|
-
return {
|
772
|
-
to: rule.all ? [] : _NativeNetworkPolicy.createRulePeers(rule),
|
773
|
-
ports: _NativeNetworkPolicy.mapPorts(rule.ports)
|
774
|
-
};
|
775
|
-
}).filter((rule) => rule.to !== void 0).concat(extraRules),
|
776
|
-
(rule) => JSON.stringify(rule)
|
777
|
-
);
|
778
|
-
}
|
779
|
-
static createRulePeers(args) {
|
780
|
-
const peers = uniqueBy(
|
781
|
-
[
|
782
|
-
..._NativeNetworkPolicy.createCidrPeers(args),
|
783
|
-
..._NativeNetworkPolicy.createServicePeers(args),
|
784
|
-
..._NativeNetworkPolicy.createSelectorPeers(args)
|
785
|
-
],
|
786
|
-
(peer) => JSON.stringify(peer)
|
787
|
-
);
|
788
|
-
return peers.length > 0 ? peers : void 0;
|
789
|
-
}
|
790
|
-
static createCidrPeers(args) {
|
791
|
-
return args.cidrs.map((cidr) => ({ ipBlock: { cidr } }));
|
792
|
-
}
|
793
|
-
static createServicePeers(args) {
|
794
|
-
return args.services.map((service) => {
|
795
|
-
const selector = mapServiceToLabelSelector(service);
|
796
|
-
return {
|
797
|
-
namespaceSelector: mapNamespaceNameToSelector(service.metadata.namespace),
|
798
|
-
podSelector: selector
|
799
|
-
};
|
800
|
-
});
|
801
|
-
}
|
802
|
-
static createSelectorPeers(args) {
|
803
|
-
const selectorPeers = args.selectors.map((selector) => ({
|
804
|
-
podSelector: mapSelectorLikeToSelector(selector)
|
805
|
-
}));
|
806
|
-
const namespacePeers = args.namespaces.map(_NativeNetworkPolicy.createNamespacePeer);
|
807
|
-
if (namespacePeers.length === 0) {
|
808
|
-
return selectorPeers;
|
809
|
-
}
|
810
|
-
if (selectorPeers.length === 0) {
|
811
|
-
return namespacePeers;
|
812
|
-
}
|
813
|
-
return flat(
|
814
|
-
selectorPeers.map((selectorPeer) => {
|
815
|
-
return namespacePeers.map((namespacePeer) => merge(selectorPeer, namespacePeer));
|
816
|
-
})
|
817
|
-
);
|
818
|
-
}
|
819
|
-
static createNamespacePeer(namespace) {
|
820
|
-
const namespaceName = mapNamespaceLikeToNamespaceName(namespace);
|
821
|
-
const namespaceSelector = mapNamespaceNameToSelector(namespaceName);
|
822
|
-
return { namespaceSelector };
|
823
|
-
}
|
824
|
-
static mapPorts(ports) {
|
825
|
-
return ports.map((port) => {
|
826
|
-
if ("port" in port) {
|
827
|
-
return {
|
828
|
-
port: port.port,
|
829
|
-
protocol: port.protocol ?? "TCP"
|
830
|
-
};
|
831
|
-
}
|
832
|
-
return {
|
833
|
-
port: port.range[0],
|
834
|
-
endPort: port.range[1],
|
835
|
-
protocol: port.protocol ?? "TCP"
|
836
|
-
};
|
837
|
-
});
|
838
|
-
}
|
839
|
-
};
|
840
|
-
|
841
556
|
// src/workload.ts
|
842
557
|
import {
|
843
|
-
normalize as
|
558
|
+
normalize as normalize2
|
844
559
|
} from "@highstate/pulumi";
|
845
560
|
import {
|
846
561
|
ComponentResource as ComponentResource4,
|
847
|
-
interpolate
|
562
|
+
interpolate,
|
848
563
|
output as output5
|
849
564
|
} from "@pulumi/pulumi";
|
850
|
-
import { uniqueBy
|
565
|
+
import { uniqueBy } from "remeda";
|
851
566
|
import { deepmerge as deepmerge2 } from "deepmerge-ts";
|
852
567
|
|
853
568
|
// src/pod.ts
|
@@ -862,16 +577,16 @@ function getWorkloadComponents(name, args, parent, opts) {
|
|
862
577
|
const labels = {
|
863
578
|
"app.kubernetes.io/name": name
|
864
579
|
};
|
865
|
-
const containers = output5(args).apply((args2) =>
|
580
|
+
const containers = output5(args).apply((args2) => normalize2(args2.container, args2.containers));
|
866
581
|
const volumes = containers.apply((containers2) => {
|
867
|
-
const containerVolumes = containers2.flatMap((container) =>
|
582
|
+
const containerVolumes = containers2.flatMap((container) => normalize2(container.volume, container.volumes)).map(mapWorkloadVolume);
|
868
583
|
const containerVolumeMounts = containers2.flatMap((container) => {
|
869
|
-
return
|
584
|
+
return normalize2(container.volumeMount, container.volumeMounts).map((volumeMount) => {
|
870
585
|
return "volume" in volumeMount ? volumeMount.volume : void 0;
|
871
586
|
}).filter(Boolean);
|
872
587
|
}).map(mapWorkloadVolume);
|
873
588
|
return output5([...containerVolumes, ...containerVolumeMounts]).apply(
|
874
|
-
|
589
|
+
uniqueBy((volume) => volume.name)
|
875
590
|
);
|
876
591
|
});
|
877
592
|
const podSpec = output5({ args, containers, volumes }).apply(({ args: args2, containers: containers2, volumes: volumes2 }) => {
|
@@ -931,7 +646,7 @@ function getExposableWorkloadComponents(name, args, parent, opts) {
|
|
931
646
|
if (args2.existing) {
|
932
647
|
return void 0;
|
933
648
|
}
|
934
|
-
const ports = containers2.flatMap((container) =>
|
649
|
+
const ports = containers2.flatMap((container) => normalize2(container.port, container.ports));
|
935
650
|
return Service.create(
|
936
651
|
name,
|
937
652
|
{
|
@@ -994,7 +709,7 @@ var Workload = class extends ComponentResource4 {
|
|
994
709
|
*/
|
995
710
|
get terminal() {
|
996
711
|
const containerName = output5(this.args).apply((args) => {
|
997
|
-
const containers =
|
712
|
+
const containers = normalize2(args.container, args.containers);
|
998
713
|
return containers[0]?.name ?? this.name;
|
999
714
|
});
|
1000
715
|
return output5({
|
@@ -1008,7 +723,7 @@ var Workload = class extends ComponentResource4 {
|
|
1008
723
|
"-it",
|
1009
724
|
"-n",
|
1010
725
|
this.metadata.namespace,
|
1011
|
-
|
726
|
+
interpolate`${this.resourceType}/${this.metadata.name}`,
|
1012
727
|
"-c",
|
1013
728
|
containerName,
|
1014
729
|
"--",
|
@@ -1074,7 +789,7 @@ var ExposableWorkload = class extends Workload {
|
|
1074
789
|
static createOrPatchGeneric(name, args, opts) {
|
1075
790
|
return output5(args).apply(async (args2) => {
|
1076
791
|
if (args2.existing?.type === "k8s.deployment") {
|
1077
|
-
const { Deployment } = await import("./deployment-
|
792
|
+
const { Deployment } = await import("./deployment-E3ZTF2IS.js");
|
1078
793
|
return Deployment.patch(
|
1079
794
|
name,
|
1080
795
|
{
|
@@ -1086,7 +801,7 @@ var ExposableWorkload = class extends Workload {
|
|
1086
801
|
);
|
1087
802
|
}
|
1088
803
|
if (args2.existing?.type === "k8s.stateful-set") {
|
1089
|
-
const { StatefulSet } = await import("./stateful-set-
|
804
|
+
const { StatefulSet } = await import("./stateful-set-NTU7QKC7.js");
|
1090
805
|
return StatefulSet.patch(
|
1091
806
|
name,
|
1092
807
|
{
|
@@ -1098,11 +813,11 @@ var ExposableWorkload = class extends Workload {
|
|
1098
813
|
);
|
1099
814
|
}
|
1100
815
|
if (args2.type === "Deployment") {
|
1101
|
-
const { Deployment } = await import("./deployment-
|
816
|
+
const { Deployment } = await import("./deployment-E3ZTF2IS.js");
|
1102
817
|
return Deployment.create(name, deepmerge2(args2, args2.deployment), opts);
|
1103
818
|
}
|
1104
819
|
if (args2.type === "StatefulSet") {
|
1105
|
-
const { StatefulSet } = await import("./stateful-set-
|
820
|
+
const { StatefulSet } = await import("./stateful-set-NTU7QKC7.js");
|
1106
821
|
return StatefulSet.create(name, deepmerge2(args2, args2.statefulSet), opts);
|
1107
822
|
}
|
1108
823
|
throw new Error(`Unknown workload type: ${args2.type}`);
|
@@ -1113,11 +828,11 @@ var ExposableWorkload = class extends Workload {
|
|
1113
828
|
export {
|
1114
829
|
PersistentVolumeClaim,
|
1115
830
|
Secret,
|
1116
|
-
|
831
|
+
ConfigMap,
|
1117
832
|
exposableWorkloadExtraArgs,
|
1118
833
|
getWorkloadComponents,
|
1119
834
|
getExposableWorkloadComponents,
|
1120
835
|
Workload,
|
1121
836
|
ExposableWorkload
|
1122
837
|
};
|
1123
|
-
//# sourceMappingURL=chunk-
|
838
|
+
//# sourceMappingURL=chunk-R43VRICF.js.map
|