| 1 |
/* |
| 2 |
Copyright 2016 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 |
"time" |
| 21 |
|
| 22 |
"k8s.io/apimachinery/pkg/runtime" |
| 23 |
"k8s.io/apimachinery/pkg/runtime/schema" |
| 24 |
"k8s.io/apiserver/pkg/storage" |
| 25 |
"k8s.io/apiserver/pkg/storage/storagebackend" |
| 26 |
flowcontrolrequest "k8s.io/apiserver/pkg/util/flowcontrol/request" |
| 27 |
"k8s.io/client-go/tools/cache" |
| 28 |
) |
| 29 |
|
| 30 |
// RESTOptions is set of resource-specific configuration options to generic registries. |
| 31 |
type RESTOptions struct { |
| 32 |
StorageConfig *storagebackend.ConfigForResource |
| 33 |
Decorator StorageDecorator |
| 34 |
|
| 35 |
EnableGarbageCollection bool |
| 36 |
DeleteCollectionWorkers int |
| 37 |
ResourcePrefix string |
| 38 |
CountMetricPollPeriod time.Duration |
| 39 |
StorageObjectCountTracker flowcontrolrequest.StorageObjectCountTracker |
| 40 |
} |
| 41 |
|
| 42 |
// Implement RESTOptionsGetter so that RESTOptions can directly be used when available (i.e. tests) |
| 43 |
func (opts RESTOptions) GetRESTOptions(schema.GroupResource, runtime.Object) (RESTOptions, error) { |
| 44 |
return opts, nil |
| 45 |
} |
| 46 |
|
| 47 |
type RESTOptionsGetter interface { |
| 48 |
// GetRESTOptions returns the RESTOptions for the given resource and example object. |
| 49 |
// The example object is used to determine the storage version for the resource. |
| 50 |
// If the example object is nil, the storage version will be determined by the resource's default storage version. |
| 51 |
GetRESTOptions(resource schema.GroupResource, example runtime.Object) (RESTOptions, error) |
| 52 |
} |
| 53 |
|
| 54 |
// StoreOptions is set of configuration options used to complete generic registries. |
| 55 |
type StoreOptions struct { |
| 56 |
RESTOptions RESTOptionsGetter |
| 57 |
TriggerFunc storage.IndexerFuncs |
| 58 |
AttrFunc storage.AttrFunc |
| 59 |
Indexers *cache.Indexers |
| 60 |
} |