Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix the namespaceScoped of cachers #19970

Merged
merged 1 commit into from
Jan 30, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 10 additions & 1 deletion examples/apiserver/rest/reststorage.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ type REST struct {
func NewREST(s storage.Interface, storageDecorator generic.StorageDecorator) *REST {
prefix := "/testtype"
newListFunc := func() runtime.Object { return &testgroup.TestTypeList{} }
// Usually you should reuse your RESTCreateStrategy.
strategy := &NotNamespaceScoped{}
storageInterface := storageDecorator(
s, 100, &testgroup.TestType{}, prefix, false, newListFunc)
s, 100, &testgroup.TestType{}, prefix, strategy, newListFunc)
store := &etcdgeneric.Etcd{
NewFunc: func() runtime.Object { return &testgroup.TestType{} },
// NewListFunc returns an object capable of storing results of an etcd list.
Expand All @@ -63,3 +65,10 @@ func NewREST(s storage.Interface, storageDecorator generic.StorageDecorator) *RE
}
return &REST{store}
}

type NotNamespaceScoped struct {
}

func (*NotNamespaceScoped) NamespaceScoped() bool {
return false
}
6 changes: 6 additions & 0 deletions pkg/api/rest/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,9 @@ func objectMetaAndKind(typer runtime.ObjectTyper, obj runtime.Object) (*api.Obje
}
return objectMeta, kind, nil
}

// NamespaceScopedStrategy has a method to tell if the object must be in a namespace.
type NamespaceScopedStrategy interface {
// NamespaceScoped returns if the object must be in a namespace.
NamespaceScoped() bool
}
2 changes: 1 addition & 1 deletion pkg/registry/configmap/etcd/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func NewREST(s storage.Interface, storageDecorator generic.StorageDecorator) *RE

newListFunc := func() runtime.Object { return &api.ConfigMapList{} }
storageInterface := storageDecorator(
s, 100, &api.ConfigMap{}, prefix, false, newListFunc)
s, 100, &api.ConfigMap{}, prefix, configmap.Strategy, newListFunc)

