Skip to content
This repository was archived by the owner on Apr 17, 2019. It is now read-only.

Commit 93247c5

Browse files
authored
Merge pull request #1195 from wojtek-t/nanny_change
Enable operating on microvalues in addong resizer
2 parents cefb6c1 + 15271d9 commit 93247c5

File tree

3 files changed

+42
-5
lines changed

3 files changed

+42
-5
lines changed

addon-resizer/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
OUT_DIR = build
2626
PACKAGE = k8s.io/contrib/addon-resizer
2727
PREFIX = gcr.io/google_containers
28-
TAG = 1.2
28+
TAG = 1.3
2929

3030
# Rules for building the real image for deployment to gcr.io
3131

addon-resizer/nanny/estimator.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ limitations under the License.
1717
package nanny
1818

1919
import (
20+
"fmt"
21+
2022
api "k8s.io/kubernetes/pkg/api/v1"
2123

2224
"k8s.io/kubernetes/pkg/api/resource"
@@ -61,10 +63,18 @@ func calculateResources(numNodes uint64, resources []Resource) *api.ResourceRequ
6163
limits := make(api.ResourceList)
6264
requests := make(api.ResourceList)
6365
for _, r := range resources {
64-
val := r.Base.MilliValue() + r.ExtraPerNode.MilliValue()*int64(numNodes)
65-
newRes := resource.NewMilliQuantity(val, r.Base.Format)
66-
limits[r.Name] = *newRes
67-
requests[r.Name] = *newRes
66+
// Since we want to enable passing values smaller than e.g. 1 millicore per node,
67+
// we need to have some more hacky solution here than operating on MilliValues.
68+
perNodeString := r.ExtraPerNode.String()
69+
var perNode float64
70+
read, _ := fmt.Sscanf(perNodeString, "%f", &perNode)
71+
overhead := resource.MustParse(fmt.Sprintf("%f%s", perNode*float64(numNodes), perNodeString[read:]))
72+
73+
newRes := r.Base
74+
newRes.Add(overhead)
75+
76+
limits[r.Name] = newRes
77+
requests[r.Name] = newRes
6878
}
6979
return &api.ResourceRequirements{
7080
Limits: limits,

addon-resizer/nanny/estimator_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,15 @@ var (
8585
},
8686
},
8787
}
88+
lessThanMilliEstimator = LinearEstimator{
89+
Resources: []Resource{
90+
{
91+
Base: resource.MustParse("0.3"),
92+
ExtraPerNode: resource.MustParse("0.5m"),
93+
Name: "cpu",
94+
},
95+
},
96+
}
8897
emptyEstimator = LinearEstimator{
8998
Resources: []Resource{},
9099
}
@@ -109,6 +118,16 @@ var (
109118
},
110119
ScaleFactor: 1.5,
111120
}
121+
exponentialLessThanMilliEstimator = ExponentialEstimator{
122+
Resources: []Resource{
123+
{
124+
Base: resource.MustParse("0.3"),
125+
ExtraPerNode: resource.MustParse("0.5m"),
126+
Name: "cpu",
127+
},
128+
},
129+
ScaleFactor: 1.5,
130+
}
112131

113132
baseResources = api.ResourceList{
114133
"cpu": resource.MustParse("0.3"),
@@ -145,6 +164,12 @@ var (
145164
"cpu": resource.MustParse("3.3"),
146165
"memory": resource.MustParse("33Mi"),
147166
}
167+
threeNodeLessThanMilliResources = api.ResourceList{
168+
"cpu": resource.MustParse("0.3015"),
169+
}
170+
threeNodeLessThanMilliExpResources = api.ResourceList{
171+
"cpu": resource.MustParse("0.308"),
172+
}
148173
noResources = api.ResourceList{}
149174

150175
sixteenNodeResources = api.ResourceList{
@@ -191,6 +216,7 @@ func TestEstimateResources(t *testing.T) {
191216
{noMemoryEstimator, 3, threeNodeNoMemoryResources, threeNodeNoMemoryResources},
192217
{noStorageEstimator, 0, noStorageBaseResources, noStorageBaseResources},
193218
{noStorageEstimator, 3, threeNodeNoStorageResources, threeNodeNoStorageResources},
219+
{lessThanMilliEstimator, 3, threeNodeLessThanMilliResources, threeNodeLessThanMilliResources},
194220
{emptyEstimator, 0, noResources, noResources},
195221
{emptyEstimator, 3, noResources, noResources},
196222
{exponentialEstimator, 0, sixteenNodeResources, sixteenNodeResources},
@@ -200,6 +226,7 @@ func TestEstimateResources(t *testing.T) {
200226
{exponentialEstimator, 17, twentyFourNodeResources, twentyFourNodeResources},
201227
{exponentialEstimator, 20, twentyFourNodeResources, twentyFourNodeResources},
202228
{exponentialEstimator, 24, twentyFourNodeResources, twentyFourNodeResources},
229+
{exponentialLessThanMilliEstimator, 3, threeNodeLessThanMilliExpResources, threeNodeLessThanMilliExpResources},
203230
}
204231

205232
for _, tc := range testCases {

0 commit comments

Comments
 (0)