k8s.io/apiserver@v0.31.1/pkg/registry/generic/storage_decorator.go (about)

     1  /*
     2  Copyright 2015 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package generic
    18  
    19  import (
    20  	"k8s.io/apimachinery/pkg/runtime"
    21  	"k8s.io/apiserver/pkg/storage"
    22  	"k8s.io/apiserver/pkg/storage/storagebackend"
    23  	"k8s.io/apiserver/pkg/storage/storagebackend/factory"
    24  	"k8s.io/client-go/tools/cache"
    25  )
    26  
    27  // StorageDecorator is a function signature for producing a storage.Interface
    28  // and an associated DestroyFunc from given parameters.
    29  type StorageDecorator func(
    30  	config *storagebackend.ConfigForResource,
    31  	resourcePrefix string,
    32  	keyFunc func(obj runtime.Object) (string, error),
    33  	newFunc func() runtime.Object,
    34  	newListFunc func() runtime.Object,
    35  	getAttrsFunc storage.AttrFunc,
    36  	trigger storage.IndexerFuncs,
    37  	indexers *cache.Indexers) (storage.Interface, factory.DestroyFunc, error)
    38  
    39  // UndecoratedStorage returns the given a new storage from the given config
    40  // without any decoration.
    41  func UndecoratedStorage(
    42  	config *storagebackend.ConfigForResource,
    43  	resourcePrefix string,
    44  	keyFunc func(obj runtime.Object) (string, error),
    45  	newFunc func() runtime.Object,
    46  	newListFunc func() runtime.Object,
    47  	getAttrsFunc storage.AttrFunc,
    48  	trigger storage.IndexerFuncs,
    49  	indexers *cache.Indexers) (storage.Interface, factory.DestroyFunc, error) {
    50  	return NewRawStorage(config, newFunc, newListFunc, resourcePrefix)
    51  }
    52  
    53  // NewRawStorage creates the low level kv storage. This is a work-around for current
    54  // two layer of same storage interface.
    55  // TODO: Once cacher is enabled on all registries (event registry is special), we will remove this method.
    56  func NewRawStorage(config *storagebackend.ConfigForResource, newFunc, newListFunc func() runtime.Object, resourcePrefix string) (storage.Interface, factory.DestroyFunc, error) {
    57  	return factory.Create(*config, newFunc, newListFunc, resourcePrefix)
    58  }