pod-overhead: add Overhead to RuntimeClass internal type

Signed-off-by: Eric Ernst <eric.ernst@intel.com>
This commit is contained in:
Eric Ernst
2019-04-23 16:57:58 -07:00
parent bcb046a443
commit 2c52cc3412
3 changed files with 89 additions and 0 deletions

View File

@@ -19,8 +19,13 @@ package validation
import (
"testing"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
utilfeature "k8s.io/apiserver/pkg/util/feature"
featuregatetesting "k8s.io/component-base/featuregate/testing"
"k8s.io/kubernetes/pkg/apis/core"
"k8s.io/kubernetes/pkg/apis/node"
"k8s.io/kubernetes/pkg/features"
"github.com/stretchr/testify/assert"
)
@@ -126,3 +131,58 @@ func TestValidateRuntimeUpdate(t *testing.T) {
})
}
}
func TestValidateOverhead(t *testing.T) {
defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.PodOverhead, true)()
successCase := []struct {
Name string
overhead *node.Overhead
}{
{
Name: "Overhead with valid cpu and memory resources",
overhead: &node.Overhead{
PodFixed: core.ResourceList{
core.ResourceName(core.ResourceCPU): resource.MustParse("10"),
core.ResourceName(core.ResourceMemory): resource.MustParse("10G"),
},
},
},
}
for _, tc := range successCase {
rc := &node.RuntimeClass{
ObjectMeta: metav1.ObjectMeta{Name: "foo"},
Handler: "bar",
Overhead: tc.overhead,
}
if errs := ValidateRuntimeClass(rc); len(errs) != 0 {
t.Errorf("%q unexpected error: %v", tc.Name, errs)
}
}
errorCase := []struct {
Name string
overhead *node.Overhead
}{
{
Name: "Invalid Resources",
overhead: &node.Overhead{
PodFixed: core.ResourceList{
core.ResourceName("my.org"): resource.MustParse("10m"),
},
},
},
}
for _, tc := range errorCase {
rc := &node.RuntimeClass{
ObjectMeta: metav1.ObjectMeta{Name: "foo"},
Handler: "bar",
Overhead: tc.overhead,
}
if errs := ValidateRuntimeClass(rc); len(errs) == 0 {
t.Errorf("%q expected error", tc.Name)
}
}
}