Skip to content

Commit

Permalink
Internal errors are internal
Browse files Browse the repository at this point in the history
  • Loading branch information
thockin committed Dec 10, 2015
1 parent 7fb8f60 commit 872faff
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
15 changes: 10 additions & 5 deletions pkg/api/rest/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ limitations under the License.
package rest

import (
"fmt"

"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/errors"
"k8s.io/kubernetes/pkg/api/validation"
Expand Down Expand Up @@ -53,19 +55,19 @@ type RESTUpdateStrategy interface {
}

// TODO: add other common fields that require global validation.
func validateCommonFields(obj, old runtime.Object) field.ErrorList {
func validateCommonFields(obj, old runtime.Object) (field.ErrorList, error) {
allErrs := field.ErrorList{}
objectMeta, err := api.ObjectMetaFor(obj)
if err != nil {
return append(allErrs, field.InternalError(field.NewPath("metadata"), err))
return nil, fmt.Errorf("failed to get new object metadata: %v", err)
}
oldObjectMeta, err := api.ObjectMetaFor(old)
if err != nil {
return append(allErrs, field.InternalError(field.NewPath("metadata"), err))
return nil, fmt.Errorf("failed to get old object metadata: %v", err)
}
allErrs = append(allErrs, validation.ValidateObjectMetaUpdate(objectMeta, oldObjectMeta, field.NewPath("metadata"))...)

return allErrs
return allErrs, nil
}

// BeforeUpdate ensures that common operations for all resources are performed on update. It only returns
Expand All @@ -87,7 +89,10 @@ func BeforeUpdate(strategy RESTUpdateStrategy, ctx api.Context, obj, old runtime
strategy.PrepareForUpdate(obj, old)

// Ensure some common fields, like UID, are validated for all resources.
errs := validateCommonFields(obj, old)
errs, err := validateCommonFields(obj, old)
if err != nil {
return errors.NewInternalError(err)
}

errs = append(errs, strategy.ValidateUpdate(ctx, obj, old)...)
if len(errs) > 0 {
Expand Down
2 changes: 1 addition & 1 deletion pkg/registry/pod/etcd/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func (r *BindingREST) Create(ctx api.Context, obj runtime.Object) (out runtime.O
// TODO: move me to a binding strategy
if len(binding.Target.Kind) != 0 && binding.Target.Kind != "Node" {
// TODO: When validation becomes versioned, this gets more complicated.
return nil, errors.NewInvalid("binding", binding.Name, field.ErrorList{field.NotSupported(field.NewPath("target", "kind"), binding.Target.Kind, []string{"Node", ""})})
return nil, errors.NewInvalid("binding", binding.Name, field.ErrorList{field.NotSupported(field.NewPath("target", "kind"), binding.Target.Kind, []string{"Node", "<empty>"})})
}
if len(binding.Target.Name) == 0 {
// TODO: When validation becomes versioned, this gets more complicated.
Expand Down

0 comments on commit 872faff

Please sign in to comment.