2015-03-26 19:50:36 +00:00
|
|
|
/*
|
2015-05-01 16:19:44 +00:00
|
|
|
Copyright 2015 The Kubernetes Authors All rights reserved.
|
2015-03-26 19:50:36 +00:00
|
|
|
|
|
|
|
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 etcd
|
|
|
|
|
|
|
|
import (
|
2015-08-05 22:03:47 +00:00
|
|
|
"k8s.io/kubernetes/pkg/api"
|
|
|
|
"k8s.io/kubernetes/pkg/fields"
|
|
|
|
"k8s.io/kubernetes/pkg/labels"
|
2016-02-05 07:47:27 +00:00
|
|
|
"k8s.io/kubernetes/pkg/registry/cachesize"
|
2015-08-05 22:03:47 +00:00
|
|
|
"k8s.io/kubernetes/pkg/registry/generic"
|
|
|
|
etcdgeneric "k8s.io/kubernetes/pkg/registry/generic/etcd"
|
|
|
|
"k8s.io/kubernetes/pkg/registry/persistentvolume"
|
|
|
|
"k8s.io/kubernetes/pkg/runtime"
|
2015-03-26 19:50:36 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type REST struct {
|
|
|
|
*etcdgeneric.Etcd
|
|
|
|
}
|
|
|
|
|
2015-08-20 09:17:04 +00:00
|
|
|
// NewREST returns a RESTStorage object that will work against persistent volumes.
|
2016-02-22 09:15:22 +00:00
|
|
|
func NewREST(opts generic.RESTOptions) (*REST, *StatusREST) {
|
2015-03-11 17:10:09 +00:00
|
|
|
prefix := "/persistentvolumes"
|
2015-10-29 09:51:32 +00:00
|
|
|
|
|
|
|
newListFunc := func() runtime.Object { return &api.PersistentVolumeList{} }
|
2016-02-22 09:15:22 +00:00
|
|
|
storageInterface := opts.Decorator(
|
|
|
|
opts.Storage, cachesize.GetWatchCacheSizeByResource(cachesize.PersistentVolumes), &api.PersistentVolume{}, prefix, persistentvolume.Strategy, newListFunc)
|
2015-10-29 09:51:32 +00:00
|
|
|
|
2015-03-26 19:50:36 +00:00
|
|
|
store := &etcdgeneric.Etcd{
|
|
|
|
NewFunc: func() runtime.Object { return &api.PersistentVolume{} },
|
2015-10-29 09:51:32 +00:00
|
|
|
NewListFunc: newListFunc,
|
2015-03-26 19:50:36 +00:00
|
|
|
KeyRootFunc: func(ctx api.Context) string {
|
|
|
|
return prefix
|
|
|
|
},
|
|
|
|
KeyFunc: func(ctx api.Context, name string) (string, error) {
|
2015-10-20 21:36:45 +00:00
|
|
|
return etcdgeneric.NoNamespaceKeyFunc(ctx, prefix, name)
|
2015-03-26 19:50:36 +00:00
|
|
|
},
|
|
|
|
ObjectNameFunc: func(obj runtime.Object) (string, error) {
|
|
|
|
return obj.(*api.PersistentVolume).Name, nil
|
|
|
|
},
|
|
|
|
PredicateFunc: func(label labels.Selector, field fields.Selector) generic.Matcher {
|
|
|
|
return persistentvolume.MatchPersistentVolumes(label, field)
|
|
|
|
},
|
2016-02-18 13:50:43 +00:00
|
|
|
QualifiedResource: api.Resource("persistentvolumes"),
|
|
|
|
DeleteCollectionWorkers: opts.DeleteCollectionWorkers,
|
2015-03-26 19:50:36 +00:00
|
|
|
|
2015-08-20 09:17:04 +00:00
|
|
|
CreateStrategy: persistentvolume.Strategy,
|
|
|
|
UpdateStrategy: persistentvolume.Strategy,
|
2016-03-21 06:15:00 +00:00
|
|
|
DeleteStrategy: persistentvolume.Strategy,
|
2015-08-20 09:17:04 +00:00
|
|
|
ReturnDeletedObject: true,
|
|
|
|
|
2015-10-29 09:51:32 +00:00
|
|
|
Storage: storageInterface,
|
2015-03-26 19:50:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
statusStore := *store
|
|
|
|
statusStore.UpdateStrategy = persistentvolume.StatusStrategy
|
|
|
|
|
|
|
|
return &REST{store}, &StatusREST{store: &statusStore}
|
|
|
|
}
|
|
|
|
|
|
|
|
// StatusREST implements the REST endpoint for changing the status of a persistentvolume.
|
|
|
|
type StatusREST struct {
|
|
|
|
store *etcdgeneric.Etcd
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *StatusREST) New() runtime.Object {
|
|
|
|
return &api.PersistentVolume{}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update alters the status subset of an object.
|
|
|
|
func (r *StatusREST) Update(ctx api.Context, obj runtime.Object) (runtime.Object, bool, error) {
|
|
|
|
return r.store.Update(ctx, obj)
|
|
|
|
}
|