This commit is contained in:
2026-10-16 15:23:28 +03:00
parent 8cde0e9371
commit 84164a72a4
32 changed files with 1019 additions and 260 deletions

View File

@@ -505,3 +505,65 @@ func migrateV2ModeValidator(fe validator.FieldLevel) bool {
fieldValue := fe.Field().String()
return IsInSlice(fieldValue, migrateV2ModeValues)
}
// pressureThresholdValidator checks if PressureThreshold is in range from 5 to 50
func pressureThresholdValidator(fe validator.FieldLevel) bool {
fieldValue := fe.Field().Uint()
return fieldValue >= uint64(pressureThresholdMin) && fieldValue <= uint64(pressureThresholdMax)
}
// deflateThresholdValidator checks if DeflateThreshold is in range from 10 to 70
func deflateThresholdValidator(fe validator.FieldLevel) bool {
fieldValue := fe.Field().Uint()
return fieldValue >= uint64(deflateThresholdMin) && fieldValue <= uint64(deflateThresholdMax)
}
func bufferPCTValidator(fe validator.FieldLevel) bool {
fieldValue := fe.Field().Uint()
return fieldValue >= uint64(bufferPCTMin) && fieldValue <= uint64(bufferPCTMax)
}
func guaranteedPCTValidator(fe validator.FieldLevel) bool {
fieldValue := fe.Field().Uint()
return fieldValue >= uint64(guaranteedPCTMin) && fieldValue <= uint64(guaranteedPCTMax)
}
func guaranteedABSMinValidator(fe validator.FieldLevel) bool {
fieldValue := fe.Field().Uint()
return fieldValue >= uint64(guaranteedABSMinMin) && fieldValue <= uint64(guaranteedABSMinMax)
}
func shrinkThresholdPCTValidator(fe validator.FieldLevel) bool {
fieldValue := fe.Field().Uint()
return fieldValue >= uint64(shrinkThresholdPCTMin) && fieldValue <= uint64(shrinkThresholdPCTMax)
}
func balloonMaxShrinkPCTValidator(fe validator.FieldLevel) bool {
fieldValue := fe.Field().Uint()
return fieldValue >= uint64(balloonMaxShrinkPCTMin) && fieldValue <= uint64(balloonMaxShrinkPCTMax)
}
func balloonMaxGrowPCTValidator(fe validator.FieldLevel) bool {
fieldValue := fe.Field().Uint()
return fieldValue >= uint64(balloonMaxGrowPCTMin) && fieldValue <= uint64(balloonMaxGrowPCTMax)
}
func vmChangeCooldownValidator(fe validator.FieldLevel) bool {
fieldValue := fe.Field().Uint()
return fieldValue >= uint64(vmChangeCooldownMin) && fieldValue <= uint64(vmChangeCooldownMax)
}
func emergencyReturnCooldownValidator(fe validator.FieldLevel) bool {
fieldValue := fe.Field().Uint()
return fieldValue >= uint64(emergencyReturnCooldownMin) && fieldValue <= uint64(emergencyReturnCooldownMax)
}
func majorFaultThresholdValidator(fe validator.FieldLevel) bool {
fieldValue := fe.Field().Uint()
return fieldValue >= uint64(majorFaultThresholdMin) && fieldValue <= uint64(majorFaultThresholdMax)
}
func logLevelValidator(fe validator.FieldLevel) bool {
fieldValue := fe.Field().String()
return IsInSlice(fieldValue, logLevelValues)
}

View File

@@ -338,5 +338,65 @@ func registerAllValidators(validate *validator.Validate) error {
err = validate.RegisterValidation("migrateV2Mode", migrateV2ModeValidator)
err = validate.RegisterValidation("pressureThreshold", pressureThresholdValidator)
if err != nil {
return err
}
err = validate.RegisterValidation("deflateThreshold", deflateThresholdValidator)
if err != nil {
return err
}
err = validate.RegisterValidation("bufferPCT", bufferPCTValidator)
if err != nil {
return err
}
err = validate.RegisterValidation("guaranteedPCT", guaranteedPCTValidator)
if err != nil {
return err
}
err = validate.RegisterValidation("guaranteedABSMin", guaranteedABSMinValidator)
if err != nil {
return err
}
err = validate.RegisterValidation("shrinkThresholdPCT", shrinkThresholdPCTValidator)
if err != nil {
return err
}
err = validate.RegisterValidation("balloonMaxShrinkPCT", balloonMaxShrinkPCTValidator)
if err != nil {
return err
}
err = validate.RegisterValidation("balloonMaxGrowPCT", balloonMaxGrowPCTValidator)
if err != nil {
return err
}
err = validate.RegisterValidation("vmChangeCooldown", vmChangeCooldownValidator)
if err != nil {
return err
}
err = validate.RegisterValidation("emergencyReturnCooldown", emergencyReturnCooldownValidator)
if err != nil {
return err
}
err = validate.RegisterValidation("majorFaultThreshold", majorFaultThresholdValidator)
if err != nil {
return err
}
err = validate.RegisterValidation("logLevel", logLevelValidator)
if err != nil {
return err
}
return nil
}

View File

@@ -86,6 +86,8 @@ var (
memoryBalloonModeValues = []string{"auto", "legacy", "none"}
migrateV2ModeValues = []string{"compute", "disks", "compute_and_disks"}
logLevelValues = []string{"DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"}
)
const (
@@ -94,4 +96,37 @@ const (
trunkTagsMin = 1
trunkTagsMax = 4095
pressureThresholdMin = 5
pressureThresholdMax = 50
deflateThresholdMin = 10
deflateThresholdMax = 70
bufferPCTMin = 5
bufferPCTMax = 50
guaranteedPCTMin = 10
guaranteedPCTMax = 50
guaranteedABSMinMin = 256
guaranteedABSMinMax = 4096
shrinkThresholdPCTMin = 30
shrinkThresholdPCTMax = 90
balloonMaxShrinkPCTMin = 5
balloonMaxShrinkPCTMax = 25
balloonMaxGrowPCTMin = 5
balloonMaxGrowPCTMax = 25
vmChangeCooldownMin = 30
vmChangeCooldownMax = 300
emergencyReturnCooldownMin = 60
emergencyReturnCooldownMax = 1800
majorFaultThresholdMin = 1
majorFaultThresholdMax = 10000
)