mirror of
https://github.com/fosrl/pangolin.git
synced 2026-01-28 22:00:51 +00:00
remove maintenance mode from oss traefik config generator
This commit is contained in:
committed by
Owen Schwartz
parent
150c51c9eb
commit
1d862131dd
@@ -60,11 +60,6 @@ export async function getTraefikConfig(
|
|||||||
proxyProtocol: resources.proxyProtocol,
|
proxyProtocol: resources.proxyProtocol,
|
||||||
proxyProtocolVersion: resources.proxyProtocolVersion,
|
proxyProtocolVersion: resources.proxyProtocolVersion,
|
||||||
|
|
||||||
maintenanceModeEnabled: resources.maintenanceModeEnabled,
|
|
||||||
maintenanceModeType: resources.maintenanceModeType,
|
|
||||||
maintenanceTitle: resources.maintenanceTitle,
|
|
||||||
maintenanceMessage: resources.maintenanceMessage,
|
|
||||||
maintenanceEstimatedTime: resources.maintenanceEstimatedTime,
|
|
||||||
// Target fields
|
// Target fields
|
||||||
targetId: targets.targetId,
|
targetId: targets.targetId,
|
||||||
targetEnabled: targets.enabled,
|
targetEnabled: targets.enabled,
|
||||||
@@ -187,11 +182,6 @@ export async function getTraefikConfig(
|
|||||||
// Store domain cert resolver fields
|
// Store domain cert resolver fields
|
||||||
domainCertResolver: row.domainCertResolver,
|
domainCertResolver: row.domainCertResolver,
|
||||||
preferWildcardCert: row.preferWildcardCert
|
preferWildcardCert: row.preferWildcardCert
|
||||||
maintenanceModeEnabled: row.maintenanceModeEnabled,
|
|
||||||
maintenanceModeType: row.maintenanceModeType,
|
|
||||||
maintenanceTitle: row.maintenanceTitle,
|
|
||||||
maintenanceMessage: row.maintenanceMessage,
|
|
||||||
maintenanceEstimatedTime: row.maintenanceEstimatedTime,
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -257,97 +247,6 @@ export async function getTraefikConfig(
|
|||||||
config_output.http.services = {};
|
config_output.http.services = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
// available healthy servers for automatic mode
|
|
||||||
const availableServers = (targets as TargetWithSite[]).filter(
|
|
||||||
(target: TargetWithSite) => {
|
|
||||||
if (!target.enabled) return false;
|
|
||||||
|
|
||||||
const anySitesOnline = (targets as TargetWithSite[]).some(
|
|
||||||
(t: TargetWithSite) => t.site.online
|
|
||||||
);
|
|
||||||
if (anySitesOnline && !target.site.online) return false;
|
|
||||||
|
|
||||||
if (target.site.type === "local" || target.site.type === "wireguard") {
|
|
||||||
return target.ip && target.port && target.method;
|
|
||||||
} else if (target.site.type === "newt") {
|
|
||||||
return target.internalPort && target.method && target.site.subnet;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
const hasHealthyServers = availableServers.length > 0;
|
|
||||||
|
|
||||||
let showMaintenancePage = false;
|
|
||||||
if (resource.maintenanceModeEnabled) {
|
|
||||||
if (resource.maintenanceModeType === "forced") {
|
|
||||||
showMaintenancePage = true;
|
|
||||||
logger.debug(
|
|
||||||
`Resource ${resource.name} (${fullDomain}) is in FORCED maintenance mode`
|
|
||||||
);
|
|
||||||
} else if (resource.maintenanceModeType === "automatic") {
|
|
||||||
showMaintenancePage = !hasHealthyServers;
|
|
||||||
if (showMaintenancePage) {
|
|
||||||
logger.warn(
|
|
||||||
`Resource ${resource.name} (${fullDomain}) has no healthy servers - showing maintenance page (AUTOMATIC mode)`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (showMaintenancePage) {
|
|
||||||
const maintenanceServiceName = `${key}-maintenance-service`;
|
|
||||||
const maintenanceRouterName = `${key}-maintenance-router`;
|
|
||||||
|
|
||||||
const maintenancePort = config.getRawConfig().traefik.maintenance_port || 8888;
|
|
||||||
const entrypointHttp = config.getRawConfig().traefik.http_entrypoint;
|
|
||||||
const entrypointHttps = config.getRawConfig().traefik.https_entrypoint;
|
|
||||||
|
|
||||||
const fullDomain = resource.fullDomain;
|
|
||||||
const domainParts = fullDomain.split(".");
|
|
||||||
const wildCard = resource.subdomain
|
|
||||||
? `*.${domainParts.slice(1).join(".")}`
|
|
||||||
: fullDomain;
|
|
||||||
|
|
||||||
const tls = {
|
|
||||||
certResolver: resource.domainCertResolver?.trim() ||
|
|
||||||
config.getRawConfig().traefik.cert_resolver,
|
|
||||||
...(config.getRawConfig().traefik.prefer_wildcard_cert
|
|
||||||
? { domains: [{ main: wildCard }] }
|
|
||||||
: {})
|
|
||||||
};
|
|
||||||
|
|
||||||
const maintenanceHost = config.getRawConfig().traefik?.maintenance_host || 'pangolin';
|
|
||||||
|
|
||||||
config_output.http.services[maintenanceServiceName] = {
|
|
||||||
loadBalancer: {
|
|
||||||
servers: [{ url: `http://${maintenanceHost}:${maintenancePort}` }],
|
|
||||||
passHostHeader: true
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const rule = `Host(\`${fullDomain}\`)`;
|
|
||||||
|
|
||||||
config_output.http.routers[maintenanceRouterName] = {
|
|
||||||
entryPoints: [resource.ssl ? entrypointHttps : entrypointHttp],
|
|
||||||
service: maintenanceServiceName,
|
|
||||||
rule,
|
|
||||||
priority: 2000,
|
|
||||||
...(resource.ssl ? { tls } : {})
|
|
||||||
};
|
|
||||||
|
|
||||||
if (resource.ssl) {
|
|
||||||
config_output.http.routers[`${maintenanceRouterName}-redirect`] = {
|
|
||||||
entryPoints: [entrypointHttp],
|
|
||||||
middlewares: [redirectHttpsMiddlewareName],
|
|
||||||
service: maintenanceServiceName,
|
|
||||||
rule,
|
|
||||||
priority: 2000
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
const domainParts = fullDomain.split(".");
|
const domainParts = fullDomain.split(".");
|
||||||
let wildCard;
|
let wildCard;
|
||||||
if (domainParts.length <= 2) {
|
if (domainParts.length <= 2) {
|
||||||
|
|||||||
Reference in New Issue
Block a user