-
-
Notifications
You must be signed in to change notification settings - Fork 663
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(server): autoscaling for application (#1250)
* feat(server): autoscaling for application * refactor(server): make targetCPUUtilizationPercentage and targetMemoryUtilizationPercentage optional in autoscaling * refactor(server): reapply hpa immediately when config is changed * refactor(server): move autoscaling to application resource bundle * fix(server): add validation for CreateAutoscalingDto
- Loading branch information
Showing
11 changed files
with
319 additions
and
33 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger' | ||
import { | ||
IsBoolean, | ||
IsInt, | ||
IsNotEmpty, | ||
IsOptional, | ||
Max, | ||
Min, | ||
ValidateIf, | ||
} from 'class-validator' | ||
|
||
export class CreateAutoscalingDto { | ||
@ApiProperty({ default: false }) | ||
@IsNotEmpty() | ||
@IsBoolean() | ||
enable: boolean | ||
|
||
@ApiProperty({ default: 1 }) | ||
@IsNotEmpty() | ||
@IsInt() | ||
@Min(1) | ||
@Max(19) | ||
@ValidateIf(({ enable }) => enable) | ||
minReplicas: number | ||
|
||
@ApiProperty({ default: 5 }) | ||
@IsNotEmpty() | ||
@IsInt() | ||
@Min(2) | ||
@Max(20) | ||
@ValidateIf(({ enable }) => enable) | ||
maxReplicas: number | ||
|
||
@ApiPropertyOptional({ default: 50 }) | ||
@IsOptional() | ||
@IsInt() | ||
@Min(0) | ||
@Max(100) | ||
@ValidateIf(({ enable }) => enable) | ||
targetCPUUtilizationPercentage?: number | ||
|
||
@ApiPropertyOptional({ default: 50 }) | ||
@IsOptional() | ||
@IsInt() | ||
@Min(0) | ||
@Max(100) | ||
@ValidateIf(({ enable }) => enable) | ||
targetMemoryUtilizationPercentage?: number | ||
|
||
validate() { | ||
if (this.enable) { | ||
if (this.maxReplicas <= this.minReplicas) { | ||
return 'Max replicas must be smaller than min replicas.' | ||
} | ||
if ( | ||
!this.targetCPUUtilizationPercentage && | ||
!this.targetMemoryUtilizationPercentage | ||
) { | ||
return 'Either targetCPUUtilizationPercentage or targetMemoryUtilizationPercentage must be specified.' | ||
} | ||
if ( | ||
this.targetCPUUtilizationPercentage && | ||
this.targetMemoryUtilizationPercentage | ||
) { | ||
return 'TargetCPUUtilizationPercentage and TargetMemoryUtilizationPercentage cannot be specified simultaneously.' | ||
} | ||
} | ||
return null | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.