@highstate/k8s 0.6.1 → 0.7.0
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/assets/charts.json +8 -0
- package/dist/helm-BV9UE-B8.js +282 -0
- package/dist/index.d.ts +98 -3
- package/dist/index.js +22 -169
- package/dist/{shared-hajqPzR4.js → shared-r5jBysdR.js} +2 -15
- package/dist/units/cert-manager/index.js +23 -6
- package/dist/units/dns01-issuer/index.js +1 -3
- package/package.json +11 -8
- package/assets/cert-manager-v1.16.3.tgz +0 -0
- package/assets/gateway-api.yaml +0 -14974
@@ -0,0 +1,282 @@
|
|
1
|
+
import { resolve } from 'path';
|
2
|
+
import { mkdir, unlink, readFile } from 'node:fs/promises';
|
3
|
+
import { ComponentResource, output, normalize, interpolate, all, toPromise } from '@highstate/pulumi';
|
4
|
+
import { core, helm } from '@pulumi/kubernetes';
|
5
|
+
import { ComponentResource as ComponentResource$1, output as output$1 } from '@pulumi/pulumi';
|
6
|
+
import spawn from 'nano-spawn';
|
7
|
+
import { sha256 } from 'crypto-hash';
|
8
|
+
import { mergeDeep, omit, pipe, map } from 'remeda';
|
9
|
+
import { local } from '@pulumi/command';
|
10
|
+
import { glob } from 'glob';
|
11
|
+
import { m as mapMetadata, c as commonExtraArgs, d as mapNamespaceLikeToNamespaceName } from './shared-r5jBysdR.js';
|
12
|
+
import { gateway } from '@highstate/gateway-api';
|
13
|
+
|
14
|
+
const serviceExtraArgs = [...commonExtraArgs, "port", "ports"];
|
15
|
+
class Service extends ComponentResource {
|
16
|
+
/**
|
17
|
+
* The underlying Kubernetes service.
|
18
|
+
*/
|
19
|
+
service;
|
20
|
+
constructor(name, args, opts) {
|
21
|
+
super("highstate:k8s:Service", name, args, opts);
|
22
|
+
this.service = output(args).apply((args2) => {
|
23
|
+
return new core.v1.Service(
|
24
|
+
name,
|
25
|
+
{
|
26
|
+
metadata: mapMetadata(args2, name),
|
27
|
+
spec: mergeDeep(
|
28
|
+
{
|
29
|
+
ports: normalize(args2.port, args2.ports)
|
30
|
+
},
|
31
|
+
omit(args2, serviceExtraArgs)
|
32
|
+
)
|
33
|
+
},
|
34
|
+
{ ...opts, parent: this }
|
35
|
+
);
|
36
|
+
});
|
37
|
+
this.registerOutputs({
|
38
|
+
service: this.service
|
39
|
+
});
|
40
|
+
}
|
41
|
+
}
|
42
|
+
function mapContainerPortToServicePort(port) {
|
43
|
+
return {
|
44
|
+
port: port.containerPort,
|
45
|
+
targetPort: port.containerPort,
|
46
|
+
protocol: port.protocol
|
47
|
+
};
|
48
|
+
}
|
49
|
+
function mapServiceToLabelSelector(service) {
|
50
|
+
return {
|
51
|
+
matchLabels: service.spec.selector
|
52
|
+
};
|
53
|
+
}
|
54
|
+
function getServiceHost(service) {
|
55
|
+
return interpolate`${service.metadata.name}.${service.metadata.namespace}.svc`;
|
56
|
+
}
|
57
|
+
function getRequiredServicePortByName(service, name) {
|
58
|
+
return service.spec.ports.apply((ports) => {
|
59
|
+
const port = ports.find((p) => p.name === name);
|
60
|
+
if (!port) {
|
61
|
+
throw new Error(`Service does not have a port with name ${name}`);
|
62
|
+
}
|
63
|
+
return port.port;
|
64
|
+
});
|
65
|
+
}
|
66
|
+
|
67
|
+
function resolveBackendRef(ref) {
|
68
|
+
if (core.v1.Service.isInstance(ref)) {
|
69
|
+
return output({
|
70
|
+
name: ref.metadata.name,
|
71
|
+
namespace: ref.metadata.namespace,
|
72
|
+
port: ref.spec.ports[0].port
|
73
|
+
});
|
74
|
+
}
|
75
|
+
if ("service" in ref) {
|
76
|
+
const service = output(ref.service);
|
77
|
+
return output({
|
78
|
+
name: service.metadata.name,
|
79
|
+
namespace: service.metadata.namespace,
|
80
|
+
port: all([ref.service, ref.port]).apply(([service2, port]) => {
|
81
|
+
return typeof port === "number" ? output(port) : getRequiredServicePortByName(service2, port);
|
82
|
+
})
|
83
|
+
});
|
84
|
+
}
|
85
|
+
return output({
|
86
|
+
name: ref.name,
|
87
|
+
namespace: ref.namespace,
|
88
|
+
port: ref.port
|
89
|
+
});
|
90
|
+
}
|
91
|
+
|
92
|
+
class HttpRoute extends ComponentResource {
|
93
|
+
/**
|
94
|
+
* The underlying Kubernetes resource.
|
95
|
+
*/
|
96
|
+
route;
|
97
|
+
constructor(name, args, opts) {
|
98
|
+
super("highstate:k8s:HttpRoute", name, args, opts);
|
99
|
+
this.route = output({
|
100
|
+
args,
|
101
|
+
gatewayNamespace: output(args.gateway).metadata.namespace
|
102
|
+
}).apply(({ args: args2, gatewayNamespace }) => {
|
103
|
+
return new gateway.v1.HTTPRoute(
|
104
|
+
name,
|
105
|
+
{
|
106
|
+
metadata: mapMetadata(
|
107
|
+
{
|
108
|
+
...args2,
|
109
|
+
namespace: gatewayNamespace
|
110
|
+
},
|
111
|
+
name
|
112
|
+
),
|
113
|
+
spec: {
|
114
|
+
hostnames: normalize(args2.hostname, args2.hostnames),
|
115
|
+
parentRefs: [
|
116
|
+
{
|
117
|
+
name: args2.gateway.metadata.name
|
118
|
+
}
|
119
|
+
],
|
120
|
+
rules: normalize(args2.rule, args2.rules).map((rule) => ({
|
121
|
+
timeouts: rule.timeouts,
|
122
|
+
matches: pipe(
|
123
|
+
normalize(rule.match, rule.matches),
|
124
|
+
map(mapHttpRouteRuleMatch),
|
125
|
+
addDefaultPathMatch
|
126
|
+
),
|
127
|
+
filters: normalize(rule.filter, rule.filters),
|
128
|
+
backendRefs: rule.backend ? [resolveBackendRef(rule.backend)] : void 0
|
129
|
+
}))
|
130
|
+
}
|
131
|
+
},
|
132
|
+
{ parent: this, ...opts }
|
133
|
+
);
|
134
|
+
});
|
135
|
+
this.registerOutputs({ route: this.route });
|
136
|
+
}
|
137
|
+
}
|
138
|
+
function addDefaultPathMatch(matches) {
|
139
|
+
return matches.length ? matches : [{ path: { type: "PathPrefix", value: "/" } }];
|
140
|
+
}
|
141
|
+
function mapHttpRouteRuleMatch(match) {
|
142
|
+
if (typeof match === "string") {
|
143
|
+
return { path: { type: "PathPrefix", value: match } };
|
144
|
+
}
|
145
|
+
return match;
|
146
|
+
}
|
147
|
+
|
148
|
+
class Chart extends ComponentResource$1 {
|
149
|
+
constructor(name, args, opts) {
|
150
|
+
super("highstate:k8s:Chart", name, args, opts);
|
151
|
+
this.name = name;
|
152
|
+
this.chart = output$1(args).apply((args2) => {
|
153
|
+
return new helm.v4.Chart(
|
154
|
+
name,
|
155
|
+
omit(
|
156
|
+
{
|
157
|
+
...args2,
|
158
|
+
chart: resolveHelmChart(args2.charts, args2.chart),
|
159
|
+
namespace: args2.namespace ? mapNamespaceLikeToNamespaceName(args2.namespace) : void 0
|
160
|
+
},
|
161
|
+
["charts", "httpRoute"]
|
162
|
+
),
|
163
|
+
{ parent: this, ...opts }
|
164
|
+
);
|
165
|
+
});
|
166
|
+
this.httpRoute = output$1(args.httpRoute).apply((httpRoute) => {
|
167
|
+
if (!httpRoute) {
|
168
|
+
return void 0;
|
169
|
+
}
|
170
|
+
return new HttpRoute(
|
171
|
+
name,
|
172
|
+
{
|
173
|
+
...httpRoute,
|
174
|
+
rule: {
|
175
|
+
backend: this.getServiceOutput(args.serviceName)
|
176
|
+
}
|
177
|
+
},
|
178
|
+
{ ...opts, parent: this }
|
179
|
+
);
|
180
|
+
});
|
181
|
+
this.registerOutputs({ chart: this.chart });
|
182
|
+
}
|
183
|
+
/**
|
184
|
+
* The underlying Helm chart.
|
185
|
+
*/
|
186
|
+
chart;
|
187
|
+
/**
|
188
|
+
* The HTTP route associated with the deployment.
|
189
|
+
*/
|
190
|
+
httpRoute;
|
191
|
+
getServiceOutput(name) {
|
192
|
+
return this.chart.apply((chart) => getChartServiceOutput(chart, name ?? this.name));
|
193
|
+
}
|
194
|
+
getService(name) {
|
195
|
+
return toPromise(this.getServiceOutput(name));
|
196
|
+
}
|
197
|
+
}
|
198
|
+
class RenderedChart extends ComponentResource$1 {
|
199
|
+
/**
|
200
|
+
* The rendered manifest of the Helm chart.
|
201
|
+
*/
|
202
|
+
manifest;
|
203
|
+
/**
|
204
|
+
* The underlying command used to render the chart.
|
205
|
+
*/
|
206
|
+
command;
|
207
|
+
constructor(name, args, opts) {
|
208
|
+
super("highstate:k8s:RenderedChart", name, args, opts);
|
209
|
+
this.command = output$1(args).apply((args2) => {
|
210
|
+
const values = args2.values ? Object.entries(args2.values).flatMap(([key, value]) => ["--set", `${key}="${value}"`]) : [];
|
211
|
+
return new local.Command(
|
212
|
+
name,
|
213
|
+
{
|
214
|
+
create: output$1([
|
215
|
+
"helm",
|
216
|
+
"template",
|
217
|
+
resolveHelmChart(args2.charts, args2.chart),
|
218
|
+
...args2.namespace ? ["--namespace", mapNamespaceLikeToNamespaceName(args2.namespace)] : [],
|
219
|
+
...values
|
220
|
+
]).apply((command) => command.join(" ")),
|
221
|
+
logging: "stderr"
|
222
|
+
},
|
223
|
+
{ parent: this, ...opts }
|
224
|
+
);
|
225
|
+
});
|
226
|
+
this.manifest = this.command.stdout;
|
227
|
+
this.registerOutputs({ manifest: this.manifest, command: this.command });
|
228
|
+
}
|
229
|
+
}
|
230
|
+
async function resolveHelmChart(charts, name) {
|
231
|
+
const entry = charts[name];
|
232
|
+
if (!entry) {
|
233
|
+
throw new Error(`Chart '${name}' not found in the charts.json`);
|
234
|
+
}
|
235
|
+
if (!process.env.HIGHSTATE_CACHE_DIR) {
|
236
|
+
throw new Error("Environment variable HIGHSTATE_CACHE_DIR is not set");
|
237
|
+
}
|
238
|
+
const chartsDir = resolve(process.env.HIGHSTATE_CACHE_DIR, "charts");
|
239
|
+
await mkdir(chartsDir, { recursive: true });
|
240
|
+
const globPattern = `${name}-*.tgz`;
|
241
|
+
const targetFileName = `${name}-${entry.version}.tgz`;
|
242
|
+
const files = await glob(globPattern, { cwd: chartsDir });
|
243
|
+
if (files.includes(targetFileName)) {
|
244
|
+
return resolve(chartsDir, targetFileName);
|
245
|
+
}
|
246
|
+
for (const file of files) {
|
247
|
+
await unlink(resolve(chartsDir, file));
|
248
|
+
}
|
249
|
+
await spawn("helm", [
|
250
|
+
"pull",
|
251
|
+
entry.name,
|
252
|
+
"--version",
|
253
|
+
entry.version,
|
254
|
+
"--repo",
|
255
|
+
entry.repo,
|
256
|
+
"--destination",
|
257
|
+
chartsDir
|
258
|
+
]);
|
259
|
+
const content = await readFile(resolve(chartsDir, targetFileName));
|
260
|
+
const actualSha256 = await sha256(content);
|
261
|
+
if (actualSha256 !== entry.sha256) {
|
262
|
+
throw new Error(`SHA256 mismatch for chart '${name}'`);
|
263
|
+
}
|
264
|
+
return resolve(chartsDir, targetFileName);
|
265
|
+
}
|
266
|
+
function getChartServiceOutput(chart, name) {
|
267
|
+
const services = chart.resources.apply((resources) => {
|
268
|
+
return resources.filter((r) => core.v1.Service.isInstance(r)).map((service) => ({ name: service.metadata.name, service }));
|
269
|
+
});
|
270
|
+
return output$1(services).apply((services2) => {
|
271
|
+
const service = services2.find((s) => s.name === name)?.service;
|
272
|
+
if (!service) {
|
273
|
+
throw new Error(`Service with name '${name}' not found in the chart resources`);
|
274
|
+
}
|
275
|
+
return service;
|
276
|
+
});
|
277
|
+
}
|
278
|
+
function getChartService(chart, name) {
|
279
|
+
return toPromise(getChartServiceOutput(chart, name));
|
280
|
+
}
|
281
|
+
|
282
|
+
export { Chart as C, HttpRoute as H, RenderedChart as R, Service as S, mapServiceToLabelSelector as a, getChartServiceOutput as b, getChartService as c, getServiceHost as g, mapContainerPortToServicePort as m, resolveHelmChart as r };
|
package/dist/index.d.ts
CHANGED
@@ -5,6 +5,7 @@ import { gateway, types as types$1 } from '@highstate/gateway-api';
|
|
5
5
|
import { PartialKeys, RequiredKeys } from '@highstate/contract';
|
6
6
|
import { DnsRecord } from '@highstate/common';
|
7
7
|
import { Input as Input$1, ComponentResource as ComponentResource$1, Output as Output$1, ComponentResourceOptions as ComponentResourceOptions$1 } from '@pulumi/pulumi';
|
8
|
+
import { local } from '@pulumi/command';
|
8
9
|
|
9
10
|
declare function createProvider(cluster: Input<k8s.Cluster>): Promise<Provider>;
|
10
11
|
declare function createNamespace(name: string, provider: Provider, args?: core.v1.NamespaceArgs): core.v1.Namespace;
|
@@ -24,7 +25,6 @@ type CommonArgs = {
|
|
24
25
|
metadata?: Input<types.input.meta.v1.ObjectMeta>;
|
25
26
|
};
|
26
27
|
declare function mapMetadata(args: Unwrap<CommonArgs>, fallbackName?: string): types.input.meta.v1.ObjectMeta;
|
27
|
-
declare function resolveChartPath(packageName: string, chartName: string, parent: string): string;
|
28
28
|
type SelectorLike = types.input.meta.v1.LabelSelector | Record<string, Input<string>>;
|
29
29
|
declare function mapSelectorLikeToSelector(selector: SelectorLike): types.input.meta.v1.LabelSelector;
|
30
30
|
declare function mapNamespaceLikeToNamespaceName(namespace: NamespaceLike): Output<string>;
|
@@ -195,7 +195,6 @@ type WorkloadVolume = types.input.core.v1.Volume | core.v1.PersistentVolumeClaim
|
|
195
195
|
type DeploymentArgs = CommonArgs & {
|
196
196
|
container?: Input<Container>;
|
197
197
|
containers?: InputArray<Container>;
|
198
|
-
gateway?: Input<gateway.v1.Gateway>;
|
199
198
|
service?: Input<ServiceArgs>;
|
200
199
|
httpRoute?: Input<HttpRouteArgs>;
|
201
200
|
} & Omit<Partial<types.input.apps.v1.DeploymentSpec>, "template"> & {
|
@@ -670,7 +669,103 @@ declare class CronJob extends ComponentResource {
|
|
670
669
|
constructor(name: string, args: CronJobArgs, opts?: ComponentResourceOptions);
|
671
670
|
}
|
672
671
|
|
672
|
+
type ChartArgs<TCharts extends ChartRepository = ChartRepository, TName extends string & keyof TCharts = string> = Omit<helm.v4.ChartArgs, "chart" | "version" | "repositoryOpts"> & {
|
673
|
+
/**
|
674
|
+
* The namespace to deploy the chart into.
|
675
|
+
*/
|
676
|
+
namespace?: Input$1<NamespaceLike>;
|
677
|
+
/**
|
678
|
+
* The custom name of the service to bind to the route.
|
679
|
+
*
|
680
|
+
* By default, it is the same as the chart name.
|
681
|
+
*/
|
682
|
+
serviceName?: string;
|
683
|
+
/**
|
684
|
+
* The content of the charts.json file.
|
685
|
+
*/
|
686
|
+
charts: TCharts;
|
687
|
+
/**
|
688
|
+
* The name of the chart to resolve.
|
689
|
+
*/
|
690
|
+
chart: TName;
|
691
|
+
/**
|
692
|
+
* The http route args to bind the service to.
|
693
|
+
*/
|
694
|
+
httpRoute?: Input$1<HttpRouteArgs>;
|
695
|
+
};
|
696
|
+
declare class Chart<TCharts extends ChartRepository = ChartRepository, TName extends string & keyof TCharts = string> extends ComponentResource$1 {
|
697
|
+
private readonly name;
|
698
|
+
/**
|
699
|
+
* The underlying Helm chart.
|
700
|
+
*/
|
701
|
+
readonly chart: Output$1<helm.v4.Chart>;
|
702
|
+
/**
|
703
|
+
* The HTTP route associated with the deployment.
|
704
|
+
*/
|
705
|
+
readonly httpRoute: Output$1<HttpRoute | undefined>;
|
706
|
+
constructor(name: string, args: ChartArgs<TCharts, TName>, opts?: ComponentResourceOptions$1);
|
707
|
+
getServiceOutput(name?: string): Output$1<core.v1.Service>;
|
708
|
+
getService(name?: string): Promise<core.v1.Service>;
|
709
|
+
}
|
710
|
+
type RenderedChartArgs<TCharts extends ChartRepository = ChartRepository, TName extends string & keyof TCharts = string> = {
|
711
|
+
/**
|
712
|
+
* The namespace to deploy the chart into.
|
713
|
+
*/
|
714
|
+
namespace?: Input$1<NamespaceLike>;
|
715
|
+
/**
|
716
|
+
* The content of the charts.json file.
|
717
|
+
*/
|
718
|
+
charts: TCharts;
|
719
|
+
/**
|
720
|
+
* The name of the chart to resolve.
|
721
|
+
*/
|
722
|
+
chart: TName;
|
723
|
+
/**
|
724
|
+
* The values to pass to the chart.
|
725
|
+
*/
|
726
|
+
values?: InputMap<string>;
|
727
|
+
};
|
728
|
+
declare class RenderedChart<TCharts extends ChartRepository = ChartRepository, TName extends string & keyof TCharts = string> extends ComponentResource$1 {
|
729
|
+
/**
|
730
|
+
* The rendered manifest of the Helm chart.
|
731
|
+
*/
|
732
|
+
readonly manifest: Output$1<string>;
|
733
|
+
/**
|
734
|
+
* The underlying command used to render the chart.
|
735
|
+
*/
|
736
|
+
readonly command: Output$1<local.Command>;
|
737
|
+
constructor(name: string, args: RenderedChartArgs<TCharts, TName>, opts?: ComponentResourceOptions$1);
|
738
|
+
}
|
739
|
+
type ChartEntry = {
|
740
|
+
repo: string;
|
741
|
+
name: string;
|
742
|
+
version: string;
|
743
|
+
sha256: string;
|
744
|
+
};
|
745
|
+
type ChartRepository = Record<string, ChartEntry>;
|
746
|
+
/**
|
747
|
+
* Downloads or reuses the Helm chart according to the charts.json file.
|
748
|
+
* Returns the full path to the chart's .tgz file.
|
749
|
+
*
|
750
|
+
* @param charts The content of the charts.json file.
|
751
|
+
* @param name The name of the chart to resolve.
|
752
|
+
*/
|
753
|
+
declare function resolveHelmChart<TCharts extends ChartRepository, TName extends string & keyof TCharts>(charts: TCharts, name: TName): Promise<string>;
|
754
|
+
/**
|
755
|
+
* Extracts the service with the given name from the chart resources.
|
756
|
+
* Throws an error if the service is not found.
|
757
|
+
*
|
758
|
+
* @param chart The Helm chart.
|
759
|
+
* @param name The name of the service.
|
760
|
+
*/
|
673
761
|
declare function getChartServiceOutput(chart: helm.v4.Chart, name: string): Output$1<core.v1.Service>;
|
762
|
+
/**
|
763
|
+
* Extracts the service with the given name from the chart resources.
|
764
|
+
* Throws an error if the service is not found.
|
765
|
+
*
|
766
|
+
* @param chart The Helm chart.
|
767
|
+
* @param name The name of the service.
|
768
|
+
*/
|
674
769
|
declare function getChartService(chart: helm.v4.Chart, name: string): Promise<core.v1.Service>;
|
675
770
|
|
676
|
-
export { type CommonArgs, type Container, type ContainerEnvironment, type ContainerEnvironmentSource, type ContainerEnvironmentVariable, type ContainerVolumeMount, CronJob, type CronJobArgs, Deployment, type DeploymentArgs, type FullNetworkPolicyArgs, HttpRoute, type HttpRouteArgs, Job, type JobArgs, type NamespaceLike, NetworkPolicy, type NetworkPolicyArgs, type NetworkPolicyPort, type NormalizedNetworkPolicyArgs, type NormalizedRuleArgs, ScriptBundle, type ScriptBundleArgs, type ScriptContainer, type ScriptDistribution, type ScriptEnvironment, type SelectorLike, Service, type ServiceArgs, StatefulSet, type StatefulSetArgs, type WorkloadVolume, createNamespace, createProvider, createScriptContainer, getChartService, getChartServiceOutput, getServiceHost, mapContainerPortToServicePort, mapMetadata, mapNamespaceLikeToNamespaceName, mapNamespaceNameToSelector, mapSelectorLikeToSelector, mapServiceToLabelSelector,
|
771
|
+
export { Chart, type ChartArgs, type ChartEntry, type ChartRepository, type CommonArgs, type Container, type ContainerEnvironment, type ContainerEnvironmentSource, type ContainerEnvironmentVariable, type ContainerVolumeMount, CronJob, type CronJobArgs, Deployment, type DeploymentArgs, type FullNetworkPolicyArgs, HttpRoute, type HttpRouteArgs, Job, type JobArgs, type NamespaceLike, NetworkPolicy, type NetworkPolicyArgs, type NetworkPolicyPort, type NormalizedNetworkPolicyArgs, type NormalizedRuleArgs, RenderedChart, type RenderedChartArgs, ScriptBundle, type ScriptBundleArgs, type ScriptContainer, type ScriptDistribution, type ScriptEnvironment, type SelectorLike, Service, type ServiceArgs, StatefulSet, type StatefulSetArgs, type WorkloadVolume, createNamespace, createProvider, createScriptContainer, getChartService, getChartServiceOutput, getServiceHost, mapContainerPortToServicePort, mapMetadata, mapNamespaceLikeToNamespaceName, mapNamespaceNameToSelector, mapSelectorLikeToSelector, mapServiceToLabelSelector, resolveHelmChart, useAccessPoint };
|
package/dist/index.js
CHANGED
@@ -1,150 +1,21 @@
|
|
1
|
-
import { m as mapMetadata, c as commonExtraArgs, a as mapSelectorLikeToSelector, b as mapNamespaceNameToSelector, d as mapNamespaceLikeToNamespaceName } from './shared-
|
2
|
-
export { f as createNamespace, e as createProvider
|
3
|
-
import {
|
1
|
+
import { m as mapMetadata, c as commonExtraArgs, a as mapSelectorLikeToSelector, b as mapNamespaceNameToSelector, d as mapNamespaceLikeToNamespaceName } from './shared-r5jBysdR.js';
|
2
|
+
export { f as createNamespace, e as createProvider } from './shared-r5jBysdR.js';
|
3
|
+
import { normalize, output, ComponentResource, toPromise, apply } from '@highstate/pulumi';
|
4
4
|
import { core, apps, networking, batch } from '@pulumi/kubernetes';
|
5
|
-
import {
|
6
|
-
import {
|
5
|
+
import { concat, map, omit, mergeDeep, capitalize, flat, merge, pipe } from 'remeda';
|
6
|
+
import { S as Service, m as mapContainerPortToServicePort, H as HttpRoute, a as mapServiceToLabelSelector } from './helm-BV9UE-B8.js';
|
7
|
+
export { C as Chart, R as RenderedChart, c as getChartService, b as getChartServiceOutput, g as getServiceHost, r as resolveHelmChart } from './helm-BV9UE-B8.js';
|
7
8
|
import { DnsRecord } from '@highstate/common';
|
9
|
+
import { gateway } from '@highstate/gateway-api';
|
8
10
|
import { ComponentResource as ComponentResource$1, output as output$1 } from '@pulumi/pulumi';
|
9
11
|
import { deepmerge } from 'deepmerge-ts';
|
10
12
|
import { trimIndentation, text } from '@highstate/contract';
|
11
|
-
import '
|
12
|
-
import 'node:
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
* The underlying Kubernetes service.
|
18
|
-
*/
|
19
|
-
service;
|
20
|
-
constructor(name, args, opts) {
|
21
|
-
super("highstate:k8s:Service", name, args, opts);
|
22
|
-
this.service = output(args).apply((args2) => {
|
23
|
-
return new core.v1.Service(
|
24
|
-
name,
|
25
|
-
{
|
26
|
-
metadata: mapMetadata(args2, name),
|
27
|
-
spec: mergeDeep(
|
28
|
-
{
|
29
|
-
ports: normalize(args2.port, args2.ports)
|
30
|
-
},
|
31
|
-
omit(args2, serviceExtraArgs)
|
32
|
-
)
|
33
|
-
},
|
34
|
-
{ ...opts, parent: this }
|
35
|
-
);
|
36
|
-
});
|
37
|
-
this.registerOutputs({
|
38
|
-
service: this.service
|
39
|
-
});
|
40
|
-
}
|
41
|
-
}
|
42
|
-
function mapContainerPortToServicePort(port) {
|
43
|
-
return {
|
44
|
-
port: port.containerPort,
|
45
|
-
targetPort: port.containerPort,
|
46
|
-
protocol: port.protocol
|
47
|
-
};
|
48
|
-
}
|
49
|
-
function mapServiceToLabelSelector(service) {
|
50
|
-
return {
|
51
|
-
matchLabels: service.spec.selector
|
52
|
-
};
|
53
|
-
}
|
54
|
-
function getServiceHost(service) {
|
55
|
-
return interpolate`${service.metadata.name}.${service.metadata.namespace}.svc`;
|
56
|
-
}
|
57
|
-
function getRequiredServicePortByName(service, name) {
|
58
|
-
return service.spec.ports.apply((ports) => {
|
59
|
-
const port = ports.find((p) => p.name === name);
|
60
|
-
if (!port) {
|
61
|
-
throw new Error(`Service does not have a port with name ${name}`);
|
62
|
-
}
|
63
|
-
return port.port;
|
64
|
-
});
|
65
|
-
}
|
66
|
-
|
67
|
-
function resolveBackendRef(ref) {
|
68
|
-
if (core.v1.Service.isInstance(ref)) {
|
69
|
-
return output({
|
70
|
-
name: ref.metadata.name,
|
71
|
-
namespace: ref.metadata.namespace,
|
72
|
-
port: ref.spec.ports[0].port
|
73
|
-
});
|
74
|
-
}
|
75
|
-
if ("service" in ref) {
|
76
|
-
const service = output(ref.service);
|
77
|
-
return output({
|
78
|
-
name: service.metadata.name,
|
79
|
-
namespace: service.metadata.namespace,
|
80
|
-
port: all([ref.service, ref.port]).apply(([service2, port]) => {
|
81
|
-
return typeof port === "number" ? output(port) : getRequiredServicePortByName(service2, port);
|
82
|
-
})
|
83
|
-
});
|
84
|
-
}
|
85
|
-
return output({
|
86
|
-
name: ref.name,
|
87
|
-
namespace: ref.namespace,
|
88
|
-
port: ref.port
|
89
|
-
});
|
90
|
-
}
|
91
|
-
|
92
|
-
class HttpRoute extends ComponentResource {
|
93
|
-
/**
|
94
|
-
* The underlying Kubernetes resource.
|
95
|
-
*/
|
96
|
-
route;
|
97
|
-
constructor(name, args, opts) {
|
98
|
-
super("highstate:k8s:HttpRoute", name, args, opts);
|
99
|
-
this.route = output({
|
100
|
-
args,
|
101
|
-
gatewayNamespace: output(args.gateway).metadata.namespace
|
102
|
-
}).apply(({ args: args2, gatewayNamespace }) => {
|
103
|
-
return new gateway.v1.HTTPRoute(
|
104
|
-
name,
|
105
|
-
{
|
106
|
-
metadata: mapMetadata(
|
107
|
-
{
|
108
|
-
...args2,
|
109
|
-
namespace: gatewayNamespace
|
110
|
-
},
|
111
|
-
name
|
112
|
-
),
|
113
|
-
spec: {
|
114
|
-
hostnames: normalize(args2.hostname, args2.hostnames),
|
115
|
-
parentRefs: [
|
116
|
-
{
|
117
|
-
name: args2.gateway.metadata.name
|
118
|
-
}
|
119
|
-
],
|
120
|
-
rules: normalize(args2.rule, args2.rules).map((rule) => ({
|
121
|
-
sessionPersistence: rule.sessionPersistence,
|
122
|
-
timeouts: rule.timeouts,
|
123
|
-
matches: pipe(
|
124
|
-
normalize(rule.match, rule.matches),
|
125
|
-
map(mapHttpRouteRuleMatch),
|
126
|
-
addDefaultPathMatch
|
127
|
-
),
|
128
|
-
filters: normalize(rule.filter, rule.filters),
|
129
|
-
backendRefs: rule.backend ? [resolveBackendRef(rule.backend)] : void 0
|
130
|
-
}))
|
131
|
-
}
|
132
|
-
},
|
133
|
-
{ parent: this, ...opts }
|
134
|
-
);
|
135
|
-
});
|
136
|
-
this.registerOutputs({ route: this.route });
|
137
|
-
}
|
138
|
-
}
|
139
|
-
function addDefaultPathMatch(matches) {
|
140
|
-
return matches.length ? matches : [{ path: { type: "PathPrefix", value: "/" } }];
|
141
|
-
}
|
142
|
-
function mapHttpRouteRuleMatch(match) {
|
143
|
-
if (typeof match === "string") {
|
144
|
-
return { path: { type: "PathPrefix", value: match } };
|
145
|
-
}
|
146
|
-
return match;
|
147
|
-
}
|
13
|
+
import 'path';
|
14
|
+
import 'node:fs/promises';
|
15
|
+
import 'nano-spawn';
|
16
|
+
import 'crypto-hash';
|
17
|
+
import '@pulumi/command';
|
18
|
+
import 'glob';
|
148
19
|
|
149
20
|
const containerExtraArgs = [
|
150
21
|
"port",
|
@@ -213,10 +84,13 @@ function mapContainerEnvironment(environment) {
|
|
213
84
|
}
|
214
85
|
function mapVolumeMount(volumeMount) {
|
215
86
|
if ("volume" in volumeMount) {
|
216
|
-
return
|
217
|
-
|
218
|
-
|
219
|
-
|
87
|
+
return omit(
|
88
|
+
{
|
89
|
+
...volumeMount,
|
90
|
+
name: output(volumeMount.volume).apply(mapWorkloadVolume).apply((volume) => output(volume.name))
|
91
|
+
},
|
92
|
+
["volume"]
|
93
|
+
);
|
220
94
|
}
|
221
95
|
return volumeMount;
|
222
96
|
}
|
@@ -269,7 +143,6 @@ const deploymentExtraArgs = [
|
|
269
143
|
...commonExtraArgs,
|
270
144
|
"container",
|
271
145
|
"containers",
|
272
|
-
"gateway",
|
273
146
|
"service",
|
274
147
|
"httpRoute"
|
275
148
|
];
|
@@ -359,15 +232,11 @@ class Deployment extends ComponentResource {
|
|
359
232
|
name,
|
360
233
|
{
|
361
234
|
...args2,
|
362
|
-
gateway: args2.gateway,
|
363
235
|
rule: {
|
364
236
|
backend: service.service
|
365
237
|
}
|
366
238
|
},
|
367
|
-
{
|
368
|
-
...opts,
|
369
|
-
parent: this
|
370
|
-
}
|
239
|
+
{ ...opts, parent: this }
|
371
240
|
);
|
372
241
|
});
|
373
242
|
this.registerOutputs({
|
@@ -933,20 +802,4 @@ class CronJob extends ComponentResource {
|
|
933
802
|
}
|
934
803
|
}
|
935
804
|
|
936
|
-
|
937
|
-
const services = chart.resources.apply((resources) => {
|
938
|
-
return resources.filter((r) => core.v1.Service.isInstance(r)).map((service) => ({ name: service.metadata.name, service }));
|
939
|
-
});
|
940
|
-
return output$1(services).apply((services2) => {
|
941
|
-
const service = services2.find((s) => s.name === name)?.service;
|
942
|
-
if (!service) {
|
943
|
-
throw new Error(`Service with name '${name}' not found in the chart resources`);
|
944
|
-
}
|
945
|
-
return service;
|
946
|
-
});
|
947
|
-
}
|
948
|
-
function getChartService(chart, name) {
|
949
|
-
return toPromise(getChartServiceOutput(chart, name));
|
950
|
-
}
|
951
|
-
|
952
|
-
export { CronJob, Deployment, HttpRoute, Job, NetworkPolicy, ScriptBundle, Service, StatefulSet, createScriptContainer, getChartService, getChartServiceOutput, getServiceHost, mapContainerPortToServicePort, mapMetadata, mapNamespaceLikeToNamespaceName, mapNamespaceNameToSelector, mapSelectorLikeToSelector, mapServiceToLabelSelector, useAccessPoint };
|
805
|
+
export { CronJob, Deployment, HttpRoute, Job, NetworkPolicy, ScriptBundle, Service, StatefulSet, createScriptContainer, mapContainerPortToServicePort, mapMetadata, mapNamespaceLikeToNamespaceName, mapNamespaceNameToSelector, mapSelectorLikeToSelector, mapServiceToLabelSelector, useAccessPoint };
|
@@ -1,6 +1,4 @@
|
|
1
|
-
import {
|
2
|
-
import { resolve } from 'node:path';
|
3
|
-
import { output, toPromise, resolvePackagePath } from '@highstate/pulumi';
|
1
|
+
import { output, toPromise } from '@highstate/pulumi';
|
4
2
|
import { Provider, core } from '@pulumi/kubernetes';
|
5
3
|
import { mergeDeep } from 'remeda';
|
6
4
|
|
@@ -31,17 +29,6 @@ function mapMetadata(args, fallbackName) {
|
|
31
29
|
namespace: args.namespace ? mapNamespaceLikeToNamespaceName(args.namespace) : void 0
|
32
30
|
};
|
33
31
|
}
|
34
|
-
function resolveChartPath(packageName, chartName, parent) {
|
35
|
-
const resolvedChartsPath = resolvePackagePath(packageName, "assets", parent);
|
36
|
-
const files = readdirSync(resolvedChartsPath).filter((file) => file.startsWith(chartName));
|
37
|
-
if (files.length === 0) {
|
38
|
-
throw new Error(`No chart found for ${chartName}`);
|
39
|
-
}
|
40
|
-
if (files.length > 1) {
|
41
|
-
throw new Error(`Multiple charts found for ${chartName}`);
|
42
|
-
}
|
43
|
-
return resolve(resolvedChartsPath, files[0]);
|
44
|
-
}
|
45
32
|
function mapSelectorLikeToSelector(selector) {
|
46
33
|
if ("matchLabels" in selector || "matchExpressions" in selector) {
|
47
34
|
return selector;
|
@@ -61,4 +48,4 @@ function mapNamespaceNameToSelector(namespace) {
|
|
61
48
|
};
|
62
49
|
}
|
63
50
|
|
64
|
-
export { mapSelectorLikeToSelector as a, mapNamespaceNameToSelector as b, commonExtraArgs as c, mapNamespaceLikeToNamespaceName as d, createProvider as e, createNamespace as f, mapMetadata as m
|
51
|
+
export { mapSelectorLikeToSelector as a, mapNamespaceNameToSelector as b, commonExtraArgs as c, mapNamespaceLikeToNamespaceName as d, createProvider as e, createNamespace as f, mapMetadata as m };
|