k3s/pkg/registry/extensions/thirdpartyresourcedata/storage/storage.go

79 lines
2.7 KiB
Go
Raw Normal View History

2015-08-19 18:02:01 +00:00
/*
Copyright 2015 The Kubernetes Authors.
2015-08-19 18:02:01 +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 storage
2015-08-19 18:02:01 +00:00
import (
2015-08-21 21:24:16 +00:00
"strings"
2017-01-11 14:09:48 +00:00
"k8s.io/apimachinery/pkg/runtime"
2017-01-26 20:16:25 +00:00
"k8s.io/kubernetes/pkg/api"
2015-10-09 22:04:41 +00:00
"k8s.io/kubernetes/pkg/apis/extensions"
2017-01-17 10:38:25 +00:00
"k8s.io/kubernetes/pkg/genericapiserver/registry/generic"
genericregistry "k8s.io/kubernetes/pkg/genericapiserver/registry/generic/registry"
"k8s.io/kubernetes/pkg/registry/cachesize"
2016-09-21 13:06:56 +00:00
"k8s.io/kubernetes/pkg/registry/extensions/thirdpartyresourcedata"
2015-08-19 18:02:01 +00:00
)
// REST implements a RESTStorage for ThirdPartyResourceData
2015-08-19 18:02:01 +00:00
type REST struct {
*genericregistry.Store
2015-12-22 18:57:12 +00:00
kind string
2015-08-19 18:02:01 +00:00
}
// NewREST returns a registry which will store ThirdPartyResourceData in the given helper
func NewREST(optsGetter generic.RESTOptionsGetter, group, kind string) *REST {
resource := extensions.Resource("thirdpartyresourcedatas")
opts, err := optsGetter.GetRESTOptions(resource)
if err != nil {
panic(err) // TODO: Propagate error up
}
2015-08-19 18:02:01 +00:00
2015-10-29 09:51:32 +00:00
// We explicitly do NOT do any decoration here yet.
opts.Decorator = generic.UndecoratedStorage // TODO use watchCacheSize=-1 to signal UndecoratedStorage
opts.ResourcePrefix = "/ThirdPartyResourceData/" + group + "/" + strings.ToLower(kind) + "s"
2015-10-29 09:51:32 +00:00
store := &genericregistry.Store{
2017-01-26 20:16:25 +00:00
Copier: api.Scheme,
2015-10-09 22:49:10 +00:00
NewFunc: func() runtime.Object { return &extensions.ThirdPartyResourceData{} },
NewListFunc: func() runtime.Object { return &extensions.ThirdPartyResourceDataList{} },
2015-08-19 18:02:01 +00:00
ObjectNameFunc: func(obj runtime.Object) (string, error) {
2015-10-09 22:49:10 +00:00
return obj.(*extensions.ThirdPartyResourceData).Name, nil
2015-08-19 18:02:01 +00:00
},
PredicateFunc: thirdpartyresourcedata.Matcher,
QualifiedResource: resource,
WatchCacheSize: cachesize.GetWatchCacheSizeByResource(resource.Resource),
2015-08-19 18:02:01 +00:00
CreateStrategy: thirdpartyresourcedata.Strategy,
UpdateStrategy: thirdpartyresourcedata.Strategy,
DeleteStrategy: thirdpartyresourcedata.Strategy,
}
options := &generic.StoreOptions{RESTOptions: opts, AttrFunc: thirdpartyresourcedata.GetAttrs} // Pass in opts to use UndecoratedStorage and custom ResourcePrefix
if err := store.CompleteWithOptions(options); err != nil {
panic(err) // TODO: Propagate error up
2015-08-19 18:02:01 +00:00
}
2015-12-22 18:57:12 +00:00
return &REST{
Store: store,
kind: kind,
2015-12-22 18:57:12 +00:00
}
}
// Implements the rest.KindProvider interface
func (r *REST) Kind() string {
return r.kind
2015-08-19 18:02:01 +00:00
}