Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(server): check website hosting in bucket deletion, add error handle to tasks; #1017

Merged
merged 1 commit into from
Apr 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 62 additions & 25 deletions deploy/build/charts/laf-web/templates/ingress.yaml
Original file line number Diff line number Diff line change
@@ -1,28 +1,65 @@

apiVersion: networking.k8s.io/v1
kind: Ingress
apiVersion: apisix.apache.org/v2
kind: ApisixRoute
metadata:
name: laf-web-ingress
spec:
# apisix-ingress-controller is only interested in Ingress
# resources with the matched ingressClass name, in our case,
# it's apisix.
ingressClassName: apisix
rules:
- host: {{ .Values.domain }}
http:
paths:
- backend:
service:
name: laf-web
port:
number: 80
path: /
pathType: Prefix
- backend:
service:
name: laf-server
port:
number: 3000
path: /v1/
pathType: Prefix
http:
- name: laf-web
match:
hosts:
- { { .Values.domain } }
paths:
- /*
backends:
- serviceName: laf-web
servicePort: 80
plugins:
- name: gzip
enable: true
config:
comp_level: 6
min_length: 100
types:
- text/plain
- text/css
- text/html
- text/xml
- text/javascript
- application/json
- application/x-javascript
- application/javascript
- image/bmp
- image/png
- font/ttf
- font/otf
- font/eot
- name: laf-web-api
match:
hosts:
- { { .Values.domain } }
paths:
- /v1/*
backends:
- serviceName: laf-server
servicePort: 3000
websocket: true
plugins:
- name: gzip
enable: true
config:
comp_level: 6
min_length: 100
types:
- text/plain
- text/css
- text/html
- text/xml
- text/javascript
- application/json
- application/x-javascript
- application/javascript
- image/bmp
- image/png
- font/ttf
- font/otf
- font/eot
49 changes: 32 additions & 17 deletions deploy/build/charts/minio/templates/ingress.yaml
Original file line number Diff line number Diff line change
@@ -1,21 +1,36 @@
---
apiVersion: networking.k8s.io/v1
kind: Ingress
apiVersion: apisix.apache.org/v2
kind: ApisixRoute
metadata:
name: oss-ingress
spec:
# apisix-ingress-controller is only interested in Ingress
# resources with the matched ingressClass name, in our case,
# it's apisix.
ingressClassName: apisix
rules:
- host: {{ .Values.domain }}
http:
paths:
- backend:
service:
name: minio
port:
number: 9000
path: /
pathType: Prefix
http:
- backends:
- serviceName: minio
servicePort: 9000
match:
hosts:
- {{ .Values.domain }}
paths:
- /*
name: laf-oss
plugins:
- config:
comp_level: 5
min_length: 1024
types:
- text/plain
- text/css
- text/html
- text/xml
- text/javascript
- application/json
- application/x-javascript
- application/javascript
- image/bmp
- image/png
- font/ttf
- font/otf
- font/eot
enable: true
name: gzip
2 changes: 2 additions & 0 deletions deploy/build/images/shim/ImageList
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ docker.io/lafyun/runtime-node-init:latest
docker.io/lafyun/runtime-node:latest
docker.io/apache/apisix-dashboard:2.13-alpine
docker.io/apache/apisix-ingress-controller:1.5.0
quay.io/minio/minio:RELEASE.2023-03-22T06-36-24Z
quay.io/minio/mc:RELEASE.2022-11-07T23-47-39Z
12 changes: 9 additions & 3 deletions server/src/application/application-task.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,19 @@ export class ApplicationTaskService {
}

// Phase `Creating` -> `Created`
this.handleCreatingPhase()
this.handleCreatingPhase().catch((err) => {
this.logger.error(err)
})

// Phase `Deleting` -> `Deleted`
this.handleDeletingPhase()
this.handleDeletingPhase().catch((err) => {
this.logger.error(err)
})

// State `Deleted`
this.handleDeletedState()
this.handleDeletedState().catch((err) => {
this.logger.error(err)
})
}

/**
Expand Down
20 changes: 15 additions & 5 deletions server/src/gateway/bucket-domain-task.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,29 @@ export class BucketDomainTaskService {
}

// Phase `Creating` -> `Created`
this.handleCreatingPhase()
this.handleCreatingPhase().catch((err) => {
this.logger.error(err)
})

// Phase `Deleting` -> `Deleted`
this.handleDeletingPhase()
this.handleDeletingPhase().catch((err) => {
this.logger.error(err)
})

// Phase `Created` -> `Deleting`
this.handleInactiveState()
this.handleInactiveState().catch((err) => {
this.logger.error(err)
})

// Phase `Deleted` -> `Creating`
this.handleActiveState()
this.handleActiveState().catch((err) => {
this.logger.error(err)
})

// Phase `Deleting` -> `Deleted`
this.handleDeletedState()
this.handleDeletedState().catch((err) => {
this.logger.error(err)
})
}

/**
Expand Down
20 changes: 15 additions & 5 deletions server/src/gateway/runtime-domain-task.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,29 @@ export class RuntimeDomainTaskService {
}

// Phase `Creating` -> `Created`
this.handleCreatingPhase()
this.handleCreatingPhase().catch((err) => {
this.logger.error(err)
})

// Phase `Deleting` -> `Deleted`
this.handleDeletingPhase()
this.handleDeletingPhase().catch((err) => {
this.logger.error(err)
})

// Phase `Created` -> `Deleting`
this.handleInactiveState()
this.handleInactiveState().catch((err) => {
this.logger.error(err)
})

// Phase `Deleted` -> `Creating`
this.handleActiveState()
this.handleActiveState().catch((err) => {
this.logger.error(err)
})

// Phase `Deleting` -> `Deleted`
this.handleDeletedState()
this.handleDeletedState().catch((err) => {
this.logger.error(err)
})
}

/**
Expand Down
20 changes: 15 additions & 5 deletions server/src/gateway/website-task.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,29 @@ export class WebsiteTaskService {
}

// Phase `Creating` -> `Created`
this.handleCreatingPhase()
this.handleCreatingPhase().catch((err) => {
this.logger.error(err)
})

// Phase `Deleting` -> `Deleted`
this.handleDeletingPhase()
this.handleDeletingPhase().catch((err) => {
this.logger.error(err)
})

// Phase `Created` -> `Deleting`
this.handleInactiveState()
this.handleInactiveState().catch((err) => {
this.logger.error(err)
})

// Phase `Deleted` -> `Creating`
this.handleActiveState()
this.handleActiveState().catch((err) => {
this.logger.error(err)
})

// Phase `Deleting` -> `Deleted`
this.handleDeletedState()
this.handleDeletedState().catch((err) => {
this.logger.error(err)
})
}

/**
Expand Down
22 changes: 15 additions & 7 deletions server/src/storage/bucket-task.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
import { RegionService } from 'src/region/region.service'
import * as assert from 'node:assert'
import { Cron, CronExpression } from '@nestjs/schedule'
import { times } from 'lodash'
import { ServerConfig, TASK_LOCK_INIT_TIME } from 'src/constants'
import { SystemDatabase } from 'src/database/system-database'
import { MinioService } from './minio/minio.service'
Expand All @@ -17,7 +16,6 @@ import { BucketDomainService } from 'src/gateway/bucket-domain.service'
@Injectable()
export class BucketTaskService {
readonly lockTimeout = 30 // in second
readonly concurrency = 1 // concurrency count
private readonly logger = new Logger(BucketTaskService.name)

constructor(
Expand All @@ -33,19 +31,29 @@ export class BucketTaskService {
}

// Phase `Creating` -> `Created`
times(this.concurrency, () => this.handleCreatingPhase())
this.handleCreatingPhase().catch((err) => {
this.logger.error(err)
})

// Phase `Deleting` -> `Deleted`
times(this.concurrency, () => this.handleDeletingPhase())
this.handleDeletingPhase().catch((err) => {
this.logger.error(err)
})

// Phase `Created` -> `Deleting`
this.handleInactiveState()
this.handleInactiveState().catch((err) => {
this.logger.error(err)
})

// Phase `Deleted` -> `Creating`
this.handleActiveState()
this.handleActiveState().catch((err) => {
this.logger.error(err)
})

// Phase `Deleting` -> `Deleted`
this.handleDeletedState()
this.handleDeletedState().catch((err) => {
this.logger.error(err)
})
}

/**
Expand Down
6 changes: 6 additions & 0 deletions server/src/storage/bucket.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,12 @@ export class BucketController {
throw new HttpException('bucket not found', HttpStatus.NOT_FOUND)
}

if (bucket?.websiteHosting) {
return ResponseUtil.error(
'bucket has website hosting enabled, please delete it first',
)
}

const res = await this.bucketService.delete(bucket)
if (!res) {
return ResponseUtil.error('delete bucket failed')
Expand Down
8 changes: 2 additions & 6 deletions server/src/storage/storage.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,9 @@ export class StorageService {
await this.prisma.storageBucket.updateMany({
where: {
appid,
state: {
not: StorageState.Deleted,
},
},
data: {
state: StorageState.Deleted,
state: { not: StorageState.Deleted },
},
data: { state: StorageState.Deleted },
})

return
Expand Down