Add more validation for updating node.
This commit is contained in:
@@ -535,3 +535,15 @@ func ValidateMinion(minion *api.Minion) errs.ValidationErrorList {
|
||||
allErrs = append(allErrs, validateLabels(minion.Labels)...)
|
||||
return allErrs
|
||||
}
|
||||
|
||||
// ValidateMinionUpdate tests to make sure a minion update can be applied. Modifies oldMinion.
|
||||
func ValidateMinionUpdate(oldMinion *api.Minion, minion *api.Minion) errs.ValidationErrorList {
|
||||
allErrs := errs.ValidationErrorList{}
|
||||
// TODO: why we need two labels for minion.
|
||||
oldMinion.Labels = minion.Labels
|
||||
oldMinion.ObjectMeta.Labels = minion.ObjectMeta.Labels
|
||||
if !reflect.DeepEqual(oldMinion, minion) {
|
||||
allErrs = append(allErrs, fmt.Errorf("Update contains more than labels changes"))
|
||||
}
|
||||
return allErrs
|
||||
}
|
||||
|
@@ -1065,3 +1065,62 @@ func TestValidateMinion(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateMinionUpdate(t *testing.T) {
|
||||
tests := []struct {
|
||||
oldMinion api.Minion
|
||||
minion api.Minion
|
||||
valid bool
|
||||
}{
|
||||
{api.Minion{}, api.Minion{}, true},
|
||||
{api.Minion{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: "foo"}},
|
||||
api.Minion{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: "bar"},
|
||||
}, false},
|
||||
{api.Minion{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: "foo",
|
||||
Labels: map[string]string{"foo": "bar"},
|
||||
},
|
||||
}, api.Minion{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: "foo",
|
||||
Labels: map[string]string{"foo": "baz"},
|
||||
},
|
||||
}, true},
|
||||
{api.Minion{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: "foo",
|
||||
},
|
||||
}, api.Minion{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: "foo",
|
||||
Labels: map[string]string{"foo": "baz"},
|
||||
},
|
||||
}, true},
|
||||
{api.Minion{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: "foo",
|
||||
Labels: map[string]string{"bar": "foo"},
|
||||
},
|
||||
}, api.Minion{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: "foo",
|
||||
Labels: map[string]string{"foo": "baz"},
|
||||
},
|
||||
}, true},
|
||||
}
|
||||
for _, test := range tests {
|
||||
errs := ValidateMinionUpdate(&test.oldMinion, &test.minion)
|
||||
if test.valid && len(errs) > 0 {
|
||||
t.Errorf("Unexpected error: %v", errs)
|
||||
t.Logf("%#v vs %#v", test.oldMinion.ObjectMeta, test.minion.ObjectMeta)
|
||||
}
|
||||
if !test.valid && len(errs) == 0 {
|
||||
t.Errorf("Unexpected non-error")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user