feat: sync workload routes to external gateway
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import * as plugins from './coreflow.plugins.js';
|
||||
import { logger } from './coreflow.logging.js';
|
||||
import { Coreflow } from './coreflow.classes.coreflow.js';
|
||||
import type { IExternalGatewayConfig } from './coreflow.connector.externalgateway.js';
|
||||
|
||||
export class ClusterManager {
|
||||
public coreflowRef: Coreflow;
|
||||
@@ -408,8 +409,11 @@ export class ClusterManager {
|
||||
* update traffic routing
|
||||
*/
|
||||
public async updateTrafficRouting(
|
||||
_clusterConfigArg: plugins.servezoneInterfaces.data.ICluster,
|
||||
clusterConfigArg: plugins.servezoneInterfaces.requests.config.IRequest_Any_Cloudly_GetClusterConfig['response'] & {
|
||||
externalGateway?: IExternalGatewayConfig;
|
||||
},
|
||||
) {
|
||||
const externalGatewayConfig = clusterConfigArg.externalGateway;
|
||||
const services = await this.coreflowRef.dockerHost.listServices();
|
||||
const webGatewayNetwork = await this.coreflowRef.dockerHost.getNetworkByName(
|
||||
this.commonDockerData.networkNames.sznWebgateway,
|
||||
@@ -420,14 +424,20 @@ export class ClusterManager {
|
||||
const reverseProxyConfigs: plugins.servezoneInterfaces.data.IReverseProxyConfig[] = [];
|
||||
|
||||
const pushProxyConfig = async (
|
||||
serviceNameArg: string,
|
||||
workloadServiceArg: plugins.servezoneInterfaces.data.IService,
|
||||
hostNameArg: string,
|
||||
containerDestinationIp: string,
|
||||
webDestinationPort: string,
|
||||
) => {
|
||||
logger.log('ok', `trying to obtain a certificate for ${hostNameArg}`);
|
||||
const certificate =
|
||||
await this.coreflowRef.cloudlyConnector.getCertificateForDomainFromCloudly(hostNameArg);
|
||||
let certificate = await this.coreflowRef.externalGatewayConnector.exportCertificateForDomain(
|
||||
externalGatewayConfig,
|
||||
hostNameArg,
|
||||
).catch((error) => {
|
||||
logger.log('warn', `external gateway certificate export failed for ${hostNameArg}: ${(error as Error).message}`);
|
||||
return undefined;
|
||||
});
|
||||
certificate = certificate || await this.coreflowRef.cloudlyConnector.getCertificateForDomainFromCloudly(hostNameArg);
|
||||
reverseProxyConfigs.push({
|
||||
destinationIps: [containerDestinationIp],
|
||||
destinationPorts: [Number(webDestinationPort)],
|
||||
@@ -437,8 +447,15 @@ export class ClusterManager {
|
||||
});
|
||||
logger.log(
|
||||
'success',
|
||||
`pushed routing config for ${hostNameArg} on workload service ${serviceNameArg}`,
|
||||
`pushed routing config for ${hostNameArg} on workload service ${workloadServiceArg.data.name}`,
|
||||
);
|
||||
await this.coreflowRef.externalGatewayConnector.syncWorkAppRoute({
|
||||
config: externalGatewayConfig,
|
||||
service: workloadServiceArg,
|
||||
hostname: hostNameArg,
|
||||
}).catch((error) => {
|
||||
logger.log('warn', `external gateway route sync failed for ${hostNameArg}: ${(error as Error).message}`);
|
||||
});
|
||||
};
|
||||
|
||||
logger.log('info', `Found ${services.length} services!`);
|
||||
@@ -473,7 +490,7 @@ export class ClusterManager {
|
||||
const webDestinationPort: string = workloadConfig.data.ports.web.toString();
|
||||
for (const hostName of hostNames) {
|
||||
await pushProxyConfig(
|
||||
workloadConfig.data.name,
|
||||
workloadConfig,
|
||||
hostName,
|
||||
containerDestinationIp,
|
||||
webDestinationPort,
|
||||
@@ -485,7 +502,7 @@ export class ClusterManager {
|
||||
const customDomainKeys = Object.keys(workloadConfig.data.ports.custom);
|
||||
for (const customDomainKey of customDomainKeys) {
|
||||
await pushProxyConfig(
|
||||
workloadConfig.data.name,
|
||||
workloadConfig,
|
||||
customDomainKey,
|
||||
containerDestinationIp,
|
||||
workloadConfig.data.ports.custom[customDomainKey],
|
||||
|
||||
Reference in New Issue
Block a user