PetSet alpha controller

This commit is contained in:
Prashanth Balasubramanian
2016-04-25 12:24:40 -07:00
parent 93e3df8e55
commit 6bc3052551
24 changed files with 2761 additions and 40 deletions

View File

@@ -86,13 +86,9 @@ func (petSetStrategy) AllowCreateOnUpdate() bool {
// ValidateUpdate is the default update validation for an end user.
func (petSetStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) field.ErrorList {
return field.ErrorList{field.Forbidden(field.NewPath("spec"), "updates to petset spec are forbidden.")}
// TODO: For now we're taking the safe route and disallowing all updates to spec.
// Enable on a case by case basis.
//validationErrorList := validation.ValidatePetSet(obj.(*apps.PetSet))
//updateErrorList := validation.ValidatePetSetUpdate(obj.(*apps.PetSet), old.(*apps.PetSet))
//return append(validationErrorList, updateErrorList...)
validationErrorList := validation.ValidatePetSet(obj.(*apps.PetSet))
updateErrorList := validation.ValidatePetSetUpdate(obj.(*apps.PetSet), old.(*apps.PetSet))
return append(validationErrorList, updateErrorList...)
}
// AllowUnconditionalUpdate is the default update policy for PetSet objects.

View File

@@ -64,6 +64,7 @@ func TestPetSetStrategy(t *testing.T) {
t.Errorf("Unexpected error validating %v", errs)
}
// Just Spec.Replicas is allowed to change
validPs := &apps.PetSet{
ObjectMeta: api.ObjectMeta{Name: ps.Name, Namespace: ps.Namespace},
Spec: apps.PetSetSpec{
@@ -74,6 +75,13 @@ func TestPetSetStrategy(t *testing.T) {
}
Strategy.PrepareForUpdate(validPs, ps)
errs = Strategy.ValidateUpdate(ctx, validPs, ps)
if len(errs) != 0 {
t.Errorf("Updating spec.Replicas is allowed on a petset.")
}
validPs.Spec.Selector = &unversioned.LabelSelector{MatchLabels: map[string]string{"a": "bar"}}
Strategy.PrepareForUpdate(validPs, ps)
errs = Strategy.ValidateUpdate(ctx, validPs, ps)
if len(errs) == 0 {
t.Errorf("Expected a validation error since updates are disallowed on petsets.")
}