mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-29 21:29:24 +00:00
PetSet alpha controller
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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.")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user