Skip to content

Commit 11e1f4b

Browse files
Add Parameter for Percentage of up/down scaling (#28)
1 parent 9a845e6 commit 11e1f4b

File tree

7 files changed

+47
-5
lines changed

7 files changed

+47
-5
lines changed

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ maxMemory: 0
4242
minMemory: 0
4343
maxCPU: 0
4444
minCPU: 0
45+
minCPUIncreasePercentage: 0
46+
minCPUDecreasePercentage: 0
47+
minMemoryIncreasePercentage: 0
48+
minMemoryDecreasePercentage: 0
4549
cpuFactor: 1
4650
memoryFactor: 1
4751
logLevel: info
@@ -86,6 +90,15 @@ persistence:
8690
--min-cpu int (default 0)
8791
--min-memory int (default 0)
8892

93+
# Min CPU and Memory (%) the controller will count as a condition to resize requests.
94+
# For Example:
95+
# If reqsizer want so change from 5m to 10m, that's a 50% increase.
96+
# It will ignore this if min-cpu-increase-percentage is less than 50.
97+
--min-cpu-increase-percentage int (default 0)
98+
--min-memory-increase-percentage int (default 0)
99+
--min-cpu-decrease-percentage int (default 0)
100+
--min-memory-decrease-percentage int (default 0)
101+
89102
# Multiply requests when reconciling
90103
--cpu-factor float (default 1)
91104
--memory-factor float (default 1)

charts/kube-reqsizer/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ type: application
1313
# This is the chart version. This version number should be incremented each time you make changes
1414
# to the chart and its templates, including the app version.
1515
# Versions are expected to follow Semantic Versioning (https://semver.org/)
16-
version: 0.9.21
16+
version: 0.9.22
1717
dependencies:
1818
- name: redis
1919
condition: persistence.enabled

charts/kube-reqsizer/templates/deployment.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ spec:
3636
- --max-memory={{.Values.maxMemory}}
3737
- --min-cpu={{.Values.minCPU}}
3838
- --min-memory={{.Values.minMemory}}
39+
- --min-cpu-increase-percentage={{.Values.minCPUIncreasePercentage}}
40+
- --min-memory-increase-percentage={{.Values.minMemoryIncreasePercentage}}
41+
- --min-cpu-decreases-percentage={{.Values.minCPUDecreasePercentage}}
42+
- --min-memory-decrease-percentage={{.Values.minMemoryDecreasePercentage}}
3943
- --cpu-factor={{.Values.cpuFactor}}
4044
- --memory-factor={{.Values.memoryFactor}}
4145
- --concurrent-workers={{.Values.concurrentWorkers}}

charts/kube-reqsizer/values.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ maxMemory: 0
77
minMemory: 0
88
maxCPU: 0
99
minCPU: 0
10+
minCPUIncreasePercentage: 0
11+
minCPUDecreasePercentage: 0
12+
minMemoryIncreasePercentage: 0
13+
minMemoryDecreasePercentage: 0
1014
cpuFactor: 1
1115
memoryFactor: 1
1216
logLevel: info

controllers/pod_controller.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ type PodReconciler struct {
5757
MaxCPU int64
5858
MinMemory int64
5959
MinCPU int64
60+
MinCPUIncreasePercentage int64
61+
MinMemoryIncreasePercentage int64
62+
MinCPUDecreasePercentage int64
63+
MinMemoryDecreasePercentage int64
6064
CPUFactor float64
6165
MemoryFactor float64
6266
RedisClient rediscache.RedisClient

controllers/pod_controller_functions.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,17 @@ func (r *PodReconciler) ValidateCPU(currentCPU, AverageUsageCPU int64) bool {
115115
if AverageUsageCPU > currentCPU {
116116
if r.EnableIncrease {
117117
if (AverageUsageCPU <= r.MaxCPU) || (r.MaxCPU == 0) {
118-
return true
118+
// From 5 to 10
119+
// ((10-5)/10 * 100) >= 50%
120+
return ((float64(AverageUsageCPU-currentCPU) / float64(currentCPU)) * 100) >= float64(r.MinCPUIncreasePercentage)
119121
}
120122
}
121123
} else {
122124
if r.EnableReduce {
123125
if (AverageUsageCPU >= r.MinCPU) || (r.MinCPU == 0) {
124-
return true
126+
// From 10 to 5
127+
// ((10-5)/10 * 100) >= 50%
128+
return ((float64(currentCPU-AverageUsageCPU) / float64(currentCPU)) * 100) >= float64(r.MinCPUDecreasePercentage)
125129
}
126130
}
127131
}
@@ -134,13 +138,13 @@ func (r *PodReconciler) ValidateMemory(currentMemory, AverageUsageMemory int64)
134138
if AverageUsageMemory > currentMemory {
135139
if r.EnableIncrease {
136140
if (AverageUsageMemory <= r.MaxMemory) || (r.MaxMemory == 0) {
137-
return true
141+
return ((float64(AverageUsageMemory-currentMemory) / float64(currentMemory)) * 100) >= float64(r.MinMemoryIncreasePercentage)
138142
}
139143
}
140144
} else {
141145
if r.EnableReduce {
142146
if (AverageUsageMemory >= r.MinMemory) || (r.MinMemory == 0) {
143-
return true
147+
return ((float64(currentMemory-AverageUsageMemory) / float64(currentMemory)) * 100) >= float64(r.MinMemoryDecreasePercentage)
144148
}
145149
}
146150
}

main.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ func main() {
6565
var maxCPU int64
6666
var minMemory int64
6767
var minCPU int64
68+
var minCPUIncreasePercentage int64
69+
var minCPUDecreasePercentage int64
70+
var minMemoryIncreasePercentage int64
71+
var minMemoryDecreasePercentage int64
6872
var concurrentWorkers uint
6973

7074
var cpuFactor float64
@@ -82,6 +86,11 @@ func main() {
8286
flag.StringVar(&redisPassword, "redis-password", "", "Redis password")
8387
flag.UintVar(&redisDB, "redis-db", 0, "Redis DB number")
8488

89+
flag.Int64Var(&minCPUIncreasePercentage, "min-cpu-increase-percentage", 0, "Minimum difference in percentage that is required to increase CPU requests")
90+
flag.Int64Var(&minMemoryIncreasePercentage, "min-memory-increase-percentage", 0, "Minimum difference in percentage that is required to increase Memory requests")
91+
flag.Int64Var(&minCPUDecreasePercentage, "min-cpu-decrease-percentage", 0, "Minimum difference in percentage that is required to decrease CPU requests")
92+
flag.Int64Var(&minMemoryDecreasePercentage, "min-memory-decrease-percentage", 0, "Minimum difference in percentage that is required to decrease Memory requests")
93+
8594
flag.BoolVar(&enableIncrease, "enable-increase", true, "Enables the controller to increase pod requests")
8695
flag.BoolVar(&enableReduce, "enable-reduce", true, "Enables the controller to reduce pod requests")
8796
flag.Int64Var(&maxMemory, "max-memory", 0, "Maximum memory in (Mi) that the controller can set a pod request to. 0 is infinite")
@@ -160,6 +169,10 @@ func main() {
160169
MaxCPU: maxCPU,
161170
MinMemory: minMemory,
162171
MinCPU: minCPU,
172+
MinCPUIncreasePercentage: minCPUIncreasePercentage,
173+
MinMemoryIncreasePercentage: minMemoryIncreasePercentage,
174+
MinCPUDecreasePercentage: minCPUDecreasePercentage,
175+
MinMemoryDecreasePercentage: minMemoryDecreasePercentage,
163176
CPUFactor: cpuFactor,
164177
MemoryFactor: memoryFactor,
165178
RedisClient: rediscache.RedisClient{Client: redisClient},

0 commit comments

Comments
 (0)