From 617078d220cfa28d35c519e5b91e7f42a0902467 Mon Sep 17 00:00:00 2001 From: Jordan Liggitt Date: Tue, 10 Jul 2018 17:15:38 -0400 Subject: [PATCH] Remove hand-written typed registries --- pkg/registry/apps/deployment/registry.go | 86 -------------- pkg/registry/apps/replicaset/registry.go | 95 ---------------- pkg/registry/apps/statefulset/registry.go | 94 ---------------- .../certificates/certificates/registry.go | 84 -------------- pkg/registry/core/configmap/registry.go | 93 ---------------- pkg/registry/core/endpoint/registry.go | 77 ------------- pkg/registry/core/namespace/registry.go | 83 -------------- pkg/registry/core/node/registry.go | 84 -------------- .../core/replicationcontroller/registry.go | 95 ---------------- pkg/registry/core/service/registry.go | 105 ------------------ .../networking/networkpolicy/registry.go | 84 -------------- .../scheduling/priorityclass/registry.go | 84 -------------- pkg/registry/settings/podpreset/registry.go | 84 -------------- .../pkg/registry/customresource/registry.go | 104 ----------------- 14 files changed, 1252 deletions(-) delete mode 100644 pkg/registry/apps/deployment/registry.go delete mode 100644 pkg/registry/apps/replicaset/registry.go delete mode 100644 pkg/registry/apps/statefulset/registry.go delete mode 100644 pkg/registry/certificates/certificates/registry.go delete mode 100644 pkg/registry/core/configmap/registry.go delete mode 100644 pkg/registry/core/endpoint/registry.go delete mode 100644 pkg/registry/core/namespace/registry.go delete mode 100644 pkg/registry/core/node/registry.go delete mode 100644 pkg/registry/core/replicationcontroller/registry.go delete mode 100644 pkg/registry/core/service/registry.go delete mode 100644 pkg/registry/networking/networkpolicy/registry.go delete mode 100644 pkg/registry/scheduling/priorityclass/registry.go delete mode 100644 pkg/registry/settings/podpreset/registry.go delete mode 100644 staging/src/k8s.io/apiextensions-apiserver/pkg/registry/customresource/registry.go diff --git a/pkg/registry/apps/deployment/registry.go b/pkg/registry/apps/deployment/registry.go deleted file mode 100644 index 6cce8f53e00..00000000000 --- a/pkg/registry/apps/deployment/registry.go +++ /dev/null @@ -1,86 +0,0 @@ -/* -Copyright 2014 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package deployment - -import ( - "context" - "fmt" - - metainternalversion "k8s.io/apimachinery/pkg/apis/meta/internalversion" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apiserver/pkg/registry/rest" - "k8s.io/kubernetes/pkg/apis/extensions" -) - -// Registry is an interface for things that know how to store Deployments. -type Registry interface { - ListDeployments(ctx context.Context, options *metainternalversion.ListOptions) (*extensions.DeploymentList, error) - GetDeployment(ctx context.Context, deploymentID string, options *metav1.GetOptions) (*extensions.Deployment, error) - CreateDeployment(ctx context.Context, deployment *extensions.Deployment, createValidation rest.ValidateObjectFunc, options *metav1.CreateOptions) (*extensions.Deployment, error) - UpdateDeployment(ctx context.Context, deployment *extensions.Deployment, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc, options *metav1.UpdateOptions) (*extensions.Deployment, error) - DeleteDeployment(ctx context.Context, deploymentID 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) ListDeployments(ctx context.Context, options *metainternalversion.ListOptions) (*extensions.DeploymentList, error) { - if options != nil && options.FieldSelector != nil && !options.FieldSelector.Empty() { - return nil, fmt.Errorf("field selector not supported yet") - } - obj, err := s.List(ctx, options) - if err != nil { - return nil, err - } - return obj.(*extensions.DeploymentList), err -} - -func (s *storage) GetDeployment(ctx context.Context, deploymentID string, options *metav1.GetOptions) (*extensions.Deployment, error) { - obj, err := s.Get(ctx, deploymentID, options) - if err != nil { - return nil, err - } - return obj.(*extensions.Deployment), nil -} - -func (s *storage) CreateDeployment(ctx context.Context, deployment *extensions.Deployment, createValidation rest.ValidateObjectFunc, options *metav1.CreateOptions) (*extensions.Deployment, error) { - obj, err := s.Create(ctx, deployment, createValidation, options) - if err != nil { - return nil, err - } - return obj.(*extensions.Deployment), nil -} - -func (s *storage) UpdateDeployment(ctx context.Context, deployment *extensions.Deployment, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc, options *metav1.UpdateOptions) (*extensions.Deployment, error) { - obj, _, err := s.Update(ctx, deployment.Name, rest.DefaultUpdatedObjectInfo(deployment), createValidation, updateValidation, false, options) - if err != nil { - return nil, err - } - return obj.(*extensions.Deployment), nil -} - -func (s *storage) DeleteDeployment(ctx context.Context, deploymentID string) error { - _, _, err := s.Delete(ctx, deploymentID, nil) - return err -} diff --git a/pkg/registry/apps/replicaset/registry.go b/pkg/registry/apps/replicaset/registry.go deleted file mode 100644 index 65b50a8a8e6..00000000000 --- a/pkg/registry/apps/replicaset/registry.go +++ /dev/null @@ -1,95 +0,0 @@ -/* -Copyright 2016 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// If you make changes to this file, you should also make the corresponding change in ReplicationController. - -package replicaset - -import ( - "context" - "fmt" - - metainternalversion "k8s.io/apimachinery/pkg/apis/meta/internalversion" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/apiserver/pkg/registry/rest" - "k8s.io/kubernetes/pkg/apis/extensions" -) - -// Registry is an interface for things that know how to store ReplicaSets. -type Registry interface { - ListReplicaSets(ctx context.Context, options *metainternalversion.ListOptions) (*extensions.ReplicaSetList, error) - WatchReplicaSets(ctx context.Context, options *metainternalversion.ListOptions) (watch.Interface, error) - GetReplicaSet(ctx context.Context, replicaSetID string, options *metav1.GetOptions) (*extensions.ReplicaSet, error) - CreateReplicaSet(ctx context.Context, replicaSet *extensions.ReplicaSet, createValidation rest.ValidateObjectFunc, options *metav1.CreateOptions) (*extensions.ReplicaSet, error) - UpdateReplicaSet(ctx context.Context, replicaSet *extensions.ReplicaSet, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc, options *metav1.UpdateOptions) (*extensions.ReplicaSet, error) - DeleteReplicaSet(ctx context.Context, replicaSetID 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) ListReplicaSets(ctx context.Context, options *metainternalversion.ListOptions) (*extensions.ReplicaSetList, error) { - if options != nil && options.FieldSelector != nil && !options.FieldSelector.Empty() { - return nil, fmt.Errorf("field selector not supported yet") - } - obj, err := s.List(ctx, options) - if err != nil { - return nil, err - } - return obj.(*extensions.ReplicaSetList), err -} - -func (s *storage) WatchReplicaSets(ctx context.Context, options *metainternalversion.ListOptions) (watch.Interface, error) { - return s.Watch(ctx, options) -} - -func (s *storage) GetReplicaSet(ctx context.Context, replicaSetID string, options *metav1.GetOptions) (*extensions.ReplicaSet, error) { - obj, err := s.Get(ctx, replicaSetID, options) - if err != nil { - return nil, err - } - return obj.(*extensions.ReplicaSet), nil -} - -func (s *storage) CreateReplicaSet(ctx context.Context, replicaSet *extensions.ReplicaSet, createValidation rest.ValidateObjectFunc, options *metav1.CreateOptions) (*extensions.ReplicaSet, error) { - obj, err := s.Create(ctx, replicaSet, createValidation, options) - if err != nil { - return nil, err - } - return obj.(*extensions.ReplicaSet), nil -} - -func (s *storage) UpdateReplicaSet(ctx context.Context, replicaSet *extensions.ReplicaSet, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc, options *metav1.UpdateOptions) (*extensions.ReplicaSet, error) { - obj, _, err := s.Update(ctx, replicaSet.Name, rest.DefaultUpdatedObjectInfo(replicaSet), createValidation, updateValidation, false, options) - if err != nil { - return nil, err - } - return obj.(*extensions.ReplicaSet), nil -} - -func (s *storage) DeleteReplicaSet(ctx context.Context, replicaSetID string) error { - _, _, err := s.Delete(ctx, replicaSetID, nil) - return err -} diff --git a/pkg/registry/apps/statefulset/registry.go b/pkg/registry/apps/statefulset/registry.go deleted file mode 100644 index 8c707a93b6d..00000000000 --- a/pkg/registry/apps/statefulset/registry.go +++ /dev/null @@ -1,94 +0,0 @@ -/* -Copyright 2017 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package statefulset - -import ( - "context" - "fmt" - - "k8s.io/apimachinery/pkg/api/errors" - metainternalversion "k8s.io/apimachinery/pkg/apis/meta/internalversion" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/apiserver/pkg/registry/rest" - "k8s.io/kubernetes/pkg/apis/apps" -) - -// Registry is an interface for things that know how to store StatefulSets. -type Registry interface { - ListStatefulSets(ctx context.Context, options *metainternalversion.ListOptions) (*apps.StatefulSetList, error) - WatchStatefulSets(ctx context.Context, options *metainternalversion.ListOptions) (watch.Interface, error) - GetStatefulSet(ctx context.Context, statefulSetID string, options *metav1.GetOptions) (*apps.StatefulSet, error) - CreateStatefulSet(ctx context.Context, statefulSet *apps.StatefulSet, createValidation rest.ValidateObjectFunc, options *metav1.CreateOptions) (*apps.StatefulSet, error) - UpdateStatefulSet(ctx context.Context, statefulSet *apps.StatefulSet, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc, options *metav1.UpdateOptions) (*apps.StatefulSet, error) - DeleteStatefulSet(ctx context.Context, statefulSetID 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) ListStatefulSets(ctx context.Context, options *metainternalversion.ListOptions) (*apps.StatefulSetList, error) { - if options != nil && options.FieldSelector != nil && !options.FieldSelector.Empty() { - return nil, fmt.Errorf("field selector not supported yet") - } - obj, err := s.List(ctx, options) - if err != nil { - return nil, err - } - return obj.(*apps.StatefulSetList), err -} - -func (s *storage) WatchStatefulSets(ctx context.Context, options *metainternalversion.ListOptions) (watch.Interface, error) { - return s.Watch(ctx, options) -} - -func (s *storage) GetStatefulSet(ctx context.Context, statefulSetID string, options *metav1.GetOptions) (*apps.StatefulSet, error) { - obj, err := s.Get(ctx, statefulSetID, options) - if err != nil { - return nil, errors.NewNotFound(apps.Resource("statefulsets/scale"), statefulSetID) - } - return obj.(*apps.StatefulSet), nil -} - -func (s *storage) CreateStatefulSet(ctx context.Context, statefulSet *apps.StatefulSet, createValidation rest.ValidateObjectFunc, options *metav1.CreateOptions) (*apps.StatefulSet, error) { - obj, err := s.Create(ctx, statefulSet, rest.ValidateAllObjectFunc, options) - if err != nil { - return nil, err - } - return obj.(*apps.StatefulSet), nil -} - -func (s *storage) UpdateStatefulSet(ctx context.Context, statefulSet *apps.StatefulSet, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc, options *metav1.UpdateOptions) (*apps.StatefulSet, error) { - obj, _, err := s.Update(ctx, statefulSet.Name, rest.DefaultUpdatedObjectInfo(statefulSet), createValidation, updateValidation, false, options) - if err != nil { - return nil, err - } - return obj.(*apps.StatefulSet), nil -} - -func (s *storage) DeleteStatefulSet(ctx context.Context, statefulSetID string) error { - _, _, err := s.Delete(ctx, statefulSetID, nil) - return err -} diff --git a/pkg/registry/certificates/certificates/registry.go b/pkg/registry/certificates/certificates/registry.go deleted file mode 100644 index dd93497d879..00000000000 --- a/pkg/registry/certificates/certificates/registry.go +++ /dev/null @@ -1,84 +0,0 @@ -/* -Copyright 2016 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package certificates - -import ( - "context" - - metainternalversion "k8s.io/apimachinery/pkg/apis/meta/internalversion" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/apiserver/pkg/registry/rest" - "k8s.io/kubernetes/pkg/apis/certificates" -) - -// Registry is an interface for things that know how to store CSRs. -type Registry interface { - ListCSRs(ctx context.Context, options *metainternalversion.ListOptions) (*certificates.CertificateSigningRequestList, error) - CreateCSR(ctx context.Context, csr *certificates.CertificateSigningRequest, createValidation rest.ValidateObjectFunc, options *metav1.CreateOptions) error - UpdateCSR(ctx context.Context, csr *certificates.CertificateSigningRequest, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc, options *metav1.UpdateOptions) error - GetCSR(ctx context.Context, csrID string, options *metav1.GetOptions) (*certificates.CertificateSigningRequest, error) - DeleteCSR(ctx context.Context, csrID string) error - WatchCSRs(ctx context.Context, options *metainternalversion.ListOptions) (watch.Interface, 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) ListCSRs(ctx context.Context, options *metainternalversion.ListOptions) (*certificates.CertificateSigningRequestList, error) { - obj, err := s.List(ctx, options) - if err != nil { - return nil, err - } - - return obj.(*certificates.CertificateSigningRequestList), nil -} - -func (s *storage) CreateCSR(ctx context.Context, csr *certificates.CertificateSigningRequest, createValidation rest.ValidateObjectFunc, options *metav1.CreateOptions) error { - _, err := s.Create(ctx, csr, createValidation, options) - return err -} - -func (s *storage) UpdateCSR(ctx context.Context, csr *certificates.CertificateSigningRequest, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc, options *metav1.UpdateOptions) error { - _, _, err := s.Update(ctx, csr.Name, rest.DefaultUpdatedObjectInfo(csr), createValidation, updateValidation, false, options) - return err -} - -func (s *storage) WatchCSRs(ctx context.Context, options *metainternalversion.ListOptions) (watch.Interface, error) { - return s.Watch(ctx, options) -} - -func (s *storage) GetCSR(ctx context.Context, name string, options *metav1.GetOptions) (*certificates.CertificateSigningRequest, error) { - obj, err := s.Get(ctx, name, options) - if err != nil { - return nil, err - } - return obj.(*certificates.CertificateSigningRequest), nil -} - -func (s *storage) DeleteCSR(ctx context.Context, name string) error { - _, _, err := s.Delete(ctx, name, nil) - return err -} diff --git a/pkg/registry/core/configmap/registry.go b/pkg/registry/core/configmap/registry.go deleted file mode 100644 index 5161517876b..00000000000 --- a/pkg/registry/core/configmap/registry.go +++ /dev/null @@ -1,93 +0,0 @@ -/* -Copyright 2015 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package configmap - -import ( - "context" - - metainternalversion "k8s.io/apimachinery/pkg/apis/meta/internalversion" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/apiserver/pkg/registry/rest" - api "k8s.io/kubernetes/pkg/apis/core" -) - -// Registry is an interface for things that know how to store ConfigMaps. -type Registry interface { - ListConfigMaps(ctx context.Context, options *metainternalversion.ListOptions) (*api.ConfigMapList, error) - WatchConfigMaps(ctx context.Context, options *metainternalversion.ListOptions) (watch.Interface, error) - GetConfigMap(ctx context.Context, name string, options *metav1.GetOptions) (*api.ConfigMap, error) - CreateConfigMap(ctx context.Context, cfg *api.ConfigMap, createValidation rest.ValidateObjectFunc, options *metav1.CreateOptions) (*api.ConfigMap, error) - UpdateConfigMap(ctx context.Context, cfg *api.ConfigMap, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc, options *metav1.UpdateOptions) (*api.ConfigMap, error) - DeleteConfigMap(ctx context.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) ListConfigMaps(ctx context.Context, options *metainternalversion.ListOptions) (*api.ConfigMapList, error) { - obj, err := s.List(ctx, options) - if err != nil { - return nil, err - } - - return obj.(*api.ConfigMapList), err -} - -func (s *storage) WatchConfigMaps(ctx context.Context, options *metainternalversion.ListOptions) (watch.Interface, error) { - return s.Watch(ctx, options) -} - -func (s *storage) GetConfigMap(ctx context.Context, name string, options *metav1.GetOptions) (*api.ConfigMap, error) { - obj, err := s.Get(ctx, name, options) - if err != nil { - return nil, err - } - - return obj.(*api.ConfigMap), nil -} - -func (s *storage) CreateConfigMap(ctx context.Context, cfg *api.ConfigMap, createValidation rest.ValidateObjectFunc, options *metav1.CreateOptions) (*api.ConfigMap, error) { - obj, err := s.Create(ctx, cfg, createValidation, options) - if err != nil { - return nil, err - } - - return obj.(*api.ConfigMap), nil -} - -func (s *storage) UpdateConfigMap(ctx context.Context, cfg *api.ConfigMap, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc, options *metav1.UpdateOptions) (*api.ConfigMap, error) { - obj, _, err := s.Update(ctx, cfg.Name, rest.DefaultUpdatedObjectInfo(cfg), createValidation, updateValidation, false, options) - if err != nil { - return nil, err - } - - return obj.(*api.ConfigMap), nil -} - -func (s *storage) DeleteConfigMap(ctx context.Context, name string) error { - _, _, err := s.Delete(ctx, name, nil) - return err -} diff --git a/pkg/registry/core/endpoint/registry.go b/pkg/registry/core/endpoint/registry.go deleted file mode 100644 index 0b4659de5ad..00000000000 --- a/pkg/registry/core/endpoint/registry.go +++ /dev/null @@ -1,77 +0,0 @@ -/* -Copyright 2014 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package endpoint - -import ( - "context" - - metainternalversion "k8s.io/apimachinery/pkg/apis/meta/internalversion" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/apiserver/pkg/registry/rest" - api "k8s.io/kubernetes/pkg/apis/core" -) - -// Registry is an interface for things that know how to store endpoints. -type Registry interface { - ListEndpoints(ctx context.Context, options *metainternalversion.ListOptions) (*api.EndpointsList, error) - GetEndpoints(ctx context.Context, name string, options *metav1.GetOptions) (*api.Endpoints, error) - WatchEndpoints(ctx context.Context, options *metainternalversion.ListOptions) (watch.Interface, error) - UpdateEndpoints(ctx context.Context, e *api.Endpoints, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc, options *metav1.UpdateOptions) error - DeleteEndpoints(ctx context.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) ListEndpoints(ctx context.Context, options *metainternalversion.ListOptions) (*api.EndpointsList, error) { - obj, err := s.List(ctx, options) - if err != nil { - return nil, err - } - return obj.(*api.EndpointsList), nil -} - -func (s *storage) WatchEndpoints(ctx context.Context, options *metainternalversion.ListOptions) (watch.Interface, error) { - return s.Watch(ctx, options) -} - -func (s *storage) GetEndpoints(ctx context.Context, name string, options *metav1.GetOptions) (*api.Endpoints, error) { - obj, err := s.Get(ctx, name, options) - if err != nil { - return nil, err - } - return obj.(*api.Endpoints), nil -} - -func (s *storage) UpdateEndpoints(ctx context.Context, endpoints *api.Endpoints, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc, options *metav1.UpdateOptions) error { - _, _, err := s.Update(ctx, endpoints.Name, rest.DefaultUpdatedObjectInfo(endpoints), createValidation, updateValidation, false, options) - return err -} - -func (s *storage) DeleteEndpoints(ctx context.Context, name string) error { - _, _, err := s.Delete(ctx, name, nil) - return err -} diff --git a/pkg/registry/core/namespace/registry.go b/pkg/registry/core/namespace/registry.go deleted file mode 100644 index 9abe821ca08..00000000000 --- a/pkg/registry/core/namespace/registry.go +++ /dev/null @@ -1,83 +0,0 @@ -/* -Copyright 2014 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package namespace - -import ( - "context" - - metainternalversion "k8s.io/apimachinery/pkg/apis/meta/internalversion" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/apiserver/pkg/registry/rest" - api "k8s.io/kubernetes/pkg/apis/core" -) - -// Registry is an interface implemented by things that know how to store Namespace objects. -type Registry interface { - ListNamespaces(ctx context.Context, options *metainternalversion.ListOptions) (*api.NamespaceList, error) - WatchNamespaces(ctx context.Context, options *metainternalversion.ListOptions) (watch.Interface, error) - GetNamespace(ctx context.Context, namespaceID string, options *metav1.GetOptions) (*api.Namespace, error) - CreateNamespace(ctx context.Context, namespace *api.Namespace, createValidation rest.ValidateObjectFunc, options *metav1.CreateOptions) error - UpdateNamespace(ctx context.Context, namespace *api.Namespace, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc, options *metav1.UpdateOptions) error - DeleteNamespace(ctx context.Context, namespaceID 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) ListNamespaces(ctx context.Context, options *metainternalversion.ListOptions) (*api.NamespaceList, error) { - obj, err := s.List(ctx, options) - if err != nil { - return nil, err - } - return obj.(*api.NamespaceList), nil -} - -func (s *storage) WatchNamespaces(ctx context.Context, options *metainternalversion.ListOptions) (watch.Interface, error) { - return s.Watch(ctx, options) -} - -func (s *storage) GetNamespace(ctx context.Context, namespaceName string, options *metav1.GetOptions) (*api.Namespace, error) { - obj, err := s.Get(ctx, namespaceName, options) - if err != nil { - return nil, err - } - return obj.(*api.Namespace), nil -} - -func (s *storage) CreateNamespace(ctx context.Context, namespace *api.Namespace, createValidation rest.ValidateObjectFunc, options *metav1.CreateOptions) error { - _, err := s.Create(ctx, namespace, createValidation, options) - return err -} - -func (s *storage) UpdateNamespace(ctx context.Context, namespace *api.Namespace, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc, options *metav1.UpdateOptions) error { - _, _, err := s.Update(ctx, namespace.Name, rest.DefaultUpdatedObjectInfo(namespace), createValidation, updateValidation, false, options) - return err -} - -func (s *storage) DeleteNamespace(ctx context.Context, namespaceID string) error { - _, _, err := s.Delete(ctx, namespaceID, nil) - return err -} diff --git a/pkg/registry/core/node/registry.go b/pkg/registry/core/node/registry.go deleted file mode 100644 index cfb27bdd721..00000000000 --- a/pkg/registry/core/node/registry.go +++ /dev/null @@ -1,84 +0,0 @@ -/* -Copyright 2014 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package node - -import ( - "context" - - metainternalversion "k8s.io/apimachinery/pkg/apis/meta/internalversion" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/apiserver/pkg/registry/rest" - api "k8s.io/kubernetes/pkg/apis/core" -) - -// Registry is an interface for things that know how to store node. -type Registry interface { - ListNodes(ctx context.Context, options *metainternalversion.ListOptions) (*api.NodeList, error) - CreateNode(ctx context.Context, node *api.Node, createValidation rest.ValidateObjectFunc, options *metav1.CreateOptions) error - UpdateNode(ctx context.Context, node *api.Node, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc, options *metav1.UpdateOptions) error - GetNode(ctx context.Context, nodeID string, options *metav1.GetOptions) (*api.Node, error) - DeleteNode(ctx context.Context, nodeID string) error - WatchNodes(ctx context.Context, options *metainternalversion.ListOptions) (watch.Interface, 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) ListNodes(ctx context.Context, options *metainternalversion.ListOptions) (*api.NodeList, error) { - obj, err := s.List(ctx, options) - if err != nil { - return nil, err - } - - return obj.(*api.NodeList), nil -} - -func (s *storage) CreateNode(ctx context.Context, node *api.Node, createValidation rest.ValidateObjectFunc, options *metav1.CreateOptions) error { - _, err := s.Create(ctx, node, createValidation, options) - return err -} - -func (s *storage) UpdateNode(ctx context.Context, node *api.Node, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc, options *metav1.UpdateOptions) error { - _, _, err := s.Update(ctx, node.Name, rest.DefaultUpdatedObjectInfo(node), createValidation, updateValidation, false, options) - return err -} - -func (s *storage) WatchNodes(ctx context.Context, options *metainternalversion.ListOptions) (watch.Interface, error) { - return s.Watch(ctx, options) -} - -func (s *storage) GetNode(ctx context.Context, name string, options *metav1.GetOptions) (*api.Node, error) { - obj, err := s.Get(ctx, name, options) - if err != nil { - return nil, err - } - return obj.(*api.Node), nil -} - -func (s *storage) DeleteNode(ctx context.Context, name string) error { - _, _, err := s.Delete(ctx, name, nil) - return err -} diff --git a/pkg/registry/core/replicationcontroller/registry.go b/pkg/registry/core/replicationcontroller/registry.go deleted file mode 100644 index 3edc3d104e3..00000000000 --- a/pkg/registry/core/replicationcontroller/registry.go +++ /dev/null @@ -1,95 +0,0 @@ -/* -Copyright 2014 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// If you make changes to this file, you should also make the corresponding change in ReplicaSet. - -package replicationcontroller - -import ( - "context" - "fmt" - - metainternalversion "k8s.io/apimachinery/pkg/apis/meta/internalversion" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/apiserver/pkg/registry/rest" - api "k8s.io/kubernetes/pkg/apis/core" -) - -// Registry is an interface for things that know how to store ReplicationControllers. -type Registry interface { - ListControllers(ctx context.Context, options *metainternalversion.ListOptions) (*api.ReplicationControllerList, error) - WatchControllers(ctx context.Context, options *metainternalversion.ListOptions) (watch.Interface, error) - GetController(ctx context.Context, controllerID string, options *metav1.GetOptions) (*api.ReplicationController, error) - CreateController(ctx context.Context, controller *api.ReplicationController, createValidation rest.ValidateObjectFunc, options *metav1.CreateOptions) (*api.ReplicationController, error) - UpdateController(ctx context.Context, controller *api.ReplicationController, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc, options *metav1.UpdateOptions) (*api.ReplicationController, error) - DeleteController(ctx context.Context, controllerID 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) ListControllers(ctx context.Context, options *metainternalversion.ListOptions) (*api.ReplicationControllerList, error) { - if options != nil && options.FieldSelector != nil && !options.FieldSelector.Empty() { - return nil, fmt.Errorf("field selector not supported yet") - } - obj, err := s.List(ctx, options) - if err != nil { - return nil, err - } - return obj.(*api.ReplicationControllerList), err -} - -func (s *storage) WatchControllers(ctx context.Context, options *metainternalversion.ListOptions) (watch.Interface, error) { - return s.Watch(ctx, options) -} - -func (s *storage) GetController(ctx context.Context, controllerID string, options *metav1.GetOptions) (*api.ReplicationController, error) { - obj, err := s.Get(ctx, controllerID, options) - if err != nil { - return nil, err - } - return obj.(*api.ReplicationController), nil -} - -func (s *storage) CreateController(ctx context.Context, controller *api.ReplicationController, createValidation rest.ValidateObjectFunc, options *metav1.CreateOptions) (*api.ReplicationController, error) { - obj, err := s.Create(ctx, controller, createValidation, options) - if err != nil { - return nil, err - } - return obj.(*api.ReplicationController), nil -} - -func (s *storage) UpdateController(ctx context.Context, controller *api.ReplicationController, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc, options *metav1.UpdateOptions) (*api.ReplicationController, error) { - obj, _, err := s.Update(ctx, controller.Name, rest.DefaultUpdatedObjectInfo(controller), createValidation, updateValidation, false, options) - if err != nil { - return nil, err - } - return obj.(*api.ReplicationController), nil -} - -func (s *storage) DeleteController(ctx context.Context, controllerID string) error { - _, _, err := s.Delete(ctx, controllerID, nil) - return err -} diff --git a/pkg/registry/core/service/registry.go b/pkg/registry/core/service/registry.go deleted file mode 100644 index cc7773199dd..00000000000 --- a/pkg/registry/core/service/registry.go +++ /dev/null @@ -1,105 +0,0 @@ -/* -Copyright 2014 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package service - -import ( - "context" - "fmt" - - metainternalversion "k8s.io/apimachinery/pkg/apis/meta/internalversion" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/apiserver/pkg/registry/rest" - api "k8s.io/kubernetes/pkg/apis/core" -) - -// Registry is an interface for things that know how to store services. -type Registry interface { - ListServices(ctx context.Context, options *metainternalversion.ListOptions) (*api.ServiceList, error) - CreateService(ctx context.Context, svc *api.Service, createValidation rest.ValidateObjectFunc, options *metav1.CreateOptions) (*api.Service, error) - GetService(ctx context.Context, name string, options *metav1.GetOptions) (*api.Service, error) - DeleteService(ctx context.Context, name string) error - UpdateService(ctx context.Context, svc *api.Service, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc, options *metav1.UpdateOptions) (*api.Service, error) - WatchServices(ctx context.Context, options *metainternalversion.ListOptions) (watch.Interface, error) - ExportService(ctx context.Context, name string, options metav1.ExportOptions) (*api.Service, 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) ListServices(ctx context.Context, options *metainternalversion.ListOptions) (*api.ServiceList, error) { - obj, err := s.List(ctx, options) - if err != nil { - return nil, err - } - return obj.(*api.ServiceList), nil -} - -func (s *storage) CreateService(ctx context.Context, svc *api.Service, createValidation rest.ValidateObjectFunc, options *metav1.CreateOptions) (*api.Service, error) { - obj, err := s.Create(ctx, svc, createValidation, options) - if err != nil { - return nil, err - } - return obj.(*api.Service), nil -} - -func (s *storage) GetService(ctx context.Context, name string, options *metav1.GetOptions) (*api.Service, error) { - obj, err := s.Get(ctx, name, options) - if err != nil { - return nil, err - } - return obj.(*api.Service), nil -} - -func (s *storage) DeleteService(ctx context.Context, name string) error { - _, _, err := s.Delete(ctx, name, nil) - return err -} - -func (s *storage) UpdateService(ctx context.Context, svc *api.Service, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc, options *metav1.UpdateOptions) (*api.Service, error) { - obj, _, err := s.Update(ctx, svc.Name, rest.DefaultUpdatedObjectInfo(svc), createValidation, updateValidation, false, options) - if err != nil { - return nil, err - } - return obj.(*api.Service), nil -} - -func (s *storage) WatchServices(ctx context.Context, options *metainternalversion.ListOptions) (watch.Interface, error) { - return s.Watch(ctx, options) -} - -// If StandardStorage implements rest.Exporter, returns exported service. -// Otherwise export is not supported. -func (s *storage) ExportService(ctx context.Context, name string, options metav1.ExportOptions) (*api.Service, error) { - exporter, isExporter := s.StandardStorage.(rest.Exporter) - if !isExporter { - return nil, fmt.Errorf("export is not supported") - } - obj, err := exporter.Export(ctx, name, options) - if err != nil { - return nil, err - } - return obj.(*api.Service), nil -} diff --git a/pkg/registry/networking/networkpolicy/registry.go b/pkg/registry/networking/networkpolicy/registry.go deleted file mode 100644 index 796515f4c98..00000000000 --- a/pkg/registry/networking/networkpolicy/registry.go +++ /dev/null @@ -1,84 +0,0 @@ -/* -Copyright 2017 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package networkpolicy - -import ( - "context" - - metainternalversion "k8s.io/apimachinery/pkg/apis/meta/internalversion" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/apiserver/pkg/registry/rest" - "k8s.io/kubernetes/pkg/apis/networking" -) - -// Registry is an interface for things that know how to store NetworkPolicies. -type Registry interface { - ListNetworkPolicies(ctx context.Context, options *metainternalversion.ListOptions) (*networking.NetworkPolicyList, error) - CreateNetworkPolicy(ctx context.Context, np *networking.NetworkPolicy, createValidation rest.ValidateObjectFunc) error - UpdateNetworkPolicy(ctx context.Context, np *networking.NetworkPolicy, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc, options *metav1.UpdateOptions) error - GetNetworkPolicy(ctx context.Context, name string, options *metav1.GetOptions) (*networking.NetworkPolicy, error) - DeleteNetworkPolicy(ctx context.Context, name string) error - WatchNetworkPolicies(ctx context.Context, options *metainternalversion.ListOptions) (watch.Interface, 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) ListNetworkPolicies(ctx context.Context, options *metainternalversion.ListOptions) (*networking.NetworkPolicyList, error) { - obj, err := s.List(ctx, options) - if err != nil { - return nil, err - } - - return obj.(*networking.NetworkPolicyList), nil -} - -func (s *storage) CreateNetworkPolicy(ctx context.Context, np *networking.NetworkPolicy, createValidation rest.ValidateObjectFunc) error { - _, err := s.Create(ctx, np, createValidation, &metav1.CreateOptions{}) - return err -} - -func (s *storage) UpdateNetworkPolicy(ctx context.Context, np *networking.NetworkPolicy, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc, options *metav1.UpdateOptions) error { - _, _, err := s.Update(ctx, np.Name, rest.DefaultUpdatedObjectInfo(np), createValidation, updateValidation, false, options) - return err -} - -func (s *storage) WatchNetworkPolicies(ctx context.Context, options *metainternalversion.ListOptions) (watch.Interface, error) { - return s.Watch(ctx, options) -} - -func (s *storage) GetNetworkPolicy(ctx context.Context, name string, options *metav1.GetOptions) (*networking.NetworkPolicy, error) { - obj, err := s.Get(ctx, name, options) - if err != nil { - return nil, err - } - return obj.(*networking.NetworkPolicy), nil -} - -func (s *storage) DeleteNetworkPolicy(ctx context.Context, name string) error { - _, _, err := s.Delete(ctx, name, nil) - return err -} diff --git a/pkg/registry/scheduling/priorityclass/registry.go b/pkg/registry/scheduling/priorityclass/registry.go deleted file mode 100644 index 2c7072d0c24..00000000000 --- a/pkg/registry/scheduling/priorityclass/registry.go +++ /dev/null @@ -1,84 +0,0 @@ -/* -Copyright 2017 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package priorityclass - -import ( - "context" - - metainternalversion "k8s.io/apimachinery/pkg/apis/meta/internalversion" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/apiserver/pkg/registry/rest" - "k8s.io/kubernetes/pkg/apis/scheduling" -) - -// Registry is an interface for things that know how to store PriorityClass. -type Registry interface { - ListPriorityClasses(ctx context.Context, options *metainternalversion.ListOptions) (*scheduling.PriorityClassList, error) - CreatePriorityClass(ctx context.Context, pc *scheduling.PriorityClass, createValidation rest.ValidateObjectFunc, options *metav1.CreateOptions) error - UpdatePriorityClass(ctx context.Context, pc *scheduling.PriorityClass, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc, options *metav1.UpdateOptions) error - GetPriorityClass(ctx context.Context, name string, options *metav1.GetOptions) (*scheduling.PriorityClass, error) - DeletePriorityClass(ctx context.Context, name string) error - WatchPriorityClasses(ctx context.Context, options *metainternalversion.ListOptions) (watch.Interface, 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) ListPriorityClasses(ctx context.Context, options *metainternalversion.ListOptions) (*scheduling.PriorityClassList, error) { - obj, err := s.List(ctx, options) - if err != nil { - return nil, err - } - - return obj.(*scheduling.PriorityClassList), nil -} - -func (s *storage) CreatePriorityClass(ctx context.Context, pc *scheduling.PriorityClass, createValidation rest.ValidateObjectFunc, options *metav1.CreateOptions) error { - _, err := s.Create(ctx, pc, createValidation, options) - return err -} - -func (s *storage) UpdatePriorityClass(ctx context.Context, pc *scheduling.PriorityClass, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc, options *metav1.UpdateOptions) error { - _, _, err := s.Update(ctx, pc.Name, rest.DefaultUpdatedObjectInfo(pc), createValidation, updateValidation, false, options) - return err -} - -func (s *storage) WatchPriorityClasses(ctx context.Context, options *metainternalversion.ListOptions) (watch.Interface, error) { - return s.Watch(ctx, options) -} - -func (s *storage) GetPriorityClass(ctx context.Context, name string, options *metav1.GetOptions) (*scheduling.PriorityClass, error) { - obj, err := s.Get(ctx, name, options) - if err != nil { - return nil, err - } - return obj.(*scheduling.PriorityClass), nil -} - -func (s *storage) DeletePriorityClass(ctx context.Context, name string) error { - _, _, err := s.Delete(ctx, name, nil) - return err -} diff --git a/pkg/registry/settings/podpreset/registry.go b/pkg/registry/settings/podpreset/registry.go deleted file mode 100644 index 39fc6a78ce4..00000000000 --- a/pkg/registry/settings/podpreset/registry.go +++ /dev/null @@ -1,84 +0,0 @@ -/* -Copyright 2016 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package podpreset - -import ( - "context" - - metainternalversion "k8s.io/apimachinery/pkg/apis/meta/internalversion" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/apiserver/pkg/registry/rest" - "k8s.io/kubernetes/pkg/apis/settings" -) - -// Registry is an interface for things that know how to store PodPresets. -type Registry interface { - ListPodPresets(ctx context.Context, options *metainternalversion.ListOptions) (*settings.PodPresetList, error) - CreatePodPreset(ctx context.Context, pp *settings.PodPreset, createValidation rest.ValidateObjectFunc, options *metav1.CreateOptions) error - UpdatePodPreset(ctx context.Context, pp *settings.PodPreset, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc, options *metav1.UpdateOptions) error - GetPodPreset(ctx context.Context, ppID string, options *metav1.GetOptions) (*settings.PodPreset, error) - DeletePodPreset(ctx context.Context, ppID string) error - WatchPodPresets(ctx context.Context, options *metainternalversion.ListOptions) (watch.Interface, 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) ListPodPresets(ctx context.Context, options *metainternalversion.ListOptions) (*settings.PodPresetList, error) { - obj, err := s.List(ctx, options) - if err != nil { - return nil, err - } - - return obj.(*settings.PodPresetList), nil -} - -func (s *storage) CreatePodPreset(ctx context.Context, pp *settings.PodPreset, createValidation rest.ValidateObjectFunc, options *metav1.CreateOptions) error { - _, err := s.Create(ctx, pp, createValidation, options) - return err -} - -func (s *storage) UpdatePodPreset(ctx context.Context, pp *settings.PodPreset, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc, options *metav1.UpdateOptions) error { - _, _, err := s.Update(ctx, pp.Name, rest.DefaultUpdatedObjectInfo(pp), createValidation, updateValidation, false, options) - return err -} - -func (s *storage) WatchPodPresets(ctx context.Context, options *metainternalversion.ListOptions) (watch.Interface, error) { - return s.Watch(ctx, options) -} - -func (s *storage) GetPodPreset(ctx context.Context, name string, options *metav1.GetOptions) (*settings.PodPreset, error) { - obj, err := s.Get(ctx, name, options) - if err != nil { - return nil, err - } - return obj.(*settings.PodPreset), nil -} - -func (s *storage) DeletePodPreset(ctx context.Context, name string) error { - _, _, err := s.Delete(ctx, name, nil) - return err -} diff --git a/staging/src/k8s.io/apiextensions-apiserver/pkg/registry/customresource/registry.go b/staging/src/k8s.io/apiextensions-apiserver/pkg/registry/customresource/registry.go deleted file mode 100644 index f722058f324..00000000000 --- a/staging/src/k8s.io/apiextensions-apiserver/pkg/registry/customresource/registry.go +++ /dev/null @@ -1,104 +0,0 @@ -/* -Copyright 2018 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package customresource - -import ( - "context" - "fmt" - "strings" - - "k8s.io/apimachinery/pkg/api/errors" - metainternalversion "k8s.io/apimachinery/pkg/apis/meta/internalversion" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" - "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/apiserver/pkg/registry/rest" -) - -// Registry is an interface for things that know how to store CustomResources. -type Registry interface { - ListCustomResources(ctx context.Context, options *metainternalversion.ListOptions) (*unstructured.UnstructuredList, error) - WatchCustomResources(ctx context.Context, options *metainternalversion.ListOptions) (watch.Interface, error) - GetCustomResource(ctx context.Context, customResourceID string, options *metav1.GetOptions) (*unstructured.Unstructured, error) - CreateCustomResource(ctx context.Context, customResource *unstructured.Unstructured, createValidation rest.ValidateObjectFunc) (*unstructured.Unstructured, error) - UpdateCustomResource(ctx context.Context, customResource *unstructured.Unstructured, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc, options *metav1.UpdateOptions) (*unstructured.Unstructured, error) - DeleteCustomResource(ctx context.Context, customResourceID 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) ListCustomResources(ctx context.Context, options *metainternalversion.ListOptions) (*unstructured.UnstructuredList, error) { - if options != nil && options.FieldSelector != nil && !options.FieldSelector.Empty() { - return nil, fmt.Errorf("field selector not supported yet") - } - obj, err := s.List(ctx, options) - if err != nil { - return nil, err - } - return obj.(*unstructured.UnstructuredList), err -} - -func (s *storage) WatchCustomResources(ctx context.Context, options *metainternalversion.ListOptions) (watch.Interface, error) { - return s.Watch(ctx, options) -} - -func (s *storage) GetCustomResource(ctx context.Context, customResourceID string, options *metav1.GetOptions) (*unstructured.Unstructured, error) { - obj, err := s.Get(ctx, customResourceID, options) - customResource, ok := obj.(*unstructured.Unstructured) - if !ok { - return nil, fmt.Errorf("custom resource must be of type Unstructured") - } - - if err != nil { - apiVersion := customResource.GetAPIVersion() - groupVersion := strings.Split(apiVersion, "/") - group := groupVersion[0] - return nil, errors.NewNotFound(schema.GroupResource{Group: group, Resource: "scale"}, customResourceID) - } - return customResource, nil -} - -func (s *storage) CreateCustomResource(ctx context.Context, customResource *unstructured.Unstructured, createValidation rest.ValidateObjectFunc) (*unstructured.Unstructured, error) { - obj, err := s.Create(ctx, customResource, rest.ValidateAllObjectFunc, &metav1.CreateOptions{}) - if err != nil { - return nil, err - } - return obj.(*unstructured.Unstructured), nil -} - -func (s *storage) UpdateCustomResource(ctx context.Context, customResource *unstructured.Unstructured, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc, options *metav1.UpdateOptions) (*unstructured.Unstructured, error) { - obj, _, err := s.Update(ctx, customResource.GetName(), rest.DefaultUpdatedObjectInfo(customResource), createValidation, updateValidation, false, options) - if err != nil { - return nil, err - } - return obj.(*unstructured.Unstructured), nil -} - -func (s *storage) DeleteCustomResource(ctx context.Context, customResourceID string) error { - _, _, err := s.Delete(ctx, customResourceID, nil) - return err -}