Skip to content

Commit

Permalink
refactor(gateway): refactor logics of ingress deletion (labring#1612)
Browse files Browse the repository at this point in the history
  • Loading branch information
maslow authored Oct 26, 2023
1 parent bf4150e commit f659c96
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 5 deletions.
2 changes: 1 addition & 1 deletion runtimes/nodejs/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

# source .env
echo "****** start service: node $FLAGS --experimental-fetch ./dist/index.js *******"
exec node $FLAGS --experimental-fetch ./dist/index.js
exec node $FLAGS ./dist/index.js
13 changes: 11 additions & 2 deletions server/src/gateway/ingress/bucket-ingress.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -56,6 +56,15 @@ export class BucketGatewayService {
},
}

// build tls
const tls: Array<V1IngressTLS> = []
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 = {
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion server/src/gateway/runtime-domain-task.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion server/src/gateway/website-task.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
51 changes: 51 additions & 0 deletions server/src/instance/instance-task.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -148,6 +151,30 @@ export class InstanceTaskService {
return
}

// active runtime domain
await db
.collection<RuntimeDomain>('RuntimeDomain')
.updateOne(
{ appid, state: DomainState.Inactive },
{ $set: { state: DomainState.Active, updatedAt: new Date() } },
)

// active website domain
await db
.collection<WebsiteHosting>('WebsiteHosting')
.updateMany(
{ appid, state: DomainState.Inactive },
{ $set: { state: DomainState.Active, updatedAt: new Date() } },
)

// active bucket domain
await db
.collection<BucketDomain>('BucketDomain')
.updateMany(
{ appid, state: DomainState.Inactive },
{ $set: { state: DomainState.Active, updatedAt: new Date() } },
)

// resume cronjobs if any
await this.cronService.resumeAll(app.appid)

Expand Down Expand Up @@ -221,6 +248,30 @@ export class InstanceTaskService {

const waitingTime = Date.now() - app.updatedAt.getTime()

// inactive runtime domain
await db
.collection<RuntimeDomain>('RuntimeDomain')
.updateOne(
{ appid, state: DomainState.Active },
{ $set: { state: DomainState.Inactive, updatedAt: new Date() } },
)

// inactive website domain
await db
.collection<WebsiteHosting>('WebsiteHosting')
.updateMany(
{ appid, state: DomainState.Active },
{ $set: { state: DomainState.Inactive, updatedAt: new Date() } },
)

// inactive bucket domain
await db
.collection<BucketDomain>('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) {
Expand Down

0 comments on commit f659c96

Please sign in to comment.