From f659c9639311d5313555facc5bd6f2022ca795fb Mon Sep 17 00:00:00 2001 From: maslow Date: Thu, 26 Oct 2023 21:45:04 +0800 Subject: [PATCH] refactor(gateway): refactor logics of ingress deletion (#1612) --- runtimes/nodejs/start.sh | 2 +- .../gateway/ingress/bucket-ingress.service.ts | 13 ++++- .../gateway/runtime-domain-task.service.ts | 2 +- server/src/gateway/website-task.service.ts | 2 +- server/src/instance/instance-task.service.ts | 51 +++++++++++++++++++ 5 files changed, 65 insertions(+), 5 deletions(-) diff --git a/runtimes/nodejs/start.sh b/runtimes/nodejs/start.sh index 98dd3edf19..d3de1df1af 100644 --- a/runtimes/nodejs/start.sh +++ b/runtimes/nodejs/start.sh @@ -2,4 +2,4 @@ # source .env echo "****** start service: node $FLAGS --experimental-fetch ./dist/index.js *******" -exec node $FLAGS --experimental-fetch ./dist/index.js \ No newline at end of file +exec node $FLAGS ./dist/index.js \ No newline at end of file diff --git a/server/src/gateway/ingress/bucket-ingress.service.ts b/server/src/gateway/ingress/bucket-ingress.service.ts index 338774fb90..f3172e1d42 100644 --- a/server/src/gateway/ingress/bucket-ingress.service.ts +++ b/server/src/gateway/ingress/bucket-ingress.service.ts @@ -3,7 +3,7 @@ import { ClusterService } from 'src/region/cluster/cluster.service' import { Region } from 'src/region/entities/region' import { BucketDomain } from '../entities/bucket-domain' import { GetApplicationNamespace } from 'src/utils/getter' -import { V1Ingress, V1IngressRule } from '@kubernetes/client-node' +import { V1Ingress, V1IngressRule, V1IngressTLS } from '@kubernetes/client-node' import { LABEL_KEY_APP_ID } from 'src/constants' @Injectable() @@ -56,6 +56,15 @@ export class BucketGatewayService { }, } + // build tls + const tls: Array = [] + const tlsConf = region.gatewayConf.tls + if (tlsConf.enabled && tlsConf.wildcardCertificateSecretName) { + // add wildcardDomain tls + const secretName = region.gatewayConf.tls.wildcardCertificateSecretName + tls.push({ secretName, hosts: [minioEndpointHost, bucketHost] }) + } + // create ingress const ingressClassName = region.gatewayConf.driver const ingressBody: V1Ingress = { @@ -75,7 +84,7 @@ export class BucketGatewayService { 'nginx.ingress.kubernetes.io/proxy-body-size': '0', }, }, - spec: { ingressClassName, rules: [minioRule, bucketRule] }, + spec: { ingressClassName, rules: [minioRule, bucketRule], tls }, } const res = await this.clusterService.createIngress(region, ingressBody) diff --git a/server/src/gateway/runtime-domain-task.service.ts b/server/src/gateway/runtime-domain-task.service.ts index bf0f509dfb..8c5648b1f3 100644 --- a/server/src/gateway/runtime-domain-task.service.ts +++ b/server/src/gateway/runtime-domain-task.service.ts @@ -170,7 +170,7 @@ export class RuntimeDomainTaskService { this.logger.debug(JSON.stringify(res)) } - { + if (doc.state === DomainState.Deleted) { // delete app custom certificate if custom domain is set const waitingTime = Date.now() - doc.updatedAt.getTime() diff --git a/server/src/gateway/website-task.service.ts b/server/src/gateway/website-task.service.ts index 8d35d6c0a2..e7129c7d38 100644 --- a/server/src/gateway/website-task.service.ts +++ b/server/src/gateway/website-task.service.ts @@ -179,7 +179,7 @@ export class WebsiteTaskService { } // delete website custom certificate if custom domain is set - if (site.isCustom) { + if (site.state === DomainState.Deleted && site.isCustom) { const waitingTime = Date.now() - site.updatedAt.getTime() // delete custom domain certificate diff --git a/server/src/instance/instance-task.service.ts b/server/src/instance/instance-task.service.ts index ad78c356bc..9533e7ab66 100644 --- a/server/src/instance/instance-task.service.ts +++ b/server/src/instance/instance-task.service.ts @@ -10,6 +10,9 @@ import { ApplicationPhase, ApplicationState, } from 'src/application/entities/application' +import { DomainState, RuntimeDomain } from 'src/gateway/entities/runtime-domain' +import { BucketDomain } from 'src/gateway/entities/bucket-domain' +import { WebsiteHosting } from 'src/website/entities/website' @Injectable() export class InstanceTaskService { @@ -148,6 +151,30 @@ export class InstanceTaskService { return } + // active runtime domain + await db + .collection('RuntimeDomain') + .updateOne( + { appid, state: DomainState.Inactive }, + { $set: { state: DomainState.Active, updatedAt: new Date() } }, + ) + + // active website domain + await db + .collection('WebsiteHosting') + .updateMany( + { appid, state: DomainState.Inactive }, + { $set: { state: DomainState.Active, updatedAt: new Date() } }, + ) + + // active bucket domain + await db + .collection('BucketDomain') + .updateMany( + { appid, state: DomainState.Inactive }, + { $set: { state: DomainState.Active, updatedAt: new Date() } }, + ) + // resume cronjobs if any await this.cronService.resumeAll(app.appid) @@ -221,6 +248,30 @@ export class InstanceTaskService { const waitingTime = Date.now() - app.updatedAt.getTime() + // inactive runtime domain + await db + .collection('RuntimeDomain') + .updateOne( + { appid, state: DomainState.Active }, + { $set: { state: DomainState.Inactive, updatedAt: new Date() } }, + ) + + // inactive website domain + await db + .collection('WebsiteHosting') + .updateMany( + { appid, state: DomainState.Active }, + { $set: { state: DomainState.Inactive, updatedAt: new Date() } }, + ) + + // inactive bucket domain + await db + .collection('BucketDomain') + .updateMany( + { appid, state: DomainState.Active }, + { $set: { state: DomainState.Inactive, updatedAt: new Date() } }, + ) + // check if the instance is removed const instance = await this.instanceService.get(app.appid) if (instance.deployment) {