Exemplo n.º 1
0
// Create registers the given Image.
func (s *REST) Create(obj interface{}) (<-chan interface{}, error) {
	image, ok := obj.(*api.Image)
	if !ok {
		return nil, fmt.Errorf("not an image: %#v", obj)
	}

	image.CreationTimestamp = util.Now()

	if errs := validation.ValidateImage(image); len(errs) > 0 {
		return nil, errors.NewInvalid("image", image.ID, errs)
	}

	return apiserver.MakeAsync(func() (interface{}, error) {
		if err := s.registry.CreateImage(image); err != nil {
			return nil, err
		}
		return s.Get(image.ID)
	}), nil
}
Exemplo n.º 2
0
// Validate validates a new image.
func (imageStrategy) Validate(ctx kapi.Context, obj runtime.Object) field.ErrorList {
	image := obj.(*api.Image)
	return validation.ValidateImage(image)
}