@highstate/k8s 0.9.18 → 0.9.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. package/dist/chunk-2EEHJZPD.js +13 -0
  2. package/dist/chunk-2EEHJZPD.js.map +1 -0
  3. package/dist/{chunk-OFFSHGC6.js → chunk-4JGXGN2L.js} +66 -48
  4. package/dist/chunk-4JGXGN2L.js.map +1 -0
  5. package/dist/chunk-A3XGSDIW.js +306 -0
  6. package/dist/chunk-A3XGSDIW.js.map +1 -0
  7. package/dist/chunk-IMTXUK2U.js +244 -0
  8. package/dist/chunk-IMTXUK2U.js.map +1 -0
  9. package/dist/chunk-JYNXQ3I3.js +287 -0
  10. package/dist/chunk-JYNXQ3I3.js.map +1 -0
  11. package/dist/{chunk-5C2BJGES.js → chunk-KDD6XUWM.js} +30 -23
  12. package/dist/chunk-KDD6XUWM.js.map +1 -0
  13. package/dist/chunk-NOFJC3EM.js +236 -0
  14. package/dist/chunk-NOFJC3EM.js.map +1 -0
  15. package/dist/chunk-NXSYCA3V.js +337 -0
  16. package/dist/chunk-NXSYCA3V.js.map +1 -0
  17. package/dist/chunk-SBC3TUIN.js +1513 -0
  18. package/dist/chunk-SBC3TUIN.js.map +1 -0
  19. package/dist/chunk-SI7X6N46.js +338 -0
  20. package/dist/chunk-SI7X6N46.js.map +1 -0
  21. package/dist/chunk-WGMJCZSK.js +360 -0
  22. package/dist/chunk-WGMJCZSK.js.map +1 -0
  23. package/dist/deployment-752P6JIT.js +8 -0
  24. package/dist/{deployment-XK3CDJOE.js.map → deployment-752P6JIT.js.map} +1 -1
  25. package/dist/highstate.manifest.json +8 -7
  26. package/dist/impl/gateway-route.js +123 -0
  27. package/dist/impl/gateway-route.js.map +1 -0
  28. package/dist/impl/tls-certificate.js +32 -0
  29. package/dist/impl/tls-certificate.js.map +1 -0
  30. package/dist/index.js +736 -208
  31. package/dist/index.js.map +1 -1
  32. package/dist/stateful-set-N64YVKR7.js +8 -0
  33. package/dist/{stateful-set-7CAQWTV2.js.map → stateful-set-N64YVKR7.js.map} +1 -1
  34. package/dist/units/cert-manager/index.js +11 -10
  35. package/dist/units/cert-manager/index.js.map +1 -1
  36. package/dist/units/dns01-issuer/index.js +27 -23
  37. package/dist/units/dns01-issuer/index.js.map +1 -1
  38. package/dist/units/existing-cluster/index.js +11 -8
  39. package/dist/units/existing-cluster/index.js.map +1 -1
  40. package/dist/units/gateway-api/index.js +2 -2
  41. package/dist/units/gateway-api/index.js.map +1 -1
  42. package/package.json +39 -13
  43. package/src/cluster.ts +30 -22
  44. package/src/config-map.ts +195 -57
  45. package/src/container.ts +5 -5
  46. package/src/cron-job.ts +403 -31
  47. package/src/deployment.ts +260 -120
  48. package/src/dns01-solver.ts +10 -0
  49. package/src/gateway/backend.ts +2 -2
  50. package/src/gateway/gateway.ts +383 -0
  51. package/src/gateway/http-route.ts +17 -24
  52. package/src/gateway/index.ts +1 -0
  53. package/src/helm.ts +83 -53
  54. package/src/impl/gateway-route.ts +155 -0
  55. package/src/impl/tls-certificate.ts +33 -0
  56. package/src/index.ts +22 -67
  57. package/src/job.ts +393 -28
  58. package/src/namespace.ts +236 -99
  59. package/src/network-policy.ts +216 -165
  60. package/src/network.ts +2 -2
  61. package/src/pvc.ts +266 -65
  62. package/src/rbac.ts +218 -0
  63. package/src/scripting/bundle.ts +9 -20
  64. package/src/scripting/container.ts +1 -1
  65. package/src/scripting/environment.ts +5 -5
  66. package/src/secret.ts +200 -62
  67. package/src/service.ts +288 -158
  68. package/src/shared.ts +94 -67
  69. package/src/stateful-set.ts +270 -117
  70. package/src/tls.ts +344 -0
  71. package/src/units/cert-manager/index.ts +2 -3
  72. package/src/units/dns01-issuer/index.ts +30 -14
  73. package/src/units/existing-cluster/index.ts +10 -7
  74. package/src/units/gateway-api/index.ts +2 -2
  75. package/src/worker.ts +26 -0
  76. package/src/workload.ts +275 -171
  77. package/dist/chunk-5C2BJGES.js.map +0 -1
  78. package/dist/chunk-5TLC5BXR.js +0 -256
  79. package/dist/chunk-5TLC5BXR.js.map +0 -1
  80. package/dist/chunk-BBIY3KUN.js +0 -1557
  81. package/dist/chunk-BBIY3KUN.js.map +0 -1
  82. package/dist/chunk-OFFSHGC6.js.map +0 -1
  83. package/dist/chunk-TZHOUJRC.js +0 -202
  84. package/dist/chunk-TZHOUJRC.js.map +0 -1
  85. package/dist/chunk-YWRJ4EZM.js +0 -192
  86. package/dist/chunk-YWRJ4EZM.js.map +0 -1
  87. package/dist/deployment-XK3CDJOE.js +0 -6
  88. package/dist/stateful-set-7CAQWTV2.js +0 -6
  89. package/dist/units/access-point/index.js +0 -21
  90. package/dist/units/access-point/index.js.map +0 -1
  91. package/src/access-point.ts +0 -191
  92. package/src/units/access-point/index.ts +0 -19
  93. package/src/units/dns01-issuer/solver.ts +0 -23
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/cluster.ts"],"names":[],"mappings":";;;;;AAMA,SAAS,YAAY,EAAA,EAAY;AAC/B,EAAA,MAAM,cAAA,GAAiB,0BAAA;AACvB,EAAA,OAAO,cAAA,CAAe,KAAK,EAAE,CAAA;AAC/B;AAEA,eAAsB,iBAAA,CACpB,YACA,iBAAA,EACmB;AACnB,EAAA,MAAM,OAAA,GAAU,UAAA,CAAW,aAAA,CAAc,SAAS,CAAA;AAClD,EAAA,MAAM,KAAA,GAAQ,MAAM,OAAA,CAAQ,QAAA,EAAS;AAErC,EAAA,OAAO,KAAA,CAAM,KAAA,CAAM,OAAA,CAAQ,CAAA,IAAA,KAAQ;AACjC,IAAA,MAAM,SAAA,GAAY,IAAA,CAAK,MAAA,EAAQ,SAAA,IAAa,EAAC;AAC7C,IAAA,MAAM,aAAa,SAAA,CAAU,IAAA,CAAK,CAAA,OAAA,KAAW,OAAA,CAAQ,SAAS,YAAY,CAAA;AAC1E,IAAA,MAAM,aAAa,SAAA,CAAU,IAAA,CAAK,CAAA,OAAA,KAAW,OAAA,CAAQ,SAAS,YAAY,CA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erminal } from \"@highstate/contract\"\nimport { fileFromString, output, type Output, type Input } from \"@highstate/pulumi\"\nimport { CoreV1Api, type KubeConfig } from \"@kubernetes/client-node\"\nimport { images } from \"./shared\"\n\nfunction isPrivateIp(ip: string) {\n const privateIpRegex = /^(10|172\\.16|192\\.168)\\./\n return privateIpRegex.test(ip)\n}\n\nexport async function detectExternalIps(\n kubeConfig: KubeConfig,\n internalIpsPolicy: k8s.InternalIpsPolicy,\n): Promise<string[]> {\n const nodeApi = kubeConfig.makeApiClient(CoreV1Api)\n const nodes = await nodeApi.listNode()\n\n return nodes.items.flatMap(node => {\n const addresses = node.status?.addresses ?? []\n const externalIp = addresses.find(address => address.type === \"ExternalIP\")\n const internalIp = addresses.find(address => address.type === \"InternalIP\")\n\n const result: string[] = []\n\n if (externalIp?.address) {\n result.push(externalIp.address)\n }\n\n if (internalIp?.address && internalIpsPolicy === \"always\") {\n result.push(internalIp.address)\n }\n\n if (internalIp?.address && internalIpsPolicy === \"public\" && !isPrivateIp(internalIp.address)) {\n result.push(internalIp.address)\n }\n\n return result\n })\n}\n\nexport function createK8sTerminal(kubeconfig: Input<string>): Output<UnitTerminal> {\n return output({\n name: \"management\",\n\n meta: {\n title: \"Cluster Management\",\n description: \"Manage the cluster using kubectl and helm\",\n icon: \"devicon:kubernetes\",\n },\n\n spec: {\n image: images[\"terminal-kubectl\"].image,\n command: [\"bash\", \"/welcome.sh\"],\n\n files: {\n \"/kubeconfig\": fileFromString(\"kubeconfig\", kubeconfig, { isSecret: true }),\n\n \"/welcome.sh\": fileFromString(\n \"welcome.sh\",\n text`\n echo \"Connecting to the cluster...\"\n kubectl cluster-info\n\n echo \"Use 'kubectl' and 'helm' to manage the cluster.\"\n echo\n\n exec bash\n `,\n ),\n },\n\n env: {\n KUBECONFIG: \"/kubeconfig\",\n },\n },\n })\n}\n"]}
@@ -0,0 +1,236 @@
1
+ import { Secret } from './chunk-IMTXUK2U.js';
2
+ import { Namespace, mapMetadata, commonExtraArgs, getProvider } from './chunk-WGMJCZSK.js';
3
+ import { cert_manager } from '@highstate/cert-manager';
4
+ import { getOrCreate } from '@highstate/contract';
5
+ import { ComponentResource, output, toPromise, interpolate } from '@highstate/pulumi';
6
+ import { omit } from 'remeda';
7
+
8
+ var Certificate = class _Certificate extends ComponentResource {
9
+ constructor(type, name, args, opts, namespace, metadata, spec, status) {
10
+ super(type, name, args, opts);
11
+ this.name = name;
12
+ this.namespace = namespace;
13
+ this.metadata = metadata;
14
+ this.spec = spec;
15
+ this.status = status;
16
+ }
17
+ /**
18
+ * The cluster where the certificate is located.
19
+ */
20
+ get cluster() {
21
+ return this.namespace.cluster;
22
+ }
23
+ /**
24
+ * The Highstate certificate entity.
25
+ */
26
+ get entity() {
27
+ return output({
28
+ type: "certificate",
29
+ clusterId: this.cluster.id,
30
+ clusterName: this.cluster.name,
31
+ metadata: this.metadata
32
+ });
33
+ }
34
+ /**
35
+ * The secret containing the certificate data.
36
+ */
37
+ get secret() {
38
+ return output({
39
+ secretName: this.spec.apply((spec) => spec.secretName),
40
+ namespace: this.namespace
41
+ }).apply(({ secretName, namespace }) => {
42
+ return Secret.get(`${this.name}.secret`, {
43
+ name: secretName,
44
+ namespace
45
+ });
46
+ });
47
+ }
48
+ /**
49
+ * Creates a new certificate.
50
+ */
51
+ static create(name, args, opts) {
52
+ return new CreatedCertificate(name, args, opts);
53
+ }
54
+ /**
55
+ * Creates a new certificate or patches an existing one.
56
+ *
57
+ * @param name The name of the resource. May not be the same as the certificate name.
58
+ * @param args The arguments to create or patch the certificate with.
59
+ * @param opts Optional resource options.
60
+ */
61
+ static createOrPatch(name, args, opts) {
62
+ if (args.existing) {
63
+ return new CertificatePatch(name, {
64
+ ...args,
65
+ name: output(args.existing).metadata.name,
66
+ namespace: Namespace.forResourceAsync(args.existing, output(args.namespace).cluster)
67
+ });
68
+ }
69
+ return new CreatedCertificate(name, args, opts);
70
+ }
71
+ /**
72
+ * Creates a new certificate or gets an existing one.
73
+ *
74
+ * @param name The name of the resource. May not be the same as the certificate name. Will not be used when existing certificate is retrieved.
75
+ * @param args The arguments to create or get the certificate with.
76
+ * @param opts Optional resource options.
77
+ */
78
+ static async createOrGet(name, args, opts) {
79
+ if (args.existing) {
80
+ return await _Certificate.forAsync(args.existing, output(args.namespace).cluster);
81
+ }
82
+ return new CreatedCertificate(name, args, opts);
83
+ }
84
+ /**
85
+ * Patches an existing certificate.
86
+ *
87
+ * Will throw an error if the certificate does not exist.
88
+ *
89
+ * @param name The name of the resource. May not be the same as the certificate name.
90
+ * @param args The arguments to patch the certificate with.
91
+ * @param opts Optional resource options.
92
+ */
93
+ static patch(name, args, opts) {
94
+ return new CertificatePatch(name, args, opts);
95
+ }
96
+ /**
97
+ * Wraps an existing cert-manager certificate.
98
+ */
99
+ static wrap(name, args, opts) {
100
+ return new WrappedCertificate(name, args, opts);
101
+ }
102
+ /**
103
+ * Gets an existing certificate.
104
+ *
105
+ * Will throw an error if the certificate does not exist.
106
+ */
107
+ static get(name, args, opts) {
108
+ return new ExternalCertificate(name, args, opts);
109
+ }
110
+ static certificateCache = /* @__PURE__ */ new Map();
111
+ /**
112
+ * Gets an existing certificate for a given entity.
113
+ * Prefer this method over `get` when possible.
114
+ *
115
+ * It automatically names the resource with the following format: `{clusterName}.{namespace}.{name}.{clusterId}`.
116
+ *
117
+ * This method is idempotent and will return the same instance for the same entity.
118
+ *
119
+ * @param entity The entity to get the certificate for.
120
+ * @param cluster The cluster where the certificate is located.
121
+ */
122
+ static for(entity, cluster) {
123
+ return getOrCreate(
124
+ _Certificate.certificateCache,
125
+ `${entity.clusterName}.${entity.metadata.namespace}.${entity.metadata.name}.${entity.clusterId}`,
126
+ (name) => {
127
+ return _Certificate.get(name, {
128
+ name: entity.metadata.name,
129
+ namespace: Namespace.forResourceAsync(entity, cluster)
130
+ });
131
+ }
132
+ );
133
+ }
134
+ /**
135
+ * Gets an existing certificate for a given entity.
136
+ * Prefer this method over `get` when possible.
137
+ *
138
+ * It automatically names the resource with the following format: `{clusterName}.{namespace}.{name}.{clusterId}`.
139
+ *
140
+ * This method is idempotent and will return the same instance for the same entity.
141
+ *
142
+ * @param entity The entity to get the certificate for.
143
+ * @param cluster The cluster where the certificate is located.
144
+ */
145
+ static async forAsync(entity, cluster) {
146
+ const resolvedEntity = await toPromise(entity);
147
+ return _Certificate.for(resolvedEntity, output(cluster));
148
+ }
149
+ };
150
+ var CreatedCertificate = class extends Certificate {
151
+ constructor(name, args, opts) {
152
+ const certificate = output(args.namespace).cluster.apply((cluster) => {
153
+ return new cert_manager.v1.Certificate(
154
+ name,
155
+ {
156
+ metadata: mapMetadata(args, name),
157
+ spec: omit(args, commonExtraArgs)
158
+ },
159
+ { ...opts, parent: this, provider: getProvider(cluster) }
160
+ );
161
+ });
162
+ super(
163
+ "highstate:k8s:Certificate",
164
+ name,
165
+ args,
166
+ opts,
167
+ output(args.namespace),
168
+ certificate.metadata,
169
+ certificate.spec,
170
+ certificate.status
171
+ );
172
+ }
173
+ };
174
+ var CertificatePatch = class extends Certificate {
175
+ constructor(name, args, opts) {
176
+ const certificate = output(args.namespace).cluster.apply((cluster) => {
177
+ return new cert_manager.v1.CertificatePatch(
178
+ name,
179
+ {
180
+ metadata: mapMetadata(args, name),
181
+ spec: omit(args, commonExtraArgs)
182
+ },
183
+ { ...opts, parent: this, provider: getProvider(cluster) }
184
+ );
185
+ });
186
+ super(
187
+ "highstate:k8s:CertificatePatch",
188
+ name,
189
+ args,
190
+ opts,
191
+ output(args.namespace),
192
+ certificate.metadata,
193
+ certificate.spec,
194
+ certificate.status
195
+ );
196
+ }
197
+ };
198
+ var WrappedCertificate = class extends Certificate {
199
+ constructor(name, args, opts) {
200
+ super(
201
+ "highstate:k8s:WrappedCertificate",
202
+ name,
203
+ args,
204
+ opts,
205
+ output(args.namespace),
206
+ output(args.certificate).metadata,
207
+ output(args.certificate).spec,
208
+ output(args.certificate).status
209
+ );
210
+ }
211
+ };
212
+ var ExternalCertificate = class extends Certificate {
213
+ constructor(name, args, opts) {
214
+ const certificate = output(args.namespace).cluster.apply((cluster) => {
215
+ return cert_manager.v1.Certificate.get(
216
+ name,
217
+ interpolate`${output(args.namespace).metadata.name}/${args.name}`,
218
+ { ...opts, parent: this, provider: getProvider(cluster) }
219
+ );
220
+ });
221
+ super(
222
+ "highstate:k8s:ExternalCertificate",
223
+ name,
224
+ args,
225
+ opts,
226
+ output(args.namespace),
227
+ certificate.metadata,
228
+ certificate.spec,
229
+ certificate.status
230
+ );
231
+ }
232
+ };
233
+
234
+ export { Certificate };
235
+ //# sourceMappingURL=chunk-NOFJC3EM.js.map
236
+ //# sourceMappingURL=chunk-NOFJC3EM.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/tls.ts"],"names":[],"mappings":";;;;;;;AA+BO,IAAe,WAAA,GAAf,MAAe,YAAA,SAAoB,iBAAA,CAAkB;AAAA,EAChD,WAAA,CACR,MACiB,IAAA,EACjB,IAAA,EACA,MAKS,SAAA,EAKA,QAAA,EAKA,MAKA,MAAA,EACT;AACA,IAAA,KAAA,CAAM,IAAA,EAAM,IAAA,EAAM,IAAA,EAAM,IAAI,CAAA;AAxBX,IAAA,IAAA,CAAA,IAAA,GAAA,IAAA;AAOR,IAAA,IAAA,CAAA,SAAA,GAAA,SAAA;AAKA,IAAA,IAAA,CAAA,QAAA,GAAA,QAAA;AAKA,IAAA,IAAA,CAAA,IAAA,GAAA,IAAA;AAKA,IAAA,IAAA,CAAA,MAAA,GAAA,MAAA;AAAA,EAGX;AAAA;AAAA;AAAA;AAAA,EAKA,IAAI,OAAA,GAA+B;AACjC,IAAA,OAAO,KAAK,SAAA,CAAU,OAAA;AAAA,EACxB;AAAA;AAAA;AAAA;AAAA,EAKA,IAAI,MAAA,GAAqC;AACvC,IAAA,OAAO,MAAA,CAAO;AAAA,MACZ,IAAA,EAAM,aAAA;AAAA,MACN,SAAA,EAAW,KAAK,OAAA,CAAQ,EAAA;AAAA,MACxB,WAAA,EAAa,KAAK,OAAA,CAAQ,IAAA;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A,MACzB,MAAA,CAAO,IAAA,CAAK,WAAW,CAAA,CAAE,IAAA;AAAA,MACzB,MAAA,CAAO,IAAA,CAAK,WAAW,CAAA,CAAE;AAAA,KAC3B;AAAA,EACF;AACF,CAAA;AAcA,IAAM,mBAAA,GAAN,cAAkC,WAAA,CAAY;AAAA,EAC5C,WAAA,CAAY,IAAA,EAAc,IAAA,EAA+B,IAAA,EAAiC;AACxF,IAAA,MAAM,cAAc,MAAA,CAAO,IAAA,CAAK,SAAS,CAAA,CAAE,OAAA,CAAQ,MAAM,CAAA,OAAA,KAAW;AAClE,MAAA,OAAO,YAAA,CAAa,GAAG,WAAA,CAAY,GAAA;AAAA,QACjC,IAAA;AAAA,QACA,WAAA,CAAA,EAAc,OAAO,IAAA,CAAK,SAAS,EAAE,QAAA,CAAS,IAAI,CAAA,CAAA,EAAI,IAAA,CAAK,IAAI,CAAA,CAAA;AAAA,QAC/D,EAAE,GAAG,IAAA,EAAM,MAAA,EAAQ,MAAM,QAAA,EAAU,WAAA,CAAY,OAAO,CAAA;AAAE,OAC1D;AAAA,IACF,CAAC,CAAA;AAED,IAAA,KAAA;AAAA,MACE,mCAAA;AAAA,MACA,IAAA;AAAA,MACA,IAAA;AAAA,MACA,IAAA;AAAA,MAEA,MAAA,CAAO,KAAK,SAAS,CAAA;AAAA,MACrB,WAAA,CAAY,QAAA;AAAA,MACZ,WAAA,CAAY,IAAA;AAAA,MACZ,WAAA,CAAY;AAAA,KACd;AAAA,EACF;AACF,CAAA","file":"chunk-NOFJC3EM.js","sourcesContent":["import type { k8s } from \"@highstate/library\"\nimport type { types } from \"@pulumi/kubernetes\"\nimport { cert_manager, type types as cmTypes } from \"@highstate/cert-manager\"\nimport { getOrCreate } from \"@highstate/contract\"\nimport {\n ComponentResource,\n type ComponentResourceOptions,\n type Input,\n type Inputs,\n interpolate,\n type Output,\n output,\n toPromise,\n} from \"@highstate/pulumi\"\nimport { omit } from \"remeda\"\nimport { Namespace } from \"./namespace\"\nimport { Secret } from \"./secret\"\nimport { commonExtraArgs, getProvider, mapMetadata, type ScopedResourceArgs } from \"./shared\"\n\nexport type CertificateArgs = ScopedResourceArgs & cmTypes.input.cert_manager.v1.CertificateSpec\n\nexport type CreateOrGetCertificateArgs = CertificateArgs & {\n /**\n * The certificate entity to patch/retrieve.\n */\n existing: Input<k8s.Certificate> | undefined\n}\n\n/**\n * Represents a cert-manager Certificate resource with metadata and secret.\n */\nexport abstract class Certificate extends ComponentResource {\n protected constructor(\n type: string,\n private readonly name: string,\n args: Inputs,\n opts: ComponentResourceOptions | undefined,\n\n /**\n * The namespace where the certificate is located.\n */\n readonly namespace: Output<Namespace>,\n\n /**\n * The metadata of the underlying cert-manager certificate.\n */\n readonly metadata: Output<types.output.meta.v1.ObjectMeta>,\n\n /**\n * The spec of the underlying cert-manager certificate.\n */\n readonly spec: Output<cmTypes.output.cert_manager.v1.CertificateSpec>,\n\n /**\n * The status of the underlying cert-manager certificate.\n */\n readonly status: Output<cmTypes.output.cert_manager.v1.CertificateStatus>,\n ) {\n super(type, name, args, opts)\n }\n\n /**\n * The cluster where the certificate is located.\n */\n get cluster(): Output<k8s.Cluster> {\n return this.namespace.cluster\n }\n\n /**\n * The Highstate certificate entity.\n */\n get entity(): Output<k8s.ScopedResource> {\n return output({\n type: \"certificate\",\n clusterId: this.cluster.id,\n clusterName: this.cluster.name,\n metadata: this.metadata,\n })\n }\n\n /**\n * The secret containing the certificate data.\n */\n get secret(): Output<Secret> {\n return output({\n secretName: this.spec.apply(spec => spec.secretName),\n namespace: this.namespace,\n }).apply(({ secretName, namespace }) => {\n return Secret.get(`${this.name}.secret`, {\n name: secretName,\n namespace,\n })\n })\n }\n\n /**\n * Creates a new certificate.\n */\n static create(name: string, args: CertificateArgs, opts?: ComponentResourceOptions): Certificate {\n return new CreatedCertificate(name, args, opts)\n }\n\n /**\n * Creates a new certificate or patches an existing one.\n *\n * @param name The name of the resource. May not be the same as the certificate name.\n * @param args The arguments to create or patch the certificate with.\n * @param opts Optional resource options.\n */\n static createOrPatch(\n name: string,\n args: CreateOrGetCertificateArgs,\n opts?: ComponentResourceOptions,\n ): Certificate {\n if (args.existing) {\n return new CertificatePatch(name, {\n ...args,\n name: output(args.existing).metadata.name,\n namespace: Namespace.forResourceAsync(args.existing, output(args.namespace).cluster),\n })\n }\n\n return new CreatedCertificate(name, args, opts)\n }\n\n /**\n * Creates a new certificate or gets an existing one.\n *\n * @param name The name of the resource. May not be the same as the certificate name. Will not be used when existing certificate is retrieved.\n * @param args The arguments to create or get the certificate with.\n * @param opts Optional resource options.\n */\n static async createOrGet(\n name: string,\n args: CreateOrGetCertificateArgs,\n opts?: ComponentResourceOptions,\n ): Promise<Certificate> {\n if (args.existing) {\n return await Certificate.forAsync(args.existing, output(args.namespace).cluster)\n }\n\n return new CreatedCertificate(name, args, opts)\n }\n\n /**\n * Patches an existing certificate.\n *\n * Will throw an error if the certificate does not exist.\n *\n * @param name The name of the resource. May not be the same as the certificate name.\n * @param args The arguments to patch the certificate with.\n * @param opts Optional resource options.\n */\n static patch(name: string, args: CertificateArgs, opts?: ComponentResourceOptions): Certificate {\n return new CertificatePatch(name, args, opts)\n }\n\n /**\n * Wraps an existing cert-manager certificate.\n */\n static wrap(\n name: string,\n args: WrappedCertificateArgs,\n opts?: ComponentResourceOptions,\n ): Certificate {\n return new WrappedCertificate(name, args, opts)\n }\n\n /**\n * Gets an existing certificate.\n *\n * Will throw an error if the certificate does not exist.\n */\n static get(\n name: string,\n args: ExternalCertificateArgs,\n opts?: ComponentResourceOptions,\n ): Certificate {\n return new ExternalCertificate(name, args, opts)\n }\n\n private static readonly certificateCache = new Map<string, Certificate>()\n\n /**\n * Gets an existing certificate for a given entity.\n * Prefer this method over `get` when possible.\n *\n * It automatically names the resource with the following format: `{clusterName}.{namespace}.{name}.{clusterId}`.\n *\n * This method is idempotent and will return the same instance for the same entity.\n *\n * @param entity The entity to get the certificate for.\n * @param cluster The cluster where the certificate is located.\n */\n static for(entity: k8s.Certificate, cluster: Input<k8s.Cluster>): Certificate {\n return getOrCreate(\n Certificate.certificateCache,\n `${entity.clusterName}.${entity.metadata.namespace}.${entity.metadata.name}.${entity.clusterId}`,\n name => {\n return Certificate.get(name, {\n name: entity.metadata.name,\n namespace: Namespace.forResourceAsync(entity, cluster),\n })\n },\n )\n }\n\n /**\n * Gets an existing certificate for a given entity.\n * Prefer this method over `get` when possible.\n *\n * It automatically names the resource with the following format: `{clusterName}.{namespace}.{name}.{clusterId}`.\n *\n * This method is idempotent and will return the same instance for the same entity.\n *\n * @param entity The entity to get the certificate for.\n * @param cluster The cluster where the certificate is located.\n */\n static async forAsync(\n entity: Input<k8s.Certificate>,\n cluster: Input<k8s.Cluster>,\n ): Promise<Certificate> {\n const resolvedEntity = await toPromise(entity)\n return Certificate.for(resolvedEntity, output(cluster))\n }\n}\n\nclass CreatedCertificate extends Certificate {\n constructor(name: string, args: CertificateArgs, opts?: ComponentResourceOptions) {\n const certificate = output(args.namespace).cluster.apply(cluster => {\n return new cert_manager.v1.Certificate(\n name,\n {\n metadata: mapMetadata(args, name),\n spec: omit(args, commonExtraArgs),\n },\n { ...opts, parent: this, provider: getProvider(cluster) },\n )\n })\n\n super(\n \"highstate:k8s:Certificate\",\n name,\n args,\n opts,\n\n output(args.namespace),\n certificate.metadata as Output<types.output.meta.v1.ObjectMeta>,\n certificate.spec,\n certificate.status,\n )\n }\n}\n\nclass CertificatePatch extends Certificate {\n constructor(name: string, args: CertificateArgs, opts?: ComponentResourceOptions) {\n const certificate = output(args.namespace).cluster.apply(cluster => {\n return new cert_manager.v1.CertificatePatch(\n name,\n {\n metadata: mapMetadata(args, name),\n spec: omit(args, commonExtraArgs),\n },\n { ...opts, parent: this, provider: getProvider(cluster) },\n )\n })\n\n super(\n \"highstate:k8s:CertificatePatch\",\n name,\n args,\n opts,\n\n output(args.namespace),\n certificate.metadata as Output<types.output.meta.v1.ObjectMeta>,\n certificate.spec,\n certificate.status,\n )\n }\n}\n\nexport type WrappedCertificateArgs = {\n /**\n * The underlying cert-manager certificate to wrap.\n */\n certificate: Input<cert_manager.v1.Certificate>\n\n /**\n * The namespace where the certificate is located.\n */\n namespace: Input<Namespace>\n}\n\nclass WrappedCertificate extends Certificate {\n constructor(name: string, args: WrappedCertificateArgs, opts?: ComponentResourceOptions) {\n super(\n \"highstate:k8s:WrappedCertificate\",\n name,\n args,\n opts,\n\n output(args.namespace),\n output(args.certificate).metadata as Output<types.output.meta.v1.ObjectMeta>,\n output(args.certificate).spec,\n output(args.certificate).status,\n )\n }\n}\n\nexport type ExternalCertificateArgs = {\n /**\n * The name of the certificate to get.\n */\n name: Input<string>\n\n /**\n * The namespace of the certificate to get.\n */\n namespace: Input<Namespace>\n}\n\nclass ExternalCertificate extends Certificate {\n constructor(name: string, args: ExternalCertificateArgs, opts?: ComponentResourceOptions) {\n const certificate = output(args.namespace).cluster.apply(cluster => {\n return cert_manager.v1.Certificate.get(\n name,\n interpolate`${output(args.namespace).metadata.name}/${args.name}`,\n { ...opts, parent: this, provider: getProvider(cluster) },\n )\n })\n\n super(\n \"highstate:k8s:ExternalCertificate\",\n name,\n args,\n opts,\n\n output(args.namespace),\n certificate.metadata as Output<types.output.meta.v1.ObjectMeta>,\n certificate.spec,\n certificate.status,\n )\n }\n}\n"]}
@@ -0,0 +1,337 @@
1
+ import { Service } from './chunk-SI7X6N46.js';
2
+ import { commonExtraArgs, mapMetadata, getProvider, Namespace } from './chunk-WGMJCZSK.js';
3
+ import { output, ComponentResource, normalizeInputsAndMap, normalizeInputs, normalize, toPromise, interpolate } from '@highstate/pulumi';
4
+ import { gateway } from '@highstate/gateway-api';
5
+ import { pipe, map, omit } from 'remeda';
6
+ import { parseL3Endpoint } from '@highstate/common';
7
+ import { getOrCreate } from '@highstate/contract';
8
+ import { deepmerge } from 'deepmerge-ts';
9
+
10
+ function resolveBackendRef(ref) {
11
+ if (Service.isInstance(ref)) {
12
+ return output({
13
+ name: ref.metadata.name,
14
+ namespace: ref.metadata.namespace,
15
+ port: ref.spec.ports[0].port
16
+ });
17
+ }
18
+ if ("service" in ref) {
19
+ const service = output(ref.service);
20
+ return output({
21
+ name: service.metadata.name,
22
+ namespace: service.metadata.namespace,
23
+ port: ref.port
24
+ });
25
+ }
26
+ return output({
27
+ name: ref.name,
28
+ namespace: ref.namespace,
29
+ port: ref.port
30
+ });
31
+ }
32
+ var HttpRoute = class extends ComponentResource {
33
+ /**
34
+ * The underlying Kubernetes resource.
35
+ */
36
+ route;
37
+ constructor(name, args, opts) {
38
+ super("highstate:k8s:HttpRoute", name, args, opts);
39
+ this.route = output(args.gateway).cluster.apply((cluster) => {
40
+ return new gateway.v1.HTTPRoute(
41
+ name,
42
+ {
43
+ metadata: mapMetadata(args, name).apply((metadata) => ({
44
+ ...metadata,
45
+ namespace: output(args.gateway).namespace.metadata.name
46
+ })),
47
+ spec: {
48
+ hostnames: normalizeInputs(args.hostname, args.hostnames),
49
+ parentRefs: [
50
+ {
51
+ name: output(args.gateway).metadata.name
52
+ }
53
+ ],
54
+ rules: normalizeInputsAndMap(args.rule, args.rules, (rule) => ({
55
+ timeouts: rule.timeouts,
56
+ matches: pipe(
57
+ normalize(rule.match, rule.matches),
58
+ map(mapHttpRouteRuleMatch),
59
+ addDefaultPathMatch
60
+ ),
61
+ filters: normalize(rule.filter, rule.filters),
62
+ backendRefs: rule.backend ? [resolveBackendRef(rule.backend)] : void 0
63
+ }))
64
+ }
65
+ },
66
+ { ...opts, parent: this, provider: getProvider(cluster) }
67
+ );
68
+ });
69
+ }
70
+ };
71
+ function addDefaultPathMatch(matches) {
72
+ return matches.length ? matches : [{ path: { type: "PathPrefix", value: "/" } }];
73
+ }
74
+ function mapHttpRouteRuleMatch(match) {
75
+ if (typeof match === "string") {
76
+ return { path: { type: "PathPrefix", value: match } };
77
+ }
78
+ return match;
79
+ }
80
+ var gatewayExtraArgs = [...commonExtraArgs, "fqdn", "fqdns"];
81
+ var Gateway = class _Gateway extends ComponentResource {
82
+ constructor(type, name, args, opts, namespace, metadata, spec, status) {
83
+ super(type, name, args, opts);
84
+ this.namespace = namespace;
85
+ this.metadata = metadata;
86
+ this.spec = spec;
87
+ this.status = status;
88
+ }
89
+ /**
90
+ * The cluster where the gateway is located.
91
+ */
92
+ get cluster() {
93
+ return this.namespace.cluster;
94
+ }
95
+ /**
96
+ * The Highstate gateway entity.
97
+ */
98
+ get entity() {
99
+ return output({
100
+ type: "gateway",
101
+ clusterId: this.cluster.id,
102
+ clusterName: this.cluster.name,
103
+ metadata: this.metadata
104
+ });
105
+ }
106
+ /**
107
+ * Returns the endpoints L3 endpoints on which the gateway is exposed.
108
+ */
109
+ get endpoints() {
110
+ return this.status.addresses.apply((addresses) => {
111
+ if (!addresses) {
112
+ return [];
113
+ }
114
+ return addresses.map((address) => parseL3Endpoint(address.value));
115
+ });
116
+ }
117
+ /**
118
+ * Creates a new gateway.
119
+ */
120
+ static create(name, args, opts) {
121
+ return new CreatedGateway(name, args, opts);
122
+ }
123
+ /**
124
+ * Creates a new gateway or patches an existing one.
125
+ *
126
+ * @param name The name of the resource. May not be the same as the gateway name.
127
+ * @param args The arguments to create or patch the gateway with.
128
+ * @param opts Optional resource options.
129
+ */
130
+ static createOrPatch(name, args, opts) {
131
+ if (args.existing) {
132
+ return new GatewayPatch(name, {
133
+ ...args,
134
+ name: output(args.existing).metadata.name,
135
+ namespace: Namespace.forResourceAsync(args.existing, output(args.namespace).cluster)
136
+ });
137
+ }
138
+ return new CreatedGateway(name, args, opts);
139
+ }
140
+ /**
141
+ * Creates a new gateway or gets an existing one.
142
+ *
143
+ * @param name The name of the resource. May not be the same as the gateway name. Will not be used when existing gateway is retrieved.
144
+ * @param args The arguments to create or get the gateway with.
145
+ * @param opts Optional resource options.
146
+ */
147
+ static async createOrGet(name, args, opts) {
148
+ if (args.existing) {
149
+ return await _Gateway.forAsync(args.existing, output(args.namespace).cluster);
150
+ }
151
+ return new CreatedGateway(name, args, opts);
152
+ }
153
+ /**
154
+ * Patches an existing gateway.
155
+ *
156
+ * Will throw an error if the gateway does not exist.
157
+ *
158
+ * @param name The name of the resource. May not be the same as the gateway name.
159
+ * @param args The arguments to patch the gateway with.
160
+ * @param opts Optional resource options.
161
+ */
162
+ static patch(name, args, opts) {
163
+ return new GatewayPatch(name, args, opts);
164
+ }
165
+ /**
166
+ * Wraps an existing Kubernetes gateway.
167
+ */
168
+ static wrap(name, args, opts) {
169
+ return new WrappedGateway(name, args, opts);
170
+ }
171
+ /**
172
+ * Gets an existing gateway.
173
+ *
174
+ * Will throw an error if the gateway does not exist.
175
+ */
176
+ static get(name, args, opts) {
177
+ return new ExternalGateway(name, args, opts);
178
+ }
179
+ static gatewayCache = /* @__PURE__ */ new Map();
180
+ /**
181
+ * Gets an existing gateway for a given entity.
182
+ * Prefer this method over `get` when possible.
183
+ *
184
+ * It automatically names the resource with the following format: `{clusterName}.{namespace}.{gatewayName}.{clusterId}`.
185
+ *
186
+ * This method is idempotent and will return the same instance for the same entity.
187
+ *
188
+ * @param entity The entity to get the gateway for.
189
+ * @param cluster The cluster where the gateway is located.
190
+ */
191
+ static for(entity, cluster) {
192
+ return getOrCreate(
193
+ _Gateway.gatewayCache,
194
+ `${entity.clusterName}.${entity.metadata.namespace}.${entity.metadata.name}.${entity.clusterId}`,
195
+ (name) => {
196
+ return _Gateway.get(name, {
197
+ name: entity.metadata.name,
198
+ namespace: Namespace.forResourceAsync(entity, cluster)
199
+ });
200
+ }
201
+ );
202
+ }
203
+ /**
204
+ * Gets an existing gateway for a given entity.
205
+ * Prefer this method over `get` when possible.
206
+ *
207
+ * It automatically names the resource with the following format: `{clusterName}.{namespace}.{gatewayName}.{clusterId}`.
208
+ *
209
+ * This method is idempotent and will return the same instance for the same entity.
210
+ *
211
+ * @param entity The entity to get the gateway for.
212
+ * @param cluster The cluster where the gateway is located.
213
+ */
214
+ static async forAsync(entity, cluster) {
215
+ const resolvedEntity = await toPromise(entity);
216
+ return _Gateway.for(resolvedEntity, output(cluster));
217
+ }
218
+ /**
219
+ * Creates a gateway with the provided name/namespace/cluster only once.
220
+ *
221
+ * It automatically names the resource with the following format: `{name}.{namespace}.{clusterName}.{clusterId}`.
222
+ *
223
+ * This method is idempotent and will return the same instance for the same name/namespace/cluster.
224
+ *
225
+ * @param name The name of the gateway to create.
226
+ * @param args The arguments to create the gateway with.
227
+ * @param opts Optional resource options.
228
+ */
229
+ static async createOnce(args, opts) {
230
+ const { name, namespace, cluster } = await toPromise({
231
+ name: args.name,
232
+ namespace: output(args.namespace).metadata.name,
233
+ cluster: output(args.namespace).cluster
234
+ });
235
+ const fullName = `${name}.${namespace}.${cluster.name}.${cluster.id}`;
236
+ return getOrCreate(
237
+ _Gateway.gatewayCache,
238
+ name,
239
+ () => _Gateway.create(
240
+ fullName,
241
+ {
242
+ ...args,
243
+ name,
244
+ namespace: args.namespace
245
+ },
246
+ opts
247
+ )
248
+ );
249
+ }
250
+ };
251
+ var CreatedGateway = class extends Gateway {
252
+ constructor(name, args, opts) {
253
+ const gatewayResource = output(args.namespace).cluster.apply((cluster) => {
254
+ return new gateway.v1.Gateway(
255
+ name,
256
+ {
257
+ metadata: mapMetadata(args, name),
258
+ spec: deepmerge({}, omit(args, gatewayExtraArgs))
259
+ },
260
+ { ...opts, parent: this, provider: getProvider(cluster) }
261
+ );
262
+ });
263
+ super(
264
+ "highstate:k8s:Gateway",
265
+ name,
266
+ args,
267
+ opts,
268
+ output(args.namespace),
269
+ gatewayResource.metadata,
270
+ gatewayResource.spec,
271
+ gatewayResource.status
272
+ );
273
+ }
274
+ };
275
+ var GatewayPatch = class extends Gateway {
276
+ constructor(name, args, opts) {
277
+ const gatewayResource = output(args.namespace).cluster.apply((cluster) => {
278
+ return new gateway.v1.GatewayPatch(
279
+ name,
280
+ {
281
+ metadata: mapMetadata(args, name),
282
+ spec: deepmerge({}, omit(args, gatewayExtraArgs))
283
+ },
284
+ { ...opts, parent: this, provider: getProvider(cluster) }
285
+ );
286
+ });
287
+ super(
288
+ "highstate:k8s:GatewayPatch",
289
+ name,
290
+ args,
291
+ opts,
292
+ output(args.namespace),
293
+ gatewayResource.metadata,
294
+ gatewayResource.spec,
295
+ gatewayResource.status
296
+ );
297
+ }
298
+ };
299
+ var WrappedGateway = class extends Gateway {
300
+ constructor(name, args, opts) {
301
+ super(
302
+ "highstate:k8s:WrappedGateway",
303
+ name,
304
+ args,
305
+ opts,
306
+ output(args.namespace),
307
+ output(args.gateway).metadata,
308
+ output(args.gateway).spec,
309
+ output(args.gateway).status
310
+ );
311
+ }
312
+ };
313
+ var ExternalGateway = class extends Gateway {
314
+ constructor(name, args, opts) {
315
+ const gatewayResource = output(args.namespace).cluster.apply((cluster) => {
316
+ return gateway.v1.Gateway.get(
317
+ name,
318
+ interpolate`${output(args.namespace).metadata.name}/${args.name}`,
319
+ { ...opts, parent: this, provider: getProvider(cluster) }
320
+ );
321
+ });
322
+ super(
323
+ "highstate:k8s:ExternalGateway",
324
+ name,
325
+ args,
326
+ opts,
327
+ output(args.namespace),
328
+ gatewayResource.metadata,
329
+ gatewayResource.spec,
330
+ gatewayResource.status
331
+ );
332
+ }
333
+ };
334
+
335
+ export { Gateway, HttpRoute, mapHttpRouteRuleMatch, resolveBackendRef };
336
+ //# sourceMappingURL=chunk-NXSYCA3V.js.map
337
+ //# sourceMappingURL=chunk-NXSYCA3V.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/gateway/backend.ts","../src/gateway/http-route.ts","../src/gateway/gateway.ts"],"names":["output","ComponentResource","gateway"],"mappings":";;;;;;;;;AAoCO,SAAS,kBAAkB,GAAA,EAAiD;AACjF,EAAA,IAAI,OAAA,CAAQ,UAAA,CAAW,GAAG,CAAA,EAAG;AAC3B,IAAA,OAAO,MAAA,CAAO;AAAA,MACZ,IAAA,EAAM,IAAI,QAAA,CAAS,IAAA;AAAA,MACnB,SAAA,EAAW,IAAI,QAAA,CAAS,SAAA;AAAA,MACxB,IAAA,EAAM,GAAA,CAAI,IAAA,CAAK,KAAA,CAAM,CAAC,CAAA,CAAE;AAAA,K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Input, output, type Output, type Unwrap } from \"@highstate/pulumi\"\nimport { Service } from \"../service\"\n\nexport interface FullBackendRef {\n /**\n * The name of the resource being referenced.\n */\n name: Input<string>\n\n /**\n * The namespace of the resource being referenced.\n * May be undefined if the resource is not in a namespace.\n */\n namespace?: Input<string | undefined>\n\n /**\n * The port of the resource being referenced.\n */\n port: Input<number>\n}\n\nexport interface ServiceBackendRef {\n /**\n * The name of the service being referenced.\n */\n service: Input<core.v1.Service>\n\n /**\n * The port of the service being referenced.\n */\n port: Input<number>\n}\n\nexport type BackendRef = FullBackendRef | ServiceBackendRef | Service\n\nexport function resolveBackendRef(ref: BackendRef): Output<Unwrap<FullBackendRef>> {\n if (Service.isInstance(ref)) {\n return output({\n name: ref.metadata.name,\n namespace: ref.metadata.namespace,\n port: ref.spec.ports[0].port,\n })\n }\n\n if (\"service\" in ref) {\n const service = output(ref.service)\n\n return output({\n name: service.metadata.name,\n namespace: service.metadata.namespace,\n port: ref.port,\n })\n }\n\n return output({\n name: ref.name,\n namespace: ref.namespace,\n port: ref.port,\n })\n}\n","import type { Gateway } from \"./gateway\"\nimport {\n ComponentResource,\n normalize,\n normalizeInputs,\n normalizeInputsAndMap,\n output,\n type Output,\n type ComponentResourceOptions,\n type Input,\n type InputArray,\n} from \"@highstate/pulumi\"\nimport { gateway, type types } from \"@highstate/gateway-api\"\nimport { map, pipe } from \"remeda\"\nimport { getProvider, mapMetadata, type ScopedResourceArgs } from \"../shared\"\nimport { resolveBackendRef, type BackendRef } from \"./backend\"\n\nexport type HttpRouteArgs = Omit<ScopedResourceArgs, \"namespace\"> & {\n /**\n * The gateway to associate with the route.\n */\n gateway: Input<Gateway>\n\n /**\n * The alias for `hostnames: [hostname]`.\n */\n hostname?: Input<string>\n\n /**\n * The rule of the route.\n */\n rule?: Input<HttpRouteRuleArgs>\n\n /**\n * The rules of the route.\n */\n rules?: InputArray<HttpRouteRuleArgs>\n} & Omit<Partial<types.input.gateway.v1.HTTPRouteSpec>, \"rules\">\n\nexport type HttpRouteRuleArgs = Omit<\n types.input.gateway.v1.HTTPRouteSpecRules,\n \"matches\" | \"filters\" | \"backendRefs\"\n> & {\n /**\n * The conditions of the rule.\n * Can be specified as string to match on the path.\n */\n matches?: InputArray<HttpRouteRuleMatchOptions>\n\n /**\n * The condition of the rule.\n * Can be specified as string to match on the path.\n */\n match?: Input<HttpRouteRuleMatchOptions>\n\n /**\n * The filters of the rule.\n */\n filters?: InputArray<types.input.gateway.v1.HTTPRouteSpecRulesFilters>\n\n /**\n * The filter of the rule.\n */\n filter?: Input<types.input.gateway.v1.HTTPRouteSpecRulesFilters>\n\n /**\n * The service to route to.\n */\n backend?: Input<BackendRef>\n}\n\nexport type HttpRouteRuleMatchOptions = types.input.gateway.v1.HTTPRouteSpecRulesMatches | string\n\nexport class HttpRoute extends ComponentResource {\n /**\n * The underlying Kubernetes resource.\n */\n public readonly route: Output<gateway.v1.HTTPRoute>\n\n constructor(name: string, args: HttpRouteArgs, opts?: ComponentResourceOptions) {\n super(\"highstate:k8s:HttpRoute\", name, args, opts)\n\n this.route = output(args.gateway).cluster.apply(cluster => {\n return new gateway.v1.HTTPRoute(\n name,\n {\n metadata: mapMetadata(args, name).apply(metadata => ({\n ...metadata,\n namespace: output(args.gateway).namespace.metadata.name,\n })),\n spec: {\n hostnames: normalizeInputs(args.hostname, args.hostnames),\n\n parentRefs: [\n {\n name: output(args.gateway).metadata.name,\n },\n ],\n\n rules: normalizeInputsAndMap(args.rule, args.rules, rule => ({\n timeouts: rule.timeouts,\n\n matches: pipe(\n normalize(rule.match, rule.matches),\n map(mapHttpRouteRuleMatch),\n addDefaultPathMatch,\n ),\n\n filters: normalize(rule.filter, rule.filters),\n backendRefs: rule.backend ? [resolveBackendRef(rule.backend)] : undefined,\n })),\n } satisfies types.input.gateway.v1.HTTPRouteSpec,\n },\n { ...opts, parent: this, provider: getProvider(cluster) },\n )\n })\n }\n}\n\nfunction addDefaultPathMatch(\n matches: types.input.gateway.v1.HTTPRouteSpecRulesMatches[],\n): types.input.gateway.v1.HTTPRouteSpecRulesMatches[] {\n return matches.length ? matches : [{ path: { type: \"PathPrefix\", value: \"/\" } }]\n}\n\nexport function mapHttpRouteRuleMatch(\n match: HttpRouteRuleMatchOptions,\n): types.input.gateway.v1.HTTPRouteSpecRulesMatches {\n if (typeof match === \"string\") {\n return { path: { type: \"PathPrefix\", value: match } }\n }\n\n return match\n}\n","import type { k8s, network } from \"@highstate/library\"\nimport type { types } from \"@pulumi/kubernetes\"\nimport type { SetRequired } from \"type-fest\"\nimport { parseL3Endpoint } from \"@highstate/common\"\nimport { getOrCreate } from \"@highstate/contract\"\nimport { gateway, type types as gwTypes } from \"@highstate/gateway-api\"\nimport {\n ComponentResource,\n type ComponentResourceOptions,\n type Input,\n type InputArray,\n type Inputs,\n interpolate,\n type Output,\n output,\n toPromise,\n} from \"@highstate/pulumi\"\nimport { deepmerge } from \"deepmerge-ts\"\nimport { omit } from \"remeda\"\nimport { Namespace } from \"../namespace\"\nimport { commonExtraArgs, getProvider, mapMetadata, type ScopedResourceArgs } from \"../shared\"\n\nexport type GatewayArgs = ScopedResourceArgs & {\n /**\n * The FQDN to configure the listeners for.\n */\n fqdn?: Input<string>\n\n /**\n * The FQDNs to configure the listeners for.\n */\n fqdns?: InputArray<string>\n} & gwTypes.input.gateway.v1.GatewaySpec\n\nexport type CreateOrGetGatewayArgs = GatewayArgs & {\n /**\n * The gateway entity to patch/retrieve.\n */\n existing: Input<k8s.Gateway> | undefined\n}\n\nconst gatewayExtraArgs = [...commonExtraArgs, \"fqdn\", \"fqdns\"] as const\n\n/**\n * Represents a Kubernetes Gateway resource.\n */\nexport abstract class Gateway extends ComponentResource {\n protected constructor(\n type: string,\n name: string,\n args: Inputs,\n opts: ComponentResourceOptions | undefined,\n\n /**\n * The namespace where the gateway is located.\n */\n readonly namespace: Output<Namespace>,\n\n /**\n * The metadata of the underlying Kubernetes gateway.\n */\n readonly metadata: Output<types.output.meta.v1.ObjectMeta>,\n\n /**\n * The spec of the underlying Gateway resource.\n */\n readonly spec: Output<gwTypes.output.gateway.v1.GatewaySpec>,\n\n /**\n * The status of the underlying Gateway resource.\n */\n readonly status: Output<gwTypes.output.gateway.v1.GatewayStatus>,\n ) {\n super(type, name, args, opts)\n }\n\n /**\n * The cluster where the gateway is located.\n */\n get cluster(): Output<k8s.Cluster> {\n return this.namespace.cluster\n }\n\n /**\n * The Highstate gateway entity.\n */\n get entity(): Output<k8s.Gateway> {\n return output({\n type: \"gateway\",\n clusterId: this.cluster.id,\n clusterName: this.cluster.name,\n metadata: this.metadata,\n })\n }\n\n /**\n * Returns the endpoints L3 endpoints on which the gateway is exposed.\n */\n get endpoints(): Output<network.L3Endpoint[]> {\n return this.status.addresses.apply(addresses => {\n if (!addresses) {\n return []\n }\n\n return addresses.map(address => parseL3Endpoint(address.value))\n })\n }\n\n /**\n * Creates a new gateway.\n */\n static create(name: string, args: GatewayArgs, opts?: ComponentResourceOptions): Gateway {\n return new CreatedGateway(name, args, opts)\n }\n\n /**\n * Creates a new gateway or patches an existing one.\n *\n * @param name The name of the resource. May not be the same as the gateway name.\n * @param args The arguments to create or patch the gateway with.\n * @param opts Optional resource options.\n */\n static createOrPatch(\n name: string,\n args: CreateOrGetGatewayArgs,\n opts?: ComponentResourceOptions,\n ): Gateway {\n if (args.existing) {\n return new GatewayPatch(name, {\n ...args,\n name: output(args.existing).metadata.name,\n namespace: Namespace.forResourceAsync(args.existing, output(args.namespace).cluster),\n })\n }\n\n return new CreatedGateway(name, args, opts)\n }\n\n /**\n * Creates a new gateway or gets an existing one.\n *\n * @param name The name of the resource. May not be the same as the gateway name. Will not be used when existing gateway is retrieved.\n * @param args The arguments to create or get the gateway with.\n * @param opts Optional resource options.\n */\n static async createOrGet(\n name: string,\n args: CreateOrGetGatewayArgs,\n opts?: ComponentResourceOptions,\n ): Promise<Gateway> {\n if (args.existing) {\n return await Gateway.forAsync(args.existing, output(args.namespace).cluster)\n }\n\n return new CreatedGateway(name, args, opts)\n }\n\n /**\n * Patches an existing gateway.\n *\n * Will throw an error if the gateway does not exist.\n *\n * @param name The name of the resource. May not be the same as the gateway name.\n * @param args The arguments to patch the gateway with.\n * @param opts Optional resource options.\n */\n static patch(name: string, args: GatewayArgs, opts?: ComponentResourceOptions): Gateway {\n return new GatewayPatch(name, args, opts)\n }\n\n /**\n * Wraps an existing Kubernetes gateway.\n */\n static wrap(name: string, args: WrappedGatewayArgs, opts?: ComponentResourceOptions): Gateway {\n return new WrappedGateway(name, args, opts)\n }\n\n /**\n * Gets an existing gateway.\n *\n * Will throw an error if the gateway does not exist.\n */\n static get(name: string, args: ExternalGatewayArgs, opts?: ComponentResourceOptions): Gateway {\n return new ExternalGateway(name, args, opts)\n }\n\n private static readonly gatewayCache = new Map<string, Gateway>()\n\n /**\n * Gets an existing gateway for a given entity.\n * Prefer this method over `get` when possible.\n *\n * It automatically names the resource with the following format: `{clusterName}.{namespace}.{gatewayName}.{clusterId}`.\n *\n * This method is idempotent and will return the same instance for the same entity.\n *\n * @param entity The entity to get the gateway for.\n * @param cluster The cluster where the gateway is located.\n */\n static for(entity: k8s.Gateway, cluster: Input<k8s.Cluster>): Gateway {\n return getOrCreate(\n Gateway.gatewayCache,\n `${entity.clusterName}.${entity.metadata.namespace}.${entity.metadata.name}.${entity.clusterId}`,\n name => {\n return Gateway.get(name, {\n name: entity.metadata.name,\n namespace: Namespace.forResourceAsync(entity, cluster),\n })\n },\n )\n }\n\n /**\n * Gets an existing gateway for a given entity.\n * Prefer this method over `get` when possible.\n *\n * It automatically names the resource with the following format: `{clusterName}.{namespace}.{gatewayName}.{clusterId}`.\n *\n * This method is idempotent and will return the same instance for the same entity.\n *\n * @param entity The entity to get the gateway for.\n * @param cluster The cluster where the gateway is located.\n */\n static async forAsync(entity: Input<k8s.Gateway>, cluster: Input<k8s.Cluster>): Promise<Gateway> {\n const resolvedEntity = await toPromise(entity)\n\n return Gateway.for(resolvedEntity, output(cluster))\n }\n\n /**\n * Creates a gateway with the provided name/namespace/cluster only once.\n *\n * It automatically names the resource with the following format: `{name}.{namespace}.{clusterName}.{clusterId}`.\n *\n * This method is idempotent and will return the same instance for the same name/namespace/cluster.\n *\n * @param name The name of the gateway to create.\n * @param args The arguments to create the gateway with.\n * @param opts Optional resource options.\n */\n static async createOnce(\n args: SetRequired<GatewayArgs, \"name\">,\n opts?: ComponentResourceOptions,\n ): Promise<Gateway> {\n const { name, namespace, cluster } = await toPromise({\n name: args.name,\n namespace: output(args.namespace).metadata.name,\n cluster: output(args.namespace).cluster,\n })\n\n const fullName = `${name}.${namespace}.${cluster.name}.${cluster.id}`\n\n return getOrCreate(Gateway.gatewayCache, name, () =>\n Gateway.create(\n fullName,\n {\n ...args,\n name,\n namespace: args.namespace,\n },\n opts,\n ),\n )\n }\n}\n\nclass CreatedGateway extends Gateway {\n constructor(name: string, args: GatewayArgs, opts?: ComponentResourceOptions) {\n const gatewayResource = output(args.namespace).cluster.apply(cluster => {\n return new gateway.v1.Gateway(\n name,\n {\n metadata: mapMetadata(args, name),\n spec: deepmerge({}, omit(args, gatewayExtraArgs)),\n },\n { ...opts, parent: this, provider: getProvider(cluster) },\n )\n })\n\n super(\n \"highstate:k8s:Gateway\",\n name,\n args,\n opts,\n\n output(args.namespace),\n gatewayResource.metadata as Output<types.output.meta.v1.ObjectMeta>,\n gatewayResource.spec,\n gatewayResource.status,\n )\n }\n}\n\nclass GatewayPatch extends Gateway {\n constructor(name: string, args: GatewayArgs, opts?: ComponentResourceOptions) {\n const gatewayResource = output(args.namespace).cluster.apply(cluster => {\n return new gateway.v1.GatewayPatch(\n name,\n {\n metadata: mapMetadata(args, name),\n spec: deepmerge({}, omit(args, gatewayExtraArgs)),\n },\n { ...opts, parent: this, provider: getProvider(cluster) },\n )\n })\n\n super(\n \"highstate:k8s:GatewayPatch\",\n name,\n args,\n opts,\n\n output(args.namespace),\n gatewayResource.metadata as Output<types.output.meta.v1.ObjectMeta>,\n gatewayResource.spec,\n gatewayResource.status,\n )\n }\n}\n\nexport type WrappedGatewayArgs = {\n /**\n * The underlying Kubernetes gateway to wrap.\n */\n gateway: Input<gateway.v1.Gateway>\n\n /**\n * The namespace where the gateway is located.\n */\n namespace: Input<Namespace>\n}\n\nclass WrappedGateway extends Gateway {\n constructor(name: string, args: WrappedGatewayArgs, opts?: ComponentResourceOptions) {\n super(\n \"highstate:k8s:WrappedGateway\",\n name,\n args,\n opts,\n\n output(args.namespace),\n output(args.gateway).metadata as Output<types.output.meta.v1.ObjectMeta>,\n output(args.gateway).spec,\n output(args.gateway).status,\n )\n }\n}\n\nexport type ExternalGatewayArgs = {\n /**\n * The name of the gateway to get.\n */\n name: Input<string>\n\n /**\n * The namespace of the gateway to get.\n */\n namespace: Input<Namespace>\n}\n\nclass ExternalGateway extends Gateway {\n constructor(name: string, args: ExternalGatewayArgs, opts?: ComponentResourceOptions) {\n const gatewayResource = output(args.namespace).cluster.apply(cluster => {\n return gateway.v1.Gateway.get(\n name,\n interpolate`${output(args.namespace).metadata.name}/${args.name}`,\n { ...opts, parent: this, provider: getProvider(cluster) },\n )\n })\n\n super(\n \"highstate:k8s:ExternalGateway\",\n name,\n args,\n opts,\n\n output(args.namespace),\n gatewayResource.metadata as Output<types.output.meta.v1.ObjectMeta>,\n gatewayResource.spec,\n gatewayResource.status,\n )\n }\n}\n"]}