adding validations on kubelet starting configurations

This commit is contained in:
huangjiuyuan
2017-08-01 14:28:04 +08:00
parent 657db0eae7
commit 39c61b0967
5 changed files with 190 additions and 5 deletions

View File

@@ -188,6 +188,14 @@ func IsValidPortNum(port int) []string {
return []string{InclusiveRangeError(1, 65535)}
}
// IsInRange tests that the argument is in an inclusive range.
func IsInRange(value int, min int, max int) []string {
if value >= min && value <= max {
return nil
}
return []string{InclusiveRangeError(min, max)}
}
// Now in libcontainer UID/GID limits is 0 ~ 1<<31 - 1
// TODO: once we have a type for UID/GID we should make these that type.
const (

View File

@@ -154,6 +154,30 @@ func TestIsValidPortNum(t *testing.T) {
}
}
func TestIsInRange(t *testing.T) {
goodValues := []struct {
value int
min int
max int
}{{1, 0, 10}, {5, 5, 20}, {25, 10, 25}}
for _, val := range goodValues {
if msgs := IsInRange(val.value, val.min, val.max); len(msgs) > 0 {
t.Errorf("expected no errors for %#v, but got %v", val, msgs)
}
}
badValues := []struct {
value int
min int
max int
}{{1, 2, 10}, {5, -4, 2}, {25, 100, 120}}
for _, val := range badValues {
if msgs := IsInRange(val.value, val.min, val.max); len(msgs) == 0 {
t.Errorf("expected errors for %#v", val)
}
}
}
func createGroupIDs(ids ...int64) []int64 {
var output []int64
for _, id := range ids {