store := &etcdgeneric.Etcd{
NewFunc: func() runtime.Object {
Expand Down
2 changes: 1 addition & 1 deletion pkg/registry/controller/etcd/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func NewREST(s storage.Interface, storageDecorator generic.StorageDecorator) (*R

newListFunc := func() runtime.Object { return &api.ReplicationControllerList{} }
storageInterface := storageDecorator(
s, 100, &api.ReplicationController{}, prefix, true, newListFunc)
s, 100, &api.ReplicationController{}, prefix, controller.Strategy, newListFunc)

store := &etcdgeneric.Etcd{
NewFunc: func() runtime.Object { return &api.ReplicationController{} },
Expand Down
2 changes: 1 addition & 1 deletion pkg/registry/daemonset/etcd/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func NewREST(s storage.Interface, storageDecorator generic.StorageDecorator) (*R

newListFunc := func() runtime.Object { return &extensions.DaemonSetList{} }
storageInterface := storageDecorator(
s, 100, &extensions.DaemonSet{}, prefix, false, newListFunc)
s, 100, &extensions.DaemonSet{}, prefix, daemonset.Strategy, newListFunc)

store := &etcdgeneric.Etcd{
NewFunc: func() runtime.Object { return &extensions.DaemonSet{} },
Expand Down
2 changes: 1 addition & 1 deletion pkg/registry/deployment/etcd/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func NewREST(s storage.Interface, storageDecorator generic.StorageDecorator) (*R

newListFunc := func() runtime.Object { return &extensions.DeploymentList{} }
storageInterface := storageDecorator(
s, 100, &extensions.Deployment{}, prefix, false, newListFunc)
s, 100, &extensions.Deployment{}, prefix, deployment.Strategy, newListFunc)

store := &etcdgeneric.Etcd{
NewFunc: func() runtime.Object { return &extensions.Deployment{} },
Expand Down
2 changes: 1 addition & 1 deletion pkg/registry/endpoint/etcd/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func NewREST(s storage.Interface, storageDecorator generic.StorageDecorator) *RE

newListFunc := func() runtime.Object { return &api.EndpointsList{} }
storageInterface := storageDecorator(
s, 1000, &api.Endpoints{}, prefix, true, newListFunc)
s, 1000, &api.Endpoints{}, prefix, endpoint.Strategy, newListFunc)

store := &etcdgeneric.Etcd{
NewFunc: func() runtime.Object { return &api.Endpoints{} },
Expand Down
5 changes: 3 additions & 2 deletions pkg/registry/generic/etcd/storage_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package etcd

import (
"k8s.io/kubernetes/pkg/api/rest"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/storage"
etcdstorage "k8s.io/kubernetes/pkg/storage/etcd"
Expand All @@ -28,9 +29,9 @@ func StorageWithCacher(
capacity int,
objectType runtime.Object,
resourcePrefix string,
namespaceScoped bool,
scopeStrategy rest.NamespaceScopedStrategy,
newListFunc func() runtime.Object) storage.Interface {
return storage.NewCacher(
storageInterface, capacity, etcdstorage.APIObjectVersioner{},
objectType, resourcePrefix, namespaceScoped, newListFunc)
objectType, resourcePrefix, scopeStrategy, newListFunc)
}
5 changes: 3 additions & 2 deletions pkg/registry/generic/storage_decorator.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package generic

import (
"k8s.io/kubernetes/pkg/api/rest"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/storage"
)
Expand All @@ -28,7 +29,7 @@ type StorageDecorator func(
capacity int,
objectType runtime.Object,
resourcePrefix string,
namespaceScoped bool,
scopeStrategy rest.NamespaceScopedStrategy,
newListFunc func() runtime.Object) storage.Interface

// Returns given 'storageInterface' without any decoration.
Expand All @@ -37,7 +38,7 @@ func UndecoratedStorage(
capacity int,
objectType runtime.Object,
resourcePrefix string,
namespaceScoped bool,
scopeStrategy rest.NamespaceScopedStrategy,
newListFunc func() runtime.Object) storage.Interface {
return storageInterface
}
2 changes: 1 addition & 1 deletion pkg/registry/horizontalpodautoscaler/etcd/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func NewREST(s storage.Interface, storageDecorator generic.StorageDecorator) (*R

newListFunc := func() runtime.Object { return &extensions.HorizontalPodAutoscalerList{} }
storageInterface := storageDecorator(
s, 100, &extensions.HorizontalPodAutoscaler{}, prefix, false, newListFunc)
s, 100, &extensions.HorizontalPodAutoscaler{}, prefix, horizontalpodautoscaler.Strategy, newListFunc)

store := &etcdgeneric.Etcd{
NewFunc: func() runtime.Object { return &extensions.HorizontalPodAutoscaler{} },
Expand Down
2 changes: 1 addition & 1 deletion pkg/registry/ingress/etcd/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func NewREST(s storage.Interface, storageDecorator generic.StorageDecorator) (*R

newListFunc := func() runtime.Object { return &extensions.IngressList{} }
storageInterface := storageDecorator(
s, 100, &extensions.Ingress{}, prefix, false, newListFunc)
s, 100, &extensions.Ingress{}, prefix, ingress.Strategy, newListFunc)

store := &etcdgeneric.Etcd{
NewFunc: func() runtime.Object { return &extensions.Ingress{} },
Expand Down
2 changes: 1 addition & 1 deletion pkg/registry/job/etcd/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func NewREST(s storage.Interface, storageDecorator generic.StorageDecorator) (*R

newListFunc := func() runtime.Object { return &extensions.JobList{} }
storageInterface := storageDecorator(
s, 100, &extensions.Job{}, prefix, false, newListFunc)
s, 100, &extensions.Job{}, prefix, job.Strategy, newListFunc)

store := &etcdgeneric.Etcd{
NewFunc: func() runtime.Object { return &extensions.Job{} },
Expand Down
2 changes: 1 addition & 1 deletion pkg/registry/limitrange/etcd/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func NewREST(s storage.Interface, storageDecorator generic.StorageDecorator) *RE

newListFunc := func() runtime.Object { return &api.LimitRangeList{} }
storageInterface := storageDecorator(
s, 100, &api.LimitRange{}, prefix, true, newListFunc)
s, 100, &api.LimitRange{}, prefix, limitrange.Strategy, newListFunc)

store := &etcdgeneric.Etcd{
NewFunc: func() runtime.Object { return &api.LimitRange{} },
Expand Down
2 changes: 1 addition & 1 deletion pkg/registry/namespace/etcd/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func NewREST(s storage.Interface, storageDecorator generic.StorageDecorator) (*R

newListFunc := func() runtime.Object { return &api.NamespaceList{} }
storageInterface := storageDecorator(
s, 100, &api.Namespace{}, prefix, true, newListFunc)
s, 100, &api.Namespace{}, prefix, namespace.Strategy, newListFunc)

store := &etcdgeneric.Etcd{
NewFunc: func() runtime.Object { return &api.Namespace{} },
Expand Down
2 changes: 1 addition & 1 deletion pkg/registry/node/etcd/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func NewREST(s storage.Interface, storageDecorator generic.StorageDecorator, con

newListFunc := func() runtime.Object { return &api.NodeList{} }
storageInterface := storageDecorator(
s, 1000, &api.Node{}, prefix, false, newListFunc)
s, 1000, &api.Node{}, prefix, node.Strategy, newListFunc)

store := &etcdgeneric.Etcd{
NewFunc: func() runtime.Object { return &api.Node{} },
Expand Down
2 changes: 1 addition & 1 deletion pkg/registry/persistentvolume/etcd/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func NewREST(s storage.Interface, storageDecorator generic.StorageDecorator) (*R

newListFunc := func() runtime.Object { return &api.PersistentVolumeList{} }
storageInterface := storageDecorator(
s, 100, &api.PersistentVolume{}, prefix, true, newListFunc)
s, 100, &api.PersistentVolume{}, prefix, persistentvolume.Strategy, newListFunc)

store := &etcdgeneric.Etcd{
NewFunc: func() runtime.Object { return &api.PersistentVolume{} },
Expand Down
2 changes: 1 addition & 1 deletion pkg/registry/persistentvolumeclaim/etcd/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func NewREST(s storage.Interface, storageDecorator generic.StorageDecorator) (*R

newListFunc := func() runtime.Object { return &api.PersistentVolumeClaimList{} }
storageInterface := storageDecorator(
s, 100, &api.PersistentVolumeClaim{}, prefix, true, newListFunc)
s, 100, &api.PersistentVolumeClaim{}, prefix, persistentvolumeclaim.Strategy, newListFunc)

store := &etcdgeneric.Etcd{
NewFunc: func() runtime.Object { return &api.PersistentVolumeClaim{} },
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 @@ -67,7 +67,7 @@ func NewStorage(

newListFunc := func() runtime.Object { return &api.PodList{} }
storageInterface := storageDecorator(
s, 1000, &api.Pod{}, prefix, true, newListFunc)
s, 1000, &api.Pod{}, prefix, pod.Strategy, newListFunc)

store := &etcdgeneric.Etcd{
NewFunc: func() runtime.Object { return &api.Pod{} },
Expand Down
2 changes: 1 addition & 1 deletion pkg/registry/podtemplate/etcd/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func NewREST(s storage.Interface, storageDecorator generic.StorageDecorator) *RE

newListFunc := func() runtime.Object { return &api.PodTemplateList{} }
storageInterface := storageDecorator(
s, 100, &api.PodTemplate{}, prefix, false, newListFunc)
s, 100, &api.PodTemplate{}, prefix, podtemplate.Strategy, newListFunc)

store := &etcdgeneric.Etcd{
NewFunc: func() runtime.Object { return &api.PodTemplate{} },
Expand Down
2 changes: 1 addition & 1 deletion pkg/registry/resourcequota/etcd/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func NewREST(s storage.Interface, storageDecorator generic.StorageDecorator) (*R

newListFunc := func() runtime.Object { return &api.ResourceQuotaList{} }
storageInterface := storageDecorator(
s, 100, &api.ResourceQuota{}, prefix, true, newListFunc)
s, 100, &api.ResourceQuota{}, prefix, resourcequota.Strategy, newListFunc)

store := &etcdgeneric.Etcd{
NewFunc: func() runtime.Object { return &api.ResourceQuota{} },
Expand Down
2 changes: 1 addition & 1 deletion pkg/registry/secret/etcd/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func NewREST(s storage.Interface, storageDecorator generic.StorageDecorator) *RE

newListFunc := func() runtime.Object { return &api.SecretList{} }
storageInterface := storageDecorator(
s, 100, &api.Secret{}, prefix, true, newListFunc)
s, 100, &api.Secret{}, prefix, secret.Strategy, newListFunc)

store := &etcdgeneric.Etcd{
NewFunc: func() runtime.Object { return &api.Secret{} },
Expand Down
2 changes: 1 addition & 1 deletion pkg/registry/service/etcd/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func NewREST(s storage.Interface, storageDecorator generic.StorageDecorator) *RE

newListFunc := func() runtime.Object { return &api.ServiceList{} }
storageInterface := storageDecorator(
s, 100, &api.Service{}, prefix, false, newListFunc)
s, 100, &api.Service{}, prefix, service.Strategy, newListFunc)

store := &etcdgeneric.Etcd{
NewFunc: func() runtime.Object { return &api.Service{} },
Expand Down
2 changes: 1 addition & 1 deletion pkg/registry/serviceaccount/etcd/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func NewREST(s storage.Interface, storageDecorator generic.StorageDecorator) *RE

newListFunc := func() runtime.Object { return &api.ServiceAccountList{} }
storageInterface := storageDecorator(
s, 100, &api.ServiceAccount{}, prefix, true, newListFunc)
s, 100, &api.ServiceAccount{}, prefix, serviceaccount.Strategy, newListFunc)

store := &etcdgeneric.Etcd{
NewFunc: func() runtime.Object { return &api.ServiceAccount{} },
Expand Down
5 changes: 3 additions & 2 deletions pkg/storage/cacher.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (

"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/meta"
"k8s.io/kubernetes/pkg/api/rest"
"k8s.io/kubernetes/pkg/client/cache"
"k8s.io/kubernetes/pkg/conversion"
"k8s.io/kubernetes/pkg/runtime"
Expand Down Expand Up @@ -115,7 +116,7 @@ func NewCacher(
versioner Versioner,
objectType runtime.Object,
resourcePrefix string,
namespaceScoped bool,
scopeStrategy rest.NamespaceScopedStrategy,
newListFunc func() runtime.Object) Interface {
config := CacherConfig{
CacheCapacity: capacity,
Expand All @@ -125,7 +126,7 @@ func NewCacher(
ResourcePrefix: resourcePrefix,
NewListFunc: newListFunc,
}
if namespaceScoped {
if scopeStrategy.NamespaceScoped() {
config.KeyFunc = func(obj runtime.Object) (string, error) {
return NamespaceKeyFunc(resourcePrefix, obj)
}
Expand Down