Skip to content

Commit

Permalink
fix(server): create hpa when hpa is not found (#1275)
Browse files Browse the repository at this point in the history
  • Loading branch information
0fatal authored Jun 17, 2023
1 parent eaad7ea commit c7469d3
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions server/src/instance/instance.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class InstanceService {
private readonly storageService: StorageService,
private readonly databaseService: DatabaseService,
private readonly applicationService: ApplicationService,
) {}
) { }

public async create(appid: string) {
const app = await this.applicationService.findOneUnsafe(appid)
Expand Down Expand Up @@ -500,15 +500,6 @@ export class InstanceService {
return spec
}

public async reapplyHorizontalPodAutoscalerByAppid(appid: string) {
const { hpa, app } = await this.get(appid)
if (!hpa) {
const labels = { [LABEL_KEY_APP_ID]: appid }
return await this.createHorizontalPodAutoscaler(app, labels)
}
return await this.reapplyHorizontalPodAutoscaler(app, hpa)
}

private async reapplyHorizontalPodAutoscaler(
app: ApplicationWithRelations,
oldHpa: V2HorizontalPodAutoscaler,
Expand All @@ -518,7 +509,6 @@ export class InstanceService {
const namespace = GetApplicationNamespaceByAppId(appid)

const hpa = oldHpa
hpa.spec = this.makeHorizontalPodAutoscalerSpec(app)

if (!app.bundle.autoscaling.enable) {
if (!hpa) return
Expand All @@ -528,11 +518,17 @@ export class InstanceService {
)
this.logger.log(`delete k8s hpa ${app.appid}`)
} else {
await hpaV2Api.replaceNamespacedHorizontalPodAutoscaler(
app.appid,
namespace,
hpa,
)
if (hpa) {
hpa.spec = this.makeHorizontalPodAutoscalerSpec(app)
await hpaV2Api.replaceNamespacedHorizontalPodAutoscaler(
app.appid,
namespace,
hpa,
)
} else {
const labels = { [LABEL_KEY_APP_ID]: appid }
await this.createHorizontalPodAutoscaler(app, labels)
}
this.logger.log(`reapply k8s hpa ${app.appid}`)
}
}
Expand Down

0 comments on commit c7469d3

Please sign in to comment.