Skip to content

Commit

Permalink
支持 maxReplicas 为可选项
Browse files Browse the repository at this point in the history
默认MaxReplicas为6

Change-Id: I741d8f85ef0ada18a8c1945f8bb2a3d46439ef0a
  • Loading branch information
caoyingjunz committed Nov 17, 2024
1 parent 86a8fd2 commit ec2f32a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ metadata:
...
# 可选,默认 minReplicas 为 1
hpa.caoyingjunz.io/minReplicas: "2" # MINPODS
# 必填
# 可选,默认 maxReplicas 为 6
hpa.caoyingjunz.io/maxReplicas: "6" # MAXPODS
...

# 支持多种 TARGETS 类型,若开启,至少选择一种,可同时支持多个 TARGETS
# CPU, in cores. (500m = .5 cores)
# Memory, in bytes. (500Gi = 500GiB = 500 * 1024 * 1024 * 1024)
Expand Down
25 changes: 13 additions & 12 deletions pkg/controller/controller_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,27 +264,28 @@ func ManageByPixiuController(hpa *autoscalingv2.HorizontalPodAutoscaler) bool {
}

func extractReplicas(annotations map[string]string, replicasType string) (int32, error) {
var Replicas int64
var err error
var (
Replicas string
exists bool
)
switch replicasType {
case MinReplicas:
minReplicas, exists := annotations[MinReplicas]
Replicas, exists = annotations[MinReplicas]
if !exists {
// Default minReplicas is 1
return 1, nil
}
if Replicas, err = strconv.ParseInt(minReplicas, 10, 32); err != nil {
return 0, err
return 1, nil // Default minReplicas is 1
}
case MaxReplicas:
maxReplicas, exists := annotations[MaxReplicas]
Replicas, exists = annotations[MaxReplicas]
if !exists {
return 0, fmt.Errorf("%s is required", MaxReplicas)
return 6, nil // Default maxReplicas is 6
}
Replicas, err = strconv.ParseInt(maxReplicas, 10, 32)
}

return int32(Replicas), err
targetReplicas, err := strconv.ParseInt(Replicas, 10, 32)
if err != nil {
return 0, err
}
return int32(targetReplicas), err
}

func extractAverageUtilization(averageUtilization string) (int32, error) {
Expand Down

0 comments on commit ec2f32a

Please sign in to comment.