Add more validation for updating node.

This commit is contained in:
Deyuan Deng
2014-11-17 13:22:27 -05:00
parent cc310e0e71
commit c20ceea170
5 changed files with 107 additions and 37 deletions

View File

@@ -105,16 +105,22 @@ func (rs *REST) Update(ctx api.Context, obj runtime.Object) (<-chan apiserver.RE
if !ok {
return nil, fmt.Errorf("not a minion: %#v", obj)
}
if errs := validation.ValidateMinion(minion); len(errs) > 0 {
// TODO: GetMinion will health check the minion, but we shouldn't require the minion to be
// running for updating labels.
oldMinion, err := rs.registry.GetMinion(ctx, minion.Name)
if err != nil {
return nil, err
}
if errs := validation.ValidateMinionUpdate(oldMinion, minion); len(errs) > 0 {
return nil, kerrors.NewInvalid("minion", minion.Name, errs)
}
return apiserver.MakeAsync(func() (runtime.Object, error) {
err := rs.registry.UpdateMinion(ctx, minion)
if err != nil {
return nil, err
}
// TODO: GetMinion will health check the minion, but we shouldn't require the minion to be
// running for updating labels.
return rs.registry.GetMinion(ctx, minion.Name)
}), nil
}