diff --git a/pkg/cmd/server/origin/master_config.go b/pkg/cmd/server/origin/master_config.go index 51a56b05500e..737b662a592f 100644 --- a/pkg/cmd/server/origin/master_config.go +++ b/pkg/cmd/server/origin/master_config.go @@ -13,7 +13,6 @@ import ( kapierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/labels" - "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/util/sets" "k8s.io/apiserver/pkg/admission" @@ -67,7 +66,6 @@ import ( admissionregistry "github.com/openshift/origin/pkg/cmd/server/origin/admission" originrest "github.com/openshift/origin/pkg/cmd/server/origin/rest" "github.com/openshift/origin/pkg/cmd/util/pluginconfig" - "github.com/openshift/origin/pkg/cmd/util/variable" imageadmission "github.com/openshift/origin/pkg/image/admission" imagepolicy "github.com/openshift/origin/pkg/image/admission/imagepolicy/api" imageapi "github.com/openshift/origin/pkg/image/apis/image" diff --git a/pkg/cmd/server/origin/storage.go b/pkg/cmd/server/origin/storage.go index 686755babfbf..a2600491eff7 100644 --- a/pkg/cmd/server/origin/storage.go +++ b/pkg/cmd/server/origin/storage.go @@ -30,7 +30,7 @@ import ( "github.com/openshift/origin/pkg/build/webhook/github" "github.com/openshift/origin/pkg/build/webhook/gitlab" deployapiv1 "github.com/openshift/origin/pkg/deploy/apis/apps/v1" - deployconfigregistry "github.com/openshift/origin/pkg/deploy/registry/deployconfig" + oappsclient "github.com/openshift/origin/pkg/deploy/generated/internalclientset" deployconfigetcd "github.com/openshift/origin/pkg/deploy/registry/deployconfig/etcd" deploylogregistry "github.com/openshift/origin/pkg/deploy/registry/deploylog" deployconfiginstantiate "github.com/openshift/origin/pkg/deploy/registry/instantiate" @@ -150,7 +150,6 @@ func (c OpenshiftAPIConfig) GetRestStorage() (map[schema.GroupVersion]map[string if err != nil { return nil, fmt.Errorf("error building REST storage: %v", err) } - deployConfigRegistry := deployconfigregistry.NewRegistry(deployConfigStorage) hostSubnetStorage, err := hostsubnetetcd.NewREST(c.GenericConfig.RESTOptionsGetter) if err != nil { @@ -260,13 +259,6 @@ func (c OpenshiftAPIConfig) GetRestStorage() (map[schema.GroupVersion]map[string Secrets: c.KubeClientInternal.Core(), } - deployRollbackClient := deployrollback.Client{ - DCFn: deployConfigRegistry.GetDeploymentConfig, - RCFn: clientDeploymentInterface{c.KubeClientInternal}.GetDeployment, - GRFn: deployrollback.NewRollbackGenerator().GenerateRollback, - } - deployConfigRollbackStorage := deployrollback.NewREST(c.DeprecatedOpenshiftClient, c.KubeClientInternal, externalVersionCodec) - projectStorage := projectproxy.NewREST(c.KubeClientInternal.Core().Namespaces(), c.ProjectAuthorizationCache, c.ProjectAuthorizationCache, c.ProjectCache) namespace, templateName, err := configapi.ParseNamespaceAndName(c.ProjectRequestTemplate) @@ -333,6 +325,20 @@ func (c OpenshiftAPIConfig) GetRestStorage() (map[schema.GroupVersion]map[string return nil, fmt.Errorf("error building REST storage: %v", err) } + originAppsClient, err := oappsclient.NewForConfig(c.GenericConfig.LoopbackClientConfig) + if err != nil { + return nil, err + } + coreClient, err := kclientset.NewForConfig(c.GenericConfig.LoopbackClientConfig) + if err != nil { + return nil, err + } + deployRollbackClient := deployrollback.Client{ + GRFn: deployrollback.NewRollbackGenerator().GenerateRollback, + DeploymentConfigGetter: originAppsClient.Apps(), + ReplicationControllerGetter: coreClient.Core(), + } + deployConfigRollbackStorage := deployrollback.NewREST(c.DeprecatedOpenshiftClient, c.KubeClientInternal, externalVersionCodec) storage := map[schema.GroupVersion]map[string]rest.Storage{ v1.SchemeGroupVersion: { // TODO: Deprecate these diff --git a/pkg/deploy/registry/deployconfig/etcd/etcd.go b/pkg/deploy/registry/deployconfig/etcd/etcd.go index 1f55dd836edd..5f5730a4b52c 100644 --- a/pkg/deploy/registry/deployconfig/etcd/etcd.go +++ b/pkg/deploy/registry/deployconfig/etcd/etcd.go @@ -51,16 +51,16 @@ func NewREST(optsGetter restoptions.Getter) (*REST, *StatusREST, *ScaleREST, err statusStore := *store statusStore.UpdateStrategy = deployconfig.StatusStrategy - statusREST := &StatusREST{store: &statusStore} - scaleREST := &ScaleREST{registry: deployconfig.NewRegistry(deploymentConfigREST)} + + scaleREST := &ScaleREST{store: store} return deploymentConfigREST, statusREST, scaleREST, nil } // ScaleREST contains the REST storage for the Scale subresource of DeploymentConfigs. type ScaleREST struct { - registry deployconfig.Registry + store *registry.Store } // ScaleREST implements Patcher @@ -73,20 +73,21 @@ func (r *ScaleREST) New() runtime.Object { // Get retrieves (computes) the Scale subresource for the given DeploymentConfig name. func (r *ScaleREST) Get(ctx apirequest.Context, name string, options *metav1.GetOptions) (runtime.Object, error) { - deploymentConfig, err := r.registry.GetDeploymentConfig(ctx, name, options) + deploymentConfig, err := r.store.Get(ctx, name, options) if err != nil { return nil, err } - return deployapi.ScaleFromConfig(deploymentConfig), nil + return deployapi.ScaleFromConfig(deploymentConfig.(*deployapi.DeploymentConfig)), nil } // Update scales the DeploymentConfig for the given Scale subresource, returning the updated Scale. func (r *ScaleREST) Update(ctx apirequest.Context, name string, objInfo rest.UpdatedObjectInfo) (runtime.Object, bool, error) { - deploymentConfig, err := r.registry.GetDeploymentConfig(ctx, name, &metav1.GetOptions{}) + uncastObj, err := r.store.Get(ctx, name, &metav1.GetOptions{}) if err != nil { return nil, false, errors.NewNotFound(extensions.Resource("scale"), name) } + deploymentConfig := uncastObj.(*deployapi.DeploymentConfig) old := deployapi.ScaleFromConfig(deploymentConfig) obj, err := objInfo.UpdatedObject(ctx, old) @@ -104,7 +105,7 @@ func (r *ScaleREST) Update(ctx apirequest.Context, name string, objInfo rest.Upd } deploymentConfig.Spec.Replicas = scale.Spec.Replicas - if err := r.registry.UpdateDeploymentConfig(ctx, deploymentConfig); err != nil { + if _, _, err := r.store.Update(ctx, deploymentConfig.Name, rest.DefaultUpdatedObjectInfo(deploymentConfig, kapi.Scheme)); err != nil { return nil, false, err } diff --git a/pkg/deploy/registry/deployconfig/etcd/etcd_test.go b/pkg/deploy/registry/deployconfig/etcd/etcd_test.go deleted file mode 100644 index aaf5b7f00206..000000000000 --- a/pkg/deploy/registry/deployconfig/etcd/etcd_test.go +++ /dev/null @@ -1,135 +0,0 @@ -package etcd - -import ( - "testing" - - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/fields" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/apimachinery/pkg/runtime" - etcdtesting "k8s.io/apiserver/pkg/storage/etcd/testing" - kapi "k8s.io/kubernetes/pkg/api" - "k8s.io/kubernetes/pkg/registry/registrytest" - - deployapi "github.com/openshift/origin/pkg/deploy/apis/apps" - _ "github.com/openshift/origin/pkg/deploy/apis/apps/install" - "github.com/openshift/origin/pkg/deploy/apis/apps/test" - "github.com/openshift/origin/pkg/deploy/registry/deployconfig" - "github.com/openshift/origin/pkg/util/restoptions" -) - -func newStorage(t *testing.T) (*REST, *etcdtesting.EtcdTestServer) { - etcdStorage, server := registrytest.NewEtcdStorage(t, "") - storage, _, _, err := NewREST(restoptions.NewSimpleGetter(etcdStorage)) - if err != nil { - t.Fatal(err) - } - return storage, server -} - -func TestStorage(t *testing.T) { - storage, _ := newStorage(t) - deployconfig.NewRegistry(storage) -} - -func validDeploymentConfig() *deployapi.DeploymentConfig { - return test.OkDeploymentConfig(1) -} - -func TestCreate(t *testing.T) { - storage, server := newStorage(t) - defer server.Terminate(t) - defer storage.Store.DestroyFunc() - test := registrytest.New(t, storage.Store) - valid := validDeploymentConfig() - valid.ObjectMeta = metav1.ObjectMeta{} - test.TestCreate( - valid, - // invalid - &deployapi.DeploymentConfig{}, - ) -} - -func TestUpdate(t *testing.T) { - storage, server := newStorage(t) - defer server.Terminate(t) - defer storage.Store.DestroyFunc() - test := registrytest.New(t, storage.Store) - test.TestUpdate( - validDeploymentConfig(), - // updateFunc - func(obj runtime.Object) runtime.Object { - object := obj.(*deployapi.DeploymentConfig) - object.Spec.Replicas = 2 - return object - }, - // invalid updateFunc - func(obj runtime.Object) runtime.Object { - object := obj.(*deployapi.DeploymentConfig) - object.Spec.Template = &kapi.PodTemplateSpec{} - return object - }, - func(obj runtime.Object) runtime.Object { - object := obj.(*deployapi.DeploymentConfig) - object.Spec.Replicas = -1 - return object - }, - ) -} - -func TestList(t *testing.T) { - storage, server := newStorage(t) - defer server.Terminate(t) - defer storage.Store.DestroyFunc() - test := registrytest.New(t, storage.Store) - test.TestList( - validDeploymentConfig(), - ) -} - -func TestGet(t *testing.T) { - storage, server := newStorage(t) - defer server.Terminate(t) - defer storage.Store.DestroyFunc() - test := registrytest.New(t, storage.Store) - test.TestGet( - validDeploymentConfig(), - ) -} - -func TestDelete(t *testing.T) { - storage, server := newStorage(t) - defer server.Terminate(t) - defer storage.Store.DestroyFunc() - test := registrytest.New(t, storage.Store) - test.TestDelete( - validDeploymentConfig(), - ) -} - -func TestWatch(t *testing.T) { - storage, server := newStorage(t) - defer server.Terminate(t) - defer storage.Store.DestroyFunc() - test := registrytest.New(t, storage.Store) - - valid := validDeploymentConfig() - valid.Name = "foo" - valid.Labels = map[string]string{"foo": "bar"} - - test.TestWatch( - valid, - // matching labels - []labels.Set{{"foo": "bar"}}, - // not matching labels - []labels.Set{{"foo": "baz"}}, - // matching fields - []fields.Set{ - {"metadata.name": "foo"}, - }, - // not matching fields - []fields.Set{ - {"metadata.name": "bar"}, - }, - ) -} diff --git a/pkg/deploy/registry/deployconfig/registry.go b/pkg/deploy/registry/deployconfig/registry.go deleted file mode 100644 index 5913ffb7da14..000000000000 --- a/pkg/deploy/registry/deployconfig/registry.go +++ /dev/null @@ -1,68 +0,0 @@ -package deployconfig - -import ( - metainternal "k8s.io/apimachinery/pkg/apis/meta/internalversion" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/watch" - apirequest "k8s.io/apiserver/pkg/endpoints/request" - "k8s.io/apiserver/pkg/registry/rest" - kapi "k8s.io/kubernetes/pkg/api" - - deployapi "github.com/openshift/origin/pkg/deploy/apis/apps" -) - -// Registry is an interface for things that know how to store DeploymentConfigs. -type Registry interface { - ListDeploymentConfigs(ctx apirequest.Context, options *metainternal.ListOptions) (*deployapi.DeploymentConfigList, error) - WatchDeploymentConfigs(ctx apirequest.Context, options *metainternal.ListOptions) (watch.Interface, error) - GetDeploymentConfig(ctx apirequest.Context, name string, options *metav1.GetOptions) (*deployapi.DeploymentConfig, error) - CreateDeploymentConfig(ctx apirequest.Context, deploymentConfig *deployapi.DeploymentConfig) error - UpdateDeploymentConfig(ctx apirequest.Context, deploymentConfig *deployapi.DeploymentConfig) error - DeleteDeploymentConfig(ctx apirequest.Context, name string) error -} - -// storage puts strong typing around storage calls -type storage struct { - rest.StandardStorage -} - -// NewRegistry returns a new Registry interface for the given Storage. Any mismatched -// types will panic. -func NewRegistry(s rest.StandardStorage) Registry { - return &storage{s} -} - -func (s *storage) ListDeploymentConfigs(ctx apirequest.Context, options *metainternal.ListOptions) (*deployapi.DeploymentConfigList, error) { - obj, err := s.List(ctx, options) - if err != nil { - return nil, err - } - return obj.(*deployapi.DeploymentConfigList), nil -} - -func (s *storage) WatchDeploymentConfigs(ctx apirequest.Context, options *metainternal.ListOptions) (watch.Interface, error) { - return s.Watch(ctx, options) -} - -func (s *storage) GetDeploymentConfig(ctx apirequest.Context, name string, options *metav1.GetOptions) (*deployapi.DeploymentConfig, error) { - obj, err := s.Get(ctx, name, options) - if err != nil { - return nil, err - } - return obj.(*deployapi.DeploymentConfig), nil -} - -func (s *storage) CreateDeploymentConfig(ctx apirequest.Context, deploymentConfig *deployapi.DeploymentConfig) error { - _, err := s.Create(ctx, deploymentConfig, false) - return err -} - -func (s *storage) UpdateDeploymentConfig(ctx apirequest.Context, deploymentConfig *deployapi.DeploymentConfig) error { - _, _, err := s.Update(ctx, deploymentConfig.Name, rest.DefaultUpdatedObjectInfo(deploymentConfig, kapi.Scheme)) - return err -} - -func (s *storage) DeleteDeploymentConfig(ctx apirequest.Context, name string) error { - _, _, err := s.Delete(ctx, name, nil) - return err -} diff --git a/pkg/deploy/registry/rollback/rest_deprecated.go b/pkg/deploy/registry/rollback/rest_deprecated.go index 4352ed28097c..51386503dcd5 100644 --- a/pkg/deploy/registry/rollback/rest_deprecated.go +++ b/pkg/deploy/registry/rollback/rest_deprecated.go @@ -10,9 +10,11 @@ import ( apirequest "k8s.io/apiserver/pkg/endpoints/request" "k8s.io/apiserver/pkg/registry/rest" kapi "k8s.io/kubernetes/pkg/api" + coreclient "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/typed/core/internalversion" deployapi "github.com/openshift/origin/pkg/deploy/apis/apps" "github.com/openshift/origin/pkg/deploy/apis/apps/validation" + deployclient "github.com/openshift/origin/pkg/deploy/generated/internalclientset/typed/apps/internalversion" deployutil "github.com/openshift/origin/pkg/deploy/util" ) @@ -31,24 +33,20 @@ type GeneratorClient interface { GetDeploymentConfig(ctx apirequest.Context, name string, options *metav1.GetOptions) (*deployapi.DeploymentConfig, error) } -// Client provides an implementation of Generator client type Client struct { - GRFn func(from, to *deployapi.DeploymentConfig, spec *deployapi.DeploymentConfigRollbackSpec) (*deployapi.DeploymentConfig, error) - RCFn func(ctx apirequest.Context, name string, options *metav1.GetOptions) (*kapi.ReplicationController, error) - DCFn func(ctx apirequest.Context, name string, options *metav1.GetOptions) (*deployapi.DeploymentConfig, error) + GRFn func(from, to *deployapi.DeploymentConfig, spec *deployapi.DeploymentConfigRollbackSpec) (*deployapi.DeploymentConfig, error) + DeploymentConfigGetter deployclient.DeploymentConfigsGetter + ReplicationControllerGetter coreclient.ReplicationControllersGetter } -// GetDeployment returns the deploymentConfig with the provided context and name func (c Client) GetDeploymentConfig(ctx apirequest.Context, name string, options *metav1.GetOptions) (*deployapi.DeploymentConfig, error) { - return c.DCFn(ctx, name, options) + return c.DeploymentConfigGetter.DeploymentConfigs(apirequest.NamespaceValue(ctx)).Get(name, *options) } -// GetDeployment returns the deployment with the provided context and name func (c Client) GetDeployment(ctx apirequest.Context, name string, options *metav1.GetOptions) (*kapi.ReplicationController, error) { - return c.RCFn(ctx, name, options) + return c.ReplicationControllerGetter.ReplicationControllers(apirequest.NamespaceValue(ctx)).Get(name, *options) } -// GenerateRollback generates a new deploymentConfig by merging a pair of deploymentConfigs func (c Client) GenerateRollback(from, to *deployapi.DeploymentConfig, spec *deployapi.DeploymentConfigRollbackSpec) (*deployapi.DeploymentConfig, error) { return c.GRFn(from, to, spec) } diff --git a/pkg/deploy/registry/rollback/rest_deprecated_test.go b/pkg/deploy/registry/rollback/rest_deprecated_test.go index e454b970badd..1be41df07f17 100644 --- a/pkg/deploy/registry/rollback/rest_deprecated_test.go +++ b/pkg/deploy/registry/rollback/rest_deprecated_test.go @@ -46,7 +46,7 @@ func TestCreateInvalidDepr(t *testing.T) { func TestCreateOkDepr(t *testing.T) { rest := DeprecatedREST{ - generator: Client{ + generator: TestClient{ GRFn: func(from, to *deployapi.DeploymentConfig, spec *deployapi.DeploymentConfigRollbackSpec) (*deployapi.DeploymentConfig, error) { return &deployapi.DeploymentConfig{}, nil }, @@ -85,7 +85,7 @@ func TestCreateOkDepr(t *testing.T) { func TestCreateGeneratorErrorDepr(t *testing.T) { rest := DeprecatedREST{ - generator: Client{ + generator: TestClient{ GRFn: func(from, to *deployapi.DeploymentConfig, spec *deployapi.DeploymentConfigRollbackSpec) (*deployapi.DeploymentConfig, error) { return nil, kerrors.NewInternalError(fmt.Errorf("something terrible happened")) }, @@ -116,7 +116,7 @@ func TestCreateGeneratorErrorDepr(t *testing.T) { func TestCreateMissingDeploymentDepr(t *testing.T) { rest := DeprecatedREST{ - generator: Client{ + generator: TestClient{ GRFn: func(from, to *deployapi.DeploymentConfig, spec *deployapi.DeploymentConfigRollbackSpec) (*deployapi.DeploymentConfig, error) { t.Fatal("unexpected call to generator") return nil, errors.New("something terrible happened") @@ -153,7 +153,7 @@ func TestCreateMissingDeploymentDepr(t *testing.T) { func TestCreateInvalidDeploymentDepr(t *testing.T) { rest := DeprecatedREST{ - generator: Client{ + generator: TestClient{ GRFn: func(from, to *deployapi.DeploymentConfig, spec *deployapi.DeploymentConfigRollbackSpec) (*deployapi.DeploymentConfig, error) { t.Fatal("unexpected call to generator") return nil, errors.New("something terrible happened") @@ -193,7 +193,7 @@ func TestCreateInvalidDeploymentDepr(t *testing.T) { func TestCreateMissingDeploymentConfigDepr(t *testing.T) { rest := DeprecatedREST{ - generator: Client{ + generator: TestClient{ GRFn: func(from, to *deployapi.DeploymentConfig, spec *deployapi.DeploymentConfigRollbackSpec) (*deployapi.DeploymentConfig, error) { t.Fatal("unexpected call to generator") return nil, errors.New("something terrible happened") @@ -229,6 +229,28 @@ func TestCreateMissingDeploymentConfigDepr(t *testing.T) { func TestNewDepr(t *testing.T) { // :) - rest := NewDeprecatedREST(Client{}, kapi.Codecs.LegacyCodec(deployv1.SchemeGroupVersion)) + rest := NewDeprecatedREST(TestClient{}, kapi.Codecs.LegacyCodec(deployv1.SchemeGroupVersion)) rest.New() } + +// Client provides an implementation of Generator client +type TestClient struct { + GRFn func(from, to *deployapi.DeploymentConfig, spec *deployapi.DeploymentConfigRollbackSpec) (*deployapi.DeploymentConfig, error) + RCFn func(ctx apirequest.Context, name string, options *metav1.GetOptions) (*kapi.ReplicationController, error) + DCFn func(ctx apirequest.Context, name string, options *metav1.GetOptions) (*deployapi.DeploymentConfig, error) +} + +// GetDeployment returns the deploymentConfig with the provided context and name +func (c TestClient) GetDeploymentConfig(ctx apirequest.Context, name string, options *metav1.GetOptions) (*deployapi.DeploymentConfig, error) { + return c.DCFn(ctx, name, options) +} + +// GetDeployment returns the deployment with the provided context and name +func (c TestClient) GetDeployment(ctx apirequest.Context, name string, options *metav1.GetOptions) (*kapi.ReplicationController, error) { + return c.RCFn(ctx, name, options) +} + +// GenerateRollback generates a new deploymentConfig by merging a pair of deploymentConfigs +func (c TestClient) GenerateRollback(from, to *deployapi.DeploymentConfig, spec *deployapi.DeploymentConfigRollbackSpec) (*deployapi.DeploymentConfig, error) { + return c.GRFn(from, to, spec) +} diff --git a/pkg/route/registry/route/registry.go b/pkg/route/registry/route/registry.go deleted file mode 100644 index 1fdc02237051..000000000000 --- a/pkg/route/registry/route/registry.go +++ /dev/null @@ -1,26 +0,0 @@ -package route - -import ( - metainternal "k8s.io/apimachinery/pkg/apis/meta/internalversion" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/watch" - apirequest "k8s.io/apiserver/pkg/endpoints/request" - - routeapi "github.com/openshift/origin/pkg/route/apis/route" -) - -// Registry is an interface for things that know how to store Routes. -type Registry interface { - // ListRoutes obtains list of routes that match a selector. - ListRoutes(ctx apirequest.Context, options *metainternal.ListOptions) (*routeapi.RouteList, error) - // GetRoute retrieves a specific route. - GetRoute(ctx apirequest.Context, routeID string, options *metav1.GetOptions) (*routeapi.Route, error) - // CreateRoute creates a new route. - CreateRoute(ctx apirequest.Context, route *routeapi.Route) error - // UpdateRoute updates a route. - UpdateRoute(ctx apirequest.Context, route *routeapi.Route) error - // DeleteRoute deletes a route. - DeleteRoute(ctx apirequest.Context, routeID string) error - // WatchRoutes watches for new/modified/deleted routes. - WatchRoutes(ctx apirequest.Context, options *metainternal.ListOptions) (watch.Interface, error) -} diff --git a/pkg/template/registry/template/etcd/etcd_test.go b/pkg/template/registry/template/etcd/etcd_test.go deleted file mode 100644 index 77bab7b31e25..000000000000 --- a/pkg/template/registry/template/etcd/etcd_test.go +++ /dev/null @@ -1,104 +0,0 @@ -package etcd - -import ( - "testing" - - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/fields" - "k8s.io/apimachinery/pkg/labels" - etcdtesting "k8s.io/apiserver/pkg/storage/etcd/testing" - "k8s.io/kubernetes/pkg/registry/registrytest" - - templateapi "github.com/openshift/origin/pkg/template/apis/template" - _ "github.com/openshift/origin/pkg/template/apis/template/install" - "github.com/openshift/origin/pkg/util/restoptions" -) - -func newStorage(t *testing.T) (*REST, *etcdtesting.EtcdTestServer) { - etcdStorage, server := registrytest.NewEtcdStorage(t, "") - storage, err := NewREST(restoptions.NewSimpleGetter(etcdStorage)) - if err != nil { - t.Fatal(err) - } - return storage, server -} - -func validTemplate() *templateapi.Template { - return &templateapi.Template{ - ObjectMeta: metav1.ObjectMeta{ - Name: "foo", - }, - } -} - -func TestCreate(t *testing.T) { - storage, server := newStorage(t) - defer server.Terminate(t) - defer storage.Store.DestroyFunc() - test := registrytest.New(t, storage.Store) - valid := validTemplate() - valid.Name = "" - valid.GenerateName = "test-" - test.TestCreate( - valid, - // invalid - &templateapi.Template{}, - ) -} - -func TestList(t *testing.T) { - storage, server := newStorage(t) - defer server.Terminate(t) - defer storage.Store.DestroyFunc() - test := registrytest.New(t, storage.Store) - test.TestList( - validTemplate(), - ) -} - -func TestGet(t *testing.T) { - storage, server := newStorage(t) - defer server.Terminate(t) - defer storage.Store.DestroyFunc() - test := registrytest.New(t, storage.Store) - test.TestGet( - validTemplate(), - ) -} - -func TestDelete(t *testing.T) { - storage, server := newStorage(t) - defer server.Terminate(t) - defer storage.Store.DestroyFunc() - test := registrytest.New(t, storage.Store).ReturnDeletedObject() - test.TestDelete( - validTemplate(), - ) -} - -func TestWatch(t *testing.T) { - storage, server := newStorage(t) - defer server.Terminate(t) - defer storage.Store.DestroyFunc() - test := registrytest.New(t, storage.Store) - - valid := validTemplate() - valid.Name = "foo" - valid.Labels = map[string]string{"foo": "bar"} - - test.TestWatch( - valid, - // matching labels - []labels.Set{{"foo": "bar"}}, - // not matching labels - []labels.Set{{"foo": "baz"}}, - // matching fields - []fields.Set{ - {"metadata.name": "foo"}, - }, - // not matching fields - []fields.Set{ - {"metadata.name": "bar"}, - }, - ) -}