fix(hwlab): route d601 v03 postgres through gateway (#957)
Co-authored-by: Codex <codex@noreply.local>
This commit is contained in:
@@ -1579,11 +1579,13 @@ export function nodeRuntimePipelinePostprocessScript(): string[] {
|
||||
"function patchExternalPostgres() {",
|
||||
" const pg = overlay.externalPostgres;",
|
||||
" if (!pg || !pg.serviceName) return false;",
|
||||
" const access = pg.runtimeAccess || { endpointAddress: pg.endpointAddress, port: pg.port };",
|
||||
" const file = path.join(runtimePath, 'external-postgres.yaml');",
|
||||
" if (!fs.existsSync(file)) return false;",
|
||||
" const doc = readYaml(file);",
|
||||
" const items = listItems(doc).filter(Boolean);",
|
||||
" let changed = false;",
|
||||
" const endpointIsIpv4 = /^[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+$/.test(String(access.endpointAddress));",
|
||||
" const endpointSliceName = String(pg.serviceName) + '-host';",
|
||||
" for (const item of items) {",
|
||||
" if (!item || typeof item !== 'object') continue;",
|
||||
@@ -1594,20 +1596,33 @@ export function nodeRuntimePipelinePostprocessScript(): string[] {
|
||||
" if (item.kind === 'Service') {",
|
||||
" item.metadata.name = pg.serviceName;",
|
||||
" item.spec = item.spec || {};",
|
||||
" item.spec.ports = [{ name: 'postgres', port: pg.port, targetPort: pg.port, protocol: 'TCP' }];",
|
||||
" if (endpointIsIpv4) {",
|
||||
" item.spec.type = 'ClusterIP';",
|
||||
" delete item.spec.externalName;",
|
||||
" } else {",
|
||||
" item.spec.type = 'ExternalName';",
|
||||
" item.spec.externalName = String(access.endpointAddress);",
|
||||
" delete item.spec.clusterIP;",
|
||||
" delete item.spec.clusterIPs;",
|
||||
" delete item.spec.ipFamilies;",
|
||||
" delete item.spec.ipFamilyPolicy;",
|
||||
" delete item.spec.internalTrafficPolicy;",
|
||||
" }",
|
||||
" item.spec.ports = [{ name: 'postgres', port: access.port, targetPort: access.port, protocol: 'TCP' }];",
|
||||
" delete item.spec.selector;",
|
||||
" changed = true;",
|
||||
" }",
|
||||
" if (item.kind === 'EndpointSlice') {",
|
||||
" if (!endpointIsIpv4) { item.__delete = true; changed = true; continue; }",
|
||||
" item.metadata.name = endpointSliceName;",
|
||||
" item.metadata.labels['kubernetes.io/service-name'] = pg.serviceName;",
|
||||
" item.addressType = 'IPv4';",
|
||||
" item.ports = [{ name: 'postgres', port: pg.port, protocol: 'TCP' }];",
|
||||
" item.endpoints = [{ addresses: [pg.endpointAddress], conditions: { ready: true } }];",
|
||||
" item.ports = [{ name: 'postgres', port: access.port, protocol: 'TCP' }];",
|
||||
" item.endpoints = [{ addresses: [access.endpointAddress], conditions: { ready: true } }];",
|
||||
" changed = true;",
|
||||
" }",
|
||||
" }",
|
||||
" if (changed) writeYaml(file, normalizeList(items));",
|
||||
" if (changed) writeYaml(file, normalizeList(items.filter((item) => !item.__delete)));",
|
||||
" return changed;",
|
||||
"}",
|
||||
"function patchHealthContract() {",
|
||||
@@ -1829,19 +1844,29 @@ export function nodeRuntimePipelinePostprocessScript(): string[] {
|
||||
"if (overlay.externalPostgres && overlay.externalPostgres.sslmode) checks.push('runtime-db-ssl-mode');",
|
||||
"const pg = overlay.externalPostgres;",
|
||||
"if (pg && pg.serviceName) {",
|
||||
" const access = pg.runtimeAccess || { endpointAddress: pg.endpointAddress, port: pg.port };",
|
||||
" const file = path.join(runtimePath, 'external-postgres.yaml');",
|
||||
" if (!fs.existsSync(file)) fail('external-postgres-missing');",
|
||||
" const items = listItems(readYaml(file)).filter(Boolean);",
|
||||
" const service = items.find((item) => item && item.kind === 'Service' && item.metadata && item.metadata.name === pg.serviceName);",
|
||||
" const endpointSlice = items.find((item) => item && item.kind === 'EndpointSlice' && item.metadata && item.metadata.name === String(pg.serviceName) + '-host');",
|
||||
" if (!service) fail('external-postgres-service-missing', { expected: pg.serviceName });",
|
||||
" if (!endpointSlice) fail('external-postgres-endpointslice-missing', { expected: String(pg.serviceName) + '-host' });",
|
||||
" const endpointIsIpv4 = /^[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+$/.test(String(access.endpointAddress));",
|
||||
" const servicePort = service.spec && Array.isArray(service.spec.ports) && service.spec.ports[0] ? service.spec.ports[0].port : null;",
|
||||
" if (!endpointIsIpv4) {",
|
||||
" if (service.spec && service.spec.type !== 'ExternalName') fail('external-postgres-service-type-mismatch', { value: service.spec.type, expected: 'ExternalName' });",
|
||||
" if (!service.spec || String(service.spec.externalName) !== String(access.endpointAddress)) fail('external-postgres-external-name-mismatch', { value: service.spec && service.spec.externalName, expected: access.endpointAddress });",
|
||||
" if (Number(servicePort) !== Number(access.port)) fail('external-postgres-port-mismatch', { servicePort, expectedPort: access.port });",
|
||||
" if (endpointSlice) fail('external-postgres-endpointslice-unexpected', { name: String(pg.serviceName) + '-host' });",
|
||||
" checks.push('external-postgres-bridge');",
|
||||
" } else {",
|
||||
" if (!endpointSlice) fail('external-postgres-endpointslice-missing', { expected: String(pg.serviceName) + '-host' });",
|
||||
" const endpointPort = Array.isArray(endpointSlice.ports) && endpointSlice.ports[0] ? endpointSlice.ports[0].port : null;",
|
||||
" const endpointAddress = Array.isArray(endpointSlice.endpoints) && endpointSlice.endpoints[0] && Array.isArray(endpointSlice.endpoints[0].addresses) ? endpointSlice.endpoints[0].addresses[0] : null;",
|
||||
" if (Number(servicePort) !== Number(pg.port) || Number(endpointPort) !== Number(pg.port)) fail('external-postgres-port-mismatch', { servicePort, endpointPort, expectedPort: pg.port });",
|
||||
" if (String(endpointAddress) !== String(pg.endpointAddress)) fail('external-postgres-address-mismatch', { endpointAddress, expectedEndpointAddress: pg.endpointAddress });",
|
||||
" if (Number(servicePort) !== Number(access.port) || Number(endpointPort) !== Number(access.port)) fail('external-postgres-port-mismatch', { servicePort, endpointPort, expectedPort: access.port });",
|
||||
" if (String(endpointAddress) !== String(access.endpointAddress)) fail('external-postgres-address-mismatch', { endpointAddress, expectedEndpointAddress: access.endpointAddress });",
|
||||
" checks.push('external-postgres-bridge');",
|
||||
" }",
|
||||
"}",
|
||||
"const exposure = overlay.publicExposure;",
|
||||
"if (exposure && exposure.enabled) {",
|
||||
|
||||
Reference in New Issue
Block a user