本文整理汇总了Golang中k8s/io/kubernetes/pkg/registry/generic/registry.NamespaceKeyRootFunc函数的典型用法代码示例。如果您正苦于以下问题:Golang NamespaceKeyRootFunc函数的具体用法?Golang NamespaceKeyRootFunc怎么用?Golang NamespaceKeyRootFunc使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NamespaceKeyRootFunc函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: DefaultKeyFunctions
// DefaultKeyFunctions sets the default behavior for storage key generation onto a Store.
func DefaultKeyFunctions(store *registry.Store, prefix string, isNamespaced bool) {
if isNamespaced {
if store.KeyRootFunc == nil {
store.KeyRootFunc = func(ctx kapi.Context) string {
return registry.NamespaceKeyRootFunc(ctx, prefix)
}
}
if store.KeyFunc == nil {
store.KeyFunc = func(ctx kapi.Context, name string) (string, error) {
return registry.NamespaceKeyFunc(ctx, prefix, name)
}
}
} else {
if store.KeyRootFunc == nil {
store.KeyRootFunc = func(ctx kapi.Context) string {
return prefix
}
}
if store.KeyFunc == nil {
store.KeyFunc = func(ctx kapi.Context, name string) (string, error) {
return registry.NoNamespaceKeyFunc(ctx, prefix, name)
}
}
}
}
示例2: NewREST
// NewREST returns a RESTStorage object that will work against services.
func NewREST(opts generic.RESTOptions) (*REST, *StatusREST) {
prefix := "/services/specs"
newListFunc := func() runtime.Object { return &api.ServiceList{} }
storageInterface := opts.Decorator(
opts.Storage, cachesize.GetWatchCacheSizeByResource(cachesize.Services), &api.Service{}, prefix, service.Strategy, newListFunc)
store := ®istry.Store{
NewFunc: func() runtime.Object { return &api.Service{} },
NewListFunc: newListFunc,
KeyRootFunc: func(ctx api.Context) string {
return registry.NamespaceKeyRootFunc(ctx, prefix)
},
KeyFunc: func(ctx api.Context, name string) (string, error) {
return registry.NamespaceKeyFunc(ctx, prefix, name)
},
ObjectNameFunc: func(obj runtime.Object) (string, error) {
return obj.(*api.Service).Name, nil
},
PredicateFunc: service.MatchServices,
QualifiedResource: api.Resource("services"),
DeleteCollectionWorkers: opts.DeleteCollectionWorkers,
CreateStrategy: service.Strategy,
UpdateStrategy: service.Strategy,
DeleteStrategy: service.Strategy,
ExportStrategy: service.Strategy,
Storage: storageInterface,
}
statusStore := *store
statusStore.UpdateStrategy = service.StatusStrategy
return &REST{store}, &StatusREST{store: &statusStore}
}
示例3: NewREST
// NewREST returns a RESTStorage object that will work against templates.
func NewREST(optsGetter restoptions.Getter) (*REST, error) {
prefix := "/templates"
store := ®istry.Store{
NewFunc: func() runtime.Object { return &api.Template{} },
NewListFunc: func() runtime.Object { return &api.TemplateList{} },
KeyRootFunc: func(ctx kapi.Context) string {
return registry.NamespaceKeyRootFunc(ctx, prefix)
},
KeyFunc: func(ctx kapi.Context, name string) (string, error) {
return registry.NamespaceKeyFunc(ctx, prefix, name)
},
ObjectNameFunc: func(obj runtime.Object) (string, error) {
return obj.(*api.Template).Name, nil
},
PredicateFunc: func(label labels.Selector, field fields.Selector) generic.Matcher {
return tregistry.Matcher(label, field)
},
QualifiedResource: api.Resource("templates"),
CreateStrategy: tregistry.Strategy,
UpdateStrategy: tregistry.Strategy,
ReturnDeletedObject: true,
}
if err := restoptions.ApplyOptions(optsGetter, store, prefix); err != nil {
return nil, err
}
return &REST{store}, nil
}
示例4: NewREST
// NewREST returns a registry which will store ThirdPartyResourceData in the given helper
func NewREST(opts generic.RESTOptions, group, kind string) *REST {
prefix := "/ThirdPartyResourceData/" + group + "/" + strings.ToLower(kind) + "s"
// We explicitly do NOT do any decoration here yet.
storageInterface, dFunc := generic.NewRawStorage(opts.StorageConfig)
store := ®istry.Store{
NewFunc: func() runtime.Object { return &extensions.ThirdPartyResourceData{} },
NewListFunc: func() runtime.Object { return &extensions.ThirdPartyResourceDataList{} },
KeyRootFunc: func(ctx api.Context) string {
return registry.NamespaceKeyRootFunc(ctx, prefix)
},
KeyFunc: func(ctx api.Context, id string) (string, error) {
return registry.NamespaceKeyFunc(ctx, prefix, id)
},
ObjectNameFunc: func(obj runtime.Object) (string, error) {
return obj.(*extensions.ThirdPartyResourceData).Name, nil
},
PredicateFunc: thirdpartyresourcedata.Matcher,
QualifiedResource: extensions.Resource("thirdpartyresourcedatas"),
DeleteCollectionWorkers: opts.DeleteCollectionWorkers,
CreateStrategy: thirdpartyresourcedata.Strategy,
UpdateStrategy: thirdpartyresourcedata.Strategy,
DeleteStrategy: thirdpartyresourcedata.Strategy,
Storage: storageInterface,
DestroyFunc: dFunc,
}
return &REST{
Store: store,
kind: kind,
}
}
示例5: NewREST
// NewREST returns a RESTStorage object that will work against egress network policy
func NewREST(optsGetter restoptions.Getter) (*REST, error) {
store := ®istry.Store{
NewFunc: func() runtime.Object { return &api.EgressNetworkPolicy{} },
NewListFunc: func() runtime.Object { return &api.EgressNetworkPolicyList{} },
KeyRootFunc: func(ctx kapi.Context) string {
return registry.NamespaceKeyRootFunc(ctx, etcdPrefix)
},
KeyFunc: func(ctx kapi.Context, name string) (string, error) {
return registry.NamespaceKeyFunc(ctx, etcdPrefix, name)
},
ObjectNameFunc: func(obj runtime.Object) (string, error) {
return obj.(*api.EgressNetworkPolicy).Name, nil
},
PredicateFunc: func(label labels.Selector, field fields.Selector) generic.Matcher {
return egressnetworkpolicy.Matcher(label, field)
},
QualifiedResource: api.Resource("egressnetworkpolicies"),
CreateStrategy: egressnetworkpolicy.Strategy,
UpdateStrategy: egressnetworkpolicy.Strategy,
}
if err := restoptions.ApplyOptions(optsGetter, store, etcdPrefix); err != nil {
return nil, err
}
return &REST{*store}, nil
}
示例6: NewREST
// NewREST returns a RESTStorage object that will work against events.
func NewREST(opts generic.RESTOptions, ttl uint64) *REST {
prefix := "/" + opts.ResourcePrefix
// We explicitly do NOT do any decoration here - switching on Cacher
// for events will lead to too high memory consumption.
storageInterface, dFunc := generic.NewRawStorage(opts.StorageConfig)
store := ®istry.Store{
NewFunc: func() runtime.Object { return &api.Event{} },
NewListFunc: func() runtime.Object { return &api.EventList{} },
KeyRootFunc: func(ctx api.Context) string {
return registry.NamespaceKeyRootFunc(ctx, prefix)
},
KeyFunc: func(ctx api.Context, id string) (string, error) {
return registry.NamespaceKeyFunc(ctx, prefix, id)
},
ObjectNameFunc: func(obj runtime.Object) (string, error) {
return obj.(*api.Event).Name, nil
},
PredicateFunc: event.MatchEvent,
TTLFunc: func(runtime.Object, uint64, bool) (uint64, error) {
return ttl, nil
},
QualifiedResource: api.Resource("events"),
DeleteCollectionWorkers: opts.DeleteCollectionWorkers,
CreateStrategy: event.Strategy,
UpdateStrategy: event.Strategy,
DeleteStrategy: event.Strategy,
Storage: storageInterface,
DestroyFunc: dFunc,
}
return &REST{store}
}
示例7: NewREST
// NewREST returns a registry which will store ThirdPartyResource in the given helper
func NewREST(opts generic.RESTOptions) *REST {
prefix := "/thirdpartyresources"
// We explicitly do NOT do any decoration here yet.
storageInterface := opts.Storage
store := ®istry.Store{
NewFunc: func() runtime.Object { return &extensions.ThirdPartyResource{} },
NewListFunc: func() runtime.Object { return &extensions.ThirdPartyResourceList{} },
KeyRootFunc: func(ctx api.Context) string {
return registry.NamespaceKeyRootFunc(ctx, prefix)
},
KeyFunc: func(ctx api.Context, id string) (string, error) {
return registry.NamespaceKeyFunc(ctx, prefix, id)
},
ObjectNameFunc: func(obj runtime.Object) (string, error) {
return obj.(*extensions.ThirdPartyResource).Name, nil
},
PredicateFunc: func(label labels.Selector, field fields.Selector) generic.Matcher {
return thirdpartyresource.Matcher(label, field)
},
QualifiedResource: extensions.Resource("thirdpartyresources"),
DeleteCollectionWorkers: opts.DeleteCollectionWorkers,
CreateStrategy: thirdpartyresource.Strategy,
UpdateStrategy: thirdpartyresource.Strategy,
DeleteStrategy: thirdpartyresource.Strategy,
Storage: storageInterface,
}
return &REST{store}
}
示例8: NewREST
// NewStorage returns a RESTStorage object that will work against Build objects.
func NewREST(optsGetter restoptions.Getter) (*REST, *DetailsREST, error) {
prefix := "/builds"
store := ®istry.Store{
NewFunc: func() runtime.Object { return &api.Build{} },
NewListFunc: func() runtime.Object { return &api.BuildList{} },
QualifiedResource: api.Resource("builds"),
KeyRootFunc: func(ctx kapi.Context) string {
return registry.NamespaceKeyRootFunc(ctx, prefix)
},
KeyFunc: func(ctx kapi.Context, id string) (string, error) {
return registry.NamespaceKeyFunc(ctx, prefix, id)
},
ObjectNameFunc: func(obj runtime.Object) (string, error) {
return obj.(*api.Build).Name, nil
},
PredicateFunc: func(label labels.Selector, field fields.Selector) generic.Matcher {
return build.Matcher(label, field)
},
CreateStrategy: build.Strategy,
UpdateStrategy: build.Strategy,
DeleteStrategy: build.Strategy,
Decorator: build.Decorator,
ReturnDeletedObject: false,
}
if err := restoptions.ApplyOptions(optsGetter, store, prefix); err != nil {
return nil, nil, err
}
detailsStore := *store
detailsStore.UpdateStrategy = build.DetailsStrategy
return &REST{store}, &DetailsREST{&detailsStore}, nil
}
示例9: NewREST
// NewREST returns a RESTStorage object that will work against routes.
func NewREST(optsGetter restoptions.Getter, allocator route.RouteAllocator) (*REST, *StatusREST, error) {
strategy := rest.NewStrategy(allocator)
prefix := "/routes"
store := ®istry.Store{
NewFunc: func() runtime.Object { return &api.Route{} },
NewListFunc: func() runtime.Object { return &api.RouteList{} },
KeyRootFunc: func(ctx kapi.Context) string {
return registry.NamespaceKeyRootFunc(ctx, prefix)
},
KeyFunc: func(ctx kapi.Context, id string) (string, error) {
return registry.NamespaceKeyFunc(ctx, prefix, id)
},
ObjectNameFunc: func(obj runtime.Object) (string, error) {
return obj.(*api.Route).Name, nil
},
PredicateFunc: func(label labels.Selector, field fields.Selector) generic.Matcher {
return rest.Matcher(label, field)
},
QualifiedResource: api.Resource("routes"),
CreateStrategy: strategy,
UpdateStrategy: strategy,
}
if err := restoptions.ApplyOptions(optsGetter, store, prefix); err != nil {
return nil, nil, err
}
statusStore := *store
statusStore.UpdateStrategy = rest.StatusStrategy
return &REST{store}, &StatusREST{&statusStore}, nil
}
示例10: NewREST
// NewREST returns a RESTStorage object that will work against horizontal pod autoscalers.
func NewREST(opts generic.RESTOptions) *REST {
prefix := "/limitranges"
newListFunc := func() runtime.Object { return &api.LimitRangeList{} }
storageInterface := opts.Decorator(
opts.Storage, cachesize.GetWatchCacheSizeByResource(cachesize.LimitRanges), &api.LimitRange{}, prefix, limitrange.Strategy, newListFunc)
store := ®istry.Store{
NewFunc: func() runtime.Object { return &api.LimitRange{} },
NewListFunc: newListFunc,
KeyRootFunc: func(ctx api.Context) string {
return registry.NamespaceKeyRootFunc(ctx, prefix)
},
KeyFunc: func(ctx api.Context, id string) (string, error) {
return registry.NamespaceKeyFunc(ctx, prefix, id)
},
ObjectNameFunc: func(obj runtime.Object) (string, error) {
return obj.(*api.LimitRange).Name, nil
},
PredicateFunc: func(label labels.Selector, field fields.Selector) generic.Matcher {
return limitrange.MatchLimitRange(label, field)
},
QualifiedResource: api.Resource("limitranges"),
DeleteCollectionWorkers: opts.DeleteCollectionWorkers,
CreateStrategy: limitrange.Strategy,
UpdateStrategy: limitrange.Strategy,
DeleteStrategy: limitrange.Strategy,
ExportStrategy: limitrange.Strategy,
Storage: storageInterface,
}
return &REST{store}
}
示例11: NewREST
// NewREST returns a RESTStorage object that will work with testtype.
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, strategy, newListFunc)
store := ®istry.Store{
NewFunc: func() runtime.Object { return &testgroup.TestType{} },
// NewListFunc returns an object capable of storing results of an etcd list.
NewListFunc: newListFunc,
// Produces a path that etcd understands, to the root of the resource
// by combining the namespace in the context with the given prefix.
KeyRootFunc: func(ctx api.Context) string {
return registry.NamespaceKeyRootFunc(ctx, prefix)
},
// Produces a path that etcd understands, to the resource by combining
// the namespace in the context with the given prefix.
KeyFunc: func(ctx api.Context, name string) (string, error) {
return registry.NamespaceKeyFunc(ctx, prefix, name)
},
// Retrieve the name field of the resource.
ObjectNameFunc: func(obj runtime.Object) (string, error) {
return obj.(*testgroup.TestType).Name, nil
},
// Used to match objects based on labels/fields for list.
PredicateFunc: func(label labels.Selector, field fields.Selector) generic.Matcher {
return generic.MatcherFunc(nil)
},
Storage: storageInterface,
}
return &REST{store}
}
示例12: NewREST
// NewREST returns a RESTStorage object that will work against service accounts.
func NewREST(opts generic.RESTOptions) *REST {
prefix := "/serviceaccounts"
newListFunc := func() runtime.Object { return &api.ServiceAccountList{} }
storageInterface := opts.Decorator(
opts.Storage, cachesize.GetWatchCacheSizeByResource(cachesize.ServiceAccounts), &api.ServiceAccount{}, prefix, serviceaccount.Strategy, newListFunc)
store := ®istry.Store{
NewFunc: func() runtime.Object { return &api.ServiceAccount{} },
NewListFunc: newListFunc,
KeyRootFunc: func(ctx api.Context) string {
return registry.NamespaceKeyRootFunc(ctx, prefix)
},
KeyFunc: func(ctx api.Context, name string) (string, error) {
return registry.NamespaceKeyFunc(ctx, prefix, name)
},
ObjectNameFunc: func(obj runtime.Object) (string, error) {
return obj.(*api.ServiceAccount).Name, nil
},
PredicateFunc: serviceaccount.Matcher,
QualifiedResource: api.Resource("serviceaccounts"),
DeleteCollectionWorkers: opts.DeleteCollectionWorkers,
CreateStrategy: serviceaccount.Strategy,
UpdateStrategy: serviceaccount.Strategy,
DeleteStrategy: serviceaccount.Strategy,
ReturnDeletedObject: true,
Storage: storageInterface,
}
return &REST{store}
}
示例13: NewREST
// NewREST returns a RESTStorage object that will work against endpoints.
func NewREST(opts generic.RESTOptions) *REST {
prefix := "/services/endpoints"
newListFunc := func() runtime.Object { return &api.EndpointsList{} }
storageInterface := opts.Decorator(
opts.Storage, cachesize.GetWatchCacheSizeByResource(cachesize.Endpoints), &api.Endpoints{}, prefix, endpoint.Strategy, newListFunc)
store := ®istry.Store{
NewFunc: func() runtime.Object { return &api.Endpoints{} },
NewListFunc: newListFunc,
KeyRootFunc: func(ctx api.Context) string {
return registry.NamespaceKeyRootFunc(ctx, prefix)
},
KeyFunc: func(ctx api.Context, name string) (string, error) {
return registry.NamespaceKeyFunc(ctx, prefix, name)
},
ObjectNameFunc: func(obj runtime.Object) (string, error) {
return obj.(*api.Endpoints).Name, nil
},
PredicateFunc: func(label labels.Selector, field fields.Selector) generic.Matcher {
return endpoint.MatchEndpoints(label, field)
},
QualifiedResource: api.Resource("endpoints"),
DeleteCollectionWorkers: opts.DeleteCollectionWorkers,
CreateStrategy: endpoint.Strategy,
UpdateStrategy: endpoint.Strategy,
DeleteStrategy: endpoint.Strategy,
Storage: storageInterface,
}
return &REST{store}
}
示例14: NewStorage
// NewStorage returns a RESTStorage object that will work against nodes.
func NewStorage(optsGetter restoptions.Getter) (*REST, error) {
store := ®istry.Store{
NewFunc: func() runtime.Object { return &authorizationapi.Policy{} },
NewListFunc: func() runtime.Object { return &authorizationapi.PolicyList{} },
QualifiedResource: authorizationapi.Resource("policies"),
KeyRootFunc: func(ctx kapi.Context) string {
return registry.NamespaceKeyRootFunc(ctx, PolicyPath)
},
KeyFunc: func(ctx kapi.Context, id string) (string, error) {
return registry.NamespaceKeyFunc(ctx, PolicyPath, id)
},
ObjectNameFunc: func(obj runtime.Object) (string, error) {
return obj.(*authorizationapi.Policy).Name, nil
},
PredicateFunc: func(label labels.Selector, field fields.Selector) generic.Matcher {
return policy.Matcher(label, field)
},
CreateStrategy: policy.Strategy,
UpdateStrategy: policy.Strategy,
}
if err := restoptions.ApplyOptions(optsGetter, store, PolicyPath); err != nil {
return nil, err
}
return &REST{store}, nil
}
示例15: NewREST
// NewREST returns a new REST.
func NewREST(optsGetter restoptions.Getter, defaultRegistry api.DefaultRegistry, subjectAccessReviewRegistry subjectaccessreview.Registry, limitVerifier imageadmission.LimitVerifier) (*REST, *StatusREST, *InternalREST, error) {
prefix := "/imagestreams"
store := registry.Store{
NewFunc: func() runtime.Object { return &api.ImageStream{} },
// NewListFunc returns an object capable of storing results of an etcd list.
NewListFunc: func() runtime.Object { return &api.ImageStreamList{} },
// Produces a path that etcd understands, to the root of the resource
// by combining the namespace in the context with the given prefix.
KeyRootFunc: func(ctx kapi.Context) string {
return registry.NamespaceKeyRootFunc(ctx, prefix)
},
// Produces a path that etcd understands, to the resource by combining
// the namespace in the context with the given prefix
KeyFunc: func(ctx kapi.Context, name string) (string, error) {
return registry.NamespaceKeyFunc(ctx, prefix, name)
},
// Retrieve the name field of an image
ObjectNameFunc: func(obj runtime.Object) (string, error) {
return obj.(*api.ImageStream).Name, nil
},
// Used to match objects based on labels/fields for list and watch
PredicateFunc: func(label labels.Selector, field fields.Selector) generic.Matcher {
return imagestream.MatchImageStream(label, field)
},
QualifiedResource: api.Resource("imagestreams"),
ReturnDeletedObject: false,
}
strategy := imagestream.NewStrategy(defaultRegistry, subjectAccessReviewRegistry, limitVerifier)
rest := &REST{Store: &store, subjectAccessReviewRegistry: subjectAccessReviewRegistry}
strategy.ImageStreamGetter = rest
store.CreateStrategy = strategy
store.UpdateStrategy = strategy
store.Decorator = strategy.Decorate
if err := restoptions.ApplyOptions(optsGetter, &store, prefix); err != nil {
return nil, nil, nil, err
}
statusStore := store
statusStore.Decorator = nil
statusStore.CreateStrategy = nil
statusStore.UpdateStrategy = imagestream.NewStatusStrategy(strategy)
internalStore := store
internalStrategy := imagestream.NewInternalStrategy(strategy)
internalStore.Decorator = nil
internalStore.CreateStrategy = internalStrategy
internalStore.UpdateStrategy = internalStrategy
return rest, &StatusREST{store: &statusStore}, &InternalREST{store: &internalStore}, nil
}