@spine-event-engine/deployment-gke 2.0.0-snapshot.11

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/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,404 @@
1
+ # Deploy a Spine TS application on GKE
2
+
3
+ `@spine-event-engine/deployment-gke` helps one standalone Gateway find ready
4
+ Spine TS application nodes through a Kubernetes headless Service. This guide
5
+ adds an editable Terraform starting point for a private, one-Gateway GKE
6
+ deployment. It is deliberately storage-neutral: your application chooses the
7
+ storage and supplies its configuration.
8
+
9
+ This is a guide for people deploying an application. For exact discovery API
10
+ and lifecycle behavior, see the [deployment reference](REFERENCE.md).
11
+
12
+ This experimental snapshot package is for operators who already own
13
+ an application, images, and a GKE cluster. Install its library API when writing
14
+ the Gateway or application entrypoint:
15
+
16
+ ```bash
17
+ pnpm add @spine-event-engine/deployment-gke@snapshot
18
+ ```
19
+
20
+ Copy the packaged Terraform directory into an operator deployment repository
21
+ only when you want its private reference topology. Installing this library, or
22
+ copying Terraform, does not create the cluster, public Gateway policy,
23
+ authentication/session implementation, application secrets, or storage.
24
+
25
+ ## Before you begin
26
+
27
+ You need an existing GKE cluster, `gcloud`, `kubectl`, Terraform 1.6 or newer,
28
+ an existing Kubernetes ServiceAccount with the image-pull and configuration
29
+ access required by your workload, and images for three processes:
30
+
31
+ - your Spine TS application-node image;
32
+ - your standalone Gateway image; and
33
+ - an image running the simple delivery server.
34
+
35
+ Publish immutable image references before deployment. The template does not
36
+ create a GKE cluster, an image registry, an identity provider, or application
37
+ secrets. Authenticate `gcloud` and select the cluster first:
38
+
39
+ ```bash
40
+ gcloud container clusters get-credentials CLUSTER --location REGION --project PROJECT
41
+ kubectl create namespace spine-app
42
+ ```
43
+
44
+ Create the two Secrets through your normal secret-management process before
45
+ running Terraform. Terraform receives only their names; it never receives or
46
+ creates their values. The application Secret holds application-selected
47
+ settings, including storage settings when the application needs them. The
48
+ Gateway Secret holds separate identity and session settings.
49
+
50
+ ## First Terraform plan
51
+
52
+ Copy the packaged template into an operator-owned deployment repository. The
53
+ following commands assume its Terraform directory is your current directory;
54
+ fill in its existing cluster, Secret names, and immutable image references,
55
+ then validate the private topology before configuring entrypoint details:
56
+
57
+ ```bash
58
+ cp terraform.tfvars.example terraform.tfvars
59
+ terraform init
60
+ terraform fmt -check
61
+ terraform validate
62
+ terraform plan -var-file=terraform.tfvars
63
+ ```
64
+
65
+ A plan showing only the Gateway, application, delivery, and private Services
66
+ is the first success. Review it before `terraform apply`.
67
+
68
+ ## What this deployment creates
69
+
70
+ The Terraform module creates three private Kubernetes Deployments and three
71
+ ClusterIP Services. One Service is headless: Kubernetes publishes the ready
72
+ Node Coordinator endpoint of each application Pod in DNS. The Gateway uses that
73
+ DNS name with `GkeNodeDiscovery`; it does not call the Kubernetes API or
74
+ maintain a separate node registry. Managed application children remain
75
+ loopback-only and are not Service endpoints.
76
+
77
+ ```mermaid
78
+ flowchart LR
79
+ Edge["Operator-managed TLS and authentication edge"] --> Gateway["One standalone Gateway"]
80
+ Gateway --> DNS["Headless application Service DNS"]
81
+ DNS --> App1["Application node"]
82
+ DNS --> App2["Application node"]
83
+ App1 --> Delivery["One simple delivery server"]
84
+ App2 --> Delivery
85
+ ```
86
+
87
+ The template intentionally keeps Gateway, application, and delivery traffic
88
+ private. It does not create a public load balancer, TLS certificate, or
89
+ authentication policy. Connect the `gateway` ClusterIP Service to the public
90
+ TLS/authentication edge your operators choose. That edge is responsible for
91
+ admitting browser traffic; the Gateway then forwards authorized requests to
92
+ the application nodes.
93
+
94
+ The simple delivery server is useful for this supported topology, but it is
95
+ in-memory, single-replica, and not highly available. It loses its state when
96
+ it restarts. Choose an operationally suitable delivery design before depending
97
+ on it for a critical production workload.
98
+
99
+ This template has one Gateway and a fixed deployment shape. Multiple-Gateway
100
+ behavior and Cloud Run are outside the supported offering.
101
+
102
+ ## Configure the template
103
+
104
+ Edit the existing `terraform.tfvars` copied for the first plan and replace every placeholder with values for
105
+ your cluster and delivery pipeline:
106
+
107
+ `terraform.tfvars` asks for the existing Secret names, immutable images, and
108
+ the kubeconfig context selected by `gcloud`. It defaults to two application
109
+ nodes, one Gateway, and one delivery server. The Gateway and delivery-server
110
+ replica counts are intentionally fixed at one in this topology.
111
+
112
+ Your application and Gateway entrypoints remain application code. The template
113
+ uses `HOST=0.0.0.0` and the matching `PORT` value for every container so its
114
+ private Kubernetes Service can reach the process. Keep that listener convention
115
+ in your image entrypoints. Put one small configuration owner beside the two
116
+ entrypoints, then have each entrypoint read its injected settings rather than
117
+ hard-coding the Terraform defaults:
118
+
119
+ Both supplied entrypoints bind `host: "0.0.0.0"` so the Kubernetes Service can
120
+ reach their listeners.
121
+
122
+ <!-- docs-snippet-path: packages/deployment-gke/examples/deployment-settings.ts -->
123
+
124
+ ```ts
125
+ export type DeploymentEnvironment = Readonly<Record<string, string | undefined>>;
126
+
127
+ export const DeploymentSettings = Object.freeze({
128
+ port(environment: DeploymentEnvironment, name: "PORT" | "BACKEND_DISCOVERY_PORT"): number {
129
+ const value = environment[name];
130
+ const port = Number(value);
131
+ if (typeof value !== "string" || !Number.isInteger(port) || port < 1 || port > 65_535)
132
+ throw new Error(`${name} must be an integer from 1 through 65535.`);
133
+ return port;
134
+ },
135
+
136
+ serviceName(environment: DeploymentEnvironment): string {
137
+ const value = environment.BACKEND_DISCOVERY_SERVICE?.trim();
138
+ if (value === undefined || value.length === 0)
139
+ throw new Error("BACKEND_DISCOVERY_SERVICE must not be blank.");
140
+ return value;
141
+ },
142
+ });
143
+ ```
144
+
145
+ The [complete shared settings owner](examples/deployment-settings.ts) is a
146
+ small source file. Each Node.js entrypoint supplies `process.env` to it.
147
+ The Gateway reads `"BACKEND_DISCOVERY_PORT"` and
148
+ `BACKEND_DISCOVERY_SERVICE` from the same source.
149
+
150
+ The standalone Gateway uses the headless Service name and application port from
151
+ the module. Choose one admission mode for it: authenticated mode supplies
152
+ sessions and may supply named durable subscription bindings; public mode
153
+ supplies `publicAccess: true`, and the framework owns process-local bindings.
154
+ Both modes supply authorization, trusted actor-context resolution, allowed
155
+ origins, a clock, and a type registry. The complete
156
+ [server browser guide](https://github.com/SpineEventEngine/spine-ts/blob/master/packages/server/README.md#browser-gateway-migration) and
157
+ [browser authentication guide](https://github.com/SpineEventEngine/spine-ts/blob/master/docs/BROWSER_CLIENT_AUTH_EXTENSION_GUIDE.md)
158
+ explain those application integration points.
159
+
160
+ <!-- docs-snippet-path: packages/deployment-gke/examples/gateway.ts -->
161
+
162
+ ```ts
163
+ import { GkeNodeDiscovery } from "@spine-event-engine/deployment-gke";
164
+ import { BrowserServer, type BrowserServerOptions } from "@spine-event-engine/server/browser";
165
+
166
+ type GatewayBrowserOptions = BrowserServerOptions extends infer Options
167
+ ? Options extends BrowserServerOptions
168
+ ? Omit<Options, "host" | "port" | "discovery">
169
+ : never
170
+ : never;
171
+
172
+ import { DeploymentSettings, type DeploymentEnvironment } from "./deployment-settings.js";
173
+
174
+ export interface GatewayOptions {
175
+ readonly browser: GatewayBrowserOptions;
176
+ }
177
+
178
+ export const GatewayEntrypoint = Object.freeze({
179
+ async run(
180
+ options: GatewayOptions,
181
+ environment: DeploymentEnvironment = process.env,
182
+ ): Promise<void> {
183
+ const discovery = new GkeNodeDiscovery({
184
+ serviceName: DeploymentSettings.serviceName(environment),
185
+ port: DeploymentSettings.port(environment, "BACKEND_DISCOVERY_PORT"),
186
+ });
187
+ await BrowserServer.run({
188
+ host: "0.0.0.0",
189
+ port: DeploymentSettings.port(environment, "PORT"),
190
+ ...options.browser,
191
+ discovery,
192
+ });
193
+ },
194
+ });
195
+ ```
196
+
197
+ The [complete Gateway entrypoint](examples/gateway.ts) receives your typed
198
+ browser collaborators as `GatewayOptions`. In authenticated mode, supply
199
+ sessions, authorization, trusted actor-context resolution, allowed origins, a
200
+ clock, type registry, and optionally named durable subscription bindings. In
201
+ public mode, supply `publicAccess: true` with the shared collaborators; it
202
+ cannot accept bindings because the framework owns process-local ones.
203
+
204
+ The application entrypoint uses the same configuration source for its managed
205
+ Coordinator. Set `application_process_count` and `delivery_shard_count`
206
+ explicitly in Terraform. The former starts complete local replicas; the latter
207
+ is passed to your context assembly and is not inferred from hardware:
208
+
209
+ <!-- docs-snippet-path: packages/deployment-gke/examples/application.ts -->
210
+
211
+ ```ts
212
+ import {
213
+ ManagedServerApplication,
214
+ type ManagedServerApplicationHandle,
215
+ type ManagedServerApplicationOptions,
216
+ type RunningServer,
217
+ } from "@spine-event-engine/server";
218
+
219
+ import { DeploymentSettings, type DeploymentEnvironment } from "./deployment-settings.js";
220
+
221
+ export interface ApplicationOptions {
222
+ readonly moduleUrl: string;
223
+ readonly createServer: (options: {
224
+ readonly host: string;
225
+ readonly port: number;
226
+ readonly deliveryShardCount: number;
227
+ }) => Promise<RunningServer>;
228
+ readonly synchronize?: ManagedServerApplicationOptions["synchronize"];
229
+ readonly restart?: ManagedServerApplicationOptions["restart"];
230
+ }
231
+
232
+ export const ApplicationEntrypoint = Object.freeze({
233
+ async run(
234
+ options: ApplicationOptions,
235
+ environment: DeploymentEnvironment = process.env,
236
+ ): Promise<ManagedServerApplicationHandle> {
237
+ const deliveryShardCount = DeploymentSettings.deliveryShardCount(environment);
238
+ return await ManagedServerApplication.run({
239
+ processCount: DeploymentSettings.processCount(environment),
240
+ host: "0.0.0.0",
241
+ port: DeploymentSettings.port(environment, "PORT"),
242
+ moduleUrl: options.moduleUrl,
243
+ createServer: async ({ host, port }) =>
244
+ await options.createServer({ host, port, deliveryShardCount }),
245
+ ...(options.synchronize === undefined ? {} : { synchronize: options.synchronize }),
246
+ ...(options.restart === undefined ? {} : { restart: options.restart }),
247
+ });
248
+ },
249
+ });
250
+ ```
251
+
252
+ The [complete application entrypoint](examples/application.ts) receives its
253
+ typed bounded-context, service, and resource configuration as
254
+ `ApplicationOptions`.
255
+
256
+ The ConfigMap in the template exposes matching service and port values as a
257
+ simple convention. Adapt the names or use another configuration loader; Spine
258
+ TS does not require a particular environment-variable format. Authenticated
259
+ production startup rejects missing or volatile bindings before opening its
260
+ browser listener. `DurableSubscriptionBindings` is the supplied durable option;
261
+ give it a stable namespace and storage factory configured by the Gateway
262
+ process. Use shared persistent storage across Gateway replacements; an
263
+ in-memory store does not preserve bindings when a Gateway is replaced. Public
264
+ mode has no supplied bindings: its framework-owned process-local definitions
265
+ end when the Gateway is replaced.
266
+
267
+ ## Deploy
268
+
269
+ Terraform applies Kubernetes resources to the cluster selected by your
270
+ kubeconfig. Keep cluster creation separate from this module, then run:
271
+
272
+ ```bash
273
+ terraform init
274
+ terraform fmt -check
275
+ terraform validate
276
+ terraform plan -var-file=terraform.tfvars
277
+ terraform apply -var-file=terraform.tfvars
278
+ ```
279
+
280
+ `plan` should show one Gateway Deployment, one delivery Deployment, one
281
+ application Deployment, and only private Services. Review it before `apply`.
282
+
283
+ ## Verify the deployment
284
+
285
+ Wait for the Deployments, then inspect the headless Service endpoints:
286
+
287
+ ```bash
288
+ kubectl get deployment,pod,service --namespace spine-app
289
+ kubectl rollout status deployment/application --namespace spine-app
290
+ kubectl rollout status deployment/gateway --namespace spine-app
291
+ kubectl rollout status deployment/delivery --namespace spine-app
292
+ kubectl get endpointslice --namespace spine-app \
293
+ --selector kubernetes.io/service-name=application
294
+ kubectl logs --namespace spine-app deployment/gateway
295
+ ```
296
+
297
+ A ready application Pod appears in the EndpointSlice and therefore becomes an
298
+ available Gateway backend. An unready Pod is not published because the Service
299
+ sets `publishNotReadyAddresses` to `false`. The Gateway refreshes the DNS
300
+ answer and reconciles its backend connections. A Gateway log or an application
301
+ metrics should show the expected ready backend count.
302
+
303
+ ## Scale application nodes
304
+
305
+ Spine TS never changes replica counts. When autoscaling is disabled, operators
306
+ scale the identical application Deployment by changing the Terraform input:
307
+
308
+ ```bash
309
+ terraform apply -var-file=terraform.tfvars -var=application_replicas=4
310
+ terraform apply -var-file=terraform.tfvars -var=application_replicas=1
311
+ ```
312
+
313
+ Scaling to zero is also explicit. The Gateway remains available but reports no
314
+ backend until a ready application node returns:
315
+
316
+ ```bash
317
+ terraform apply -var-file=terraform.tfvars -var=application_replicas=0
318
+ terraform apply -var-file=terraform.tfvars -var=application_replicas=2
319
+ ```
320
+
321
+ The optional HPA is disabled by default. Its minimum is one application node.
322
+ When your platform team already operates an external-metrics adapter, set
323
+ `autoscaling_enabled = true` and choose its metric name, target, minimum, and
324
+ maximum in `terraform.tfvars`.
325
+ When it is enabled, Terraform deliberately omits the Deployment replica value
326
+ so routine applies do not reset changes made by the HPA. To return to manual
327
+ capacity, disable autoscaling and set `application_replicas` in the same apply.
328
+ CPU alone cannot wake an application Deployment from zero because no Pod is
329
+ running to report CPU. On Standard GKE, Google documents KEDA as the scale from
330
+ zero path. For that policy, set `autoscaling_enabled = false` and let
331
+ operator-managed KEDA be the sole autoscaler for the Deployment. HPA and KEDA
332
+ are mutually exclusive: never run the module HPA and a KEDA-managed HPA
333
+ together. Add the KEDA configuration
334
+ separately; this editable template does not install CRDs or assume a metric
335
+ provider.
336
+
337
+ ## Replace an application version
338
+
339
+ Use immutable image digests and keep the previous digest in your deployment
340
+ record. A compatible replacement can use Kubernetes' normal rolling update:
341
+
342
+ ```bash
343
+ terraform apply -var-file=terraform.tfvars \
344
+ -var='application_image=REGION-docker.pkg.dev/PROJECT/spine/application@sha256:NEW'
345
+ ```
346
+
347
+ During overlap, old and new nodes can process work. Pending Inbox work may run
348
+ under the new business logic, so operators—not Spine TS—must decide whether the
349
+ two versions are compatible. For an incompatible replacement, first disable
350
+ the module HPA if it controls capacity, stop every application node, apply the new
351
+ image, then restore one chosen capacity policy:
352
+
353
+ ```bash
354
+ terraform apply -var-file=terraform.tfvars \
355
+ -var=autoscaling_enabled=false -var=application_replicas=0
356
+ terraform apply -var-file=terraform.tfvars \
357
+ -var='application_image=REGION-docker.pkg.dev/PROJECT/spine/application@sha256:NEW' \
358
+ -var=application_replicas=2
359
+ ```
360
+
361
+ Keep manual capacity by leaving `autoscaling_enabled = false`. Restore the
362
+ module HPA by applying `autoscaling_enabled = true` only when KEDA is absent.
363
+ For KEDA, leave the module HPA disabled and restore the operator-managed KEDA
364
+ policy only after the new application version is ready. Before the stop-all
365
+ step, suspend or remove the KEDA policy so it cannot create a node while the
366
+ replacement is intentionally at zero.
367
+
368
+ Replacing the single Gateway interrupts connected clients. The
369
+ Gateway-configured durable subscription registry preserves definitions across
370
+ the replacement; clients reconnect and re-query authoritative state after the
371
+ Gateway is ready again.
372
+
373
+ ## Roll back
374
+
375
+ Roll back by applying a known compatible image digest and the prior replica
376
+ count. For an incompatible rollback, first disable the module HPA, use the
377
+ same stop-all, apply-old-image, start sequence, then restore exactly one of
378
+ manual replicas, the module HPA, or the operator-managed KEDA policy. Confirm
379
+ ready application endpoints and a successful Gateway connection before
380
+ declaring the rollback complete. Suspend or remove the KEDA policy before the
381
+ stop-all step, then restore it only after the old version is ready.
382
+
383
+ ## Troubleshooting
384
+
385
+ | Symptom | Check | Likely next step |
386
+ | -------------------------- | ---------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------- |
387
+ | Gateway has no backend | `kubectl get endpointslice -n spine-app -l kubernetes.io/service-name=application` | Check application logs and readiness; only ready Pods enter headless DNS. |
388
+ | Pods do not start | `kubectl describe pod -n spine-app POD` | Verify image access, ServiceAccount permissions, and that both existing Secret names are correct. |
389
+ | Terraform cannot connect | `kubectl config current-context` | Re-run `gcloud container clusters get-credentials` and match `kubeconfig_context`. |
390
+ | HPA shows no data | `kubectl describe hpa -n spine-app application` | Confirm the external-metrics adapter and metric name; the template does not install either. |
391
+ | Browser clients disconnect | Gateway logs and the public edge | Expect interruption during Gateway replacement; reconnect and re-query. |
392
+
393
+ ## Remove the deployment
394
+
395
+ Remove only the Terraform-managed resources when the application is no longer
396
+ needed:
397
+
398
+ ```bash
399
+ terraform destroy -var-file=terraform.tfvars
400
+ ```
401
+
402
+ The existing namespace, image registry, public edge, and Secrets are
403
+ managed by the operator and remain. Delete them separately only after verifying that no
404
+ other workload needs them.
package/REFERENCE.md ADDED
@@ -0,0 +1,56 @@
1
+ # GKE deployment reference
2
+
3
+ The [deployment guide](README.md) is for people deploying an application. This
4
+ reference records the exact package and Terraform-template contract.
5
+
6
+ ## Discovery package
7
+
8
+ `GkeNodeDiscovery` implements `NodeDiscovery`. It reads A and AAAA answers for
9
+ a headless-Service DNS name and publishes each successful answer as a complete
10
+ ready-Coordinator snapshot. Each answer reaches one node-local Coordinator,
11
+ not a managed child listener. Its default refresh interval is 10 seconds. A
12
+ positive DNS TTL can schedule an earlier refresh; zero, missing, and unusable
13
+ TTLs use the configured interval. Empty and name-not-found answers publish an
14
+ empty snapshot immediately and retry at the configured interval.
15
+
16
+ HTTPS connects to Pod IP addresses while retaining the configured Service name
17
+ for TLS server-name verification. Resolver failures retain the last valid
18
+ membership until its deadline, then publish one empty snapshot while retries
19
+ continue. `close()` cancels timers and resolver work, waits for admitted work,
20
+ and prevents later snapshots.
21
+
22
+ Supplying discovery to `BrowserServer.run(...)` from
23
+ `@spine-event-engine/server/browser` selects standalone Gateway hosting. It
24
+ does not build or attach local contexts, and closing the Gateway stops
25
+ discovery. When an application supplies both fixed
26
+ `backend` URLs and discovery, discovery is the active membership source; fixed
27
+ URLs are not reconciled.
28
+
29
+ ## Terraform template
30
+
31
+ `terraform/` targets an existing Kubernetes context. It does not provision a
32
+ GKE cluster. The module uses versioned Kubernetes-provider resources and keeps
33
+ the three process Services private. `application` is headless with
34
+ `publish_not_ready_addresses = false`; its ready Coordinator endpoint addresses
35
+ are the Gateway discovery source. `gateway` and `delivery` each have exactly one
36
+ replica. The delivery server is in-memory and not highly available.
37
+
38
+ The module creates no Kubernetes Secret and accepts only the names of
39
+ operator-created application and Gateway Secrets. It selects no storage engine,
40
+ identity provider, public load balancer, TLS certificate, Cloud Run service, or
41
+ application command. The topology has exactly one Gateway; Multiple-Gateway
42
+ behavior is outside its contract. Application code configures
43
+ `GkeNodeDiscovery`, storage, identity, public-edge integration, and any session
44
+ or secret resolution.
45
+
46
+ `autoscaling_enabled` defaults to `false`. When true, the module creates one
47
+ external-metric HPA with a minimum of one and the operator's metric, target,
48
+ and maximum
49
+ and omits the Deployment replica value, leaving capacity control with the
50
+ HPA. When false, Terraform manages `application_replicas`. The HPA is not a
51
+ scale-to-zero mechanism; external request or queue activation such as
52
+ operator-managed KEDA is required for that behavior on Standard GKE. KEDA is
53
+ the sole autoscaler for its target Deployment: set `autoscaling_enabled` to
54
+ `false` before applying a KEDA policy. Suspend or remove KEDA before an
55
+ incompatible stop-all replacement or rollback, and restore it only after the
56
+ selected version is ready.
@@ -0,0 +1,11 @@
1
+ import type { ILogLayer } from "loglayer";
2
+ /**
3
+ * Records a contained GKE discovery warning without changing discovery outcomes.
4
+ *
5
+ * @param logger Receives the contained record when supplied.
6
+ */
7
+ export declare const gkeDiscoveryLog: Readonly<{
8
+ warn(logger: ILogLayer | undefined): void;
9
+ isPromiseLike(value: unknown): value is PromiseLike<unknown>;
10
+ }>;
11
+ //# sourceMappingURL=gke-log.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gke-log.d.ts","sourceRoot":"","sources":["../../src/discovery/gke-log.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAE1C;;;;GAIG;AACH,eAAO,MAAM,eAAe,EAAE,QAAQ,CAAC;IACrC,IAAI,CAAC,MAAM,EAAE,SAAS,GAAG,SAAS,GAAG,IAAI,CAAC;IAC1C,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,WAAW,CAAC,OAAO,CAAC,CAAC;CAC9D,CAyBC,CAAC"}