Skip to content

Commit

Permalink
etcd storage redo
Browse files Browse the repository at this point in the history
  • Loading branch information
soltysh committed Jan 19, 2016
1 parent 7ec7fc1 commit 18a203e
Show file tree
Hide file tree
Showing 5 changed files with 1,293 additions and 1,662 deletions.
6 changes: 5 additions & 1 deletion pkg/image/api/v1/conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@ import (
kapi "k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/util"

_ "github.com/openshift/origin/pkg/api/latest"
newer "github.com/openshift/origin/pkg/image/api"
_ "github.com/openshift/origin/pkg/image/api/docker10"
_ "github.com/openshift/origin/pkg/image/api/dockerpre012"
_ "github.com/openshift/origin/pkg/image/api/install"
_ "github.com/openshift/origin/pkg/image/api/v1"
_ "github.com/openshift/origin/pkg/image/api/v1beta3"
testutil "github.com/openshift/origin/test/util/api"
)

Expand Down
78 changes: 25 additions & 53 deletions pkg/image/registry/image/etcd/etcd.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package etcd

import (
"errors"

kapi "k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/errors"
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/fields"
"k8s.io/kubernetes/pkg/labels"
"k8s.io/kubernetes/pkg/registry/generic"
etcdgeneric "k8s.io/kubernetes/pkg/registry/generic/etcd"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/storage"
Expand All @@ -18,65 +18,57 @@ import (

// REST implements a RESTStorage for images against etcd.
type REST struct {
store *etcdgeneric.Etcd
*etcdgeneric.Etcd
}

// NewREST returns a new REST.
func NewREST(s storage.Interface) *REST {
prefix := "/images"

store := &etcdgeneric.Etcd{
NewFunc: func() runtime.Object { return &api.Image{} },
NewFunc: func() runtime.Object { return &api.Image{} },

// NewListFunc returns an object capable of storing results of an etcd list.
NewListFunc: func() runtime.Object { return &api.ImageList{} },
// Produces a path that etcd understands, to the root of the resource
// by combining the namespace in the context with the given prefix.
// Yet images are not namespace scoped, so we're returning just prefix here.
KeyRootFunc: func(ctx kapi.Context) string {
// images are not namespace scoped
return prefix
},
// Produces a path that etcd understands, to the resource by combining
// the namespace in the context with the given prefix
// Yet images are not namespace scoped, so we're returning just prefix here.
KeyFunc: func(ctx kapi.Context, name string) (string, error) {
// images are not namespace scoped
return etcdgeneric.NoNamespaceKeyFunc(ctx, prefix, name)
},
// Retrieve the name field of an image
ObjectNameFunc: func(obj runtime.Object) (string, error) {
return obj.(*api.Image).Name, nil
},
// Used to match objects based on labels/fields for list and watch
PredicateFunc: func(label labels.Selector, field fields.Selector) generic.Matcher {
return image.MatchImage(label, field)
},
EndpointName: "image",

// Used to validate image creation
CreateStrategy: image.Strategy,

// Used to validate image updates
UpdateStrategy: image.Strategy,

ReturnDeletedObject: false,

Storage: s,
}
return &REST{store: store}
}

// New returns a new object
func (r *REST) New() runtime.Object {
return r.store.NewFunc()
}

// NewList returns a new list object
func (r *REST) NewList() runtime.Object {
return r.store.NewListFunc()
}

// List obtains a list of images with labels that match selector.
func (r *REST) List(ctx kapi.Context, options *unversioned.ListOptions) (runtime.Object, error) {
label := labels.Everything()
if options != nil && options.LabelSelector.Selector != nil {
label = options.LabelSelector.Selector
}
field := fields.Everything()
if options != nil && options.FieldSelector.Selector != nil {
field = options.FieldSelector.Selector
}
return r.store.ListPredicate(ctx, image.MatchImage(label, field), options)
return &REST{store}
}

// Watch begins watching for new, changed, or deleted images.
func (r *REST) Watch(ctx kapi.Context, options *unversioned.ListOptions) (watch.Interface, error) {
if !options.FieldSelector.Selector.Empty() {
return nil, errors.New("field selectors are not supported on images")
if options != nil && options.FieldSelector.Selector != nil {
return nil, errors.NewBadRequest("field selectors are not supported on images")
}
label := labels.Everything()
if options != nil && options.LabelSelector.Selector != nil {
Expand All @@ -87,25 +79,5 @@ func (r *REST) Watch(ctx kapi.Context, options *unversioned.ListOptions) (watch.
if options != nil {
resourceVersion = options.ResourceVersion
}
return r.store.WatchPredicate(ctx, image.MatchImage(label, field), resourceVersion)
}

// Get gets a specific image specified by its ID.
func (r *REST) Get(ctx kapi.Context, name string) (runtime.Object, error) {
return r.store.Get(ctx, name)
}

// Create creates an image based on a specification.
func (r *REST) Create(ctx kapi.Context, obj runtime.Object) (runtime.Object, error) {
return r.store.Create(ctx, obj)
}

// Update alters an existing image.
func (r *REST) Update(ctx kapi.Context, obj runtime.Object) (runtime.Object, bool, error) {
return r.store.Update(ctx, obj)
}

// Delete deletes an existing image specified by its ID.
func (r *REST) Delete(ctx kapi.Context, name string, options *kapi.DeleteOptions) (runtime.Object, error) {
return r.store.Delete(ctx, name, options)
return r.WatchPredicate(ctx, image.MatchImage(label, field), resourceVersion)
}
Loading

0 comments on commit 18a203e

Please sign in to comment.