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

Commit 4865b21

Browse files
committed
Updated addon resizer to be compatible with the newest version of Kubernetes
1 parent d934146 commit 4865b21

File tree

3 files changed

+24
-20
lines changed

3 files changed

+24
-20
lines changed

addon-resizer/nanny/estimator.go

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ import (
2020
api "k8s.io/kubernetes/pkg/api/v1"
2121

2222
"k8s.io/kubernetes/pkg/api/resource"
23-
24-
inf "speter.net/go/exp/math/dec/inf"
2523
)
2624

2725
// Resource defines the name of a resource, the quantity, and the marginal value.
@@ -39,17 +37,10 @@ func (e LinearEstimator) scaleWithNodes(numNodes uint64) *api.ResourceRequiremen
3937
limits := make(api.ResourceList)
4038
requests := make(api.ResourceList)
4139
for _, r := range e.Resources {
42-
num := inf.NewDec(int64(numNodes), 0)
43-
num.Mul(num, r.ExtraPerNode.Amount)
44-
num.Add(num, r.Base.Amount)
45-
limits[r.Name] = resource.Quantity{
46-
Amount: num,
47-
Format: r.Base.Format,
48-
}
49-
requests[r.Name] = resource.Quantity{
50-
Amount: num,
51-
Format: r.Base.Format,
52-
}
40+
val := r.Base.MilliValue() + r.ExtraPerNode.MilliValue()*int64(numNodes)
41+
newRes := resource.NewMilliQuantity(val, r.Base.Format)
42+
limits[r.Name] = *newRes
43+
requests[r.Name] = *newRes
5344
}
5445
return &api.ResourceRequirements{
5546
Limits: limits,

addon-resizer/nanny/estimator_test.go

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

1919
import (
20-
"reflect"
2120
"testing"
2221

2322
resource "k8s.io/kubernetes/pkg/api/resource"
@@ -128,6 +127,21 @@ var (
128127
noResources = api.ResourceList{}
129128
)
130129

130+
func verifyResources(t *testing.T, kind string, got, want api.ResourceList) {
131+
if len(got) != len(want) {
132+
t.Errorf("%s not equal got: %+v want: %+v", kind, got, want)
133+
}
134+
for res, val := range want {
135+
actVal, ok := got[res]
136+
if !ok {
137+
t.Errorf("missing resource %s in %s", res, kind)
138+
}
139+
if val.Cmp(actVal) != 0 {
140+
t.Errorf("not equal resource %s in %s, got: %+v, want: %+v", res, kind, actVal, val)
141+
}
142+
}
143+
}
144+
131145
func TestEstimateResources(t *testing.T) {
132146
testCases := []struct {
133147
e ResourceEstimator
@@ -147,14 +161,13 @@ func TestEstimateResources(t *testing.T) {
147161
{emptyEstimator, 3, noResources, noResources},
148162
}
149163

150-
for i, tc := range testCases {
164+
for _, tc := range testCases {
151165
got := tc.e.scaleWithNodes(tc.numNodes)
152166
want := &api.ResourceRequirements{
153167
Limits: tc.limits,
154168
Requests: tc.requests,
155169
}
156-
if !reflect.DeepEqual(got, want) {
157-
t.Errorf("scaleWithNodes got %v, want %v in test case %d", got, want, i)
158-
}
170+
verifyResources(t, "limits", got.Limits, want.Limits)
171+
verifyResources(t, "requests", got.Requests, want.Limits)
159172
}
160173
}

addon-resizer/nanny/nanny_lib.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ import (
2424
"time"
2525

2626
log "github.com/golang/glog"
27+
inf "gopkg.in/inf.v0"
2728
api "k8s.io/kubernetes/pkg/api/v1"
28-
inf "speter.net/go/exp/math/dec/inf"
2929
)
3030

3131
// checkResource determines whether a specific resource needs to be over-written.
@@ -38,7 +38,7 @@ func checkResource(threshold int64, actual, expected api.ResourceList, res api.R
3838
if !ok && !expOk {
3939
return false
4040
}
41-
q := new(inf.Dec).QuoRound(val.Amount, expVal.Amount, 2, inf.RoundDown)
41+
q := new(inf.Dec).QuoRound(val.AsDec(), expVal.AsDec(), 2, inf.RoundDown)
4242
lower := inf.NewDec(100-threshold, 2)
4343
upper := inf.NewDec(100+threshold, 2)
4444
if q.Cmp(lower) == -1 || q.Cmp(upper) == 1 {

0 commit comments

Comments
 (0)