Add support for pre-allocated hugepages with 2 sizes

Remove the validation for pre-allocated hugepages on node level.
Validation is currently the only thing making it impossible to use
pre-allocated huge pages in more than one size.

We have now quite a few reports from real users that this feature is
welcome.
This commit is contained in:
Odin Ugedal
2019-09-18 11:39:25 +02:00
parent 0255614f29
commit 6e411b6c0a
5 changed files with 300 additions and 15 deletions

View File

@@ -17,9 +17,12 @@ limitations under the License.
package node
import (
"context"
"reflect"
"testing"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/fields"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/util/diff"
@@ -234,3 +237,107 @@ func TestDropFields(t *testing.T) {
}()
}
}
func TestValidateUpdate(t *testing.T) {
tests := []struct {
oldNode api.Node
node api.Node
valid bool
}{
{api.Node{
ObjectMeta: metav1.ObjectMeta{
Name: "hugepage-change-values-from-0",
},
Status: api.NodeStatus{
Capacity: api.ResourceList{
api.ResourceName("hugepages-2Mi"): resource.MustParse("0"),
api.ResourceName("hugepages-1Gi"): resource.MustParse("2Gi"),
},
},
}, api.Node{
ObjectMeta: metav1.ObjectMeta{
Name: "hugepage-change-values-from-0",
},
Status: api.NodeStatus{
Capacity: api.ResourceList{
api.ResourceName("hugepages-2Mi"): resource.MustParse("2Gi"),
api.ResourceName("hugepages-1Gi"): resource.MustParse("2Gi"),
},
},
}, false},
{api.Node{
ObjectMeta: metav1.ObjectMeta{
Name: "hugepage-change-values",
},
Status: api.NodeStatus{
Capacity: api.ResourceList{
api.ResourceName("hugepages-2Mi"): resource.MustParse("1Gi"),
api.ResourceName("hugepages-1Gi"): resource.MustParse("2Gi"),
},
},
}, api.Node{
ObjectMeta: metav1.ObjectMeta{
Name: "hugepage-change-values",
},
Status: api.NodeStatus{
Capacity: api.ResourceList{
api.ResourceName("hugepages-2Mi"): resource.MustParse("2Gi"),
api.ResourceName("hugepages-1Gi"): resource.MustParse("2Gi"),
},
},
}, true},
}
for i, test := range tests {
test.node.ObjectMeta.ResourceVersion = "1"
errs := (nodeStrategy{}).ValidateUpdate(context.Background(), &test.node, &test.oldNode)
if test.valid && len(errs) > 0 {
t.Errorf("%d: Unexpected error: %v", i, errs)
t.Logf("%#v vs %#v", test.oldNode.ObjectMeta, test.node.ObjectMeta)
}
if !test.valid && len(errs) == 0 {
t.Errorf("%d: Unexpected non-error", i)
}
}
}
func TestValidate(t *testing.T) {
tests := []struct {
node api.Node
valid bool
}{
{api.Node{
ObjectMeta: metav1.ObjectMeta{
Name: "one-hugepage-size",
},
Status: api.NodeStatus{
Capacity: api.ResourceList{
api.ResourceCPU: resource.MustParse("100"),
api.ResourceMemory: resource.MustParse("10000"),
api.ResourceName("hugepages-2Mi"): resource.MustParse("0"),
api.ResourceName("hugepages-1Gi"): resource.MustParse("2Gi"),
},
},
}, true},
{api.Node{
ObjectMeta: metav1.ObjectMeta{
Name: "multiple-hugepage-sizes",
},
Status: api.NodeStatus{
Capacity: api.ResourceList{
api.ResourceCPU: resource.MustParse("100"),
api.ResourceMemory: resource.MustParse("10000"),
api.ResourceName("hugepages-2Mi"): resource.MustParse("2Gi"),
api.ResourceName("hugepages-1Gi"): resource.MustParse("2Gi"),
},
},
}, false},
}
for i, test := range tests {
test.node.ObjectMeta.ResourceVersion = "1"
errs := (nodeStrategy{}).Validate(context.Background(), &test.node)
if test.valid && len(errs) > 0 {
t.Errorf("%d: Unexpected error: %v", i, errs)
}
if !test.valid && len(errs) == 0 {
t.Errorf("%d: Unexpected non-error", i)
}
}
}